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

modbus_set_slave() disallows Slave IDs above 247 #38

Closed
AaronOpfer opened this issue Nov 11, 2011 · 17 comments
Closed

modbus_set_slave() disallows Slave IDs above 247 #38

AaronOpfer opened this issue Nov 11, 2011 · 17 comments
Assignees
Milestone

Comments

@AaronOpfer
Copy link

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.

@stephane
Copy link
Owner

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

@ghost ghost assigned stephane Jan 28, 2012
@ivanwagner
Copy link

Dear Stephane,

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

Thank you for the feedback

@stephane
Copy link
Owner

Nope, not yet.

@stephane
Copy link
Owner

@mhei
Copy link
Contributor

mhei commented Feb 20, 2015

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

@stephane
Copy link
Owner

Quirks or compliance. Opinion asked on mailing list.

@stephane stephane added this to the v3.2.0 milestone May 11, 2016
@stephane
Copy link
Owner

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

@karlp
Copy link
Contributor

karlp commented Jan 23, 2019

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

@viktor-av
Copy link

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

@plbarrio
Copy link

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.

@watsocd
Copy link

watsocd commented Jul 11, 2021 via email

@plbarrio
Copy link

plbarrio commented Aug 1, 2021

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.

@stephane
Copy link
Owner

stephane commented Aug 4, 2021

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?

@mhei
Copy link
Contributor

mhei commented Aug 4, 2021

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 😇

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.

@karlp
Copy link
Contributor

karlp commented Aug 4, 2021

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

@Guiorgy
Copy link

Guiorgy commented Jun 8, 2022

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.

@stephane
Copy link
Owner

See updated is_compliant branch.

epsilonrt pushed a commit to epsilonrt/libmodbus that referenced this issue Jun 19, 2023
Useful functions when you are confronted with equipment which does
not respect the protocol, which behaves strangely or when you wish
to move away from the standard.

Thank you @mhei for the great initial version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants