VisualHMI 告警过滤:on_filter_warning 多デバイス告警分流

freeFree Technical Resource

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

告警过滤回调 on_filter_warning(warning_id)(定制固件专属):决定某条告警表示まだ不表示。戻る 0 不表示、1 表示。典型场景:一台 HMI 管理两台デバイス,device 1 的告警(ID 1~100)在画面 0 看,device 2 的告警(ID 101~200)在画面 2 看——不靠过滤就得建两套告警。

1. 有効过滤

on_init 里置位有効:

function on_init()
  set_uint16(VT_LW, 0x0115, 1)   -- 有効告警过滤
end

function on_filter_warning(warning_id)
  local cur = get_uint16(VT_LW, 0x0114)   -- 当前画面/デバイス号
  if cur == 0 then
    return (warning_id >= 1 and warning_id = 101 and warning_id <= 200) and 1 or 0
  end
  return 1
end

2. 结合 warning_set 分发

多スレーブ场景:告警データ从 Modbus 读回来,用 warning_set 批量触发,过滤回调只放行当前デバイス相关的:

-- 读回告警后逐个触发
function on_cmd_resp(slave, vtype, addr, count, ret, wr)
  ...
  for j = 0, 15 do
    local bitv = (val >> j) & 0x01
    warning_set(idx + slave * 100, bitv, 1)   -- デバイス号编码进告警ID
  end
end

-- 过滤:只表示当前选中デバイス的告警
function on_filter_warning(warning_id)
  local dev = get_uint16(VT_LW, 0x0114)      -- 当前デバイス号
  local wdev = math.floor(warning_id / 100)  -- 告警所属デバイス
  return (wdev == dev) and 1 or 0
end

リフレッシュ表示:切换デバイス后往 0x0114 写 0x0022 触发告警リストリフレッシュ(不同版本リフレッシュ机制看固件手册)。

2つ坑:①on_filter_warning 戻る 0 是非表示、1 是表示,别写反;②过滤和告警控件是連動关系——过滤只影响表示,告警データ本身还在,切换条件后要主动リフレッシュリスト才能看到变化。

整理自 广州大彩科技 VisualHMI 开发ドキュメント(hmi-doc.gz-dc.com)LUA Tutorial「告警过滤」,著作権は大彩科技すべての。

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