-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Can't read more than 9 to 10 values at once with Modbus #18088
Comments
Hi @jeroenst
As there are possible exits from Wouldn't be better to always compute byteCount there (without the test) ? Or may be go once and for all with a single alloc which would handle maximum expected size (64 registers) By the way I think line is wrong:
IMHO it should be:
|
The MBR driver error is thrown by the existing modbus driver in Tasmota as far as I remember. Error codes are documented at https://tasmota.github.io/docs/Modbus-Bridge/#driver-errors which states it's an crc error combined with an not enough data error. My first suspicion is that the modbus driver in Tasmota can't handle that much data at once. About the code in line 245 I think it's actually correct, but I will take a look at it. About the count in line 756 I think you are correct although I did test this afaik. I will take a further look at this next week after my holiday. |
After digging into the code I suspect that the modbus receive timeout in TasmotaMobus.cpp is to low causing the CRC error followed by a not enough data error because not all data is received fast enough. Maybe the modbus device is sending the data in chunks.
@Gvico Can you maybe change it to 100ms and retry to read 10+ registers? Maybe we can make the receiving process not waiting for timeout but waiting for the specified number of bytes to receive (with a longer timeout if an receive error occurs). |
I updated this line (along with line 189 of the same file), it now reliably reads up to 43 registers, which is more than enough for me. |
The 100ms timeout seems fine to me, the code already starts processing the received packet immediately when the nr of bytes expected are received. @barbudor is it fine to change this timeout to 100ms and make a pull request? I also will fix line 245 and 756 in xdrv_63_modbus_bridge.ino |
@Gvico Can you try my latest commit in https://github.com/jeroenst/Tasmota? If it works ok I will create a pull request. Can you maybe also try the using function code 1,2 or 15 to test bitmode? I don't have a setup over here currently to test the code. |
@TheChatty I remember that we had a long conversation about bitmode while reading coils and inputs, do you have time to check if my changes don't disturb your setup? |
The timeout is not on the overall of the message as it is recomputed at every reception so it doesn't make sense to increase it because of larger expected message. This timeout hits when the delay between bytes within the message itself is greater than 10ms. I wouldn't go for a possible breaking change before hooking up a scope and having a look at the timing of the message.
Beside the timeout problem, I believe there is a problem with that logic here: Tasmota/tasmota/tasmota_xdrv_driver/xdrv_63_modbus_bridge.ino Lines 245 to 246 in 7167884
On a normal execution, you clear
But you have 2 cases where you could exit the function without clearing it: Tasmota/tasmota/tasmota_xdrv_driver/xdrv_63_modbus_bridge.ino Lines 247 to 251 in 7167884
Tasmota/tasmota/tasmota_xdrv_driver/xdrv_63_modbus_bridge.ino Lines 312 to 317 in 7167884
Which means the next time you reach line 245,
So I think that at least
My experience with embedded system is that dynamic memory allocation creates more problem that it solves as it can create memory fragmentation which is much more critical on small systems that on system that support virtual memory. |
Thank you for helping. |
@jeroenst I tried the commit and it works just fine! |
@jeroenst You are mistaken. I'm using ModBrTCP and mainly holding registers. I flashed 38af70f and quickly tried to read a single holding register: works. I started TrovisView (the bulk data reading software): it started to connect but after a few seconds it failed - like before. Still need to investigate further with Wireshark when having more free time... |
I have connected a hardware modbus plc to an esp32. When I'm done testing I will submit a PR. |
The new proposed changes of @barbudor work, but the 10ms timeout is still to small to read many registers. With 10ms timeout I can read up to 12 uint16 registers. I will create a PR with the changes and a 20ms timeout. |
@arendst This issue can be closed now the solution is merged into development branch |
PROBLEM DESCRIPTION
I'm trying to read 24 registers from a Modbus slave, but can't get to read more than 9-10 at a time.
If i try to go higher, i don't get any answer.
REQUESTED INFORMATION
Backlog Template; Module; GPIO 255
:Backlog Rule1; Rule2; Rule3
:Status 0
:weblog
to 4 and then, when you experience your issue, provide the output of the Console log:TO REPRODUCE
ModBusSend {"deviceaddress": 1, "functioncode": 3, "startaddress": 26, "type":"uint16", "count":24}
EXPECTED BEHAVIOUR
A response like
{"ModbusReceived":{"DeviceAddress":1,"FunctionCode":3,"StartAddress":26,"Length":21,"Count":8,"Values":[x,x,x,x...]}}
SCREENSHOTS
If applicable, add screenshots to help explain your problem.
ADDITIONAL CONTEXT
Add any other context about the problem here.
(Please, remember to close the issue when the problem has been addressed)
The text was updated successfully, but these errors were encountered: