Skip to content

Commit 182b019

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. Signed-off-by: Scott Fan <[email protected]>
1 parent bb13443 commit 182b019

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
@@ -371,7 +371,8 @@ static int _modbus_rtu_check_integrity(modbus_t *ctx, uint8_t *msg, const int ms
371371
}
372372

373373
/* Filter on the Modbus unit identifier (slave) in RTU mode */
374-
if (slave != ctx->slave && slave != MODBUS_BROADCAST_ADDRESS) {
374+
if (slave != ctx->slave && slave != MODBUS_BROADCAST_ADDRESS &&
375+
!(ctx->quirks & MODBUS_QUIRK_IGNORE_RTU_SLAVE_CHECK)) {
375376
if (ctx->debug) {
376377
printf("Request for slave %d ignored (not %d)\n", slave, ctx->slave);
377378
}

src/modbus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ typedef enum {
185185
MODBUS_QUIRK_NONE = 0,
186186
MODBUS_QUIRK_MAX_SLAVE = (1 << 1),
187187
MODBUS_QUIRK_REPLY_TO_BROADCAST = (1 << 2),
188+
MODBUS_QUIRK_IGNORE_RTU_SLAVE_CHECK = (1 << 3),
188189
MODBUS_QUIRK_ALL = 0xFF
189190
} modbus_quirks;
190191

0 commit comments

Comments
 (0)