forked from espressif/esp-modbus
fix master broadcast request issue
This commit is contained in:
@ -205,7 +205,7 @@ eMBMasterSerialInit( eMBMode eMode, UCHAR ucPort, ULONG ulBaudRate, eMBParity eP
|
|||||||
pxMBMasterFrameCBByteReceived = xMBMasterRTUReceiveFSM;
|
pxMBMasterFrameCBByteReceived = xMBMasterRTUReceiveFSM;
|
||||||
pxMBMasterFrameCBTransmitterEmpty = xMBMasterRTUTransmitFSM;
|
pxMBMasterFrameCBTransmitterEmpty = xMBMasterRTUTransmitFSM;
|
||||||
pxMBMasterPortCBTimerExpired = xMBMasterRTUTimerExpired;
|
pxMBMasterPortCBTimerExpired = xMBMasterRTUTimerExpired;
|
||||||
eMBMasterCurrentMode = MB_ASCII;
|
eMBMasterCurrentMode = eMode;
|
||||||
|
|
||||||
eStatus = eMBMasterRTUInit(ucPort, ulBaudRate, eParity);
|
eStatus = eMBMasterRTUInit(ucPort, ulBaudRate, eParity);
|
||||||
break;
|
break;
|
||||||
@ -220,7 +220,7 @@ eMBMasterSerialInit( eMBMode eMode, UCHAR ucPort, ULONG ulBaudRate, eMBParity eP
|
|||||||
pxMBMasterFrameCBByteReceived = xMBMasterASCIIReceiveFSM;
|
pxMBMasterFrameCBByteReceived = xMBMasterASCIIReceiveFSM;
|
||||||
pxMBMasterFrameCBTransmitterEmpty = xMBMasterASCIITransmitFSM;
|
pxMBMasterFrameCBTransmitterEmpty = xMBMasterASCIITransmitFSM;
|
||||||
pxMBMasterPortCBTimerExpired = xMBMasterASCIITimerT1SExpired;
|
pxMBMasterPortCBTimerExpired = xMBMasterASCIITimerT1SExpired;
|
||||||
eMBMasterCurrentMode = MB_RTU;
|
eMBMasterCurrentMode = eMode;
|
||||||
|
|
||||||
eStatus = eMBMasterASCIIInit(ucPort, ulBaudRate, eParity );
|
eStatus = eMBMasterASCIIInit(ucPort, ulBaudRate, eParity );
|
||||||
break;
|
break;
|
||||||
@ -391,6 +391,10 @@ eMBMasterPoll( void )
|
|||||||
break;
|
break;
|
||||||
case EV_MASTER_EXECUTE:
|
case EV_MASTER_EXECUTE:
|
||||||
if (xCurTransactionId == xEvent.xTransactionId) {
|
if (xCurTransactionId == xEvent.xTransactionId) {
|
||||||
|
if ( xMBMasterRequestIsBroadcast()
|
||||||
|
&& (( ucMBMasterGetCommMode() == MB_RTU ) || ( ucMBMasterGetCommMode() == MB_ASCII ) ) ) {
|
||||||
|
ucMBRcvFrame = ucMBSendFrame;
|
||||||
|
}
|
||||||
MB_PORT_CHECK(ucMBRcvFrame, MB_EILLSTATE, "receive buffer initialization fail.");
|
MB_PORT_CHECK(ucMBRcvFrame, MB_EILLSTATE, "receive buffer initialization fail.");
|
||||||
ESP_LOGD(MB_PORT_TAG, "%" PRIu64 ":EV_MASTER_EXECUTE", xEvent.xTransactionId);
|
ESP_LOGD(MB_PORT_TAG, "%" PRIu64 ":EV_MASTER_EXECUTE", xEvent.xTransactionId);
|
||||||
ucFunctionCode = ucMBRcvFrame[MB_PDU_FUNC_OFF];
|
ucFunctionCode = ucMBRcvFrame[MB_PDU_FUNC_OFF];
|
||||||
|
@ -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
|
// 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);
|
int comp_result = memcmp((const void*)name, (const void*)reg_ptr->param_key, (size_t)param_key_len);
|
||||||
if (comp_result == 0) {
|
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
|
// 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->slave_addr = reg_ptr->mb_slave_addr;
|
||||||
request->reg_start = reg_ptr->mb_reg_start;
|
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
|
// Set the type of parameter found in the table
|
||||||
*type = reg_info.param_type;
|
*type = reg_info.param_type;
|
||||||
} else {
|
} 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;
|
error = ESP_ERR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
return error;
|
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;
|
*type = reg_info.param_type;
|
||||||
free(pdata);
|
free(pdata);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "%s: The requested cid(%u) not found in the data dictionary.",
|
ESP_LOGE(TAG, "%s: The requested cid(%u) is not configured correctly. Check data dictionary for correctness.",
|
||||||
__FUNCTION__, (unsigned)reg_info.cid);
|
__FUNCTION__, (unsigned)cid);
|
||||||
error = ESP_ERR_INVALID_ARG;
|
error = ESP_ERR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
version: "1.0.13"
|
version: "1.0.14"
|
||||||
description: ESP-MODBUS is the official Modbus library for Espressif SoCs.
|
description: ESP-MODBUS is the official Modbus library for Espressif SoCs.
|
||||||
url: https://github.com/espressif/esp-modbus
|
url: https://github.com/espressif/esp-modbus
|
||||||
dependencies:
|
dependencies:
|
||||||
|
Reference in New Issue
Block a user