CODESYS鐨凢loat锛孌INT锛孌WORD鏁版嵁澶у皬绔浆鎹-CODESYS璧勬簮涓嬭浇鍖-閰峰痉缃 - CoDeSys杞欢鏁欑▼涓嬭浇,CoDeSys宸ユ帶璧勮闂ㄦ埛
HSC6490-cn涓浗鍒堕狅紝涓浗鑺瘇
鏌ョ湅: 61|鍥炲: 0

CODESYS鐨凢loat锛孌INT锛孌WORD鏁版嵁澶у皬绔浆鎹

[澶嶅埗閾炬帴]
  • TA鐨勬瘡鏃ュ績鎯
    寮蹇
    2017-11-20 22:07
  • 绛惧埌澶╂暟: 2 澶

    [LV.1]鍒濇潵涔嶅埌

    鍙戣〃浜 2024-11-5 22:23:25 | 鏄剧ず鍏ㄩ儴妤煎眰 |闃呰妯″紡
    鍦ㄥ拰瑗块棬瀛愭垨Modbus璁惧閫氳鏃跺鏄撻亣鍒板ぇ灏忕闂锛屼竴涓32浣嶇殑鏁版嵁浼氭媶鍒嗘垚4涓猙yte锛屽鏋滃彂閫佹柟鏄疉BCD锛屽垯鎺ユ敹绔彲鑳芥槸CDAB锛岃繖灏辨槸澶у皬绔棶棰樸 澶у皬绔湁寰堝绉嶈В娉曪紝渚嬪鍒涘缓鏁扮粍鍏宠仈姣忎竴浣嶃佸垱寤鸿仈鍚堜綋绛夛紝鍦ㄨ繖閲屾彁鍑轰竴涓緝绠鍗曠殑鍐欐硶锛1銆DINT绫诲瀷鐨勪氦鎹㈠ぇ灏忕锛濡傚浘锛
    155616o2pbiamjuoabwcpz.png


    FUNCTION SWAP : DWORD
    VAR_INPUT
            IN锛 DWORD;
    END_VAR
    VAR
    END_VAR


    SWAP:=SHL(IN,16) OR SHR(IN,16);
    璇ユ柟娉曞彧閫傜敤浜嶥WORD锛屽鏋滄偍浣跨敤鐨勫彉閲忔槸DINT鎴朢EAL锛屽垯澶栭儴杩橀渶瑕佽浆鎹紝渚嬪锛
    aa := DWORD_TO_DINT(SWAP(bb));
    cc := SWAP(DINT_TO_DWORD(dd));


    2銆Float绫诲瀷鐨勪氦鎹㈠ぇ灏忕锛岄渶瑕佸厛杞崲涓16杩涘埗锛岀劧鍚庝娇鐢―INT杞崲鐨勬柟寮忎氦鎹㈠ぇ灏忕浠ュ悗锛屽湪杞崲涓哄皬鏁濡傚浘锛
    155616qbnw5eubuen5qz5n.png 160056gx9drv4ul4lixc77.png

    TYPE DUT :
    UNION
            float:REAL;
            diDint锛 DINT;
            dwDword锛 DWORD;
    END_UNION
    END_TYPE


    FUNCTION 娴偣鏁拌浆鎹 : REAL
    VAR_INPUT
            IN:REAL;
    END_VAR
    VAR_OUTPUT
    END_VAR
    VAR
            indut锛 Dut;
            outdut锛 Dut;        
            outDword锛 DWORD;        
            tempDword锛 DWORD;        
    END_VAR


    indut.float:=IN;
    tempDword:=indut.dwDword;
    outDword:=SHL(tempDword,16) OR SHR(tempDword,16);
    outdut.dwDword:=outDword;
    娴偣鏁拌浆鎹:=outdut.float;


    3銆佹晥鏋滃鍥炬墍绀猴細
    155616clsheh3sssf3kkrk.png
    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒
    鍥炲

    浣跨敤閬撳叿 涓炬姤

    鎮ㄩ渶瑕佺櫥褰曞悗鎵嶅彲浠ュ洖甯 鐧诲綍 | 绔嬪嵆娉ㄥ唽 鏂版氮寰崥鐧婚檰

    鏈増绉垎瑙勫垯

    椤堕儴qrcode搴曢儴
    鍏虫敞閰峰痉缃戣闃呭彿锛岃幏鍙栨洿澶氳祫璁紒

    QQ|灏忛粦灞|鎵嬫満鐗|Archiver|閰峰痉璁哄潧 ( 鑻廔CP澶16065247鍙-1 )|缃戠珯鍦板浘

    GMT+8, 2024-11-23 17:05 , Processed in 0.147505 second(s), 62 queries .

    閰峰痉缃

    © 2001-2013 Hicodesys. 鎶鏈敮鎸 by 閰峰痉缃

    蹇熷洖澶 杩斿洖椤堕儴 杩斿洖鍒楄〃