Modbus- Reading a Float register SOLVED

Hello,
I am trying to use the PAC Control integration kit.
Using PAC version R10.4c.
I have a device that has data held in two registers as floats. Here is a screenshot from the manual:

sensorex

I want to retrieve the probe_value that is held in registers 3 and 4.
My issue is that I am not sure how to get 1 value out of 2 registers.
I am a somewhat familiar with the Modbus integration kit, I think I am just not setting it up correctly.
I have tried both these configurations and neither has given 1 number as a value:

PH17_subStatus = O22Modbus03ReadHoldingRegistersAsInt(chWWTP_01, PH17_Parameters, 4, 4, intTable_Test1, 1, PH17_Status);

PH17_subStatus = O22Modbus03ReadHoldingRegistersAsFloat(chWWTP_01, PH17_Parameters, 4, PH17_ph, 1, PH17_Status);

I have also tried moving the starting register + and -1, and also tried increasing the NumReturnValues
I can read the modbus_address using 1 as the starting address as an uint, but can’t get any floats working.
Could somebody please point me in the right direction or let me know what is wrong?
Thank you!

I would need to pull the code down to have a go at answering this, but I bet @philip knows it off the top of his head.

1 Like

That looks correct for what you are reading. Since the address in the documentation (Sensorex?) starts with 0, you would add 1 to this, since the integration kit uses register numbers.

How do you have the PH17_Parameters table setup? What value ends up in PH17_ph after the call?

2 Likes
PH17_Parameters[0] = 0;//Protocol - 0 = Serial RTU, 1 = Serial ASCII, 2 = Modbus/TCP
PH17_Parameters[1] = 172;//Slave Address - serial 0-247 - Modbus/TCP 0-255
PH17_Parameters[2] = 1000;//Timeout in ms
PH17_Parameters[3] = 0;//Word Order - 0 = Lower register least significant, 1 = Lower register most significant
PH17_Parameters[4] = 0;//Dword Order - Reserved - set to 0

After the call, I am getting 4.167739e-016 in PH17_ph

Change index 3 to 1 on your parameters and try it again.

The device is big endian. Value is around 7.8, which makes sense for pH.

3 Likes

Thank you! Seems to be working as expected now.
I knew it had to be something simple :sweat_smile:

1 Like

No problem, just one of those common Modbus idiosyncrasies.

1 Like