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