plestylib.traffic
=================

.. py:module:: plestylib.traffic


Submodules
----------

.. toctree::
   :maxdepth: 1

   /reference/plestylib/traffic/serial/index
   /reference/plestylib/traffic/tcp_ip/index
   /reference/plestylib/traffic/usb_utils/index
   /reference/plestylib/traffic/utils/index
   /reference/plestylib/traffic/visa/index


Classes
-------

.. autoapisummary::

   plestylib.traffic.TrafficManager


Functions
---------

.. autoapisummary::

   plestylib.traffic.handle_error


Package Contents
----------------

.. py:function:: handle_error(err, error_msg=None, silent=False, func_name='Unknown Function')

   Helper to handle error caught


.. py:class:: TrafficManager(address: str, timeout: int = 5)

   Bases: :py:obj:`abc.ABC`


   An abstract base class for managing communication with various types of resources (e.g., serial, VISA).

   This class defines the common interface and basic functionality for opening, closing, and sending commands
   to resources. The private methods (_open, _send_command, _close) are meant to be implemented by subclasses
   to handle the specific details of each type of resource. We leave the public methods (open, send_command,
   close) as the standard interface for users to interact with, and leave the private methods for developers
   to implement because we want to automatically handle resource management and error handling in a consistent
   way across all types of resources, so that the developers can focus on the specific implementation details.

   Initialize the TrafficManager with the given address and timeout.

   :param address: The address of the resource.
   :type address: str
   :param timeout: The timeout for operations in seconds. Defaults to 5.
   :type timeout: int, optional


   .. py:attribute:: _resource_in_use


   .. py:attribute:: address


   .. py:attribute:: timeout
      :value: 5



   .. py:attribute:: inst
      :value: None



   .. py:property:: is_open


   .. py:method:: _open(*args, **kwargs)
      :abstractmethod:


      Open the connection to the resource.

      This method should be implemented by subclasses to handle the specific
      details of opening the connection.

      :param args: Positional arguments for the specific implementation.
      :param kwargs: Keyword arguments for the specific implementation.



   .. py:method:: open(*args, **kwargs) -> bool


   .. py:method:: _send_command(command: str, timeout=None, *args, **kwargs) -> Any
      :abstractmethod:


      Send a command to the resource and return the response.

      :param command: The command to send.
      :type command: str
      :param timeout: The timeout for the command in seconds.
                      Defaults to the instance's timeout.
      :type timeout: int, optional

      :returns: The response from the resource, or False if the command failed or timed out.
      :rtype: Any



   .. py:method:: send_command(command: str, timeout=None, *args, **kwargs) -> Any


   .. py:method:: _close()
      :abstractmethod:


      Close the connection to the resource.

      This method should be implemented by subclasses to handle the specific details of closing the connection.



   .. py:method:: close() -> bool


   .. py:method:: __enter__()


   .. py:method:: __exit__(exc_type, exc_val, exc_tb)


