plestylib.traffic#
Submodules#
Classes#
An abstract base class for managing communication with various types of resources (e.g., serial, VISA). |
Functions#
|
Helper to handle error caught |
Package Contents#
- plestylib.traffic.handle_error(err, error_msg=None, silent=False, func_name='Unknown Function')#
Helper to handle error caught
- class plestylib.traffic.TrafficManager(address: str, timeout: int = 5)#
Bases:
abc.ABCAn 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.
- Parameters:
address (str) – The address of the resource.
timeout (int, optional) – The timeout for operations in seconds. Defaults to 5.
- _resource_in_use#
- address#
- timeout = 5#
- inst = None#
- property is_open#
- abstractmethod _open(*args, **kwargs)#
Open the connection to the resource.
This method should be implemented by subclasses to handle the specific details of opening the connection.
- Parameters:
args – Positional arguments for the specific implementation.
kwargs – Keyword arguments for the specific implementation.
- open(*args, **kwargs) bool#
- Return type:
bool
- abstractmethod _send_command(command: str, timeout=None, *args, **kwargs) Any#
Send a command to the resource and return the response.
- Parameters:
command (str) – The command to send.
timeout (int, optional) – The timeout for the command in seconds. Defaults to the instance’s timeout.
- Returns:
The response from the resource, or False if the command failed or timed out.
- Return type:
Any
- send_command(command: str, timeout=None, *args, **kwargs) Any#
- Parameters:
command (str)
- Return type:
Any
- abstractmethod _close()#
Close the connection to the resource.
This method should be implemented by subclasses to handle the specific details of closing the connection.
- close() bool#
- Return type:
bool
- __enter__()#
- __exit__(exc_type, exc_val, exc_tb)#