Visual HMI Modbus One Masterマルチスレーブ:start_readポーリング、サイクルスケジューリング、および読み書きスレーブ

freeFree Technical Resource

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

Modbus One Masterマルチスレーブ:HMIはModbusホストとして機能し、start_readバックグラウンドを介して複数のスレーブレジスタをポーリングします。コア関数start_readbuild、get_xxxリードキャッシュ、on_cmd_resp結果-スクリプトをブロックしません。

1. start_readパラメータ

start_read(index, vtype, addr, quantity, cycle, cycle_run, mode)
パラメータ説明書は
indexタスクインデックス0~127、_read index
vtypeレジスタの(VT_0x/VT_3x/VT_4xなど)
addrアドレスの開始
quantity読み出し数1~120レジスタ
cycle選択、ポーリングサイクル倍数(デフォルト0=サイクルごとに読み取られる)
cycle_runオプション、サイクル内で何回目に実行されるか(0ベース、サイクルが必要)
modeオプション、0=連続読み取り(デフォルト)/1= 1回のみ読み取り(create_resp_queが必要)

2.基本的な用法

function on_init
  --スレーブ0の4 x 1000~ 100 9(10レジスタ)をサイクルごとに読み取る。
  start_read 0、VT_4x、0x1000、10
  --スレーブ1の4 x 2000~2009を3サイクルごとに読み取り、サイクル内で3回目の実行
  start_read 1、VT_4x、0x2000、10、3、2
End of Endシングル

function on_run screen
  - データを直接キャッシュに読み取り、Communicationオーバーヘッドゼロ
  local v = get_uint16 VT_4x、0x1000
  local f = get_float VT_4x、0x2000
End of Endシングル

start_readはタスクのみを構築し、実際のデータはget_xxxに依存してローカルキャッシュから読み取ります。レジスタOperationと同じメカニズムです。読み取り完了通知を受け取るには、on_cmd_respコールバック(create_resp_queを使用)を使用します。

3.マルチスレーブポーリングスケジュール

8 台のスレーブ、各20レジスタを読み取り、バスの混雑を避けるためにサイクルをずらします。
function on_init
  i = 0,7 do
    start_read i VT_4x 0x0000 20 8 i--8サイクルごとに1つずつ読み出す
  End of Endシングル
End of Endシングル

function on__resp slave vtype count ret wr
  if ret == 0 then
    --スレーブは正常に読み取り、データを処理します。
  elseさん
    --通信異常、フラグスレーブオフライン
  End of Endシングル
End of Endシングル

スレーブマシンはバス帯域幅が限られており、サイクル/サイクル/サイクル_runエラーピーク読み取りを使用しています。on_cmd_respの異常ret 非 0判定、オフラインフラグ。

3つの穴最大数は120。start_readを複数回実行する。cycle_runはcycleより小さいcycle_runは0からカウントされます。③ stop_readタスクの停止後にキャッシュが最後の値を保持オフラインはon_cmd_respのretに依存します。

広州大彩科技Visual HMI開発ドキュメント(hmi-doc.gz-dc.com)からのLUAチュートリアル“Modbus One Master Multipared”、著作権は大彩科技に帰属します。

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 *.