ngch
深圳工控小匠
级别: 网络英雄

精华主题: 0
发帖数量: 775 个
工控威望: 8895 点
下载积分: 1689 分
在线时间: 969(小时)
注册时间: 2009-09-30
最后登录: 2024-11-12
查看ngch的 主题 / 回贴
楼主  发表于: 2012-08-07 20:23
图片:
请教!
omron串行通信接收数据如何转换成浮点数
ASCII码:302E+3344=D300+D301=0.34
程序如何进行换算得到0.34
深圳工控小匠:
工业非标设备电气自动化控制
(深圳光明区、宝安区、龙华区、东莞长安)
QQ:357405496
jx_einstein
级别: 论坛先锋
精华主题: 0
发帖数量: 868 个
工控威望: 1047 点
下载积分: 2421 分
在线时间: 860(小时)
注册时间: 2010-01-09
最后登录: 2024-08-05
查看jx_einstein的 主题 / 回贴
1楼  发表于: 2012-08-10 17:39
写个块:
IF S_INT1<58 AND S_INT1>47 THEN
    S_INT1R:= INT_TO_REAL(S_INT1)-48.0;
    ELSE
    ;
END_IF;
IF S_INT1=46 THEN
    ZeroPoint:=1;
ELSE
    ;
END_IF;

IF S_INT2<58 AND S_INT2>47 THEN
    S_INT2R:= INT_TO_REAL(S_INT2)-48.0;
ELSIF S_INT2=46 THEN
    ZeroPoint:=2;
ELSE
    ;
END_IF;

IF S_INT3<58 AND S_INT3>47 THEN
    S_INT3R:= INT_TO_REAL(S_INT3)-48.0;
ELSIF S_INT3=46 THEN
    ZeroPoint:=3;
ELSE
    ;
END_IF;

IF S_INT4<58 AND S_INT4>47 THEN
    S_INT4R:= INT_TO_REAL(S_INT4)-48.0;
ELSIF S_INT4=46 THEN
    ZeroPoint:=4;
ELSE
    ZeroPoint:=14;
END_IF;

IF S_INT5<58 AND S_INT5>47 THEN
    S_INT5R:= INT_TO_REAL(S_INT5)-48.0;
ELSIF S_INT5=46 THEN
    ZeroPoint:=5;
ELSE
    ;
END_IF;

IF S_INT6<58 AND S_INT6>47 THEN
    S_INT6R:= INT_TO_REAL(S_INT6)-48.0;
ELSIF S_INT6=46 THEN
    ZeroPoint:=6;
ELSE
    ;
END_IF;

CASE ZeroPoint OF
    1:
     Value:=(S_INT2R*0.1+S_INT3R*0.01+S_INT4R*0.001+S_INT5R*0.0001+S_INT6R*0.00001)*1000.0;
     2:
     Value:=(S_INT1R*1.0+S_INT3R*0.1+S_INT4R*0.01+S_INT5R*0.001+S_INT6R*0.0001)*1000.0;
     3:
     Value:=(S_INT1R*10.0+S_INT2R+S_INT4R*0.1+S_INT5R*0.01+S_INT6R*0.001)*1000.0;
     4:
     Value:=(S_INT1R*100.0+S_INT2R*10.0+S_INT3R+S_INT5R*0.1+S_INT6R*0.01)*1000.0;
     5:
     Value:=(S_INT1R*1000.0+S_INT2R*100.0+S_INT3R*10.0+S_INT4R+S_INT6R*0.1)*1000.0;
     6:
      Value:=(S_INT1R*10000.0+S_INT2R*1000.0+S_INT3R*100.0+S_INT4R*10.0+S_INT5R)*1000.0;
ELSE
;
END_CASE;