|
12 | 12 | # --------------------------------------------------------------------------- # |
13 | 13 | from pymodbus.server import StartTcpServer, ServerStop |
14 | 14 |
|
15 | | -from pymodbus.device import ModbusDeviceIdentification |
| 15 | +from pymodbus.pdu.device import ModbusDeviceIdentification |
16 | 16 | from pymodbus.datastore import ModbusSequentialDataBlock |
17 | | -from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext |
| 17 | +from pymodbus.datastore import ModbusDeviceContext, ModbusServerContext |
18 | 18 |
|
19 | 19 |
|
20 | 20 | class MockModbusServer(object): |
@@ -51,42 +51,42 @@ def run_async_server(self): |
51 | 51 | # or simply do not pass them to have them initialized to 0x00 on the full |
52 | 52 | # address range:: |
53 | 53 | # |
54 | | - # store = ModbusSlaveContext(di = ModbusSequentialDataBlock.create()) |
55 | | - # store = ModbusSlaveContext() |
| 54 | + # store = ModbusDeviceContext(di = ModbusSequentialDataBlock.create()) |
| 55 | + # store = ModbusDeviceContext() |
56 | 56 | # |
57 | 57 | # Finally, you are allowed to use the same DataBlock reference for every |
58 | 58 | # table or you you may use a seperate DataBlock for each table. |
59 | 59 | # This depends if you would like functions to be able to access and modify |
60 | 60 | # the same data or not:: |
61 | 61 | # |
62 | 62 | # block = ModbusSequentialDataBlock(0x00, [0]*0xff) |
63 | | - # store = ModbusSlaveContext(di=block, co=block, hr=block, ir=block) |
| 63 | + # store = ModbusDeviceContext(di=block, co=block, hr=block, ir=block) |
64 | 64 | # |
65 | 65 | # The server then makes use of a server context that allows the server to |
66 | | - # respond with different slave contexts for different unit ids. By default |
| 66 | + # respond with different device_id contexts for different unit ids. By default |
67 | 67 | # it will return the same context for every unit id supplied (broadcast |
68 | 68 | # mode). |
69 | 69 | # However, this can be overloaded by setting the single flag to False |
70 | 70 | # and then supplying a dictionary of unit id to context mapping:: |
71 | 71 | # |
72 | | - # slaves = { |
73 | | - # 0x01: ModbusSlaveContext(...), |
74 | | - # 0x02: ModbusSlaveContext(...), |
75 | | - # 0x03: ModbusSlaveContext(...), |
| 72 | + # device_ids = { |
| 73 | + # 0x01: ModbusDeviceContext(...), |
| 74 | + # 0x02: ModbusDeviceContext(...), |
| 75 | + # 0x03: ModbusDeviceContext(...), |
76 | 76 | # } |
77 | | - # context = ModbusServerContext(slaves=slaves, single=False) |
| 77 | + # context = ModbusServerContext(device_ids=device_ids, single=False) |
78 | 78 | # |
79 | | - # The slave context can also be initialized in zero_mode which means that a |
| 79 | + # The device_id context can also be initialized in zero_mode which means that a |
80 | 80 | # request to address(0-7) will map to the address (0-7). The default is |
81 | 81 | # False which is based on section 4.4 of the specification, so address(0-7) |
82 | 82 | # will map to (1-8):: |
83 | 83 | # |
84 | | - # store = ModbusSlaveContext(..., zero_mode=True) |
| 84 | + # store = ModbusDeviceContext(..., zero_mode=True) |
85 | 85 | # ----------------------------------------------------------------------- # |
86 | | - store = ModbusSlaveContext( |
| 86 | + store = ModbusDeviceContext( |
87 | 87 | hr=ModbusSequentialDataBlock(0, [0]*3000), |
88 | 88 | ir=ModbusSequentialDataBlock(0, [0]*3000)) |
89 | | - self.context = ModbusServerContext(slaves=store, single=True) |
| 89 | + self.context = ModbusServerContext(devices=store, single=True) |
90 | 90 |
|
91 | 91 | # ----------------------------------------------------------------------- # |
92 | 92 | # initialize the server information |
@@ -122,12 +122,12 @@ def update_context(self, register, address, values): |
122 | 122 | :param values: List of values |
123 | 123 | """ |
124 | 124 | assert register == 3 or register == 4 |
125 | | - slave_id = 0x00 |
126 | | - old_values = self.context[slave_id].getValues(register, |
| 125 | + device_id = 0x00 |
| 126 | + old_values = self.context[device_id].getValues(register, |
127 | 127 | address, count=1) |
128 | 128 | self.log.debug("Change value at address {} from {} to {}".format( |
129 | 129 | address, old_values, values)) |
130 | | - self.context[slave_id].setValues(register, address, values) |
| 130 | + self.context[device_id].setValues(register, address, values) |
131 | 131 |
|
132 | 132 | def update_holding_register(self, address, value): |
133 | 133 | """ Update value of a holding register. |
|
0 commit comments