Transport
Transport backends handle the physical communication channel. Located in pepper_c1/transport.py.
All transports implement the abstract Transport base class and support the context manager protocol. Pass a transport instance to PepperC1().
UARTTransport
Communicates with the reader over a serial (RS-232 / USB-Serial) connection using pyserial.
UARTTransport
(port, baudrate=115200, timeout=0.1, post_open_delay=0.0)
UART
Open a serial port and configure it for communication with the Peeper C1. DTR and RTS lines are explicitly held low to prevent accidental resets.
| Parameter | Type | Default | Description |
|---|---|---|---|
| port | str | — | Serial port name, e.g. "COM3" on Windows or "/dev/ttyUSB0" on Linux/macOS. |
| baudrate | int | 115200 | Baud rate. The Peeper C1 default is 115200. |
| timeout | float | 0.1 | Read timeout in seconds for each _read_chunk() call. |
| post_open_delay | float | 0.0 | Optional delay (seconds) after opening the port. If > 0, the input buffer is also flushed. Useful for boards that reset on DTR edge. |
RaisesTransportError — if the port cannot be opened.
ImportError — if
pyserial is not installed.from pepper_c1 import PepperC1, UARTTransport # Windows with PepperC1(UARTTransport('COM3')) as reader: print(reader.get_version()) # Linux / macOS with PepperC1(UARTTransport('/dev/ttyUSB0')) as reader: print(reader.get_version()) # Custom baud rate, with post-open stabilization delay transport = UARTTransport('COM5', baudrate=9600, post_open_delay=0.5) with PepperC1(transport) as reader: print(reader.get_version())
TCPTransport
Communicates with the reader over a TCP socket. Useful when the reader is connected to a network adapter or embedded Wi-Fi module.
TCPTransport
(host, port, timeout=2.0)
TCP
Open a TCP connection to the reader. The socket uses a short internal read timeout (0.1 s) so the response polling loop can check the deadline accurately.
| Parameter | Type | Default | Description |
|---|---|---|---|
| host | str | — | Hostname or IP address of the reader, e.g. "192.168.1.100". |
| port | int | — | TCP port number. |
| timeout | float | 2.0 | Connection timeout in seconds. |
RaisesTransportError — if the connection cannot be established.
from pepper_c1 import PepperC1, TCPTransport with PepperC1(TCPTransport('192.168.1.100', 1234)) as reader: print(reader.get_version())
Transport Base Class
If you need to implement a custom transport (e.g. Bluetooth, USB HID), subclass Transport and implement the three abstract methods:
| Method | Signature | Description |
|---|---|---|
| write | (data: bytes) → None |
Send raw bytes to the device. Raise TransportError on failure. |
| _read_chunk | (n: int) → bytes |
Read up to n bytes. Returns fewer bytes or empty bytes if nothing is available. Raise TransportError on hard error. |
| close | () → None |
Release the underlying connection. |
The base class provides read_frame(timeout) which loops over _read_chunk() and returns a complete validated payload.
from pepper_c1.transport import Transport from pepper_c1.exceptions import TransportError class MyCustomTransport(Transport): def write(self, data: bytes) -> None: ... # send data def _read_chunk(self, n: int) -> bytes: ... # read up to n bytes, return b"" if nothing available def close(self) -> None: ... # release resources