66The synchronous server is implemented in pure python without any third
77party libraries (unless you need to use the serial protocols which require
88pyserial). This is helpful in constrained or old environments where using
9- twisted just is not feasable . What follows is an examle of its use:
9+ twisted is just not feasible . What follows is an example of its use:
1010"""
11- # --------------------------------------------------------------------------- #
11+ # --------------------------------------------------------------------------- #
1212# import the various server implementations
13- # --------------------------------------------------------------------------- #
13+ # --------------------------------------------------------------------------- #
1414from pymodbus .server .sync import StartTcpServer
1515from pymodbus .server .sync import StartUdpServer
1616from pymodbus .server .sync import StartSerialServer
2020from pymodbus .datastore import ModbusSlaveContext , ModbusServerContext
2121
2222from pymodbus .transaction import ModbusRtuFramer , ModbusBinaryFramer
23- # --------------------------------------------------------------------------- #
23+ # --------------------------------------------------------------------------- #
2424# configure the service logging
25- # --------------------------------------------------------------------------- #
25+ # --------------------------------------------------------------------------- #
2626import logging
2727FORMAT = ('%(asctime)-15s %(threadName)-15s'
2828 ' %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s' )
3232
3333
3434def run_server ():
35- # ----------------------------------------------------------------------- #
35+ # ----------------------------------------------------------------------- #
3636 # initialize your data store
37- # ----------------------------------------------------------------------- #
37+ # ----------------------------------------------------------------------- #
3838 # The datastores only respond to the addresses that they are initialized to
3939 # Therefore, if you initialize a DataBlock to addresses of 0x00 to 0xFF, a
4040 # request to 0x100 will respond with an invalid address exception. This is
@@ -58,7 +58,7 @@ def run_server():
5858 # store = ModbusSlaveContext()
5959 #
6060 # Finally, you are allowed to use the same DataBlock reference for every
61- # table or you you may use a seperate DataBlock for each table.
61+ # table or you may use a separate DataBlock for each table.
6262 # This depends if you would like functions to be able to access and modify
6363 # the same data or not::
6464 #
@@ -85,20 +85,20 @@ def run_server():
8585 # will map to (1-8)::
8686 #
8787 # store = ModbusSlaveContext(..., zero_mode=True)
88- # ----------------------------------------------------------------------- #
88+ # ----------------------------------------------------------------------- #
8989 store = ModbusSlaveContext (
9090 di = ModbusSequentialDataBlock (0 , [17 ]* 100 ),
9191 co = ModbusSequentialDataBlock (0 , [17 ]* 100 ),
9292 hr = ModbusSequentialDataBlock (0 , [17 ]* 100 ),
9393 ir = ModbusSequentialDataBlock (0 , [17 ]* 100 ))
9494
9595 context = ModbusServerContext (slaves = store , single = True )
96-
97- # ----------------------------------------------------------------------- #
96+
97+ # ----------------------------------------------------------------------- #
9898 # initialize the server information
99- # ----------------------------------------------------------------------- #
99+ # ----------------------------------------------------------------------- #
100100 # If you don't set this or any fields, they are defaulted to empty strings.
101- # ----------------------------------------------------------------------- #
101+ # ----------------------------------------------------------------------- #
102102 identity = ModbusDeviceIdentification ()
103103 identity .VendorName = 'Pymodbus'
104104 identity .ProductCode = 'PM'
@@ -109,7 +109,7 @@ def run_server():
109109
110110 # ----------------------------------------------------------------------- #
111111 # run the server you want
112- # ----------------------------------------------------------------------- #
112+ # ----------------------------------------------------------------------- #
113113 # Tcp:
114114 StartTcpServer (context , identity = identity , address = ("localhost" , 5020 ))
115115
@@ -119,11 +119,11 @@ def run_server():
119119
120120 # Udp:
121121 # StartUdpServer(context, identity=identity, address=("0.0.0.0", 5020))
122-
122+
123123 # Ascii:
124124 # StartSerialServer(context, identity=identity,
125125 # port='/dev/ttyp0', timeout=1)
126-
126+
127127 # RTU:
128128 # StartSerialServer(context, framer=ModbusRtuFramer, identity=identity,
129129 # port='/dev/ttyp0', timeout=.005, baudrate=9600)
0 commit comments