PymateIO-HMI-numeric-input: Difference between revisions

From pymate.io wiki
Jump to navigation Jump to search
Line 26: Line 26:
Just press the field on the HMI Display to encode the new value
Just press the field on the HMI Display to encode the new value


[[File:02-edit-value.jpg|800px]]


Entering a value will issue a function 6 ModBus request.
== 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.


  <nowiki>Modbus: HREGS READ <Request fct=3 qty=2 addr=0 data=None>
  <nowiki>Modbus: HREGS READ <Request fct=3 qty=2 addr=0 data=None>
Line 35: Line 38:
Modbus: HREGS READ <Request fct=3 qty=2 addr=0 data=None>
Modbus: HREGS READ <Request fct=3 qty=2 addr=0 data=None>
</nowiki>
</nowiki>
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": {
    }
}
</syntaxhighlight>


{{PYMATE-TRAILER}}
{{PYMATE-TRAILER}}

Revision as of 18:51, 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.

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

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


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.

  1. 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": {
   }

} </syntaxhighlight>




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