fix master broadcast request issue

This commit is contained in:
Alex Lisitsyn
2024-04-30 15:27:36 +08:00
parent e26c0c2f5a
commit c63a6d7114
3 changed files with 16 additions and 6 deletions

View File

@ -205,7 +205,7 @@ eMBMasterSerialInit( eMBMode eMode, UCHAR ucPort, ULONG ulBaudRate, eMBParity eP
pxMBMasterFrameCBByteReceived = xMBMasterRTUReceiveFSM;
pxMBMasterFrameCBTransmitterEmpty = xMBMasterRTUTransmitFSM;
pxMBMasterPortCBTimerExpired = xMBMasterRTUTimerExpired;
eMBMasterCurrentMode = MB_ASCII;
eMBMasterCurrentMode = eMode;
eStatus = eMBMasterRTUInit(ucPort, ulBaudRate, eParity);
break;
@ -220,7 +220,7 @@ eMBMasterSerialInit( eMBMode eMode, UCHAR ucPort, ULONG ulBaudRate, eMBParity eP
pxMBMasterFrameCBByteReceived = xMBMasterASCIIReceiveFSM;
pxMBMasterFrameCBTransmitterEmpty = xMBMasterASCIITransmitFSM;
pxMBMasterPortCBTimerExpired = xMBMasterASCIITimerT1SExpired;
eMBMasterCurrentMode = MB_RTU;
eMBMasterCurrentMode = eMode;
eStatus = eMBMasterASCIIInit(ucPort, ulBaudRate, eParity );
break;
@ -391,6 +391,10 @@ eMBMasterPoll( void )
break;
case EV_MASTER_EXECUTE:
if (xCurTransactionId == xEvent.xTransactionId) {
if ( xMBMasterRequestIsBroadcast()
&& (( ucMBMasterGetCommMode() == MB_RTU ) || ( ucMBMasterGetCommMode() == MB_ASCII ) ) ) {
ucMBRcvFrame = ucMBSendFrame;
}
MB_PORT_CHECK(ucMBRcvFrame, MB_EILLSTATE, "receive buffer initialization fail.");
ESP_LOGD(MB_PORT_TAG, "%" PRIu64 ":EV_MASTER_EXECUTE", xEvent.xTransactionId);
ucFunctionCode = ucMBRcvFrame[MB_PDU_FUNC_OFF];

View File

@ -358,6 +358,11 @@ static esp_err_t mbc_serial_master_set_request(char* name, mb_param_mode_t mode,
// Compare the name of parameter with parameter key from table
int comp_result = memcmp((const void*)name, (const void*)reg_ptr->param_key, (size_t)param_key_len);
if (comp_result == 0) {
// Returns an error in case of broadcast read request
if (!reg_ptr->mb_slave_addr && (mode == MB_PARAM_READ)) {
error = ESP_ERR_INVALID_ARG;
break;
}
// The correct line is found in the table and reg_ptr points to the found parameter description
request->slave_addr = reg_ptr->mb_slave_addr;
request->reg_start = reg_ptr->mb_reg_start;
@ -417,7 +422,8 @@ static esp_err_t mbc_serial_master_get_parameter(uint16_t cid, char* name, uint8
// Set the type of parameter found in the table
*type = reg_info.param_type;
} else {
ESP_LOGE(TAG, "%s: The cid(%u) not found in the data dictionary.", __FUNCTION__, reg_info.cid);
ESP_LOGE(TAG, "%s: The requested cid(%u) is not configured correctly. Check data dictionary for correctness.",
__FUNCTION__, (unsigned)cid);
error = ESP_ERR_INVALID_ARG;
}
return error;
@ -465,8 +471,8 @@ static esp_err_t mbc_serial_master_set_parameter(uint16_t cid, char* name, uint8
*type = reg_info.param_type;
free(pdata);
} else {
ESP_LOGE(TAG, "%s: The requested cid(%u) not found in the data dictionary.",
__FUNCTION__, (unsigned)reg_info.cid);
ESP_LOGE(TAG, "%s: The requested cid(%u) is not configured correctly. Check data dictionary for correctness.",
__FUNCTION__, (unsigned)cid);
error = ESP_ERR_INVALID_ARG;
}
return error;

View File

@ -1,4 +1,4 @@
version: "1.0.13"
version: "1.0.14"
description: ESP-MODBUS is the official Modbus library for Espressif SoCs.
url: https://github.com/espressif/esp-modbus
dependencies: