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} ℃| Field | Meaning |
|---|---|
| data | Parameter ID, starting from 0, up to 4 (data0~data3) |
| num1 | Number of spaces before the integer (for alignment) |
| num2 | Zero-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.
Compiled from Guangzhou Dacai Technology VisualHMI Development Documentation (hmi-doc.gz-dc.com) LUA Tutorial "Alarm Parameters", copyright belongs to Dacai Technology.
Leave a Reply