VisualHMI LUA alarm centralized management: batch triggering of warning_set and parsing by 8 slaves

freeFree Technical Resource

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

Alarm centralized management:warning_set(warning_id, value, count)Batch trigger alarms +on_parse_warningCustom alarm text. Typical scenario: HMI reads the fault bits of the slaves from Modbus and maps them bit by bit into alarms - 8 slaves, each with 96 alarms, all triggered by one command.

1. API overview

FunctionDescription
warning_set_mode(en)Global enable: 1=on/0=off
warning_set(warning_id, value, count)Bit mask batch trigger: The lower count bits of value correspond to alarms starting from warning_id (bit0→warning_id, count 1~16)
on_parse_warning(id, text, screen_id, control_id, p0, p1, p2, p3)Custom alarm text callback, returns (string, encode), encode 1=UTF-8/0=GBK

2. 8 slaves × 96 alarm cases

Architecture: 8 slaves, each reading 6 consecutive registers (16bit×6=96 bit alarms) starting from Modbus 4x1000. In on_init, create_resp_que, and in on_cmd_resp, call warning_set bit by bit for each slave and each register.

_warningTb = {}   -- 0x1000~0x1005 各 bit 的告警名

function on_init()
  set_auto_read(0)
  create_resp_que()
  -- 告警设置里预配 768 条(8 台 × 96)
end

function on_cmd_resp(slave, vtype, addr, count, ret, wr)
  if ret == 0 and wr == 0 then
    -- slave 从机,addr 起始,读回 count 个寄存器
    for i = 0, 5 do
      local val = get_uint16(vtype, addr + i)
      for j = 0, 15 do
        local bitv = (val >> j) & 0x01
        local wid = (addr - 0x1000) * 16 + j + slave * 100
        warning_set(wid, bitv, 1)     -- 单 bit 触发
      end
    end
  end
end

function on_parse_warning(id, text, screen_id, control_id, p0, p1, p2, p3)
  local slave_no = math.floor(id / 96) + 1   -- 从机号
  local msg_id = id % 96                      -- 消息 ID
  local name = _warningTb[0x1000 + math.floor(msg_id / 16)] or "未知告警"
  local msg = "从机"..slave_no.." : "..name
  return msg, 1      -- 1=UTF-8
end

Alarm ID encoding convention: slave number × 100 + bit sequence number, reversed during parsing. Alarm settings need to be preconfigured for all 768 entries, with the text dynamically generated using on_parse_warning (prefixed by the slave number), which is much more convenient than statically configuring 768 texts.

Three pits:① The low count bit of the value of warning_set corresponds to the alarm starting from warning_id, where bit0→warning_id and bit1→warning_id+1. Batch triggering a command can handle it;② The count range is 1~16, and if it exceeds, it should be split into multiple times;③ The return values of on_parse_warning are firstly the text and secondly the code(1=UTF-8/0=GBK). Don't use the wrong code for Chinese screens.

Compiled from Guangzhou Dacai Technology VisualHMI development documentation (hmi-doc.gz-dc.com) LUA tutorial "Centralized Alarm Management", 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 *.