plestylib.traffic.serial#
Classes#
A TrafficManager implementation for managing serial communication. |
Module Contents#
- class plestylib.traffic.serial.SerialTrafficManager(port, baudrate=9600, timeout=5, write_termination='\r', read_termination='\r\n')#
Bases:
plestylib.traffic.TrafficManagerA TrafficManager implementation for managing serial communication.
This class provides methods to open, close, and communicate with serial devices.
Initialize the SerialTrafficManager with the given port, baudrate, timeout, and termination characters.
- Parameters:
port (str) – The serial port to connect to (e.g., ‘COM3’ or ‘/dev/ttyUSB0’).
baudrate (int, optional) – The baud rate for the serial communication. Defaults to 9600.
timeout (float, optional) – The timeout for serial operations in seconds. Defaults to 5.
write_termination (str, optional) – Termination suffix appended on write. Default is carriage return.
read_termination (str, optional) – Termination sequence used when reading responses. Default is carriage return plus newline.
- port#
- baudrate = 9600#
- write_termination = '\r'#
- read_termination = Multiline-String#
Show Value
""" """
- _open(baudrate: int = None, timeout: float = None, parity: str = None, stopbits: str = None, bytesize: int = None)#
Open the serial connection with the specified parameters.
- Parameters:
baudrate (int, optional) – The baud rate for the serial communication. Defaults to the instance’s baudrate.
timeout (float, optional) – The timeout for serial operations in seconds. Defaults to the instance’s timeout.
parity (str, optional) – The parity for the serial communication. Must be ‘none’, ‘even’, or ‘odd’. Defaults to None.
stopbits (str, optional) – The stop bits for the serial communication. Must be ‘one’. Defaults to None.
bytesize (int, optional) – The byte size for the serial communication. Must be 8. Defaults to None.
- _clear_buffer()#
Clear the input and output buffers of the serial connection.
- _waite_for_response(timeout=None)#
Wait for a response from the device until the expected termination is received or timeout occurs.
- _send_command(command: str, timeout=None) Any#
Send a command to the device and wait for the response.
- Parameters:
command (str) – The command to send to the device.
timeout (float, optional) – The timeout for waiting for the response. Defaults to the instance’s timeout.
- Returns:
The response from the device, or False if the command failed or timed out.
- Return type:
Any
- _close()#
Close the serial connection.