mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
freemodbus: fix incorrectly set coils read event
incorrect set of the MB_EVENT_COILS_WR event is changed while read coils in mbcontroller.c file added read/write handling for appropriate registers in freemodbus.c example file Closes https://github.com/espressif/esp-idf/issues/3289
This commit is contained in:
parent
f871cc5ffa
commit
eebbced5b6
@ -422,8 +422,8 @@ eMBErrorCode eMBRegCoilsCB(UCHAR* pucRegBuffer, USHORT usAddress,
|
|||||||
usCoils--;
|
usCoils--;
|
||||||
}
|
}
|
||||||
// Send an event to notify application task about event
|
// Send an event to notify application task about event
|
||||||
(void)send_param_access_notification(MB_EVENT_COILS_WR);
|
(void)send_param_access_notification(MB_EVENT_COILS_RD);
|
||||||
(void)send_param_info(MB_EVENT_COILS_WR, (uint16_t)usAddress,
|
(void)send_param_info(MB_EVENT_COILS_RD, (uint16_t)usAddress,
|
||||||
(uint8_t*)(pucCoilsDataBuf), (uint16_t)usNCoils);
|
(uint8_t*)(pucCoilsDataBuf), (uint16_t)usNCoils);
|
||||||
break;
|
break;
|
||||||
case MB_REG_WRITE:
|
case MB_REG_WRITE:
|
||||||
|
@ -24,6 +24,13 @@
|
|||||||
#define MB_PAR_INFO_GET_TOUT (10) // Timeout for get parameter info
|
#define MB_PAR_INFO_GET_TOUT (10) // Timeout for get parameter info
|
||||||
#define MB_CHAN_DATA_MAX_VAL (10)
|
#define MB_CHAN_DATA_MAX_VAL (10)
|
||||||
#define MB_CHAN_DATA_OFFSET (0.01f)
|
#define MB_CHAN_DATA_OFFSET (0.01f)
|
||||||
|
#define MB_READ_MASK (MB_EVENT_INPUT_REG_RD \
|
||||||
|
| MB_EVENT_HOLDING_REG_RD \
|
||||||
|
| MB_EVENT_DISCRETE_RD \
|
||||||
|
| MB_EVENT_COILS_RD)
|
||||||
|
#define MB_WRITE_MASK (MB_EVENT_HOLDING_REG_WR \
|
||||||
|
| MB_EVENT_COILS_WR)
|
||||||
|
#define MB_READ_WRITE_MASK (MB_READ_MASK | MB_WRITE_MASK)
|
||||||
|
|
||||||
static const char *TAG = "MODBUS_SLAVE_APP";
|
static const char *TAG = "MODBUS_SLAVE_APP";
|
||||||
|
|
||||||
@ -124,18 +131,16 @@ void app_main()
|
|||||||
|
|
||||||
// The cycle below will be terminated when parameter holdingRegParams.dataChan0
|
// The cycle below will be terminated when parameter holdingRegParams.dataChan0
|
||||||
// incremented each access cycle reaches the CHAN_DATA_MAX_VAL value.
|
// incremented each access cycle reaches the CHAN_DATA_MAX_VAL value.
|
||||||
for(;holding_reg_params.data_chan0 < MB_CHAN_DATA_MAX_VAL;){
|
for(;holding_reg_params.data_chan0 < MB_CHAN_DATA_MAX_VAL;) {
|
||||||
// Check for read/write events of Modbus master for certain events
|
// Check for read/write events of Modbus master for certain events
|
||||||
mb_event_group_t event = mbcontroller_check_event((MB_EVENT_HOLDING_REG_WR
|
mb_event_group_t event = mbcontroller_check_event(MB_READ_WRITE_MASK);
|
||||||
| MB_EVENT_INPUT_REG_RD
|
const char* rw_str = (event & MB_READ_MASK) ? "READ" : "WRITE";
|
||||||
| MB_EVENT_HOLDING_REG_RD
|
|
||||||
| MB_EVENT_DISCRETE_RD
|
|
||||||
| MB_EVENT_COILS_RD));
|
|
||||||
// Filter events and process them accordingly
|
// Filter events and process them accordingly
|
||||||
if((event & MB_EVENT_HOLDING_REG_WR) || (event & MB_EVENT_HOLDING_REG_RD)) {
|
if(event & (MB_EVENT_HOLDING_REG_WR | MB_EVENT_HOLDING_REG_RD)) {
|
||||||
// Get parameter information from parameter queue
|
// Get parameter information from parameter queue
|
||||||
ESP_ERROR_CHECK(mbcontroller_get_param_info(®_info, MB_PAR_INFO_GET_TOUT));
|
ESP_ERROR_CHECK(mbcontroller_get_param_info(®_info, MB_PAR_INFO_GET_TOUT));
|
||||||
printf("HOLDING READ/WRITE: time_stamp(us):%u, mb_addr:%u, type:%u, st_address:0x%.4x, size:%u\r\n",
|
printf("HOLDING %s: time_stamp(us):%u, mb_addr:%u, type:%u, st_address:0x%.4x, size:%u\r\n",
|
||||||
|
rw_str,
|
||||||
(uint32_t)reg_info.time_stamp,
|
(uint32_t)reg_info.time_stamp,
|
||||||
(uint32_t)reg_info.mb_offset,
|
(uint32_t)reg_info.mb_offset,
|
||||||
(uint32_t)reg_info.type,
|
(uint32_t)reg_info.type,
|
||||||
@ -161,9 +166,10 @@ void app_main()
|
|||||||
(uint32_t)reg_info.type,
|
(uint32_t)reg_info.type,
|
||||||
(uint32_t)reg_info.address,
|
(uint32_t)reg_info.address,
|
||||||
(uint32_t)reg_info.size);
|
(uint32_t)reg_info.size);
|
||||||
} else if (event & MB_EVENT_COILS_RD) {
|
} else if (event & (MB_EVENT_COILS_RD | MB_EVENT_COILS_WR)) {
|
||||||
ESP_ERROR_CHECK(mbcontroller_get_param_info(®_info, MB_PAR_INFO_GET_TOUT));
|
ESP_ERROR_CHECK(mbcontroller_get_param_info(®_info, MB_PAR_INFO_GET_TOUT));
|
||||||
printf("COILS READ: time_stamp(us):%u, mb_addr:%u, type:%u, st_address:0x%.4x, size:%u\r\n",
|
printf("COILS %s: time_stamp(us):%u, mb_addr:%u, type:%u, st_address:0x%.4x, size:%u\r\n",
|
||||||
|
rw_str,
|
||||||
(uint32_t)reg_info.time_stamp,
|
(uint32_t)reg_info.time_stamp,
|
||||||
(uint32_t)reg_info.mb_offset,
|
(uint32_t)reg_info.mb_offset,
|
||||||
(uint32_t)reg_info.type,
|
(uint32_t)reg_info.type,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user