~ubuntu-branches/ubuntu/raring/pymodbus/raring-proposed

« back to all changes in this revision

Viewing changes to examples/contrib/serial-forwarder.py

  • Committer: Package Import Robot
  • Author(s): Thomas Bechtold
  • Date: 2012-10-27 12:55:45 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20121027125545-60e94bpztv8vx8om
Tags: 1.1.0-1
* New upstream release.
* debian/control: Add Thomas Bechtold to Uploaders.
* debian/watch: Use github tags for new releases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
'''
 
3
Pymodbus Synchronous Serial Forwarder
 
4
--------------------------------------------------------------------------
 
5
 
 
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).
 
9
'''
 
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
 
15
 
 
16
from pymodbus.datastore.remote import RemoteSlaveContext
 
17
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
 
18
 
 
19
#---------------------------------------------------------------------------# 
 
20
# configure the service logging
 
21
#---------------------------------------------------------------------------# 
 
22
import logging
 
23
logging.basicConfig()
 
24
log = logging.getLogger()
 
25
log.setLevel(logging.DEBUG)
 
26
 
 
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)
 
33
 
 
34
#---------------------------------------------------------------------------# 
 
35
# run the server you want
 
36
#---------------------------------------------------------------------------# 
 
37
StartServer(context)