VisualHMI alarm parameter (Lua): on_parse_warning concatenates p0~p3 dynamic text

freeFree Technical Resource

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

Alarm parameter callbackon_get_warning_param(warning_id)to solve a problem:The alarm content should include real-time values. For example, "Temperature too high: current 85.5℃" - the alarm text is a template, and the numbers are generated at runtime. The callback returns up to 4 parameters (data0~data3), which are filled into the placeholder {#N:num1.num2} in the alarm settings.

1. Placeholder format: {#data:num1.num2}

In the alarm settings, the alarm content can be written as:

温度过高:{#0:2.2} ℃
FieldMeaning
dataParameter ID, starting from 0, up to 4 (data0~data3)
num1Number of spaces before the integer (for alignment)
num2Zero-padding in decimal places

Example: {#0:2.2} indicates that data0 displays 2 digits (padded with spaces before) + 2 decimal places (padded with zeros).

2. Callback implementation

function on_get_warning_param(warning_id)
  -- 返回最多 4 个参数
  local data0 = get_uint16(VT_LW, 0x1001) / 100   -- 缩小100倍:85.5 存的是 8550
  local data1 = get_uint16(VT_LW, 0x1002)
  local data2 = get_uint16(VT_LW, 0x1003)
  local data3 = get_uint16(VT_LW, 0x1004)
  return data0, data1, data2, data3
end

Temperature 85.5℃ is stored as 8550 in the register (magnified by 100 times), restored by dividing by 100 in the callback, and then formatted into the format of "#0:2.2" to display as "85.50".

3. Difference from on_parse_warning

on_get_warning_param is only responsible for returning numerical parameters, and the text template is configured in the alarm settings; whereasThe text template is configured in the alarm settings; on_parse_warning(id, text, screen_id, control_id, p0, p1, p2, p3) isfully takes over the generation of alarm text- returning (string, encoding), where encoding 1=GBK (recommended for Chinese screens) / 0=UTF-8. The two are mutually exclusive; if using parameter filling, do not use full takeover.

Three pitfalls:① The callback only takes effect for alarms with placeholders set to {#N:...}Alarms without placeholders will not be adjusted;② Up to 4 parameters(data0~data3), exceeding will not be displayed;③ Pay attention to units when scaling-- The register stores the amplified value, which must be restored in the callback, otherwise 8550 will be displayed instead of 85.50.

Compiled from Guangzhou Dacai Technology VisualHMI Development Documentation (hmi-doc.gz-dc.com) LUA Tutorial "Alarm Parameters", 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 *.