-
Notifications
You must be signed in to change notification settings - Fork 97
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
ReadCoils endianness #47
Comments
Hi Arkadii, i believe that the modbus spec does specify endianness/bit ordering for coils and binary inputs, but I could be wrong. I'll look into it and post back here with my findings. |
So here's what the spec has to say: As I understand it, coils/discrete inputs are packed on byte boundaries. So there's no latitude for byte or bit-order interpretation here, and the library seems to do what it should (see encoding.go). I'm tempted to say that the fault might lie with your device, but I don't really know anything about it. What make/model is it? |
@simonvetter thanks for looking into it, I have listed the hardware in the original message:
The connectivity is following:
Since my compensation code works fine and I don't have any other relays available to test I would suggest to close this issue unless we had more confidence where the root of the problem is. |
The ETH to RTU gateway should be fine. I've got a few in production and they mostly work as they should. The RTU relay board seem to have it backwards, though, and even documented it:
That's exactly what you're describing: relay #0 status is at bit #0 of byte #6 of the reply above (counting from 0). According to the modbus spec referenced above, it should be at bit #0 of byte #3. This is all confirmed by your wireshark analysis which shows coil #19 being set after a write to coil #11. You may be able to get them to fix the firmware by pointing to this issue and/or explaining it to them in better words :) |
Hi!
I'm currently experimenting with Modbus RTU Relay 32ch connected to the ethernet via RS485_TO_ETH.
I'm using
rtuovertcp://
scheme to connect and send commands to the RTU Relay.Your library works perfectly controlling Relays/Coils, but I have a problems when reading status of the relays using ReadCoils API call. It looks like either library uses wrong endianness when parsing ReadCoils response or my hardware uses wrong endianness when reporting the status of the coils.
Here is the Wireshark captures (I'm setting coil number 12 on, zero-based 11, and the requesting the status):
The TCP steam is following:
Decoded, the response looks like this:
ReadCoils response (the bit number 19 is set):
But effectively response should look like this:
ReadCoils corrected (the bit number 12 is set):
For correction the response of ReadCoils API response I'm currently using following:
Shall library take endianness into account when parsing ReadCoil status or it's just my hardware firmware is broken?
The text was updated successfully, but these errors were encountered: