06-28-2024 08:18 AM
I have a sbRIO-9637 that I'm trying to setup as a Modbus slave. I've made a simple example (attached) that has a Unit ID of 112 and to return 3.14 (approx pi) as a single precision float (this uses two registers for a total of four bytes returned to the master) in Holding Registers with a starting address of 100.
I'm running LabVIEW 2020 and am using the NI Modbus Library from VI Package Manager. When I try use the NI Modbus Library master to get the value from the sbRIO it times out. In an attempt to figure out what was going on I used NI IO Trace to record to what was actually on the serial port.
My master is sending the bytes I'd expect, see the attached files Capture.txt and Capture.nitrace.
70 Unit ID, 112 in hex
03 Read multiple holding registers
00 64 Starting address 100
00 02 Send two registers
8F 35 CRC16, I used an external tool to check it, it's correct
The slave on the sbRIO returns to me some unexpected data.
00 Unit ID,This should be 70
03 Read multiple holding registers
04 Four bytes will be returned
40 49 0F DA Approx 3.14 as an IEEE 754 floating point number, I used an external tool to check it, it's correct.
DB 49 CRC16, this is the incorrect CRC if the Unit ID returning the data was actually 00, it's correct if the Unit ID was correctly set to 70, this causes the CRC check to fail
The Modbus master on my PC times out because it expecting a reply from Unit ID 112 and it ignores the reply from Unit ID 0.
I also used a https://fte.com/products/serialanalyzers-rs422485.aspx to monitor what was actually on the bus and it matches the above, see the file Capture-2024-06-27_145518.txt.
I've also attached a NI Max report about the SW installed on the sbRIO as well as the demo project that duplicates the problem.
Why does the Modbus slave return the wrong Unit ID and how do I fix it?
08-30-2024 12:06 PM
Ben,
My apologies this is taking so long. I've escalated this within NI.
08-30-2024 02:01 PM
The source is up on GitHub and the VIs aren't password protected there if that helps you debug. The VI package build is what adds the password to the VIs (it's "bestbus").
I'm not sure how the CRC could be calculated with the correct unit id but the unit id wouldn't be sent. The VI below shows what I'm pretty sure is called by the slave in response which shows how the unit id is placed before the PDU, The CRC is calculated, added to the end of the array, and then sent over the serial bus.
09-02-2024 05:01 PM
Could be something else, but it reminds me of this:
https://forums.ni.com/t5/Real-Time-Measurement-and/Loss-of-data-from-serial-port-on-sbRIO-9607-after...
09-03-2024 03:30 PM
Thanks, it'll take me some time to set this all up for debugging.
It is weird that it reads and writes the Unit ID in multiple places, perhaps something is getting mixed up in there.