CODESYS 瀹炴垬锛氬疄鐜伴殢鏈烘暟鐢熸垚鍔熻兘-CODESYS璧勬簮涓嬭浇鍖-閰峰痉缃 - CoDeSys杞欢鏁欑▼涓嬭浇,CoDeSys宸ユ帶璧勮闂ㄦ埛
HSC6490-cn涓浗鍒堕狅紝涓浗鑺瘇
鏌ョ湅: 238|鍥炲: 1

CODESYS 瀹炴垬锛氬疄鐜伴殢鏈烘暟鐢熸垚鍔熻兘

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

    [LV.1]鍒濇潵涔嶅埌

    鍙戣〃浜 2024-9-6 08:49:50 | 鏄剧ず鍏ㄩ儴妤煎眰 |闃呰妯″紡

    寮曡█

    鍦ㄨ嚜鍔ㄥ寲鎺у埗绯荤粺涓紝闅忔満鏁扮敓鎴愬櫒甯哥敤浜庢ā鎷熸祴璇曘侀殢鏈洪夋嫨绛夊満鏅傛湰鏂囧皢閫氳繃涓涓畝鍗曠殑 CODESYS 鍑芥暟鍧楃ず渚嬶紝璁茶В濡備綍瀹炵幇涓涓彲閰嶇疆涓婁笅闄愮殑闅忔満鏁扮敓鎴愬櫒銆
    1   绋嬪簭璁捐鎬濊矾
    鎴戜滑鐨勭洰鏍囨槸鍒涘缓涓涓彲浠ュ湪鐗瑰畾鑼冨洿鍐呯敓鎴愰殢鏈烘暟鐨勫嚱鏁板潡銆傝鍑芥暟鍧楁帴鍙楄Е鍙戜俊鍙峰拰涓婁笅闄愬弬鏁帮紝杈撳嚭涓涓湪鑼冨洿鍐呯殑闅忔満鏁般備负浜嗙‘淇濋殢鏈烘э紝鎴戜滑灏嗕娇鐢ㄥ綋鍓嶆椂闂村垵濮嬪寲绉嶅瓙锛屽苟鍦ㄦ瘡娆¤Е鍙戞椂鏇存柊绉嶅瓙銆
    2   绋嬪簭浠g爜

    [AppleScript] 绾枃鏈煡鐪 澶嶅埗浠g爜
    FUNCTION_BLOCK PM_RandomNumber
    VAR_INPUT
      Trigger : BOOL; (* 涓婂崌娌胯Е鍙戜俊鍙 *)
        UpperLimit : REAL; (* 闅忔満鏁颁笂闄 *)
        LowerLimit : REAL; (* 闅忔満鏁颁笅闄 *)
    END_VAR
    VAR_OUTPUT
      RandomNumber : REAL; (* 杈撳嚭鐨勯殢鏈烘暟 *)
    END_VAR
    VAR
      LastTrigger : BOOL; (* 涓婁竴娆$殑瑙﹀彂淇″彿鐘舵 *)
      RandomSeed : DWORD; (* 闅忔満绉嶅瓙 *)
    END_VAR
    
    (*
    鐗堟湰璁板綍锛
    鐗堟湰          鏃ユ湡          浣滆
     V1         2024-3-09 
    *)
    
    // 鍒濆鍖栭殢鏈虹瀛
    IF RandomSeed = 0 THEN
        RandomSeed := TO_DWORD(TIME_TO_TOD(TIME())); // 浣跨敤褰撳墠鏃堕棿浣滀负绉嶅瓙
    END_IF
    
    // 妫娴嬩笂鍗囨部
    IF Trigger AND NOT LastTrigger THEN
        // 鐢熸垚 0 鍒 1 涔嬮棿鐨勯殢鏈烘暟
        RandomSeed := RandomSeed * 1664525 + 1013904223;
        RandomNumber := TO_REAL(RandomSeed MOD 10000) / 10000.0;
        
        // 缂╂斁鍒版寚瀹氱殑涓婁笅闄愯寖鍥
        RandomNumber := LowerLimit + RandomNumber * (UpperLimit - LowerLimit);
    END_IF
    
    // 鏇存柊涓婁竴娆$殑瑙﹀彂淇″彿鐘舵
    LastTrigger := Trigger;

    3   浠g爜瑙i噴

    杈撳叆杈撳嚭鍙橀噺
    Trigger锛氭帶鍒堕殢鏈烘暟鐢熸垚鐨勮Е鍙戜俊鍙枫俇pperLimit 鍜 LowerLimit锛氬畾涔夌敓鎴愰殢鏈烘暟鐨勮寖鍥淬俁andomNumber锛氳緭鍑虹粨鏋溿

    鍐呴儴鍙橀噺
    LastTrigger锛氱敤浜庢娴嬩俊鍙风殑涓婂崌娌裤俁andomSeed锛氱敤浜庣敓鎴愰殢鏈烘暟鐨勭瀛愩

    闅忔満鏁扮敓鎴愰昏緫
    鍒濆鏃讹紝浣跨敤褰撳墠鏃堕棿鍒濆鍖栭殢鏈虹瀛愩傚湪妫娴嬪埌瑙﹀彂淇″彿鐨勪笂鍗囨部鏃讹紝鏇存柊闅忔満绉嶅瓙骞剁敓鎴愰殢鏈烘暟銆傞殢鏈烘暟缂╂斁鑷虫寚瀹氳寖鍥村唴銆
    4   搴旂敤鍦烘櫙
    璇ラ殢鏈烘暟鐢熸垚鍣ㄥ彲浠ョ敤浜庢ā鎷熷姩鎬佽緭鍏ャ佸垱寤烘祴璇曠敤渚嬨佹垨鑰呭湪闇瑕侀殢鏈洪夋嫨鐨勫満鍚堛傞氳繃閰嶇疆涓婁笅闄愶紝鐢ㄦ埛鑳藉鐏垫椿鍦拌皟鏁磋緭鍑鸿寖鍥淬
    5   鎷撳睍鎬濊
    鍦ㄥ疄闄呭簲鐢ㄤ腑锛屽彲浠ヨ冭檻浣跨敤涓嶅悓鐨勯殢鏈虹瀛愮敓鎴愮畻娉曚互鎻愰珮闅忔満鎬,渚嬪锛歅LC鎵弿鏃堕棿锛孭LC寰幆璁℃暟鎴栧閮ㄦā鎷熼噺浼犳劅鍣紝濡傛俯婀垮害鍘嬪姏绛夈傝繕鍙互瀹炵幇瀵圭瀛愮殑澶栭儴璁剧疆鍔熻兘锛屼粠鑰屽湪涓嶅悓鐨勮繍琛屽満鏅腑瀹炵幇鍙噸澶嶇殑闅忔満搴忓垪銆
    6   寮婧愮増鏈鏄
    璇ョ▼搴忛伒寰紑婧愬師鍒欙紝浠讳綍浜洪兘鍙互浣跨敤銆佷慨鏀瑰拰鍒嗗彂姝や唬鐮併傚湪浣跨敤鍓嶅簲杩涜鍏呭垎鐨勬祴璇曪紝淇敼浠g爜鏃讹紝璇风鎸佸垎浜簿绁烇紝灏嗘偍鐨勬敼杩涘拰鎴愭灉杩涜鍒嗕韩锛屼互渚挎洿澶氫汉鍙楃泭銆
    鎬荤粨
    閫氳繃鏈枃鐨勪粙缁嶏紝鎴戜滑瀹炵幇浜嗕竴涓熀鏈殑闅忔満鏁扮敓鎴愬櫒锛屽苟鎺㈣浜嗗畠鐨勫簲鐢ㄥ満鏅拰鍙兘鐨勬嫇灞曟柟鍚戙傝繖涓哄湪 CODESYS 鐜涓疄鐜版洿澶嶆潅鐨勫姛鑳芥彁渚涗簡涓涓壇濂界殑璧风偣銆傚笇鏈涜繖鑳戒负鎮ㄧ殑椤圭洰甯︽潵甯姪銆

    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒
    鍥炲

    浣跨敤閬撳叿 涓炬姤

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

    鏈増绉垎瑙勫垯

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

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

    GMT+8, 2024-11-23 20:31 , Processed in 0.152666 second(s), 57 queries .

    閰峰痉缃

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

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