Beckhoff: Questions about Data Types for Modbus?

FNC

Member
Join Date
May 2010
Location
NJ
Posts
84
I am using a Beckhoff PLC and trying to convert a REAL to 2 WORDS to send over Modbus.

Does anyone know how to do this?

Also how would I convert 2 WORDS to a REAL if I am reading over Modbus?

Since the data types is WORD how would I send a negative # like -123?
WORD is 0 to 65525 as opposed to an integer that is -32768 to 32767.
 
do a search on this forum for the terms

  • modbus
  • 32-bit real
  • 16-bit word
The sign of the real is carried in a single bit of the the 16-bit word, so if you copy the bits from REAL to WORDs and back again, that will take care of itself.

If you can envision the two contiguous 16-bit registers as one 32-bit entity, then the guts of what you want to do are more or less explained here: https://en.wikipedia.org/wiki/Single-precision_floating-point_format#IEEE_754_standard:_binary32

The trick on either end is to copy the 32 bits themselves, not the WORD or REAL values.

Bottom line: on the Beckhoff/TwinCat side you want to use a Union, so the REAL bits overlay the two WORDs' bits. What to do on the other end of the Modbus pipe depends on the data manipulation tools at that other end.

Also, you may or may not need to swap the words. You should not need to swap bytes within the word as proper Modbus libraries will handle that for you, but beware that not every published Modbus library is proper; cf. items (i) and (vii) below.
 
Last edited:
For reading over modbus, here is an example FB that I created and usage of it. The FB takes as input two integers and outputs a real. The endianess of the real can be changed by whatever order you assign the two integers as hi, lo.

The second picture is using the FB. You can see that I am feeding the FB two integers that are array elements. The values in the array are read via modbus from another plc.

Beckhoff_FB_IntsToReal.PNG ConvertIntsToReal.PNG
 
And here is a FB to take 1 real and output two integers. You can see in the example I am using the FB to first convert the integers read from an outside PLC and output a real. I then put that real into the FB to convert to integers. The integers are the same going into the first FB as coming out of the second.

Beckhoff_FB_RealToInts.PNG ConvertRealToInts.PNG
 

Similar Topics

Hello Long time lurker. I am flailing around trying to figure out how to implement MODBUS TCP on a W2000 IPC that controls one of my company's...
Replies
10
Views
5,886
I would be using Beckhoff EL1002 Digital input module for my EMO switch. Attached is the connection details of the same. I presume that the 24V DC...
Replies
5
Views
2,832
I would be using Beckhoff EL1002 Digital input module for my EMO switch. Attached is the connection details of the same. I presume that the 24V DC...
Replies
0
Views
1,672
Hi. I started a tread about CoDeSys, but my interest is narrowing down to Beckhoff. Thats why I start a new thread. So far I have these...
Replies
31
Views
19,205
Hi everyone, This is my first time posting, so please forgive any omissions or mistakes. I am attempting to control the velocity of a stepper...
Replies
18
Views
1,018
Back
Top Bottom