Hello,
I want to set up a gateway betwen two networks which enables modbus communication. Another requirement is to do so through the web interface of revpi connect. On both sides (on both networks) I only have one slave and the gateway should periodically update one side with the registers of the other side. I think that by having two masters on the revpi who share their registers it could work out but I can't see how to do so.
Is it possible at all ? Is there a recommended way ? Being able to simply forward the modbus messages could work out as well, I can have one network hold a master.
Marc
Sharing registers between modbus masters
Re: Sharing registers between modbus masters
Hi Marc, this is an interesting requirement.
I have understood your requirement looks like this:
Just configure two Modbus TCP Masters so they will communicate with each slave.
Now comes the "glue" you just have to write some code that copies the Output data from Master A to Input data of Master B and vice versa.
With RevPiModIO Python library it would consist of just a few lines of code. Just an example to point you there:
But you could also use the raw method by just looking at the offsets via "piTest -d" and seek and write them, more or less like so:
I have understood your requirement looks like this:
Code: Select all
[Modbus TCP Slave] - [Modbus TCP Master] - [Modbus TCP Master] - [Modbus TCP Slave]
Now comes the "glue" you just have to write some code that copies the Output data from Master A to Input data of Master B and vice versa.
With RevPiModIO Python library it would consist of just a few lines of code. Just an example to point you there:
Code: Select all
#!/usr/bin/env python3
# BitMirror.py
# Mirror DIO channel 1 input to DIO channel 1 output
import revpimodio2
import time
rpi = revpimodio2.RevPiModIO(autorefresh=True)
while True:
rpi.io.O_1.value = rpi.io.I_1.value
time.sleep(0.02)
Code: Select all
#!/usr/bin/python3
import time
#LED ein- und ausschalten
f=open("/dev/piControl0","wb+",0)
while True:
f.seek(119)
f.write(b'1')
time.sleep(1)
f.seek(119)
f.write(b'0')
time.sleep(1)