From 05b9b3b5783b1d89f23ef1231adb642467de7641 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Thu, 20 Jul 2023 19:58:58 +0200 Subject: [PATCH] Check if serial is installed. --- pymodbus/transport/serial_asyncio/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pymodbus/transport/serial_asyncio/__init__.py b/pymodbus/transport/serial_asyncio/__init__.py index a52ef7b284..e9858d9c4d 100644 --- a/pymodbus/transport/serial_asyncio/__init__.py +++ b/pymodbus/transport/serial_asyncio/__init__.py @@ -19,9 +19,10 @@ import os -with contextlib.suppress(ImportError): +try: import serial - +except ImportError: + serial = None try: import termios @@ -48,6 +49,9 @@ class SerialTransport(asyncio.Transport): """ def __init__(self, loop, protocol, serial_instance): + assert ( + not serial + ), '***ERROR*** "serial" not installed, needed to run modbus serial communication' super().__init__() self._loop = loop self._protocol = protocol