Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quirks flag MODBUS_QUIRK_IGNORE_RTU_SLAVE_CHECK. #672

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/modbus_enable_quirks.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ offers the following flags:
- `MODBUS_QUIRK_MAX_SLAVE` allows slave adresses between 247 and 255.
- `MODBUS_QUIRK_REPLY_TO_BROADCAST` force a reply to a broacast request when the
device is a slave in RTU mode (should be enabled on the slave device).
- `MODBUS_QUIRK_IGNORE_RTU_SLAVE_CHECK` allows no filtering on the Modbus unit
identifier (slave) in RTU mode while checking integrity.

You can combine the flags by using the bitwise OR operator.

Expand Down
3 changes: 2 additions & 1 deletion src/modbus-rtu.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ static int _modbus_rtu_check_integrity(modbus_t *ctx, uint8_t *msg, const int ms

/* Filter on the Modbus unit identifier (slave) in RTU mode to avoid useless
* CRC computing. */
if (slave != ctx->slave && slave != MODBUS_BROADCAST_ADDRESS) {
if (slave != ctx->slave && slave != MODBUS_BROADCAST_ADDRESS &&
!(ctx->quirks & MODBUS_QUIRK_IGNORE_RTU_SLAVE_CHECK)) {
if (ctx->debug) {
printf("Request for slave %d ignored (not %d)\n", slave, ctx->slave);
}
Expand Down
1 change: 1 addition & 0 deletions src/modbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ typedef enum {
MODBUS_QUIRK_NONE = 0,
MODBUS_QUIRK_MAX_SLAVE = (1 << 1),
MODBUS_QUIRK_REPLY_TO_BROADCAST = (1 << 2),
MODBUS_QUIRK_IGNORE_RTU_SLAVE_CHECK = (1 << 3),
MODBUS_QUIRK_ALL = 0xFF
} modbus_quirks;

Expand Down