PySerial¶
driver: jumpstarter.drivers.pyserial.driver.PySerial
The methods of this client are dynamic, and they are generated from
the methods
field of the exporter driver configuration.
Driver configuration¶
export:
my_serial:
type: "jumpstarter.drivers.pyserial.driver.PySerial"
config:
url: "/dev/ttyUSB0"
baudrate: 115200
Config parameters¶
Parameter |
Description |
Type |
Required |
Default |
---|---|---|---|---|
url |
The serial port to connect to, in pyserial format |
str |
yes |
|
baudrate |
The baudrate to use for the serial connection |
int |
no |
115200 |
PySerialClient API¶
- class jumpstarter.drivers.pyserial.client.PySerialClient(*, uuid: ~uuid.UUID = <factory>, labels: dict[str, str] = <factory>, channel: ~grpc.aio._base_channel.Channel, children: dict[str, DriverClient] = <factory>, portal: BlockingPortal)¶
A client for handling serial communication using pexpect.
- close()¶
Close the open stream session without a context manager.
- open() fdspawn ¶
Open a pexpect session. You can find the pexpect documentation here: https://pexpect.readthedocs.io/en/stable/api/pexpect.html#spawn-class
- Returns:
fdspawn: The pexpect session object.
- open_stream() BlockingStream ¶
Open a blocking stream session without a context manager.
- Returns:
blocking stream session object.
- Return type:
BlockingStream
- pexpect()¶
Create a pexpect adapter context manager.
- Yields:
PexpectAdapter: The pexpect adapter object.
- stream(method='connect')¶
Open a blocking stream session with a context manager.
- Parameters:
method (str) – method name of streaming driver call
- Returns:
blocking stream session object context manager.
Examples¶
Using expect with a context manager
with pyserialclient.pexpect() as session:
session.sendline("Hello, world!")
session.expect("Hello, world!")
Using expect without a context manager
session = pyserialclient.open()
session.sendline("Hello, world!")
session.expect("Hello, world!")
session.close()
Using a simple BlockingStream with a context manager
with pyserialclient.stream() as stream:
stream.write(b"Hello, world!")
data = stream.read(13)
Using a simple BlockingStream without a context manager
stream = pyserialclient.open_stream()
stream.write(b"Hello, world!")
data = stream.read(13)
stream.close()