PymateIO-HMI
After the Modbus basics let's learn how to use it with an HMI display like the HMI-043U2S.
For this the Pymate must act as a Modbus Slave since the HMI is working as a Modbus Master.
HMI Example Project
The HMI content is designed with the CommandHMI software. The software manages '.skm' project file that can be uploaded to the HMI.
The demonstration script is based on the "HMI_PyMateIO_Modbus_MASTER.skm" project.
It contains various controls starting with two "Numeric Display".
It also contains a "Bit Lamp" displaying the status of a bit stored on the Pymate.
Finally the "Bit Switch" have a LED controled by the HMI Display (when switch is pressed). Later, the LED is updated by the Pymate to confirm the actual on/off state on the Pymate
Pymate Script
The slave act as following:
- change the "Bit Lamp" state every 5 seconds.
- change the "Bit Switch" state (its LED) every 10 seconds.
- capture the "Bit Switch" on/off event and displays a message in REPL.
- display the number of milliseconds in the "Numeric Input" 4x1
- display the number of HMI Request in the "Numeric Input" 4x0
The modbus_slave.py script perform the following tasks:
- Declare the Modbus registers exposed by Pymate
- Implement the callback handlers attached to registers
- Pumps the Modbus messages in the MainLoop
Register declaration
The slave will declare its registers as follow:
- The both "numeric imput" fields are stored within a single HRegs register with double Integer. The master do reads two consecutive values from the same register.
- The both "Bit Switch" and "bit Lamp" do share the same byte register (8 bits) but at different bit position.
# Registers and their default values
slave_registers = {
"COILS": {
"0x bits": {
"register": 0,
"len": 8,
# WARNING: Bit 7 on left, Bit 0 on right
# bit 1 = LED; bit 0 = Btn LED
"val": [False,False,False,False,False,False,False,False],
"on_get_cb" : get_addr0_state,
"on_set_cb" : set_addr0_state
}
},
"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
}
},
"ISTS": {
},
"IREGS": {
}
}Note the entries on_get_cb and on_set_cb
PymateIO all right reserved © 2026 - Written by MCHobby for PymateIO






