commaai/openpilot · error · SerialException
could not configure port: {e}
Error message
could not configure port: {e} What it means
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.
Source
Thrown at openpilot/common/serial.py:264
cflag |= termios.CS8
cflag &= ~(termios.PARENB | termios.PARODD | termios.CSTOPB)
if hasattr(termios, "CRTSCTS"):
if self._rtscts:
cflag |= termios.CRTSCTS
else:
cflag &= ~termios.CRTSCTS
speed = self._baud_constant(self._baudrate)
cc = list(cc)
# Non-blocking reads are handled via select + O_NONBLOCK; keep VMIN/VTIME at 0.
cc[termios.VMIN] = 0
cc[termios.VTIME] = 0
try:
termios.tcsetattr(self._fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, speed, speed, cc])
except termios.error as e:
raise SerialException(f"could not configure port: {e}") from e
# Keep the fd non-blocking so timeout=0 and select work consistently.
flags = fcntl.fcntl(self._fd, fcntl.F_GETFL)
fcntl.fcntl(self._fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
def _set_line(self, _bit: int, packed: bytes, enabled: bool) -> None:
request = TIOCMBIS if enabled else TIOCMBIC
fcntl.ioctl(self._fd, request, packed)
View on GitHub (pinned to 516ec1e682)
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
Example fix
// before ser = Serial(devpath, 921600, xonxoff=False, rtscts=True) // after ser = Serial(devpath, 115200, rtscts=False)
Defensive patterns
Strategy: try-catch
Validate before calling
import termios
def baud_supported(baudrate: int) -> bool:
return hasattr(termios, f'B{baudrate}') Try / catch
from common.serial import SerialException
try:
ser = Serial(devpath, baudrate, rtscts=True)
except SerialException as e:
ser = Serial(devpath, 115200, rtscts=False) # fall back to safe settings Prevention
- 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
When it happens
Trigger: 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.
Common situations: Nonstandard baud rates (e.g., 500000 or 921600) on cheap USB-serial chips, flow-control mismatch, or a disappearing device mid-open.
Related errors
- could not get port attributes: {e}
- AT command timed out
- AT command failed: {line}
- Failed to open ISD-R after retries
- Missing +CGLA response
AI-assisted analysis of commaai/openpilot@516ec1e682 (2026-08-15).
Data as JSON: /api/errors/9e080e5338ddd905.
Report an issue: GitHub.