77twisted library as its backend. This allows it to scale to many thousands
88of nodes which can be helpful for testing monitoring software.
99"""
10- # --------------------------------------------------------------------------- #
10+ # --------------------------------------------------------------------------- #
1111# import the various server implementations
12- # --------------------------------------------------------------------------- #
13- from pymodbus .server . async import StartTcpServer , StopServer
12+ # --------------------------------------------------------------------------- #
13+ from pymodbus .server import StartTcpServer , ServerStop
1414
1515from pymodbus .device import ModbusDeviceIdentification
1616from pymodbus .datastore import ModbusSequentialDataBlock
1717from pymodbus .datastore import ModbusSlaveContext , ModbusServerContext
1818
1919
2020class MockModbusServer (object ):
21- # --------------------------------------------------------------------------- #
21+ # --------------------------------------------------------------------------- #
2222 # configure the service logging
23- # --------------------------------------------------------------------------- #
23+ # --------------------------------------------------------------------------- #
2424 import logging
2525 FORMAT = ('%(asctime)-15s %(threadName)-15s'
2626 ' %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s' )
@@ -29,9 +29,9 @@ class MockModbusServer(object):
2929 log .setLevel (logging .DEBUG )
3030
3131 def run_async_server (self ):
32- # ----------------------------------------------------------------------- #
32+ # ----------------------------------------------------------------------- #
3333 # initialize your data store
34- # ----------------------------------------------------------------------- #
34+ # ----------------------------------------------------------------------- #
3535 # The datastores only respond to the addresses that they are initialized to
3636 # Therefore, if you initialize a DataBlock to addresses from 0x00 to 0xFF,
3737 # a request to 0x100 will respond with an invalid address exception.
@@ -82,17 +82,17 @@ def run_async_server(self):
8282 # will map to (1-8)::
8383 #
8484 # store = ModbusSlaveContext(..., zero_mode=True)
85- # ----------------------------------------------------------------------- #
85+ # ----------------------------------------------------------------------- #
8686 store = ModbusSlaveContext (
8787 hr = ModbusSequentialDataBlock (0 , [0 ]* 3000 ),
8888 ir = ModbusSequentialDataBlock (0 , [0 ]* 3000 ))
8989 self .context = ModbusServerContext (slaves = store , single = True )
9090
91- # ----------------------------------------------------------------------- #
91+ # ----------------------------------------------------------------------- #
9292 # initialize the server information
93- # ----------------------------------------------------------------------- #
93+ # ----------------------------------------------------------------------- #
9494 # If you don't set this or any fields, they are defaulted to empty strings.
95- # ----------------------------------------------------------------------- #
95+ # ----------------------------------------------------------------------- #
9696 identity = ModbusDeviceIdentification ()
9797 identity .VendorName = 'Pymodbus'
9898 identity .ProductCode = 'PM'
@@ -101,15 +101,15 @@ def run_async_server(self):
101101 identity .ModelName = 'Pymodbus Server'
102102 identity .MajorMinorRevision = '1.5'
103103
104- # ----------------------------------------------------------------------- #
104+ # ----------------------------------------------------------------------- #
105105 # run the server you want
106- # ----------------------------------------------------------------------- #
106+ # ----------------------------------------------------------------------- #
107107
108108 # TCP Server
109109 StartTcpServer (self .context , identity = identity , address = ("localhost" , 5020 ))
110110
111111 def stop_async_server (self ):
112- StopServer ()
112+ ServerStop ()
113113
114114 def update_context (self , register , address , values ):
115115 """ Update values of the active context. It should be noted
0 commit comments