【问题标题】:IEEE 754 Single precision to REAL CodesysIEEE 754 单精度到 REAL Codesys
【发布时间】:2016-02-24 00:14:02
【问题描述】:

我使用的是 Wago 750 PLC,实际上我正在通过 ModBus 从其他设备读取 32 位寄存器,并将值保存到 var POINT TO REAL 中,在这种特定情况下,值为 0000 40A0。我将 MSW 和 LSW 反转为 40A0 0000 (IEEE 754),十进制为 5.0。我的问题是我不知道如何使用 CODESYS 将此 POINTER TO REAL 格式化为 REAL 变量,以便将其转换为 STRING。

提前致谢。

【问题讨论】:

  • 您能否发布您在反转 MSW 和 LSW 的代码以及您尝试转换为字符串的任何尝试?

标签: plc codesys


【解决方案1】:

省略下面交换单词的逻辑是您如何将POINTER TO REAL 转换为REAL 以转换为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);

关键是^,这是取消引用指针的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-24
    • 2021-10-06
    • 2016-05-26
    • 2013-10-04
    • 1970-01-01
    • 2014-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多