Sign in to follow this  
wolftek

Data Conversion

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,

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Kenny,

If your writing to the RMC's 'Floats'

You need to used a Data Type of 'Float Reversed Words' and offset the address by -1

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Like Wolftek, you are trying too hard. DAQFactory already has a Modbus I/O type that handles 32 bit registers, combining two 16 bit registers into one 32 bit one.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this