Reading Floating point value from modbus slave

You could replace the two UINT channels by using a single REAL channel directly. As an example from register 3 this would then use registers 3 and 4 and combine those to a REAL value. This only works if the byte order is the same with the X20 CPU and the modbus slave.

If it is different then you need to take the two UINT values, change their byte order to match and combine these to a REAL variable in the code. An approach I use quite often is to put the UINT values to an array and then create a REAL pointer to the array.

Variables:

VAR
	UINTArray : ARRAY[0..1] OF UINT;
	realValue : REFERENCE TO REAL;
END_VAR

Code

PROGRAM _INIT
	UINTArray[0] := 59769;
	UINTArray[1] := 17142;
END_PROGRAM

PROGRAM _CYCLIC

	realValue ACCESS ADR(UINTArray);
	
END_PROGRAM

Result:
image

2 Likes