stephane/libmodbus — Issue #38: modbus_set_slave() disallows Slave IDs above 247
Author: AaronOpfer
Created: 2011-11-11 18:36:17+00:00
State: open

A particular modbus device that I am using defaults to a slave ID above 247 (specifically, 254) and does broadcast on IDs 255 and 0. This means that I cannot interact with this device directly.

There are workarounds involving taking the device onto it's own bus not shared with other devices and then using the broadcast address to set the device ID to a normal value. However, this is not ideal for my situation.

in modbus-tcp.c and modbus-rtu.c exists the following line:

if (slave >= 0 && slave <= 247) {

I recompiled the library with these lines changed to:

if (slave >= 0 && slave <= 255) {

and this fixed my issue.

I believe this restriction is in place in order to adhere to modbus standards, however, with the large number of non-compliant devices out there, I believe libmodbus should give this power to the developer. Another possibility is printing a warning message if this is performed while the library is in debug mode when using addresses from that range.