diff --git a/pymodbus/client/serial.py b/pymodbus/client/serial.py index a94502624..5f688947e 100644 --- a/pymodbus/client/serial.py +++ b/pymodbus/client/serial.py @@ -82,6 +82,8 @@ def __init__( # pylint: disable=too-many-arguments "Serial client requires pyserial " 'Please install with "pip install pyserial" and try again.' ) + if framer not in [FramerType.ASCII, FramerType.RTU]: + raise TypeError("Only FramerType RTU/ASCII allowed.") self.comm_params = CommParams( comm_type=CommType.SERIAL, host=port, @@ -163,6 +165,8 @@ def __init__( # pylint: disable=too-many-arguments retries: int = 3, ) -> None: """Initialize Modbus Serial Client.""" + if framer not in [FramerType.ASCII, FramerType.RTU]: + raise TypeError("Only RTU/ASCII allowed.") self.comm_params = CommParams( comm_type=CommType.SERIAL, host=port, diff --git a/pymodbus/client/tcp.py b/pymodbus/client/tcp.py index 0983f2c19..d38b8e871 100644 --- a/pymodbus/client/tcp.py +++ b/pymodbus/client/tcp.py @@ -66,6 +66,8 @@ def __init__( # pylint: disable=too-many-arguments ) -> None: """Initialize Asyncio Modbus TCP Client.""" if not hasattr(self,"comm_params"): + if framer not in [FramerType.SOCKET, FramerType.RTU, FramerType.ASCII]: + raise TypeError("Only FramerType SOCKET/RTU/ASCII allowed.") self.comm_params = CommParams( comm_type=CommType.TCP, host=host, @@ -138,6 +140,8 @@ def __init__( ) -> None: """Initialize Modbus TCP Client.""" if not hasattr(self,"comm_params"): + if framer not in [FramerType.SOCKET, FramerType.RTU, FramerType.ASCII]: + raise TypeError("Only FramerType SOCKET/RTU/ASCII allowed.") self.comm_params = CommParams( comm_type=CommType.TCP, host=host, diff --git a/pymodbus/client/tls.py b/pymodbus/client/tls.py index 0b4d6a44c..6667a675c 100644 --- a/pymodbus/client/tls.py +++ b/pymodbus/client/tls.py @@ -65,6 +65,8 @@ def __init__( # pylint: disable=too-many-arguments on_connect_callback: Callable[[bool], None] | None = None, ): """Initialize Asyncio Modbus TLS Client.""" + if framer not in [FramerType.TLS]: + raise TypeError("Only FramerType TLS allowed.") self.comm_params = CommParams( comm_type=CommType.TLS, host=host, @@ -159,6 +161,8 @@ def __init__( # pylint: disable=too-many-arguments retries: int = 3, ): """Initialize Modbus TLS Client.""" + if framer not in [FramerType.TLS]: + raise TypeError("Only FramerType TLS allowed.") self.comm_params = CommParams( comm_type=CommType.TLS, host=host, diff --git a/pymodbus/client/udp.py b/pymodbus/client/udp.py index 86c05895f..c00064da2 100644 --- a/pymodbus/client/udp.py +++ b/pymodbus/client/udp.py @@ -77,6 +77,8 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max=reconnect_delay_max, timeout_connect=timeout, ) + if framer not in [FramerType.SOCKET, FramerType.RTU, FramerType.ASCII]: + raise TypeError("Only FramerType SOCKET/RTU/ASCII allowed.") ModbusBaseClient.__init__( self, framer, @@ -139,6 +141,8 @@ def __init__( retries: int = 3, ) -> None: """Initialize Modbus UDP Client.""" + if framer not in [FramerType.SOCKET, FramerType.RTU, FramerType.ASCII]: + raise TypeError("Only FramerType SOCKET/RTU/ASCII allowed.") self.comm_params = CommParams( comm_type=CommType.UDP, host=host, diff --git a/test/sub_client/test_client.py b/test/sub_client/test_client.py index 7c0861a56..281f6816d 100755 --- a/test/sub_client/test_client.py +++ b/test/sub_client/test_client.py @@ -167,9 +167,9 @@ def fake_execute(_self, _no_response_expected, request): "tls": { "pos_arg": "192.168.1.2", "opt_args": { - "port": 211, - "framer": FramerType.ASCII, - "source_address": ("195.6.7.8", 1025), + "port": 802, + "framer": FramerType.TLS, + "source_address": None, "sslctx": None, }, "defaults": { diff --git a/test/sub_client/test_client_sync.py b/test/sub_client/test_client_sync.py index 529c18787..ac42b6bd9 100755 --- a/test/sub_client/test_client_sync.py +++ b/test/sub_client/test_client_sync.py @@ -17,7 +17,6 @@ from pymodbus.framer import ( FramerAscii, FramerRTU, - FramerSocket, FramerTLS, ) from test.conftest import mockSocket @@ -313,10 +312,6 @@ def test_sync_serial_client_instantiation(self): ModbusSerialClient("/dev/null", framer=FramerType.RTU).framer, FramerRTU, ) - assert isinstance( - ModbusSerialClient("/dev/null", framer=FramerType.SOCKET).framer, - FramerSocket, - ) def test_sync_serial_rtu_client_timeouts(self): """Test sync serial rtu."""