Skip to content

Instantly share code, notes, and snippets.

@nbuchwitz
Created March 11, 2022 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbuchwitz/c170030ada9c14f994b34409dd907def to your computer and use it in GitHub Desktop.
Save nbuchwitz/c170030ada9c14f994b34409dd907def to your computer and use it in GitHub Desktop.
RevPi: Copy data from virtual modbus registers to gateway component
#!/usr/bin/env python3
import revpimodio2
def loop_function(ct):
# copy 5 input register from modbus to gateway
rpi.io.Gateway_Output_Word_1.value = rpi.io.Input_Word_1.value
rpi.io.Gateway_Output_Word_2.value = rpi.io.Input_Word_2.value
rpi.io.Gateway_Output_Word_3.value = rpi.io.Input_Word_3.value
rpi.io.Gateway_Output_Word_4.value = rpi.io.Input_Word_4.value
rpi.io.Gateway_Output_Word_5.value = rpi.io.Input_Word_5.value
# create revpimodio instance
rpi = revpimodio2.RevPiModIO(autorefresh=True)
# cleanup on ctrl + c
rpi.handlesignalend()
# register IOs (modbus register = WORD, gateway BYTE -> use 2 BYTE for 1 WORD)
# create 5 output words on gateway
rpi.io.Output_1.replace_io("Gateway_Output_Word_1", "h")
rpi.io.Output_3.replace_io("Gateway_Output_Word_2", "h")
rpi.io.Output_5.replace_io("Gateway_Output_Word_3", "h")
rpi.io.Output_7.replace_io("Gateway_Output_Word_4", "h")
rpi.io.Output_9.replace_io("Gateway_Output_Word_5", "h")
# cycle every 1000 ms (1 second)
rpi.cycletime = 1000
# run loop_function every cycle
rpi.cycleloop(loop_function)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment