Skip to content

Commit 2f87de9

Browse files
authored
Change slave to device_id and slave= to device_id=. (#2600)
1 parent 9432d2b commit 2f87de9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+802
-765
lines changed

API_changes.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ API changes
22
===========
33
Versions (X.Y.Z) where Z > 0 e.g. 3.0.1 do NOT have API changes!
44

5-
-----------------
6-
API changes 3.9.0
5+
API changes 4.0.0
76
-----------------
87
- Python 3.9 is reaching end of life, and no longer supported.
98
Depending on the usage the code might still work
10-
- Start*Server, custom_functions -> custom_pdu (handled by Modbus<x>Server)
11-
- payload removed (replaced by "convert_combined_to/from_registers")
9+
- Start*Server, custom_functions is now custom_pdu (handled by Modbus<x>Server)
10+
- ModbusSlaveContext replaced by ModbusDeviceContext
11+
- payload removed (replaced by "convert_to/from_registers")
12+
- slave=, slaves= replaced by device_id=, device_ids=
13+
- slave request names changed to device
1214

1315
API changes 3.8.0
1416
-----------------

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Please select a topic in the left hand column.
88
:caption: Contents:
99
:hidden:
1010

11+
source/upgrade_40
1112
source/api_changes
1213
source/client
1314
source/server

doc/source/_static/examples.tgz

-2.08 KB
Binary file not shown.

doc/source/_static/examples.zip

-34 Bytes
Binary file not shown.

doc/source/client.rst

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ Synchronous example
127127

128128
from pymodbus.client import ModbusTcpClient
129129

130-
client = ModbusTcpClient('MyDevice.lan') # Create client object
131-
client.connect() # connect to device
132-
client.write_coil(1, True, slave=1) # set information in device
133-
result = client.read_coils(2, 3, slave=1) # get information from device
134-
print(result.bits[0]) # use information
135-
client.close() # Disconnect device
130+
client = ModbusTcpClient('MyDevice.lan') # Create client object
131+
client.connect() # connect to device
132+
client.write_coil(1, True, device_id=1) # set information in device
133+
result = client.read_coils(2, 3, device_id=1) # get information from device
134+
print(result.bits[0]) # use information
135+
client.close() # Disconnect device
136136

137137
The line :mod:`client.connect()` connects to the device (or comm port). If this cannot connect successfully within
138138
the timeout it throws an exception. After this initial connection, further
@@ -147,22 +147,22 @@ Asynchronous example
147147

148148
from pymodbus.client import AsyncModbusTcpClient
149149

150-
client = AsyncModbusTcpClient('MyDevice.lan') # Create client object
151-
await client.connect() # connect to device, reconnect automatically
152-
await client.write_coil(1, True, slave=1) # set information in device
153-
result = await client.read_coils(2, 3, slave=1) # get information from device
154-
print(result.bits[0]) # use information
155-
client.close() # Disconnect device
150+
client = AsyncModbusTcpClient('MyDevice.lan') # Create client object
151+
await client.connect() # connect to device, reconnect automatically
152+
await client.write_coil(1, True, device_id=1) # set information in device
153+
result = await client.read_coils(2, 3, device_id=1) # get information from device
154+
print(result.bits[0]) # use information
155+
client.close() # Disconnect device
156156

157157
The line :mod:`client = AsyncModbusTcpClient('MyDevice.lan')` only creates the object; it does not activate
158158
anything.
159159

160160
The line :mod:`await client.connect()` connects to the device (or comm port), if this cannot connect successfully within
161161
the timeout it throws an exception. If connected successfully reconnecting later is handled automatically
162162

163-
The line :mod:`await client.write_coil(1, True, slave=1)` is an example of a write request, set address 1 to True on device 1 (slave).
163+
The line :mod:`await client.write_coil(1, True, device_id=1)` is an example of a write request, set address 1 to True on device 1.
164164

165-
The line :mod:`result = await client.read_coils(2, 3, slave=1)` is an example of a read request, get the value of address 2, 3 and 4 (count = 3) from device 1 (slave).
165+
The line :mod:`result = await client.read_coils(2, 3, device_id=1)` is an example of a read request, get the value of address 2, 3 and 4 (count = 3) from device 1.
166166

167167
The last line :mod:`client.close()` closes the connection and render the object inactive.
168168

@@ -194,13 +194,13 @@ Client device addressing
194194
------------------------
195195

196196
With **TCP**, **TLS** and **UDP**, the tcp/ip address of the physical device is defined when creating the object.
197-
Logical devices represented by the device is addressed with the :mod:`slave=` parameter.
197+
Logical devices represented by the device is addressed with the :mod:`device_id=` parameter.
198198

199199
With **Serial**, the comm port is defined when creating the object.
200-
The physical devices are addressed with the :mod:`slave=` parameter.
200+
The physical devices are addressed with the :mod:`device_id=` parameter.
201201

202-
:mod:`slave=0` is defined as broadcast in the modbus standard, but pymodbus treats it as a normal device.
203-
please note :mod:`slave=0` can only be used to address devices that truly have id=0 ! Using :mod:`slave=0` to
202+
:mod:`device_id=0` is defined as broadcast in the modbus standard, but pymodbus treats it as a normal device.
203+
please note :mod:`device_id=0` can only be used to address devices that truly have id=0 ! Using :mod:`device_id=0` to
204204
address a single device with id not 0 is against the protocol.
205205

206206
If an application is expecting multiple responses to a broadcast request, it must call :mod:`client.execute` and deal with the responses.
@@ -217,7 +217,7 @@ All simple request calls (mixin) return a unified result independent whether it
217217
The application should evaluate the result generically::
218218

219219
try:
220-
rr = await client.read_coils(1, 1, slave=1)
220+
rr = await client.read_coils(1, 1, device_id=1)
221221
except ModbusException as exc:
222222
_logger.error(f"ERROR: exception in pymodbus {exc}")
223223
raise exc

doc/source/library/datastore.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Datastore classes
1111
:members:
1212
:member-order: bysource
1313

14-
.. autoclass:: pymodbus.datastore.ModbusSlaveContext
14+
.. autoclass:: pymodbus.datastore.ModbusDeviceContext
1515
:members:
1616
:member-order: bysource
1717

doc/source/library/simulator/calls_response.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
},
7373
{
7474
"value": 17,
75-
"text": "report_slave_id",
75+
"text": "report_device_id",
7676
"selected": false
7777
},
7878
{
@@ -131,7 +131,7 @@
131131
},
132132
{
133133
"value": 4,
134-
"text": "SLAVE_FAILURE",
134+
"text": "DEVICE_FAILURE",
135135
"selected": false
136136
},
137137
{
@@ -141,7 +141,7 @@
141141
},
142142
{
143143
"value": 6,
144-
"text": "SLAVE_BUSY",
144+
"text": "DEVICE_BUSY",
145145
"selected": false
146146
},
147147
{
@@ -164,4 +164,4 @@
164164
"call_rows": [],
165165
"foot": "not active",
166166
"result": "ok"
167-
}
167+
}

doc/source/library/simulator/config.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Server configuration examples
8787
"comm": "tcp",
8888
"host": "0.0.0.0",
8989
"port": 5020,
90-
"ignore_missing_slaves": false,
90+
"ignore_missing_devices": false,
9191
"framer": "socket",
9292
"identity": {
9393
"VendorName": "pymodbus",
@@ -123,7 +123,7 @@ Server configuration examples
123123
"port": 5020,
124124
"certfile": "certificates/pymodbus.crt",
125125
"keyfile": "certificates/pymodbus.key",
126-
"ignore_missing_slaves": false,
126+
"ignore_missing_devices": false,
127127
"framer": "tls",
128128
"identity": {
129129
"VendorName": "pymodbus",
@@ -138,7 +138,7 @@ Server configuration examples
138138
"comm": "udp",
139139
"host": "0.0.0.0",
140140
"port": 5020,
141-
"ignore_missing_slaves": false,
141+
"ignore_missing_devices": false,
142142
"framer": "socket",
143143
"identity": {
144144
"VendorName": "pymodbus",

doc/source/roadmap.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ The following bullet points are what the maintainers focus on:
2020
- 4.0.0, with:
2121
- Simulator datastore, with simple configuration
2222
- Remove remote_datastore
23-
- Remove BinaryPayload
2423
- Server becomes Simulator
2524
- client async with sync/async API
2625
- Only one datastore, but with different API`s
2726
- 4.1.0, with:
28-
- ModbusControlBlock pr slave
27+
- ModbusControlBlock pr device
2928
- New custom PDU (function codes)
3029
- New serial forwarder
3130
- GUI client, to analyze devices

doc/source/upgrade_40.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Pymodbus 4.0 upgrade procedure
2+
==============================
3+
4+
Pymodbus 4.0 contains a number of incompatibilities with Pymodbus 3.x, however
5+
most of these are simple edits.
6+
7+
Python 3.9
8+
----------
9+
Python 3.9 is reaching end of life and from october 2025 no longer receives security updates.
10+
11+
Pymodbus starting with v4.0 start using python 3.10 features, and thus users need to update to
12+
at least python v3.10
13+
14+
Users that cannot upgrade the python version, should not upgrade pymodbus to v4.X
15+
16+
17+
Start<x>Server
18+
--------------
19+
custom_funcion= is changed to custom_pdu= and is handled by Modbus<x>Server.
20+
21+
22+
payload classes removed
23+
-----------------------
24+
Please replace by result.convert_from_registers() and/or convert_to_registers()
25+
26+
27+
Simple replacements
28+
-------------------
29+
30+
please replace
31+
- slave= with device_id=
32+
- slaves= with device_ids=
33+
- ModbusServerContext(slaves=) with ModbusServerContext(devices=)
34+
35+
please rename
36+
- ModbusSlaveContext to ModbusDeviceContext
37+
- RemoteSlaveContext to RemoteDeviceContext
38+
- report_slave_id() with report_device_id()
39+
- diag_read_slave_message_count with diag_read_device_message_count
40+
- diag_read_slave_no_response_count with diag_read_device_no_response_count
41+
- diag_read_slave_nak_count with diag_read_device_nak_count
42+
- diag_read_slave_busy_count with diag_read_device_busy_count
43+
- ReturnSlaveMessageCountRequest with ReturnDeviceMessageCountRequest
44+
- ReturnSlaveNoResponseCountRequest with ReturnDeviceNoResponseCountRequest
45+
- ReturnSlaveNAKCountRequest with ReturnDeviceNAKCountRequest
46+
- ReturnSlaveBusyCountRequest with ReturnDeviceBusyCountRequest
47+
- ReturnSlaveBusCharacterOverrunCountRequest with ReturnDeviceBusCharacterOverrunCountRequest

0 commit comments

Comments
 (0)