def __init__(self, port, baudrate): super().__init__() try: self._serial = serial.Serial(port, baudrate=baudrate, timeout=None) except SerialException as error: err_str = str(error) if "FileNotFoundError" in err_str: err_str = "port not found" message = "Unable to connect to " + port + ": " + err_str # TODO: check if these error codes also apply to Linux and Mac if error.errno == 13 and platform.system() == "Linux": # TODO: check if user already has this group message += "\n\n" + dedent("""\ Try adding yourself to the 'dialout' group: > sudo usermod -a -G dialout <username> (NB! This needs to be followed by reboot or logging out and logging in again!)""" ) elif "PermissionError" in message: message += "\n\n" + dedent("""\ If you have serial connection to the device from another program, then disconnect it there.""") elif error.errno == 16: message += "\n\n" + "Try restarting the device." raise ConnectionFailedException(message) self._reading_thread = threading.Thread(target=self._listen_serial, daemon=True) self._reading_thread.start()
def _resolve_executable(self, executable): result = self._which(executable) if result: return result else: msg = "Executable '%s' not found. Please check your configuration!" % executable if not executable.startswith("/"): msg += " You may need to provide its absolute path." raise ConnectionFailedException(msg)