API reference

class trio_serial.abstract.AbstractSerialStream(port, *, exclusive=False, baudrate=115200, bytesize=8, parity=Parity.NONE, stopbits=StopBits.ONE, 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

abstract async aclose()[source]

Cleanly close the port.

Do nothing if already closed.

Return type:

None

abstract async aopen()[source]

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

Return type:

None

abstract async discard_input()[source]

Discard any unread input.

Return type:

None

abstract async discard_output()[source]

Discard any unwritten output.

Return type:

None

abstract async get_cts()[source]

Retrieve current Clear To Send state.

Returns:

Current CTS state

Return type:

bool

abstract async get_hangup()[source]

Retrieve current Hangup on Close state.

Returns:

Current Hangup on Close state

Return type:

bool

abstract async 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

async receive_some(max_bytes=None)[source]

Receive some bytes from the serial port.

Parameters:

max_bytes (int | None) – Maximum number of bytes to receive.

Returns:

On success, between 1 and max_bytes bytes. On End-of-file (e.g. serial port is gone) an empty bytes object is returned.

Return type:

bytes

async send_all(data)[source]

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

Parameters:

data (ByteString) –

Return type:

None

abstract async 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

abstract async set_hangup(value)[source]

Set Hangup on Close state.

Parameters:

value (bool) – New Hangup on Close state

Return type:

None

abstract async set_rts(value)[source]

Set Ready To Send state.

Parameters:

value (bool) – New Ready To Send state

Return type:

None

async 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, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[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, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Enumeration of stop bit lengths.

ONE = 1

One bit

ONE_POINT_FIVE = 2

One and a half bits

TWO = 3

Two bits