3
Pymodbus Synchronous Serial Forwarder
4
--------------------------------------------------------------------------
6
We basically set the context for the tcp serial server to be that of a
7
serial client! This is just an example of how clever you can be with
8
the data context (basically anything can become a modbus device).
10
#---------------------------------------------------------------------------#
11
# import the various server implementations
12
#---------------------------------------------------------------------------#
13
from pymodbus.server.sync import StartTcpServer as StartServer
14
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
16
from pymodbus.datastore.remote import RemoteSlaveContext
17
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
19
#---------------------------------------------------------------------------#
20
# configure the service logging
21
#---------------------------------------------------------------------------#
24
log = logging.getLogger()
25
log.setLevel(logging.DEBUG)
27
#---------------------------------------------------------------------------#
28
# initialize the datastore(serial client)
29
#---------------------------------------------------------------------------#
30
client = ModbusClient(method='ascii', port='/dev/pts/14')
31
store = RemoteSlaveContext(client)
32
context = ModbusServerContext(slaves=store, single=True)
34
#---------------------------------------------------------------------------#
35
# run the server you want
36
#---------------------------------------------------------------------------#