Hello,
I have been writing a program which reads values of reactive power from power analyser over Modbus RTU. Reactive power is represented by 32 bits while the MSb determine the sign. Program doesn't read the whole 32 bits instead of it reads two 16 bits words. After reading 32 bits I need to convert the value into REAL data type. So I wrote following conversion code in Structured text:
(structure stLovato_power contains in its items 16 bits words, which forms 32 bits representation of reactive power). It seems that reading is OK but something in the conversion is wrong. I still get 0 despite the values in iQ_HW and iQ_LW are nonzero. Can somebody tell me where I do a mistake? Thanks.
I have been writing a program which reads values of reactive power from power analyser over Modbus RTU. Reactive power is represented by 32 bits while the MSb determine the sign. Program doesn't read the whole 32 bits instead of it reads two 16 bits words. After reading 32 bits I need to convert the value into REAL data type. So I wrote following conversion code in Structured text:
Code:
rQs: REAL := 0.0;
rQs := DINT_TO_REAL(DWORD_TO_DINT((SHL(WORD_TO_DWORD(stLovato_power.iQ_HW),16) + WORD_TO_DWORD(stLovato_power.iQ_LW))))/100.0;