Data Conversion


wolftek

Recommended Posts

I am having a problem with data conversion using modbus TCP. From what I can gather my data in DAQ is 64-Bit floating point. I am trying to write to a modbus register that is 32-bit floating point. Therefore there is a overflow into the next register.

Modbus_Reg = 2756

Device.Ft_RMC.SetRegisterFloat(0, Modbus_Reg, Data])

//Modbus Register #2756 is a 32-Bit floating point register. "Data" is a 64-Bit floating point.

So the question is how do I convert the 64-Bit Floating Point to a 32-Bit Floating point.

Thank you,

Link to comment
Share on other sites

You are thinking too hard. DAQFactory might be 64 bit internally, but the Modbus protocol driver takes care of all the conversion for you. It is very, very rare that you ever have to worry about data types in DAQFactory other than number and string.

If you have a 32 bit floating point register its going to take up two Modbus registers, in your case 2756 because Modbus registers are only 16 bit. If it appears to roll into the next value on your PLC, then you probably are off by one. The value is probably registers 2755 and 2756 and not 2756 and 2757 as your request will affect.

Link to comment
Share on other sites

  • 4 months later...

Hi DF Team;

How could i convert two Modbus 16bit register to long or Ulong(32bit)?when i seached the guide i found

"byte conversion functions", so i thought that i should firstly convert the 16bit values to byte values. then i

tried to convert it via "to.uLong(,,,)" function. But i didn't succeed. Do you have any way?

Link to comment
Share on other sites

i'm sorry my mistake! i didn't tell you that the device doesn't let me to get values in single register.. For example i have to get seventeen values at a time. So there is many kinds of values with out ulong(32 bit)values.

Link to comment
Share on other sites

Oh, I see, so you have to read 17 registers and some of them need to be combined, but some are normal 16 bit registers?

Well, you were on the right track using the To. and From. functions, but they all work in bytes, not words (16 bit values), so you have to take the 16 bit values from the modbus read and break it into bytes, combine those bytes into an array of 4 bytes (32 bits) then use the to. function on it. So, use From. to convert to bytes, concat to combine the two arrays, then to. to convert it back.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.