VisualHMI warning parameter: {#0:num1.num2} placeholder and on_get_warning_param

freeFree Technical Resource

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

The alarm parameter allows the alarm text to be dynamically embedded with real-time register valuesEmbedded real-time register value- such as "1# Compressor Current Too High: Current 12.5A", rather than using rigid, fixed text. The system supports up to 4 independent parameter fields, each of which can be individually configured with a display format (leading spaces for integer digits, and zero padding for decimal places). The alarm content is automatically concatenated. Applicable to HMI&M series & Dx series.

1. API: on_get_warning_param(warning_id)

After enabling "Alarm Parameter" in the engineering alarm settings, the system automatically calls this callback when displaying alarm details. The parameter warning_id is the unique identifier for the alarm, distinguishing business logic by ID. It returns up to 4 numerical/status parameters:

Return ValueRequiredPurpose
data0NoFill in {#0:num1.num2} in the alarm settings, or fill in p0 of on_parse_warning with {#1:num1.num2}, or fill in p1 of on_parse_warning with {#2:num1.num2}, or fill in p2 of on_parse_warning with {#3:num1.num2}, or fill in p3 of on_parse_warning
data1NoFill in the value of {#1:num1.num2}, or p1 in on_parse_warning
data2NoFill in {#2:num1.num2}, or p2 for on_parse_warning
data3NoFill in {#3:num1.num2}, or p3 in on_parse_warning

2. Alarm content format: {#data:num1.num2}

When writing alarm content in the alarm settings, the parameter placeholders should follow this format:

FieldMeaningExample
dataAlarm parameter ID, up to 4, starting from 0{#0:2.2} Use data0
num1Number of leading spaces for integersnum1=2: The value 12.5 is displayed as ' 12.5' (2 leading spaces)
num2Number of decimal places, padded with zerosnum2=2: The value 12.5 is displayed as "12.50"

Example: The alarm content is written as "1# Compressor Current Too High: {#0:2.2}A", and data0 returns 12.5, which is displayed as "1# Compressor Current Too High: 12.50A".

VisualHMI warning parameter: {#0:num1.num2} placeholder and on_get_warning_param插图

3. Application Case: Current/Temperature Alarm with Parameters

3.1 Screen Configuration

Alarm Display Control: Alarm Mode = Historical Alarms, Time Sequence, Display Date and Time, Time First, Column Width Ratio 20;

Two bit status indicator lights trigger/clear alarms: read addresses LW1000.0 and LW1000.1, and switch the switch type.

Four numeric controls simulate alarm parameters: read addresses LW1001~LW1004, enable input.

3.2 Lua: Return parameters by alarm ID

The meaning of {#0:2.2} in the alarm content is that data0 needs to be displayed at a scale of 1/100 (the value stored in the register is the value magnified by 100 times). Therefore, divide by 100 in the callback:

function on_get_warning_param(warning_id)
  if warning_id == 0 or warning_id == 1 then   -- 告警ID 0 或 1
    local data0, data1, data2, data3 = 0, 0, 0, 0
    data0 = get_uint16(VT_LW, 0x1001) / 100   -- 放大100倍存储,除以100还原
    data1 = get_uint16(VT_LW, 0x1002) / 100
    data2 = get_uint16(VT_LW, 0x1003) / 100
    data3 = get_uint16(VT_LW, 0x1004)         -- 这个不缩
    return data0, data1, data2, data3
  end
end

Run the virtual screen, enter 1250 for LW1001 via the keyboard, trigger alarm 0, and the {#0:2.2} in the alarm content displays 12.50 - all the scaling and conversion are done in the callback, so the display side does not need to process it further.

Three key points:The placeholder format must be in the format of {'data:num1.num2'}, data starts from 0 and can have up to 4 entries. If the format parameter is written incorrectly, it will not be displayed;② num1 is the number of integer digits before the decimal point, not the number of integer digits;—— only use if you want right alignment; if not needed, write 0;③ num2 is the number of decimal places padded with zeros;The engineering value stored in the register is magnified by 10/100 times. Remember to divide it back in the callback. This callback and on_parse_warning are two separate mechanisms: on_get_warning_param only fills in numerical parameters, while on_parse_warning is used to customize the entire warning text.

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