How to convert float to real in MODBUS TCP
We are reading the 2 register with uint data type.
with register address %IW10#XX.
tried to use the function uint_to_real but not matching with the actual value.
Could any one help in this regards
Answers
You can use Words_To_Real Function Block It converts two seperare words regirter to real value.
Hope it helps you.
For this purpose, normally IEE754 Library is to be used. You can also use the below document to create your own functional block which can be used in your program.
https://forum-controlsystems.abb.com/...
*Parameter*
LSBDint dint retain in yes 0
MSBDint dint retain in yes 0
OutReal real retain out yes 0
*Variables*
In1 boolean16 retain
In2 boolean16 retain
Out11 boolean16 retain
Out12 boolean16 retain
Out21 boolean16 retain
Out22 boolean16 retain
Byte1 dint retain
Byte2 dint retain
Byte3 dint retain
Byte4 dint retain
S1 dint retain
S2 dint retain
S3 dint retain
S4 dint retain
S5 dint retain
S6 dint retain
*Code*
DIntToBool16( Int := LSBDint,
BoolStruct => In1,
Status => S1);
DIntToBool16( Int := MSBDint,
BoolStruct => In2,
Status => S2);
Out11.B0 := In1.B0;
Out11.B1 := In1.B1;
Out11.B2 := In1.B2;
Out11.B3 := In1.B3;
Out11.B4 := In1.B4;
Out11.B5 := In1.B5;
Out11.B6 := In1.B6;
Out11.B7 := In1.B7;
Out12.B0 := In1.B8;
Out12.B1 := In1.B9;
Out12.B2 := In1.B10;
Out12.B3 := In1.B11;
Out12.B4 := In1.B12;
Out12.B5 := In1.B13;
Out12.B6 := In1.B14;
Out12.B7 := In1.B15;
Out21.B0 := In2.B0;
Out21.B1 := In2.B1;
Out21.B2 := In2.B2;
Out21.B3 := In2.B3;
Out21.B4 := In2.B4;
Out21.B5 := In2.B5;
Out21.B6 := In2.B6;
Out21.B7 := In2.B7;
Out22.B0 := In2.B8;
Out22.B1 := In2.B9;
Out22.B2 := In2.B10;
Out22.B3 := In2.B11;
Out22.B4 := In2.B12;
Out22.B5 := In2.B13;
Out22.B6 := In2.B14;
Out22.B7 := In2.B15;
Bool16ToDInt( BoolStruct := Out11,
Int => Byte4,
Status => S3 );
Bool16ToDInt( BoolStruct := Out12,
Int => Byte3,
Status => S4 );
Bool16ToDInt( BoolStruct := Out21,
Int => Byte2,
Status => S5 );
Bool16ToDInt( BoolStruct := Out22,
Int => Byte1,
Status => S6 );
BytesToReal( Byte1 := Byte1,
Byte2 := Byte2,
Byte3 := Byte3,
Byte4 := Byte4,
Float => OutReal );
Add new comment