Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneeded parameters. #2272

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions API_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Versions (X.Y.Z) where Z > 0 e.g. 3.0.1 do NOT have API changes!

API changes 3.7.0
-----------------
- default slave changed to 1 from 0 (which is broadcast).
- broadcast_enable, retry_on_empty, no_resend_on_retry parameters removed.
- class method generate_ssl() added to TLS client (sync/async).
- removed certfile, keyfile, password from TLS client, please use generate_ssl()
- on_reconnect_callback() removed from clients (sync/async).
Expand Down
3 changes: 2 additions & 1 deletion doc/source/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ The physical devices are addressed with the :mod:`slave=` parameter.

:mod:`slave=0` is used as broadcast in order to address all devices.
However experience shows that modern devices do not allow broadcast, mostly because it is
inheriently dangerous. With :mod:`slave=0` the application can get upto 254 responses on a single request!
inheriently dangerous. With :mod:`slave=0` the application can get upto 254 responses on a single request,
and this is not handled with the normal API calls!

The simple request calls (mixin) do NOT support broadcast, if an application wants to use broadcast
it must call :mod:`client.execute` and deal with the responses.
Expand Down
5 changes: 0 additions & 5 deletions examples/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ def setup_async_client(description=None, cmdline=None):
retries=3,
reconnect_delay=1,
reconnect_delay_max=10,
# retry_on_empty=False,
# TCP setup parameters
# source_address=("localhost", 0),
)
elif args.comm == "udp":
Expand All @@ -76,7 +74,6 @@ def setup_async_client(description=None, cmdline=None):
framer=args.framer,
timeout=args.timeout,
# retries=3,
# retry_on_empty=False,
# UDP setup parameters
# source_address=None,
)
Expand All @@ -87,7 +84,6 @@ def setup_async_client(description=None, cmdline=None):
# framer=ModbusRtuFramer,
timeout=args.timeout,
# retries=3,
# retry_on_empty=False,
# Serial setup parameters
baudrate=args.baudrate,
# bytesize=8,
Expand All @@ -103,7 +99,6 @@ def setup_async_client(description=None, cmdline=None):
framer=args.framer,
timeout=args.timeout,
# retries=3,
# retry_on_empty=False,
# TLS setup parameters
sslctx=modbusClient.AsyncModbusTlsClient.generate_ssl(
certfile=helper.get_certificate("crt"),
Expand Down
6 changes: 3 additions & 3 deletions examples/client_custom_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CustomModbusResponse(ModbusResponse):
function_code = 55
_rtu_byte_count_pos = 2

def __init__(self, values=None, slave=0, transaction=0, protocol=0, skip_encode=False):
def __init__(self, values=None, slave=1, transaction=0, protocol=0, skip_encode=False):
"""Initialize."""
ModbusResponse.__init__(self, slave, transaction, protocol, skip_encode)
self.values = values or []
Expand Down Expand Up @@ -68,7 +68,7 @@ class CustomModbusRequest(ModbusRequest):
function_code = 55
_rtu_frame_size = 8

def __init__(self, address=None, slave=0, transaction=0, protocol=0, skip_encode=False):
def __init__(self, address=None, slave=1, transaction=0, protocol=0, skip_encode=False):
"""Initialize."""
ModbusRequest.__init__(self, slave, transaction, protocol, skip_encode)
self.address = address
Expand Down Expand Up @@ -100,7 +100,7 @@ def execute(self, context):
class Read16CoilsRequest(ReadCoilsRequest):
"""Read 16 coils in one request."""

def __init__(self, address, count=None, slave=0, transaction=0, protocol=0, skip_encode=False):
def __init__(self, address, count=None, slave=1, transaction=0, protocol=0, skip_encode=False):
"""Initialize a new instance.

:param address: The address to start reading from
Expand Down
4 changes: 0 additions & 4 deletions examples/client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def setup_sync_client(description=None, cmdline=None):
framer=args.framer,
timeout=args.timeout,
# retries=3,
# retry_on_empty=False,y
# TCP setup parameters
# source_address=("localhost", 0),
)
Expand All @@ -79,7 +78,6 @@ def setup_sync_client(description=None, cmdline=None):
framer=args.framer,
timeout=args.timeout,
# retries=3,
# retry_on_empty=False,
# UDP setup parameters
# source_address=None,
)
Expand All @@ -90,7 +88,6 @@ def setup_sync_client(description=None, cmdline=None):
# framer=ModbusRtuFramer,
timeout=args.timeout,
# retries=3,
# retry_on_empty=False,
# Serial setup parameters
baudrate=args.baudrate,
# bytesize=8,
Expand All @@ -106,7 +103,6 @@ def setup_sync_client(description=None, cmdline=None):
framer=args.framer,
timeout=args.timeout,
# retries=3,
# retry_on_empty=False,
# TLS setup parameters
sslctx=modbusClient.ModbusTlsClient.generate_ssl(
certfile=helper.get_certificate("crt"),
Expand Down
1 change: 0 additions & 1 deletion examples/contrib/solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def main():
# Common optional parameters:
framer=ModbusSocketFramer,
timeout=1,
retry_on_empty=True,
)
client.connect()
_logger.info("### Client connected")
Expand Down
2 changes: 1 addition & 1 deletion examples/package_test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async def client_calls(client):
"""Test client API."""
Log.debug("--> Client calls starting.")
try:
resp = await client.read_holding_registers(address=124, count=4, slave=0)
resp = await client.read_holding_registers(address=124, count=4, slave=1)
except ModbusException as exc:
txt = f"ERROR: exception in pymodbus {exc}"
Log.error(txt)
Expand Down
3 changes: 0 additions & 3 deletions examples/simple_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ async def run_async_simple_client(comm, host, port, framer=FramerType.SOCKET):
framer=framer,
# timeout=10,
# retries=3,
# retry_on_empty=False,
# source_address=("localhost", 0),
)
elif comm == "udp":
Expand All @@ -43,7 +42,6 @@ async def run_async_simple_client(comm, host, port, framer=FramerType.SOCKET):
framer=framer,
# timeout=10,
# retries=3,
# retry_on_empty=False,
# source_address=None,
)
elif comm == "serial":
Expand All @@ -52,7 +50,6 @@ async def run_async_simple_client(comm, host, port, framer=FramerType.SOCKET):
framer=framer,
# timeout=10,
# retries=3,
# retry_on_empty=False,
baudrate=9600,
bytesize=8,
parity="N",
Expand Down
3 changes: 0 additions & 3 deletions examples/simple_sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def run_sync_simple_client(comm, host, port, framer=FramerType.SOCKET):
framer=framer,
# timeout=10,
# retries=3,
# retry_on_empty=False,y
# source_address=("localhost", 0),
)
elif comm == "udp":
Expand All @@ -45,7 +44,6 @@ def run_sync_simple_client(comm, host, port, framer=FramerType.SOCKET):
framer=framer,
# timeout=10,
# retries=3,
# retry_on_empty=False,
# source_address=None,
)
elif comm == "serial":
Expand All @@ -54,7 +52,6 @@ def run_sync_simple_client(comm, host, port, framer=FramerType.SOCKET):
framer=framer,
# timeout=10,
# retries=3,
# retry_on_empty=False,
baudrate=9600,
bytesize=8,
parity="N",
Expand Down
20 changes: 3 additions & 17 deletions pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ def __init__(
self,
framer: FramerType,
retries: int,
retry_on_empty: bool,
broadcast_enable: bool,
no_resend_on_retry: bool,
on_connect_callback: Callable[[bool], None] | None,
comm_params: CommParams | None = None,
) -> None:
Expand All @@ -40,14 +37,11 @@ def __init__(
if comm_params:
self.comm_params = comm_params
self.retries = retries
self.retry_on_empty = retry_on_empty
self.ctx = ModbusClientProtocol(
framer,
self.comm_params,
on_connect_callback,
)
self.no_resend_on_retry = no_resend_on_retry
self.broadcast_enable = broadcast_enable

# Common variables.
self.use_udp = False
Expand Down Expand Up @@ -119,10 +113,9 @@ async def async_execute(self, request) -> ModbusResponse:
while count <= self.retries:
async with self._lock:
req = self.build_response(request)
if not count or not self.no_resend_on_retry:
self.ctx.framer.resetFrame()
self.ctx.send(packet)
if self.broadcast_enable and not request.slave_id:
self.ctx.framer.resetFrame()
self.ctx.send(packet)
if not request.slave_id:
resp = None
break
try:
Expand Down Expand Up @@ -184,19 +177,13 @@ def __init__(
self,
framer: FramerType,
retries: int,
retry_on_empty: bool,
broadcast_enable: bool,
no_resend_on_retry: bool,
comm_params: CommParams | None = None,
) -> None:
"""Initialize a client instance."""
ModbusClientMixin.__init__(self) # type: ignore[arg-type]
if comm_params:
self.comm_params = comm_params
self.retries = retries
self.broadcast_enable = bool(broadcast_enable)
self.retry_on_empty = retry_on_empty
self.no_resend_on_retry = no_resend_on_retry
self.slaves: list[int] = []

# Common variables.
Expand All @@ -205,7 +192,6 @@ def __init__(
)(ClientDecoder(), self)
self.transaction = SyncModbusTransactionManager(
self,
retry_on_empty,
self.retries,
)
self.reconnect_delay_current = self.comm_params.reconnect_delay or 0
Expand Down
Loading