diff --git a/pyproject.toml b/pyproject.toml index 9d40302..ed65e74 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,8 +30,6 @@ dependencies = [ [tool.ruff] # Allow lines to be as long as 119 characters. line-length = 119 -# Ignore errors of unused module imports in __init__.py -ignore-init-module-imports = true [tool.black] # Allow lines to be as long as 119 characters. diff --git a/src/elliptec/controller.py b/src/elliptec/controller.py index 42c2ed2..323c5a4 100644 --- a/src/elliptec/controller.py +++ b/src/elliptec/controller.py @@ -1,6 +1,5 @@ """This module contains the Controller class, which is the base class for all devices.""" -import sys import serial from .tools import parse @@ -23,7 +22,8 @@ def __init__(self, write_timeout=0.5, debug=True): self.debug = debug - if port == None: + self.port = port # Store the port parameter as an instance variable + if port is None: self.__search_and_connect(baudrate, bytesize, parity, @@ -79,7 +79,8 @@ def __search_and_connect(self, write_timeout): port_list = serial.tools.list_ports.comports() for port in port_list: - self.__connect_to_port(port, + self.port = port + self.__connect_to_port(self.port, baudrate, bytesize, parity, @@ -88,12 +89,6 @@ def __search_and_connect(self, write_timeout) break - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_val, exc_tb): - self.close() - def read_response(self): """Reads the response from the controller.""" response = self.s.read_until(b"\r\n") # Waiting until response read