本文目录
- 1. 1. on_filter_warning(warning_id)
- 2. 2. 案例:双设备告警分流
多设备告警要分流显示:设备 1 的告警只在”设备1列表”出现,设备 2 的只在”设备2列表”。用 on_filter_warning 按告警 ID 过滤。
1. on_filter_warning(warning_id)
一条告警被触发时系统调用,根据 warning_id 和当前画面 ID,返回 1(允许显示)或 0(不显示)。定制固件专属。
function on_filter_warning(warning_id)
local screen = get_cur_screen() -- 当前画面
if screen == 0 then
return (warning_id 100) and 1 or 0 -- 画面2只显示设备2告警
end
return 1
end

2. 案例:双设备告警分流
HMI 连 2 台设备(Modbus),读取各自告警:设备 1 告警 ID 1~100、设备 2 告警 ID 101~200。画面 0 显示设备 1 告警,画面 2 显示设备 2 告警。
初始化:
function on_init() set_auto_read(0) -- 脚本控制读取 create_resp_que() -- 队列发送 select_slave(0) start_read(1, VT_4x, 0x1000, 1) -- 读从机1告警 select_slave(1) start_read(2, VT_4x, 0x1000, 1) -- 读从机2告警 set_uint16(VT_LW, 0x0115, 1) -- 启用告警过滤 warning_set_mode(1) -- 启用脚本解析告警 end
解析(区分设备):
function on_cmd_resp(slave, vtype, addr, count, ret, wr)
if ret == 0 and wr == 0 then
if vtype == VT_4x and addr == 0x1000 and count == 1 then
select_slave(slave)
local val = get_uint16(VT_4x, 0x1000)
local base = (slave == 0) and 1 or 101 -- 设备1:1~16, 设备2:101~116
for i = 0, 15 do
warning_set(i + base, ((val >> i) & 0x01), 1)
end
set_uint16(VT_LW, 0x0114, 0x0022) -- 刷新告警
end
end
end
function on_parse_warning(warning_id, text, screen_id, control_id)
local curWarnMsg
if warning_id <= 100 then
curWarnMsg = "设备1 : " .. _warningTb[warning_id]
else
curWarnMsg = "设备2 : " .. _warningTb[warning_id % 100]
end
return curWarnMsg, 1
end

告警过滤依赖 LW0115 写 1 启用,忘了写过滤不生效。设备划分用 ID 区间(1~100 / 101~200),规划告警 ID 时留好余量。
整理自 广州大彩科技 VisualHMI 开发文档(hmi-doc.gz-dc.com)LUA 教程「告警过滤」,版权归大彩科技所有。
发表回复