VisualHMI 告警参数(Lua):on_parse_warning 拼接 p0~p3 动态文本

freeFree Technical Resource

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

告警参数回调 on_get_warning_param(warning_id) 解决一个问题:告警内容里要带实时数值。比如「温度过高:current 85.5℃」——告警文本是模板,数字是运行时的。回调返回最多 4 个参数(데이터0~데이터3),填入告警设置里的 {#N:num1.num2} 占位符。

1. 占位符格式 {#데이터:num1.num2}

在告警设置里,告警内容可以写成:

温度过高:{#0:2.2} ℃
field含义
데이터파라미터 ID,从 0 开始,最多 4 个(데이터0~데이터3)
num1整数位前置空格数(对齐用)
num2小数位补零数

例:{#0:2.2} 表示 데이터0 显示 2 位整数(不足前补空格)+ 2 位小数(不足补零)。

2. 回调实现

function on_get_warning_param(warning_id)
  -- 返回最多 4 个参数
  local 데이터0 = get_uint16(VT_LW, 0x1001) / 100   -- 缩小100倍:85.5 存的是 8550
  local 데이터1 = get_uint16(VT_LW, 0x1002)
  local 데이터2 = get_uint16(VT_LW, 0x1003)
  local 데이터3 = get_uint16(VT_LW, 0x1004)
  return 데이터0, 데이터1, 데이터2, 데이터3
end

temperature 85.5℃ 在寄存器里存 8550(放大 100 倍),回调里 /100 还原,再按 {#0:2.2} 格式化成「85.50」显示。

3. 与 on_parse_warning 的区别

on_get_warning_param 只负责返回数值参数,文本模板在告警设置里配;而 on_parse_warning(id, text, screen_id, control_id, p0, p1, p2, p3)完全接管告警文本生成——返回 (字符串, Coding),Coding 1=GBK(中文屏推荐)/0=UTF-8。两者互斥,用参数填充就别用全接管。

三个坑:①回调只对设置了 {#N:...} 占位符的告警生效,没占位符的告警不会调它;②参数最多 4 个(데이터0~데이터3),超了不显示;③缩放注意单位——寄存器存的是放大值,回调里必须还原,否则显示 8550 而不是 85.50。

整理自 广州大彩科技 VisualHMI 开发文档(hmi-doc.gz-dc.com)LUA Tutorial「告警参数」,版权归大彩科技所有。

Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC 검증 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 주소 will not be published. Required fields are marked *.