API reference

class trio_serial.abstract.AbstractSerialStream(port, *, exclusive=False, baudrate=115200, bytesize=8, parity=<Parity.NONE: 1>, stopbits=<StopBits.ONE: 1>, xonxoff=False, rtscts=False)[source]

Operating system independant public interface of SerialStream.

Create new SerialStream object.

Parameters
  • port (str) – Name of port. Format depends on implementation. This could be “/dev/ttyUSB0” on Linux or “COM7” on Windows.

  • exclusive (bool) – Lock port for exclusive use

  • baudrate (int) – Initial Port speed

  • bytesize (int) – Number of bits per byte

  • parity (Parity) – Parity

  • stopbits (StopBits) – Number of stop bits

  • xonxoff (bool) – Software Flow Control with XON/XOFF

  • rtscts (bool) – Hardware Flow Control with RTS/CTS

Return type

None

abstractmethod await aclose()[source]

Cleanly close the port.

Do nothing if already closed.

Return type

None

abstractmethod await aopen()[source]

Open the port and configure it with the initial state from __init__().

Return type

None

abstractmethod await discard_input()[source]

Discard any unread input.

Return type

None

abstractmethod await discard_output()[source]

Discard any unwritten output.

Return type

None

abstractmethod await get_cts()[source]

Retrieve current Clear To Send state.

Returns

Current CTS state

Return type

bool

abstractmethod await get_hangup()[source]

Retrieve current Hangup on Close state.

Returns

Current Hangup on Close state

Return type

bool

abstractmethod await get_rts()[source]

Retrieve current Ready To Send state.

Returns

Current RTS state

Return type

bool

property port: str

Get the port name.

Returns

port name or device

await receive_some(max_bytes=None)[source]

Receive between 1 and max_bytes bytes from the serial port.

Parameters

max_bytes (Optional[int]) – Maximum number of bytes to receive.

Return type

bytes

await send_all(data)[source]

Send data to the serial port. :param data: Data to send

Parameters

data (ByteString) –

Return type

None

abstractmethod await send_break(duration=0.25)[source]

Transmit a continuous stream of zero-valued bits for a specific duration.

Params:

duration: Number of seconds

Parameters

duration (float) –

Return type

None

abstractmethod await set_hangup(value)[source]

Set Hangup on Close state.

Parameters

value (bool) – New Hangup on Close state

Return type

None

abstractmethod await set_rts(value)[source]

Set Ready To Send state.

Parameters

value (bool) – New Ready To Send state

Return type

None

await wait_send_all_might_not_block()[source]

Wait until sending might not block (it still might block).

Return type

None

class trio_serial.abstract.Parity(value)[source]

Enumeration of parity types.

EVEN = 2

Even parity

MARK = 4

Parity bit always 1

NONE = 1

No parity

ODD = 3

Odd parity

SPACE = 5

Parity bit always 0

class trio_serial.abstract.StopBits(value)[source]

Enumeration of stop bit lengths.

ONE = 1

One bit

ONE_POINT_FIVE = 2

One and a half bits

TWO = 3

Two bits