fg71
Its a exiting world we are living in there simplicity make a mark in a big way. In the PLC world we think about HMI (Human Machine Interface) to visual data or be input to our plc program.
 
I like to show you how simple its to make a button in web UI that could perform a action for Modbus communication.
That is not so different from HMI or Scada application. The UI module I will use in this example are from NiceGUI.
 
You need: -> pip install pymodbus nicegui
 
The code need a IP to ModbusTcp Server that has PLC program with a input to activate output. You also need to set the ADDRESS for your Modbus client
 
In the Web UI there is button that perform action to trigger "button_action"
 
NiceGui Documentation: NiceGUI Documentation
 
The great thing about using NiceGUI it only use 3 line of code to make a buttom with action
 
Here is Python code
from nicegui import ui
from pymodbus.client import ModbusTcpClient
from time import sleep

def button_action():
    client = ModbusTcpClient("YOUR_IP", port=502)
    client.connect()
    client.write_coil(YOUR_ADDRESS, True)
    sleep(2)
    client.write_coil(YOUR_ADDRESS, False)
    client.close()

def main():
    ui.label("Start Button")
    ui.button("M1", on_click=button_action)
    ui.run()

if __name__ == "__main__":
    main()
 
If you have done everything correct you will have something like this in your web browser
 
[203128%2F9177277%2Fmceclip0]
Reply 1 0
kortenbach
Looks nice, but NiceGUI doesn't run in Micropython or circuitPython AFAIK, so you would need to add a PC or Raspberry Pi to your project to get a nice GUI going...
Reply 0 0
fg71
I'm not sure it would be any benefit if it was possible to port NiceGUI to MicroPython. You still need a second MCU or SBC to run your plc program.
On other hand you could use Raspberry Pi and do everything on that.
Reply 0 0
Reply