0

I am using a Wago 750 PLC, actually I am reading thru ModBus a 32bit register from other device and I saving the value into a var POINT TO REAL, in this specific case the value is 0000 40A0. I am inverting MSW and LSW to have 40A0 0000 (IEEE 754) with in decimal is 5.0. My problem is that I don't know how to format this POINTER TO REAL into a REAL variable with CODESYS for converting it in a STRING.

Thanks in advance.

  • can you post the code you have where you are inverting the MSW and LSW and any attempts you have tried with converting to string? – mrsargent Feb 24 '16 at 14:33

1 Answers1

0

Omitting the logic for swapping words below is how you would converter your POINTER TO REAL to a REAL for converting to a STRING

VAR
   realVal:REAL:=5.0;
   pRealVal:POINTER TO REAL;
   newReal:REAL;
   someString:STRING;
END_VAR

(*save real value to pointer *)
pRealVal:=ADR(realVal);

(*dereference the pointer to some other real value *)
someOtherReal:=pRealVal^;

(*convert real value to string *)
aString:=REAL_TO_STRING(someOtherReal);

the key is the ^ which is what dereferenced the pointer.

mrsargent
  • 2,267
  • 3
  • 19
  • 36