-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Unreliable connection in RTU and TCP modes #776
Comments
Unfortunately, this is not unusual behavior and I have often observed it on many devices.
I bet, this is a problem with your inverter. I recommend to double-check with any GUI tool of your choice to rule out the library. You did not write which inverter you are using, maybe you can share a link to the datasheet so that people can comment about similar observed behavior etc. And in your test program above, I cannot see a small sleep between the queries: I have often seen devices, which need a little delay between each query because their UART and/or Modbus implementation is really poor. |
I am using a Fronius Primo 4.0 and a self written c++ wrapper library around libmodbus together with Froniusd, a little daemon to read the data from the inverter. I tried adding a delay between register queries and the extra delay doesn't improve the reliability of the connection. The inverter has both a serial cable and a network cable attached and the data readout over a serial Modbus RTU connection is already running stable since last year with only a few occasional timeouts. Recently I added TCP support to Froniusd to make it more usable for other people who do not want to connect an extra serial cable. But the Modbus TCP connection is almost not usable, both in Froniusd and the little demo program I posted above. I'll try a Modbus GUI as you suggested to see if in principle the inverter Modbus TCP implementation is usable or not. I also believe this is probably not related to libmodbus. I could try disabling the cloud connection to the solar.web API while reading the data with Modbus TCP. Maybe the little embedded processor in the inverter cannot handle both connections simultaneously very well. EDIT: disabling the solar.web connection makes no difference, the above program terminates with connection timeout message after 100-200 register reads. |
I tested the communication again but this time not with libmodbus. A simple python test program written with pymodbus works without timeouts both with sync and async TCP clients. This is the async test code:
Output:
The loop runs 1000 times without interruption. No extra delays were added in the code example, but I guess that internally pymodbus adds delays at various stages when reading or writing holding registers. Do you have a suggestion where to add the delay when using libmodbus? I tried adding a 100 ms delay between reading the two registers inside the loop, but the timeouts still happen.
|
At this stage I'd be scoping the bus lines. You're looking at both the inter frame time, but also, depending on your hardware, the time between DE being asserted and the data being transmitted, and between the end of your data and the DE being de-asserted. |
Setting the response timeout to something greater than 500 ms seems to solve the issue. Reading register 40000 for 1000 times in a loop like I did before gives the following error rates:
Below 300 ms the error rate is 100 % and it cannot read the register at all. Without setting the response timeout the error rate is comparable to a response timeout of 400 ms. What is the behavior of the libmodbus library when not setting the response timeout at all? |
Correct me if I am wrong, calling Thanks for your initial help. I guess you can close this issue now. |
Yes, I confirm that not setting a response timeout by yourself results in the usage of the default value of 500 ms. Thanks for sharing your analysis and your insights, very appreciated. |
All I have is this manual of the Fronius Datamanager, which is freely available on the Fronius website. But it doesn't contain modbus timing diagrams like the one shown above. But on page 65 it contains the following statement: " Execute the queries with a timeout of at least 10 seconds. Queries at millisecond intervals can lead to long response times." Anyway, I am glad that I found a solution and libmodbus works great in my project now. |
libmodbus version
libmodbus-3.1.11
OS and/or distribution
Arch Linux AUR (libmodbus compiled from source), Docker (Alpine)
Environment
x86_64, aarch64
Description
I am working on a library to read SunSpec compatible photovoltaic inverters via Modbus TCP and RTU. The connection to the inverter is unreliable (better in RTU mode than in TCP mode) and I get frequent connection timeouts when reading multiple registers in a row. I am not sure if this is an issue with my inverter or with libmodbus. I've played around with response and byte timeouts, but changing these doesn't seem to have much effect.
Actual behavior if applicable
I've written a simple test program which reads register 40000 from the inverter and returns the string "SunS". The test program inconsistently times out after reading the first few registers and gives the debug error message "ERROR Connection timed out: select".
Expected behavior or suggestion
Reliable communication in RTU and TCP mode.
Steps to reproduce the behavior (commands or source code)
libmodbus output with debug mode enabled
The text was updated successfully, but these errors were encountered: