{"record":{"id":"9e080e5338ddd905","repo":"commaai/openpilot","slug":"could-not-configure-port-e","errorCode":null,"errorMessage":"could not configure port: {e}","messagePattern":"could not configure port: (.+?)","errorType":"exception","errorClass":"SerialException","httpStatus":null,"severity":"error","filePath":"openpilot/common/serial.py","lineNumber":264,"sourceCode":"    cflag |= termios.CS8\n    cflag &= ~(termios.PARENB | termios.PARODD | termios.CSTOPB)\n\n    if hasattr(termios, \"CRTSCTS\"):\n      if self._rtscts:\n        cflag |= termios.CRTSCTS\n      else:\n        cflag &= ~termios.CRTSCTS\n\n    speed = self._baud_constant(self._baudrate)\n    cc = list(cc)\n    # Non-blocking reads are handled via select + O_NONBLOCK; keep VMIN/VTIME at 0.\n    cc[termios.VMIN] = 0\n    cc[termios.VTIME] = 0\n\n    try:\n      termios.tcsetattr(self._fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, speed, speed, cc])\n    except termios.error as e:\n      raise SerialException(f\"could not configure port: {e}\") from e\n\n    # Keep the fd non-blocking so timeout=0 and select work consistently.\n    flags = fcntl.fcntl(self._fd, fcntl.F_GETFL)\n    fcntl.fcntl(self._fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)\n\n  def _set_line(self, _bit: int, packed: bytes, enabled: bool) -> None:\n    request = TIOCMBIS if enabled else TIOCMBIC\n    fcntl.ioctl(self._fd, request, packed)\n","sourceCodeStart":246,"sourceCodeEnd":273,"githubUrl":"https://github.com/commaai/openpilot/blob/516ec1e68203439a73f340f1d0b3b91eabc626ee/openpilot/common/serial.py#L246-L273","documentation":"Raised by Serial._configure when termios.tcsetattr fails while applying the raw 8N1 mode, baud constant, and VMIN/VTIME=0 settings. The kernel rejects the requested attribute set (typically EINVAL) because the combination is not supported by this tty driver.","triggerScenarios":"Passing a baud rate whose B<rate> constant exists but the driver cannot set (some USB CDC adapters only support standard rates), enabling CRTSCTS on a 2-wire adapter without RTS/CTS, or the device disconnecting between tcgetattr and tcsetattr.","commonSituations":"Nonstandard baud rates (e.g., 500000 or 921600) on cheap USB-serial chips, flow-control mismatch, or a disappearing device mid-open.","solutions":["Try a standard baud rate (9600/115200) to confirm the port works at all","Disable flow control in the Serial constructor if the adapter lacks RTS/CTS lines","Confirm the device is still attached (dmesg) and reopen"],"exampleFix":"// before\nser = Serial(devpath, 921600, xonxoff=False, rtscts=True)\n\n// after\nser = Serial(devpath, 115200, rtscts=False)","handlingStrategy":"try-catch","validationCode":"import termios\n\ndef baud_supported(baudrate: int) -> bool:\n    return hasattr(termios, f'B{baudrate}')","typeGuard":null,"tryCatchPattern":"from common.serial import SerialException\ntry:\n    ser = Serial(devpath, baudrate, rtscts=True)\nexcept SerialException as e:\n    ser = Serial(devpath, 115200, rtscts=False)  # fall back to safe settings","preventionTips":["Prefer standard baud rates supported by the USB-serial chip","Only enable rtscts when the adapter actually wires RTS/CTS","Test port configuration at connection time, not mid-session"],"tags":["serial","termios","configuration","baud-rate"],"backgroundTag":null,"analyzedSha":"516ec1e68203439a73f340f1d0b3b91eabc626ee","analyzedAt":"2026-08-15T00:17:37.461Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}