Converting Float to 2 Integers for Modbus?

Can't you address modbus register word directly to real variable?
If so then you can directly write and read real via modbus if your modbus master support reals.


Only byte order can make some problems.
 
Can't you address modbus register word directly to real variable?
If so then you can directly write and read real via modbus if your modbus master support reals.


Only byte order can make some problems.

Regarding this, I worked with two devices that both support modbus real. So, no problem, right? Only that they somehow interpreter the word order differently and I had no way to swap it. (ok, there's probably a way by doing a bunch of manipulation).

In my case it is a EZPLC and a Webport (Spectrum Control's E W O N equivalent). I ended up just giving up on precision and used an integer.
 
Originally posted by FNC:

I need to convert a IEEE754 real to 2 integers.

FNC, you keep saying convert so I will assume for the sake of this post that you really mean convert. So, what do you mean by convert? What is the device on the other side of the Modbus link looking for? What form is the number supposed to take?

Are you trying to take a REAL and convert it to an implied decimal point format (1234.56 becomes a DINT that is 123456 and the device on the other side knows the number needs to be divided by 100 before use)?

Are you trying to come up with a format that has an implied LBW/MSW (for example, a number like 1234.5678 is sent as 5678 in the LSW and 1234 in the MSW)?

Both of these cases are fairly common methods of doing something that is pretty atypical in the first place. If you really are doing a conversion (the device on the other side IS NOT expecting a REAL) then you need to tell us what format the converted number needs to take.

If the device on the other side is expecting an IEEE754 REAL then no "conversion" is necessary. As we have all been saying, you need to get the bit pattern of the REAL into two consecutive 16-bit integers with whatever instructions are available to do that.

Keith
 
You don't need a real conversion, you need to do a bitwise copy of the 32bit REAL into two 16bits registers, the 16 most significant bits in one register and the 16 less significant in the other, then the two registers should be transmitted via Modbus as two consecutive 16bit register.

But as already said it may be that the receiving side expects the words in the reverse order, then one of the sides should swap the words.
 
Last edited:
Is this for communicating to a touchscreen or to another controller? What is the device that the ILC-191 communicates with?

This might help solidifying what you need to do.

If you are using PC Worx, then it should support all IEC61131 stuff but as Peter said, not all "standards" are standard.
 
Are you trying to take a REAL and convert it to an implied decimal point format (1234.56 becomes a DINT that is 123456 and the device on the other side knows the number needs to be divided by 100 before use)?
Keith

Be careful when converting! Real to dint 1234.56 becomes 1235. The multiplication need to come first real_to_dint(1234.56 * 100) then divide into a real on the other end


REAL_TO-/ LREAL_TO Conversions
Converting from the variable type REAL or LREAL to a different type:

The value will be rounded up or down to the nearest whole number and converted into the new variable type. Exceptions to this are the variable types STRING, BOOL, REAL and LREAL.
 
Modbus

My need is to convert a REAL to 2 Integers (16 bit each) so that I can write a floating point value over Modbus by writing the resulting 2 integers.

____________________________________________________________________________________________________________________
A user said:

you need to do a bitwise copy of the 32bit REAL into two 16bits registers, the 16 most significant bits in one register and the 16 less significant in the other, then the two registers should be transmitted via Modbus as two consecutive 16bit register.


Will this work for me??
 
Last edited:
Originally posted by FNC:

Will this work for me??

This is what we have been saying all along. You have been telling us this isn't what you need.

So, one thing at a time. What is the target Modbus device (the thing the plc is communicating with) looking for? Is it looking for an IEEE754 REAL or is it something else. Only you can tell us what the target device is looking for.

Keith
 
A user said:

you need to do a bitwise copy of the 32bit REAL into two 16bits registers, the 16 most significant bits in one register and the 16 less significant in the other, then the two registers should be transmitted via Modbus as two consecutive 16bit register.


Will this work for me??

Yes, Modbus works in that way, it transmits the pure binary, but since Modbus can only transmit 16bit words then it is sent in two parts.
You do not need any conversion, just transmit the bits
 
Last edited:

Similar Topics

I need help converting from a floating register to two integer words. I'm using a SLC 5/05 and need to be able to write 32 bit data to a servo...
Replies
2
Views
4,708
How do I convert a float to an integer? I've got a floating-point number D606, value 3999.863. I need to convert it to an integer (4000), then I...
Replies
14
Views
4,148
Dear Experts, I need to send Boolean array from PLC (1769-L19ER) to device which recieve only float data. So, How can I convert Bool array to...
Replies
4
Views
2,250
I have a 3-axis sensor that I'm working on integrating with a Micrologic PLC. The sensor has a RS-422 output and I'm using an RTA Automation PLC...
Replies
5
Views
3,237
Can someone help...? In Logix5000, I am trying to convert float/real numbers to bcd. I used a TOD function to convert a binary to bcd. So if I...
Replies
3
Views
2,932
Back
Top Bottom