jacdac-python/jacdac/serial/client.py

105 строки
3.1 KiB
Python

# Autogenerated file. Do not edit.
from jacdac.bus import Bus, Client
from .constants import *
from typing import Optional
class SerialClient(Client):
"""
An asynchronous serial communication service capable of sending and receiving buffers of data.
* Settings default to 115200 baud 8N1.
Implements a client for the `Serial <https://microsoft.github.io/jacdac-docs/services/serial>`_ service.
"""
def __init__(self, bus: Bus, role: str) -> None:
super().__init__(bus, JD_SERVICE_CLASS_SERIAL, JD_SERIAL_PACK_FORMATS, role)
@property
def connected(self) -> Optional[bool]:
"""
Indicates if the serial connection is active.,
"""
return self.register(JD_SERIAL_REG_CONNECTED).bool_value()
@connected.setter
def connected(self, value: bool) -> None:
self.register(JD_SERIAL_REG_CONNECTED).set_values(value)
@property
def connection_name(self) -> Optional[str]:
"""
(Optional) User-friendly name of the connection.,
"""
return self.register(JD_SERIAL_REG_CONNECTION_NAME).value()
@property
def baud_rate(self) -> Optional[int]:
"""
A positive, non-zero value indicating the baud rate at which serial communication is be established., _: baud
"""
return self.register(JD_SERIAL_REG_BAUD_RATE).value()
@baud_rate.setter
def baud_rate(self, value: int) -> None:
self.register(JD_SERIAL_REG_BAUD_RATE).set_values(value)
@property
def data_bits(self) -> Optional[int]:
"""
The number of data bits per frame. Either 7 or 8.,
"""
return self.register(JD_SERIAL_REG_DATA_BITS).value()
@data_bits.setter
def data_bits(self, value: int) -> None:
self.register(JD_SERIAL_REG_DATA_BITS).set_values(value)
@property
def stop_bits(self) -> Optional[int]:
"""
The number of stop bits at the end of a frame. Either 1 or 2., _: #
"""
return self.register(JD_SERIAL_REG_STOP_BITS).value()
@stop_bits.setter
def stop_bits(self, value: int) -> None:
self.register(JD_SERIAL_REG_STOP_BITS).set_values(value)
@property
def parity_mode(self) -> Optional[SerialParityType]:
"""
The parity mode.,
"""
return self.register(JD_SERIAL_REG_PARITY_MODE).value()
@parity_mode.setter
def parity_mode(self, value: SerialParityType) -> None:
self.register(JD_SERIAL_REG_PARITY_MODE).set_values(value)
@property
def buffer_size(self) -> Optional[int]:
"""
A positive, non-zero value indicating the size of the read and write buffers that should be created., _: #
"""
return self.register(JD_SERIAL_REG_BUFFER_SIZE).value()
@buffer_size.setter
def buffer_size(self, value: int) -> None:
self.register(JD_SERIAL_REG_BUFFER_SIZE).set_values(value)
def send(self, data: bytes) -> None:
"""
Send a buffer of data over the serial transport.
"""
self.send_cmd_packed(JD_SERIAL_CMD_SEND, data)