PymateIO-HMI-numeric-input: Difference between revisions

From pymate.io wiki
Jump to navigation Jump to search
Line 40: Line 40:
The Pymate script just need to declare the '''on_set_cb''' for the '''HREGS''' register definition to catch the call.
The Pymate script just need to declare the '''on_set_cb''' for the '''HREGS''' register definition to catch the call.


<syntaxhighlight lang="python" line>
# Registers and their default values
# Registers and their default values
slave_registers = {
slave_registers = {

Revision as of 18:52, 14 June 2026


Abstract

After our first example with the HMI Display and PymateIO it is time to look for some advanced feature.

02-edit-value.jpg

This example will show how Pymate script will grab the integer value sent by the HMI display.

Just press the field on the HMI Display to encode the new value

HMI Example Project

The demonstration script is still based on the "HMI_PyMateIO_Modbus_MASTER.skm" project introduced in HMI Display and PymateIO tutorial.

Attentive reader would have noticed a slightly difference between the numeric fields:

  • The 4x1 field is a "Numeric display" only
  • The 4x0 field is a "Numeric Input" field where the user can encode some value.

02-01.png

With the following field definition

PymateIO-HMI-01-03.png

Pymate Script

Entering a value on the HMI display will issue a function 6 ModBus request.

Capturing the modbus_slave debug message put this in evidence.

Modbus: HREGS READ <Request fct=3 qty=2 addr=0 data=None>
Modbus: COILS READ <Request fct=1 qty=8 addr=0 data=None>
Modbus: HREGS WRITE <Request fct=6 qty=None addr=0 data=bytearray(b'\x01,')>
Modbus: HREGS READ <Request fct=3 qty=2 addr=0 data=None>

The Pymate script just need to declare the on_set_cb for the HREGS register definition to catch the call.

# Registers and their default values
slave_registers = {
    "COILS": {
        ....
    },
    "HREGS": {
        "4x fields": {
            "register": 0,
            "len": 2,
            # 1st-> 4x0 field = 65280 ; 2nd-> 4x1 field = 1 
            # Values must be uint16 0-65535
            "val": [0xFF00,1 ], 
            "on_get_cb" : get_counters,
            "on_set_cb" : set_counter
        }
    },
    "ISTS": {        
    },
    "IREGS": {
    }
}




PymateIO all right reserved © 2026 - Written by MCHobby for PymateIO