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.
ParameterTypeDefaultDescription
portstrSerial port name, e.g. "COM3" on Windows or "/dev/ttyUSB0" on Linux/macOS.
baudrateint115200Baud rate. The Peeper C1 default is 115200.
timeoutfloat0.1Read timeout in seconds for each _read_chunk() call.
post_open_delayfloat0.0Optional 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.
ParameterTypeDefaultDescription
hoststrHostname or IP address of the reader, e.g. "192.168.1.100".
portintTCP port number.
timeoutfloat2.0Connection 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:

MethodSignatureDescription
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