VisualHMI warning filtering: on_filter_warning multi-device warning distribution

freeFree Technical Resource

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

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
end

2. 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
end

Refresh 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).

Two Pitfalls:①on_filter_warning returns 0 for hiding and 1 for displaying, don't write them inversely;② The filtering and alarm control components are interrelated.- Filtering only affects the display, while the alarm data itself remains unchanged. After switching conditions, you need to actively refresh the list to see the changes.

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.

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