brainelectronics / micropython-modbus

MicroPython Modbus RTU Slave/Master and TCP Server/Slave library
GNU General Public License v3.0
104 stars 45 forks source link

Raspberry Pico Modbus TCP IO Device #66

Closed cprobotik closed 1 year ago

cprobotik commented 1 year ago

Description

Iam New with micropython and the Raspberry Pico W and i would like to create a Modbus TCP IO Divice for a PLC on an Raspberry Pico W I would read some GPIO to send they over Modbus TCP to the Modbus Master

Can someone show me an code example to fix my problem.

Thank you so much

Reproduction steps

1.install Micropython an Modbus on Raspberry was okay 2.I use the Thonny IDE and I can run the TCP Client Example on the Raspberry Pico

  1. but I down know how can I send GPIO Data to the Modbus Master
  2. I need a example for send A Bool GPIO value (coil)
  3. I need a example for send A ADC value (holding register)

MicroPython version

v1.19.1

MicroPython board

Raspberry Pico

MicroPython Modbus version

v2.3.3

Relevant log output

No response

User code

No response

Additional informations

No response

beyonlo commented 1 year ago

@cprobotik Here there are all examples. As your PICO-W will be the Modbus TCP Slave, you can to follow this example: tcp_client_example.py

About to serve a GPIO and/or an ADC on the Slave to the Master request it, you can use the amazing callback feature. In that example above, there is a function def my_inputs_register_get_cb(reg_type, address, val): that does exactly what you want. And doc about callback feature you can found here

cprobotik commented 1 year ago

Thank you for your answer, the callback Funktion works great.

The examples you have given are perfekt.

Thank you for the Professional Code.

brainelectronics commented 1 year ago

@cprobotik may you close this issue if your request has been resolved?