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 触发告警列表刷新(不同版本刷新机制看固件手册)。

两个坑:①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 검증 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 주소 will not be published. Required fields are marked *.