Using Pymodbus, I want to tie coil states to GPIO pins within my server not from a client

215 Views Asked by At

I am writing a PyModbus asynchronous updating server based on the example on the Pymodbus Asynchronous Server Example and I want to link the states of the coils to GPIO pin states, such as when coil 1 is True pin 21 is high and when coil 1 is False pin 21 is low without having a separate client check the coil status. Is it possible to link the coil directly to the pins? I am using a PI Zero for this project.

If you want to look at my code here the link to my git. I know the value are stored in a variable. I am not sure where I can pull them from to link them to the pins and have them regularly get updated.

1

There are 1 best solutions below

0
On

I was using the getValue command wrong before.

Within the updating_writer I used:

coils = context[slave_id].getValues(function,register,amount)

doing this I can now set a conditional statement to change the GPIO pins.