Skip to content

Commit 568b9fc

Browse files
committed
Add quirks flag MODBUS_QUIRK_IGNORE_RTU_SLAVE_CHECK.
The Modbus RTU mode currently only allows a single slave, the message is ignored when not from the expected slave. The MODBUS_QUIRK_IGNORE_RTU_SLAVE_CHECK flag allow ignore the Modbus unit identifier (slave) checking, in this way, the RTU slave device can acts as a multi-channels gateway, receive the request messages for different slave from upstream channel, then forward those to the downstream channel in transparent mode.
1 parent b25629b commit 568b9fc

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

docs/modbus_enable_quirks.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ offers the following flags:
2222
- `MODBUS_QUIRK_MAX_SLAVE` allows slave adresses between 247 and 255.
2323
- `MODBUS_QUIRK_REPLY_TO_BROADCAST` force a reply to a broacast request when the
2424
device is a slave in RTU mode (should be enabled on the slave device).
25+
- `MODBUS_QUIRK_IGNORE_RTU_SLAVE_CHECK` allows no filtering on the Modbus unit
26+
identifier (slave) in RTU mode while checking integrity.
2527
2628
You can combine the flags by using the bitwise OR operator.
2729

src/modbus-rtu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ static int _modbus_rtu_check_integrity(modbus_t *ctx, uint8_t *msg, const int ms
354354

355355
/* Filter on the Modbus unit identifier (slave) in RTU mode to avoid useless
356356
* CRC computing. */
357-
if (slave != ctx->slave && slave != MODBUS_BROADCAST_ADDRESS) {
357+
if (slave != ctx->slave && slave != MODBUS_BROADCAST_ADDRESS &&
358+
!(ctx->quirks & MODBUS_QUIRK_IGNORE_RTU_SLAVE_CHECK)) {
358359
if (ctx->debug) {
359360
printf("Request for slave %d ignored (not %d)\n", slave, ctx->slave);
360361
}

src/modbus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ typedef enum {
181181
MODBUS_QUIRK_NONE = 0,
182182
MODBUS_QUIRK_MAX_SLAVE = (1 << 1),
183183
MODBUS_QUIRK_REPLY_TO_BROADCAST = (1 << 2),
184+
MODBUS_QUIRK_IGNORE_RTU_SLAVE_CHECK = (1 << 3),
184185
MODBUS_QUIRK_ALL = 0xFF
185186
} modbus_quirks;
186187

0 commit comments

Comments
 (0)