Visual HMIタイマー:start_timer/on_timerとカウントダウンの完全なケース

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

Visual HMIのLuaサポート32のソフトウェアタイマー(インデックス0 - 31)起動後のタイムアウトのトリガーon_timer(timer_id)コールバック、定期的なタスク、遅延操作、ステータスポーリングを行う。↓️これはアプリケーション層ソフトウェアタイマシステム負荷の影響を受け、ハードリアルタイム制御にはしない

1. APIの概要

関数の機能パラメータ説明書は
start_timer(timer_id, timeout, countdown, repeat)timeoutミリ秒(最小10~20ミリ秒);countdown 0=連続時間/1=カウントダウン;repeat 0=無限反復/N= N回トリガー後に自動的にStopタイマーの起動。
stop_timer(timer_id)タイマー ID。直ちにStopする。
on_timer(timer_id)タイムアウト·コールバック統合ポータルtimer_idによる同時タイマーの区別
get_timer_value(timer_id)タイマー ID。現在のタイミング値(ms)を取得し、順/カウントダウンをサポート

countdownパラメータ内部タイミング表示/デバッグのみに影響on_timerのトリガ動作を変更せずに、タイムアウトトリガーにカウントダウンし、タイムアウトから0トリガーにカウントダウンし、コールバックはすべて同じです。

2.基本的な用法

function on_init
  start_mer 0 1000 0 0   -1秒周期、無限反復
  start_mer 1 5000 1 1   5秒のカウントダウン、1回だけトリガー
End of Endシングル

function on_mer mer_id
  if timer_id == 0 then
    毎秒1回実行:ステータスポーリング
  elseif timer_id == 1 then
    5秒後に実行します。
  End of Endシングル
End of Endシングル

3.アプリケーション:カウントダウン完了後のPLCへの指示

要求:設定時/分後にカウントダウン、カウントダウン終了リセットボタンとマザーボードへの指示。制御レイアウト:ビットステータスインジケータLW1002(トグルスイッチ)が開始とStopを制御します。スクロールホイールコントロールLW1000(時間、0~23)、LW1001(min)は時間を設定します。テキストコントロールLW1010はカウントダウンを表示します。

_ER_REPEAT_ = 0     合計時間(秒)
_ER__ = 0        --トリガーされた回数

function on_update slave vtype
  vtype == VT_LWとaddr == 0 x 1002の場合
    if get_uint16 VT_LW、0x1002 == 1 and_TIMER_REPEAT_0 then
      _
      start_mer 0 1000 0_ER_REPEAT_--1秒に1回、repeat回
    elseさん
      stop_timer 0
    End of Endシングル
  End of Endシングル
End of Endシングル

function on_mer mer_id
  if timer_id == 0 then
    _ER__=_ER__1
    local remain = _ER_REPEAT_ - _ER__
    --タイムバランスmm ssを表示
    set_string VT_LW、0x1010、
      string.format " % 02d % 02d" math.floor remain / 60 remain % 60
    if remain === 0 then
      set_uint16_LW、0x1002、0x00   --開始ボタンをリセットする
      set_uint16 VT_LW、0x1003、0x01   - ボードに指示を出す
    End of Endシングル
  End of Endシングル
End of Endシングル

ポイント:_TIMER_REPEAT_は、ユーザが設定した時間(時間 * 36 00+min *60)で計算されます。start_timerの総反復回数は、on_timerが_TIMER_CNT_を加算するたびに終了します。set_notify 0/1は、タイマー中に命令通知を発行するかどうかを制御し、1を発行する必要があります。

3つの穴ソフトウェアタイマ精度はシステム負荷の影響を受けるハードリアルタイム制御を行う。タイムアウト最小10~20ms1ミリ秒の期待を送信しないでください。repeat=N回トリガーすると自動的にStopする無限ループで0を送信するには、複数のタイマが同時にexistenceする場合はtimer_idで区別され、on_timerは統一エントリです。

Guangzhou Dai Technology Visual HMI開発ドキュメント(hmi-doc.gz-dc.com)LUAチュートリアル“タイマー”、著作権はDai Dai Technologyにあります。

Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.