WIP modbus write

This commit is contained in:
Duke NUCem 2021-10-10 12:12:39 +02:00
parent 051509155e
commit e2f8ab3405
3 changed files with 8 additions and 5 deletions

View File

@ -108,7 +108,7 @@ uint16_t sps30_measured_data[10];
/* Struct to store the sensor config */
config_t sensor_config;
uint8_t sensor_config_pending_write = 0;
uint8_t baudrate_changed = 0;
/* USER CODE END PV */
@ -255,7 +255,10 @@ int main(void)
/* Reset the RX DONE flag */
lpuart1_rx_done = 0;
}
/* if config changed (MODBUS write), reflect changes to EEPROM */
if (sensor_config_pending_write) {
// config_write(&sensor_config);
}
if (baudrate_changed == 1)
{
/* TODO: TEST */
@ -717,7 +720,7 @@ int8_t modbus_slave_callback(modbus_transaction_t *transaction)
}
/* TODO: Set modbus address on change */
/* TODO: Set UART baudrate on change */
config_write(&sensor_config);
sensor_config_pending_write = 1;
return MODBUS_OK;
case MODBUS_WRITE_MULTIPLE_REGISTERS:
for (int i = 0; i < transaction->register_count; i++, register_number++)

View File

@ -62,7 +62,7 @@ int8_t modbus_copy_reply_to_buffer(uint8_t *buffer, uint8_t *msg_len, modbus_tra
buffer[1] = transaction->function_code;
*msg_len = 5;
if (transaction->function_code | MODBUS_ERROR_FLAG) {
if (transaction->function_code & MODBUS_ERROR_FLAG) {
/* sending error reply */
buffer[2] = transaction->exception.exception_code;
} else {

View File

@ -45,5 +45,5 @@ print('---- Reading from holding registers ----')
#baudrate = {baudrate}
#''')
# write to holding register
print('---- Writing to holding registers ----)')
print('---- Writing to holding registers ----')
instrument.write_register(LED_on_register, 0, functioncode=6)