Search code examples
plcstructured-text

Getting values from energy meter to Schneider PLC


I am trying to read the values from an energy meter, and convert them to REAL (32bit float). In this case I am reading phase 1 voltage. Each value is read across two registers. So I have received to WORDS of values 17268 (MSW) and 2456 (LSW) converted them into a DWORD, and then to a REAL value after multiplying by 0.1, but I am not getting the answer I'm expecting. I should be getting 245.0375 volts. However I am getting 1.13E+08 Please see snip of structured text with live values. snip


Solution

  • The problem is that DWORD_TO_REAL is trying to do a type conversion; that is, make the value of a DWORD match the format of a REAL. In your case, the contents of MSW and LSW are simply a IEEE754 value split in half and just need to be forced into the corresponding bits of a REAL variable. With TwinCAT (Beckhoff) I would do a direct memory copy:

    MEMCPY(ADR(realValue)+2, ADR(MSW), 2);
    MEMCPY(ADR(realValue), ADR(LSW), 2);
    

    I would assume Schneider has a similar command.