libmodbus icon indicating copy to clipboard operation
libmodbus copied to clipboard

modbus_set_slave() disallows Slave IDs above 247

Open AaronOpfer opened this issue 13 years ago • 16 comments

modbus_set_slave() disallows Slave IDs above 247. 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.

AaronOpfer avatar Nov 11 '11 18:11 AaronOpfer

I think I'll increase standard conformance (for modbus_reply for example) and offer a new setting to disable it!

stephane avatar Jan 28 '12 21:01 stephane

Dear Stephane,

is there now a way to address a slave address greater than 247 without patching the library?

Thank you for the feedback

ivanwagner avatar Aug 12 '14 11:08 ivanwagner

Nope, not yet.

stephane avatar Aug 22 '14 07:08 stephane

https://github.com/stephane/libmodbus/tree/compliance

stephane avatar Feb 18 '15 16:02 stephane

I prefer to call this 'quirks' instead of compliance, see my proposal here: https://github.com/mhei/libmodbus/commits/quirks

mhei avatar Feb 20 '15 19:02 mhei

Quirks or compliance. Opinion asked on mailing list.

stephane avatar May 11 '16 15:05 stephane

I intend to relax the rules by default and to offer a strict mode.

stephane avatar Jan 20 '17 11:01 stephane

Running into this again, how are we going on getting this into a released version?

karlp avatar Jan 23 '19 10:01 karlp

FYI, I applied @mhei 'quirks' branch to current master #533 Maybe it can be merged some day. Feedback is welcome.

viktor-av avatar May 21 '20 09:05 viktor-av

Some devices use 248 address for point to point communication. https://innovatorsguru.com/wp-content/uploads/2019/06/PZEM-004T-V3.0-Datasheet-User-Manual.pdf

I was using Qmodbus testing, and getting crazy. Thanks that it has a Modbus monitor I discovered this issue.

Please enable a mechanism to override this.

plbarrio avatar Jul 11 '21 10:07 plbarrio

This is an opensource project. If you want to customize the source code to do something unique, go ahead. That is one of the advantages of opensource.

From the manual you linked:

The address 0xF8 (248) is used as the general address, this address can be only used in ****** single-slave environment and can be used for calibration ******* etc.

The 248 special address is a unique function of this specific device in a very specific use case outside the documented MODBUS address range from 1-247.

You are on your own.

From: plbarrio @.> Sent: Sunday, July 11, 2021 6:06 AM To: stephane/libmodbus @.> Cc: Subscribed @.***> Subject: Re: [stephane/libmodbus] modbus_set_slave() disallows Slave IDs above 247 (#38)

Some devices use 248 address for point to point communication. https://innovatorsguru.com/wp-content/uploads/2019/06/PZEM-004T-V3.0-Datasheet-User-Manual.pdf

I was using Qmodbus https://github.com/ed-chemnitz/qmodbus/ testing, and getting crazy. Thanks that it has a Modbus monitor I discovered this issue.

Please enable a mechanism to override this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stephane/libmodbus/issues/38#issuecomment-877773371 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFDSAIDIMLMFQWLRQCWLDTTXFUI3ANCNFSM4ASZZMJQ . https://github.com/notifications/beacon/AAFDSAKWBIHW7ZJZAG4PLFDTXFUI3A5CNFSM4ASZZMJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGRI4EOY.gif

watsocd avatar Jul 11 '21 14:07 watsocd

Yes, I know that is an opensource project and that I could fork my self, I have even located the line code. I also know that 248 address is not standard. The problem with that device is that is the default address and some users can have problems with it. This library is 'de facto' modbus standard.

I was using Qmodbus for testing the device, but my final idea was to use with Influx and Telegraf. But i am not confident that telegraf is not using this library and what i see in its source code there is a note as 248-255 address are 'reserved'. Yes i have to test, but i think we should save all this testing to users even for non standard address.

https://github.com/influxdata/telegraf/tree/master/plugins/inputs/modbus

I see that the package is sended, but the slave response causes an exception '[inputs.modbus] Error in plugin: modbus: exception '2' (illegal data address), function '131'

I was just asking for a 'non-standard' flag, which other users above in this thread have suggested to be merged. I think that it is a pity that i have to start a virtual windows machine and use non open source software to change this device address due this issue. I know that i could program it myself but i have still nightmares debugging 'easy modbus' from Omron PLCs.

plbarrio avatar Aug 01 '21 08:08 plbarrio

I think it's time to resolve this issue!

@mhei started a branch to set the various quirks (https://github.com/mhei/libmodbus/commits/quirks). I did something similar in https://github.com/stephane/libmodbus/tree/compliance and today in https://github.com/stephane/libmodbus/tree/is_compliant

I need your feedback to know if we should use a smart mask or stupid global flag. The more I think about it, the more I think the mask is best idea (a bit complex to use BTW) to avoid the bad situation where only a specific not compliant behavior would be useful. The term 'quirk' goes further by offering a different behavior (not related to the standard).

Does the term 'quirk' is clear for everyone?

stephane avatar Aug 04 '21 11:08 stephane

Even 6 years after my PR, I still like the idea of naming it "quirk" - stolen from Linux kernel where similar things exists for e.g. USB devices :innocent:

a bit complex to use BTW

From library user view, or do you means inside the library itself? The later might be addressed with more convenience macros...

The term 'quirk' goes further by offering a different behavior (not related to the standard).

Yes, my original PR was just an initial shot, room for improvement is always there. I think that for each "quirk" it should exactly be documented how this affects the library and which are the consequences from user point of view.

mhei avatar Aug 04 '21 20:08 mhei

Quirk is good for me :) there's a few things that could be covered...

karlp avatar Aug 04 '21 20:08 karlp

Quirk is fine for me too, I don't really care. However,

I intend to relax the rules by default and to offer a strict mode.

I'd prefer the default setting to be full compliance to the standard. Any additional quirks or nice features should be opt in by the user IMO.

Guiorgy avatar Jun 08 '22 11:06 Guiorgy

See updated is_compliant branch.

stephane avatar Sep 27 '22 22:09 stephane