AdvancedClimateSystems / uModbus

Python implementation of the Modbus protocol.
Mozilla Public License 2.0
211 stars 81 forks source link

Can i control if single or multiple Modbus payloads are in a single TCP frame? #128

Open StefanR71 opened 5 months ago

StefanR71 commented 5 months ago

Hi,

i'm using the modbus-cli which uses uModbus.

When i'm doing a query for some registers, modbus-cli is grouping this registers and i need perhaps 3 modbus requests. This 3 requests will be put in 2 TCP packets, the first TCP packet has one Modbus payload and the second TCP packet contains the last 2 Modbus payloads.

image

Who is controlling the creation of the TCP packets?

Can i change here something, that each Modbus packet is getting a own TCP packet?

And this is every time the same, ich have every time 2 TCP packets, the first TCP packet has every time one Modbus packet inside and the second TCP packet has all the rest inside, i have seen up to 19 Modbus packets here in my tests.

Best Regards Stefan

acolomb commented 5 months ago

Just as a heads-up, this project seems currently abandoned. I haven't got feedback on my issues and pull requests for a couple of years, so I don't expect anyone to jump in and answer your questions.

As to your actual matter, sorry I can't help you much, having used only the RTU version so far. But in principle, TCP is a stream protocol, not packet-oriented. The operating system's network stack usually decides where to cut off that stream and push it into an underlying IP packet. The logic / heuristics for that can be buried quite deeply. If you can trace it down to actual network writes to the TCP socket within the Python code, that would of course be a natural opportunity to split at. But as long as TCP is not directly implemented in Python, it could be unpredictable, with shorter packets or even waiting to assemble longer packets.

Sorry if that doesn't really help you. Hope someone more knowledgeable will turn up ;-)

StefanR71 commented 5 months ago

No problem, this are already some helpful comments, perhaps someone else has seen a similar behavior and found a solution.

So let's see if someone else has a comment or hint to this problem.