plesty.lib.traffic.serial ========================= .. py:module:: plesty.lib.traffic.serial .. autoapi-nested-parse:: Serial traffic manager for Plesty device communication. Classes ------- .. autoapisummary:: plesty.lib.traffic.serial.SerialTrafficManager Module Contents --------------- .. py:class:: SerialTrafficManager(port, baudrate=9600, timeout=5, write_termination='\r', read_termination='\r\n', response_flag=None, parity: str | None = None, stopbits: str | None = None, bytesize: int | None = None) Bases: :py:obj:`plesty.lib.traffic.TrafficManager` A TrafficManager implementation for managing serial communication. This class provides methods to open, close, and communicate with serial devices. Initialize SerialTrafficManager with port, baud rate, and communication settings. :param port: The serial port to connect to (e.g., 'COM3' or '/dev/ttyUSB0'). :param baudrate: The baud rate for the serial communication. Defaults to 9600. :param timeout: The timeout for serial operations in seconds. Defaults to 5. :param write_termination: Termination suffix appended on write. :param read_termination: Termination sequence used when reading responses. :param response_flag: A string indicating a successful response from the device. :param parity: The parity setting; must be 'none', 'even', or 'odd'. :param stopbits: The stop bits setting; must be 'one'. :param bytesize: The byte size; must be 8. .. py:attribute:: port .. py:attribute:: baudrate :value: 9600 .. py:attribute:: write_termination :value: '\r' .. py:attribute:: read_termination :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """ """ .. raw:: html
.. py:attribute:: response_flag :value: None .. py:attribute:: parity .. py:attribute:: stopbits .. py:attribute:: bytesize :value: 8 .. py:property:: is_open :type: bool Return True if the serial connection is open. .. py:method:: _open(baudrate: int | None = None, timeout: float | None = None) Open the serial connection with the specified parameters. :param baudrate: The baud rate; defaults to the instance's baudrate. :param timeout: The timeout in seconds; defaults to the instance's timeout. .. py:method:: _explain_open_error(exc: BaseException) -> str | None Say whether the port was held or forbidden rather than absent. .. py:method:: _clear_buffer() Clear the input and output buffers of the serial connection. .. py:method:: _waite_for_response(timeout=None) Wait for a response until expected termination is received or timeout. .. py:method:: _send_command(command: str, timeout=None) -> Any Send a command to the device and wait for the response. :param command: The command to send to the device. :param timeout: Timeout for waiting for the response; defaults to instance's timeout. :returns: The response from the device, or False if the command failed or timed out. :rtype: Any .. py:method:: orphan(command: str) -> bool Transmit *command* without waiting for or reading its answer. The buffer is deliberately not cleared afterwards: the unread answer staying there is the whole point. :param command: A command the device will answer. :returns: ``True`` once transmitted. .. py:method:: _close() Close the serial connection.