Sharing registers between modbus masters

Topics about the Software of Revolution Pi
Post Reply
charlo
Posts: 1
Joined: 18 Nov 2020, 17:11
Answers: 0

Sharing registers between modbus masters

Post by charlo »

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
User avatar
dirk
KUNBUS
Posts: 1942
Joined: 15 Dec 2016, 13:19
Answers: 4

Re: Sharing registers between modbus masters

Post by dirk »

Hi Marc, this is an interesting requirement.
I have understood your requirement looks like this:

Code: Select all

[Modbus TCP Slave] - [Modbus TCP Master] - [Modbus TCP Master] - [Modbus TCP Slave]
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:

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)

	
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:

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)
Post Reply