Join us today!
Converting REAL to 2 WORDS
Some of the Modbus configurations only accept WORD type variables. If you need to convert a REAL value to 2 WORDS, you can use UNION data type to achieve this easily. Different data types in the UNION share the same memory space.
Create a DUT called ST_REAL_TO_aWORD:
TYPE ST_REAL_TO_aWORD: UNION fREAL : REAL; aWord : ARRAY[1..2] OF WORD; END_UNION END_TYPE
Declare the variables in your program:
fRealValue : REAL := 0.81; stData : ST_REAL_TO_aWORD;
You will see that the REAL value is converted to 2 WORDS automatically in the UNION type.
You can also apply this method to other data conversions (BYTE to REAL, INT to BITS, WORD to BYTE etc...) as well.
In case you want to say thank you !)
We'd be very grateful if you could share this community with your colleagues and friends. You can also buy us a coffee to keep us fueled 😊 This is the best way to say thank you to this project and support your community.
twinControls - https://twincontrols.com/
-
Multi-line editing in TwinCAT
2 years ago
-
Local Enumeration Declaration
2 years ago
- 17 Forums
- 265 Topics
- 932 Posts
- 2 Online
- 689 Members