diff --git a/modbus/include/mbconfig.h b/modbus/include/mbconfig.h index f9efc55..efdd1bc 100644 --- a/modbus/include/mbconfig.h +++ b/modbus/include/mbconfig.h @@ -158,6 +158,14 @@ PR_BEGIN_EXTERN_C #define MB_STRICT_ADDRESSING ( 1 ) #endif +/*! \brief Quirk mode to allow replies to broadcast reads, but not writes. + * This is an alternative to relaxing MB_STRICT_ADDRESSING, which would + * also allow replies to broadcast writes. + */ +#ifndef MB_QUIRK_REPLY_BROADCAST_READ +#define MB_QUIRK_REPLY_BROADCAST_READ ( 0 ) +#endif + /*! \brief provide a notification hook in the rx path. * Must provide a hook function of the form: * vMBPortNotifyRX(UCHAR *rxdata, USHORT length) diff --git a/modbus/mb.c b/modbus/mb.c index 1f5c920..e97dbc9 100644 --- a/modbus/mb.c +++ b/modbus/mb.c @@ -391,6 +391,20 @@ eMBPoll( void ) if( ucRcvAddress != MB_ADDRESS_BROADCAST ) { #endif + +#if MB_QUIRK_REPLY_BROADCAST_READ > 0 + /* + * reply to any non-broadcast, and also broadcasts for these + * few functions used for discovering devices. + */ + if (!(ucRcvAddress == MB_ADDRESS_BROADCAST) || + ((ucRcvAddress == MB_ADDRESS_BROADCAST) && ( + (ucFunctionCode == MB_FUNC_READ_INPUT_REGISTER) || + (ucFunctionCode == MB_FUNC_READ_HOLDING_REGISTER) || + (ucFunctionCode == MB_FUNC_OTHER_REPORT_SLAVEID)) + )) { +#endif + if( eException != MB_EX_NONE ) { /* An exception occured. Build an error frame. */ @@ -411,6 +425,10 @@ eMBPoll( void ) #endif /* Receive address == our address, or broadcast, if allowed */ eStatus = peMBFrameSendCur( ucRcvAddress, ucMBFrame, usLength ); +#if MB_QUIRK_REPLY_BROADCAST_READ > 0 + } +#endif + #if MB_STRICT_ADDRESSING > 0 } #endif