LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus register conversion

Solved!
Go to solution

Hi all.  I'm trying to convert these register values into a serial number and sensor value using the info from the device manual pasted below.  Any help would be much appreciated.  Thank you.  

 

JNew_0-1643311560945.png

 

0 Kudos
Message 1 of 6
(271 Views)
Solution
Accepted by topic author J.New

Does not compute to expected value.

 

If you expect 71963431, the registers should be 1098 and 4903. I suspect you are reading registers 1 and 2 of the input registers, but reading register 0 and 1 will actually return registers 30001 and 30002. Try that, and use type cast on the arrays of u16. Wire any u32 for the serial and a single precision float to the measurement value.

 

Screenshot 2022-01-27 151109.png

Message 2 of 6
(240 Views)

Great.  I'm almost there. Two out of three are working.  I am getting the correct serial number and value 1 (humidity), but I still can't get value 2 (temp).  You were right about reading the wrong registers for the serial number.  I guess I expected the modbus read input register vi to return 30001 and 30002 by wiring 30001 as the starting address and 2 as the number of input registers.  But I had to wire 30000 as the starting address to get the right serial.  Is it supposed to work that way or could the chart be incorrect?

 

To get value 1, I had to use 31001 as the starting address, which was what I expected from the chart.  But I can't find any way to get value 2.  If I start at 31003 with 2 registers, I get Error -389113 occurred at an unidentified location.  I can read a max of 4 registers starting at 30000 and not sure how to get value two out of those, which is expected to be around 70.

 

I'm stumped on value 2.  Any ideas there?

.

JNew_2-1643387642015.png

 

 

 

0 Kudos
Message 3 of 6
(194 Views)

Hello,

 

If you look at the help the starting address is 0 indexed and the Modbus specification is 1 indexed.  I have made this mistake many times....

 

Screenshot 2022-01-28 115714.png

Dan Shangraw, P.E.


   

Message 4 of 6
(189 Views)
Solution
Accepted by topic author J.New

I think the device is sending the registers in different order. It's a bit odd they do it for floats and not for the u32 serial, but if you swap the registers it gives data that seems believable (21 C for room temperature)

 

So change the read to be 0-indexed and then reverse or otherwise swap the registers before type cast.

 

Screenshot 2022-01-28 102622.png

Message 5 of 6
(177 Views)

Great that does it.  Thanks much!  The funny part is that I did manage to get the 21 temp value before, but derped and didn't realize that it was in C because the device is set to F so I thought it was wrong.  Thanks again! 

0 Kudos
Message 6 of 6
(168 Views)