pymodbus-dev / pymodbus

A full modbus protocol written in python
Other
2.23k stars 911 forks source link

v3.7.0 Coil read actually send broadcast write #2297

Closed ulfaric closed 2 weeks ago

ulfaric commented 2 weeks ago

Versions

Pymodbus Specific

Description

in 3.7.0, when call client.read_coils(), it sends a broadcast write rather than read.

Code and Logs

# code and logs here.

# please use the following to format logs when posting them here
import pymodbus

pymodbus.pymodbus_apply_logging_config("DEBUG")
janiversen commented 2 weeks ago

You do not show your code, so it is impossible to help you. You talk about "broadcast write" which type of write (modbus function code).

Probably you have forgotten the slave parameter, please see the documentation.

please add a debug log, as requested (see your own text above), so we can see what actually happens.

ulfaric commented 2 weeks ago

Hi Jan

Reverse back 3.8 fixed the issue. My codes remained same, it is clear a issue of 3.9

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: jan iversen @.> Sent: Monday, August 26, 2024 9:16:26 PM To: pymodbus-dev/pymodbus @.> Cc: ulfaric @.>; Author @.> Subject: Re: [pymodbus-dev/pymodbus] v3.7.0 Coil read actually send broadcast write (Issue #2297)

You do not show your code, so it is impossible to help you.

Probably you have forgotten the slave parameter, please see the documentation.

— Reply to this email directly, view it on GitHubhttps://github.com/pymodbus-dev/pymodbus/issues/2297#issuecomment-2310193008, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A2CCCX6ZAG6Z26LUAJ54JRTZTMTCVAVCNFSM6AAAAABNDBKGE2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJQGE4TGMBQHA. You are receiving this because you authored the thread.Message ID: @.***>

janiversen commented 2 weeks ago

We have a couple of users that use pymodbus on android (I cannot tell you how), and at least 1 is using with python 3.11 without problems.

I do not think that "broadcast write" can be caused by a android problem.

Please remark we no longer support python 3.8, so please do not report issues with that version.

Anyhow happy you got it working,

ulfaric commented 2 weeks ago

Hi Jan

No, I mean the version of pymodbus, not the python version. I reversed back to one version earlier of pymodbus without changing any of my codes and the issue disappeared.

Pymodbus 3.9 has the read coils function broken.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: jan iversen @.> Sent: Tuesday, August 27, 2024 3:45:44 AM To: pymodbus-dev/pymodbus @.> Cc: ulfaric @.>; Author @.> Subject: Re: [pymodbus-dev/pymodbus] v3.7.0 Coil read actually send broadcast write (Issue #2297)

Closed #2297https://github.com/pymodbus-dev/pymodbus/issues/2297 as not planned.

— Reply to this email directly, view it on GitHubhttps://github.com/pymodbus-dev/pymodbus/issues/2297#event-14018192759, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A2CCCX736Y6PJXH44IL3FBLZTOAWRAVCNFSM6AAAAABNDBKGE2VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJUGAYTQMJZGI3TKOI. You are receiving this because you authored the thread.Message ID: @.***>

janiversen commented 2 weeks ago

That is impossible! we have not even defined version 3.9 yet !

Our current version is 3.7.0

You still have not shared your code, so I cannot tell you if your code have been updated properly to 3.7+

Also you have still not made a debug log so we can see what is actually happening.

ulfaric commented 2 weeks ago

Ops, I mean 3.6.9 is broken. 3.6.8 is working

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: jan iversen @.> Sent: Tuesday, August 27, 2024 2:27:13 PM To: pymodbus-dev/pymodbus @.> Cc: ulfaric @.>; Author @.> Subject: Re: [pymodbus-dev/pymodbus] v3.7.0 Coil read actually send broadcast write (Issue #2297)

That is impossible! we have not even defined version 3.9 yet !

Our current version is 3.7.0

You still have not shared your code, so I cannot tell you if your code have been updated properly to 3.7+

Also you have still not made a debug log so we can see what is actually happening.

— Reply to this email directly, view it on GitHubhttps://github.com/pymodbus-dev/pymodbus/issues/2297#issuecomment-2311674135, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A2CCCX2T2JTPGXZZWIFT2ZLZTQL4DAVCNFSM6AAAAABNDBKGE2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJRGY3TIMJTGU. You are receiving this because you authored the thread.Message ID: @.***>

ulfaric commented 2 weeks ago

3.7.0 is broken too 😢

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Yifei Ren @.> Sent: Tuesday, August 27, 2024 2:27:59 PM To: pymodbus-dev/pymodbus @.>; pymodbus-dev/pymodbus @.> Cc: Author @.> Subject: Re: [pymodbus-dev/pymodbus] v3.7.0 Coil read actually send broadcast write (Issue #2297)

Ops, I mean 3.6.9 is broken. 3.6.8 is working

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: jan iversen @.> Sent: Tuesday, August 27, 2024 2:27:13 PM To: pymodbus-dev/pymodbus @.> Cc: ulfaric @.>; Author @.> Subject: Re: [pymodbus-dev/pymodbus] v3.7.0 Coil read actually send broadcast write (Issue #2297)

That is impossible! we have not even defined version 3.9 yet !

Our current version is 3.7.0

You still have not shared your code, so I cannot tell you if your code have been updated properly to 3.7+

Also you have still not made a debug log so we can see what is actually happening.

— Reply to this email directly, view it on GitHubhttps://github.com/pymodbus-dev/pymodbus/issues/2297#issuecomment-2311674135, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A2CCCX2T2JTPGXZZWIFT2ZLZTQL4DAVCNFSM6AAAAABNDBKGE2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJRGY3TIMJTGU. You are receiving this because you authored the thread.Message ID: @.***>

janiversen commented 2 weeks ago

Please submit your code and debug log (see the description you added, it contains the instructions).

The difference between 3.6.8 and 3.6.9 should not contain any function code changes, so I am confused as to how it can send a wrong function call.

Please add:

without these 3 items I cannot help you.

You wrote "in 3.7.0, when call client.read_coils(), it sends a broadcast write rather than read.". that is what you need to clarify, because there are no broadcast write in modbus.

ulfaric commented 2 weeks ago

Hi Jan

My code is a bit complicated, but I am using pymodbus client as an interface to talk with PLC. In 3.7.0, any read call results in "b'Broadcast write sent - no response expected'" as the ModbusResponse.

I don't understand how this is happening either. But without any change of my code, by just using 3.6.8, everything works as intended....

Did you use AI tool? Sometimes, they mess up with codes.

By the way, I am creating a modbuspy...I hope you dont mind the name


From: jan iversen @.> Sent: Tuesday, 27 August 2024 15:01 To: pymodbus-dev/pymodbus @.> Cc: ulfaric @.>; Author @.> Subject: Re: [pymodbus-dev/pymodbus] v3.7.0 Coil read actually send broadcast write (Issue #2297)

Please submit your code and debug log (see the description you added, it contains the instructions).

The difference between 3.6.8 and 3.6.9 should not contain any function code changes, so I am confused as to how it can send a wrong function call.

Please add:

without these 3 items I cannot help you.

— Reply to this email directly, view it on GitHubhttps://github.com/pymodbus-dev/pymodbus/issues/2297#issuecomment-2311723544, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A2CCCX42EMM4IS2ISYLFFV3ZTQP5HAVCNFSM6AAAAABNDBKGE2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJRG4ZDGNJUGQ. You are receiving this because you authored the thread.Message ID: @.***>

janiversen commented 2 weeks ago

This is happening because you are NOT addressing your device, but relying on default, which is to send the message with the broadcast id. It does NOT change the function code.

Please read our documention, or at the very least follow the signature (especially in 3.7.0) of the call that details the parameters.

This is an open world, so why would I mind you make another version. If you use any code from pymodbus, then please remember to fork pymodbus, and base your code on that....copying the code without attribution is breaking the license (which github is monitoring).

The FOSS way would be to submit your changes to pymodbus and keep that updated for all users, but it is of course your choice.

ulfaric commented 2 weeks ago

Was the parameter order changed in 3.7.0 compared to previous versions?

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: jan iversen @.> Sent: Tuesday, August 27, 2024 3:49:14 PM To: pymodbus-dev/pymodbus @.> Cc: ulfaric @.>; Author @.> Subject: Re: [pymodbus-dev/pymodbus] v3.7.0 Coil read actually send broadcast write (Issue #2297)

This is happening because you are NOT addressing your device, but relying on default, which is to send the message with the broadcast id. It does NOT change the function code.

Please read our documention, or at the very least follow the signature (especially in 3.7.0) of the call that details the parameters.

— Reply to this email directly, view it on GitHubhttps://github.com/pymodbus-dev/pymodbus/issues/2297#issuecomment-2311806514, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A2CCCXYYVQN3C2JBOUQ4GP3ZTQVPVAVCNFSM6AAAAABNDBKGE2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJRHAYDMNJRGQ. You are receiving this because you authored the thread.Message ID: @.***>

janiversen commented 2 weeks ago

Have a look at API_changes.rst ! but yes there are api changes since it is a x.y version…the only versions without API changes are x.y.z

the API changes in 3.7.0, does not affect well behaved programs, but only programs the violate the call signatures, and 3.7.0 adapted code can be used with all 3.6.z versions.

ulfaric commented 2 weeks ago

Hi Jan

Here is a screen shot of my last layer of wrapper before calling the functions of pymodbus client. As you can see, the slave is always addressed.

I am not sure where is issue, and I checked your docs, there seems to be no changes for read_coils()

[cid:b8ddbcc9-e269-492f-8082-b843640c9a10]


From: jan iversen @.> Sent: Tuesday, 27 August 2024 15:49 To: pymodbus-dev/pymodbus @.> Cc: ulfaric @.>; Author @.> Subject: Re: [pymodbus-dev/pymodbus] v3.7.0 Coil read actually send broadcast write (Issue #2297)

This is happening because you are NOT addressing your device, but relying on default, which is to send the message with the broadcast id. It does NOT change the function code.

Please read our documention, or at the very least follow the signature (especially in 3.7.0) of the call that details the parameters.

— Reply to this email directly, view it on GitHubhttps://github.com/pymodbus-dev/pymodbus/issues/2297#issuecomment-2311806514, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A2CCCXYYVQN3C2JBOUQ4GP3ZTQVPVAVCNFSM6AAAAABNDBKGE2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJRHAYDMNJRGQ. You are receiving this because you authored the thread.Message ID: @.***>

janiversen commented 2 weeks ago

There are not screen shot, just copy/paste the call that is easier.

You probably use slave as a positional parameter which are likely to cause problems, or have slave=0, which is the broadcast id, so the message is correct.

ulfaric commented 2 weeks ago

Hi Jan

I found the problem. 3.6.8 allows a slave to have ID 0. But 3.7.0 does not, if the slave ID is 0, it will lead to a broadcase.


From: jan iversen @.> Sent: Tuesday, 27 August 2024 15:57 To: pymodbus-dev/pymodbus @.> Cc: ulfaric @.>; Author @.> Subject: Re: [pymodbus-dev/pymodbus] v3.7.0 Coil read actually send broadcast write (Issue #2297)

Have a look at API_changes.rst ! but yes there are api changes since it is a x.y version…the only versions without API changes are x.y.z

the API changes in 3.7.0, does not affect well behaved programs, but only programs the violate the call signatures, and 3.7.0 adapted code can be used with all 3.6.z versions.

— Reply to this email directly, view it on GitHubhttps://github.com/pymodbus-dev/pymodbus/issues/2297#issuecomment-2311822031, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A2CCCX4ORPJZWOOQ6YX4AO3ZTQWN3AVCNFSM6AAAAABNDBKGE2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJRHAZDEMBTGE. You are receiving this because you authored the thread.Message ID: @.***>

janiversen commented 2 weeks ago

That is NOT true !!!

slave=0 is broadcast pr modbus definition, the difference is that in 3.6.8 pymodbus falsely returned the first response instead of returning without waiting for response as the protocol defines.

ulfaric commented 2 weeks ago

🙂I like things starts with 0 ...

But good to know 0 is reserved...


From: jan iversen @.> Sent: Tuesday, 27 August 2024 16:06 To: pymodbus-dev/pymodbus @.> Cc: ulfaric @.>; Author @.> Subject: Re: [pymodbus-dev/pymodbus] v3.7.0 Coil read actually send broadcast write (Issue #2297)

That is NOT true !!!

slave=0 is broadcast pr modbus definition, the difference is that in 3.6.8 pymodbus falsely returned the first response instead of returning without waiting for response as the protocol defines.

— Reply to this email directly, view it on GitHubhttps://github.com/pymodbus-dev/pymodbus/issues/2297#issuecomment-2311840436, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A2CCCX3DI5J2JNPMYO2LVXTZTQXR7AVCNFSM6AAAAABNDBKGE2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJRHA2DANBTGY. You are receiving this because you authored the thread.Message ID: @.***>

janiversen commented 2 weeks ago

3.7.1 will for other reasons, return the first response and disconnect if there are further responses when slave=0

janiversen commented 2 weeks ago

Hmmm…..you might like things to start with 0, but it actually does not depend on you, but on the device you are addressing.

janiversen commented 2 weeks ago

Reopen as a 3.7.1 reminder.