Alarm Filtering Callbackon_filter_warning(warning_id)(Exclusive for Customized Firmware): Decides whether to display or not displaya certain alarm. Returns 0 for not displaying and 1 for displaying. Typical Scenario: One HMI manages two devices, with alarms (ID 1~100) of Device 1 viewed on Screen 0, and alarms (ID 101~200) of Device 2 viewed on Screen 2 - without filtering, two sets of alarms would have to be established.
1. Enable filtering by setting the bit in on_init:
Set the bit to enable in 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
end2. Combine with warning_set to distribute
in multiple slave scenarios: Alarm data is read back from Modbus and triggered in batches using warning_set, with the filtering callback only allowing those related to the current device:
-- 读回告警后逐个触发
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
endRefresh Display: After switching devices, write 0x0022 to 0x0114 to trigger a refresh of the alarm list (refer to the firmware manual for refresh mechanisms in different versions).
This content is adapted from the VisualHMI development documentation of Guangzhou Dacai Technology (hmi-doc.gz-dc.com), specifically the LUA tutorial titled "Alarm Filtering". The copyright belongs to Dacai Technology.
Leave a Reply