unitelabs.bus.utils.device_manager
Attributes
- Name
devices
- Type
- Value
= SerialDeviceManager().get_all()
- Description
Classes
NoSuchDeviceFound
- Bases
- Exception
DeviceInfo
Translation of `serial.tools.list_ports.ListPortInfo` for unified interface between USB and Serial `DeviceManagers`. Attrs here represent valid filter criteria during device search.
- Decorators
- dataclasses.dataclass
Methods
__init__(
- self,
- device : str,
- name : str,
- description : typing.Optional[str],
- hwid : typing.Optional[str],
- vid : typing.Optional[str],
- pid : typing.Optional[str],
- serial_number : typing.Optional[str],
- location : typing.Optional[str],
- manufacturer : typing.Optional[str],
- product : typing.Optional[str],
- interface : typing.Optional[str]
Parameters
- Name
self
- Type
- Default
- Description
- Name
device
- Type
- str
- Default
- Description
- Name
name
- Type
- str
- Default
- Description
- Name
description
- Type
- typing.Optional[str]
- Default
- = None
- Description
- Name
hwid
- Type
- typing.Optional[str]
- Default
- = None
- Description
- Name
vid
- Type
- typing.Optional[str]
- Default
- = None
- Description
- Name
pid
- Type
- typing.Optional[str]
- Default
- = None
- Description
- Name
serial_number
- Type
- typing.Optional[str]
- Default
- = None
- Description
- Name
location
- Type
- typing.Optional[str]
- Default
- = None
- Description
- Name
manufacturer
- Type
- typing.Optional[str]
- Default
- = None
- Description
- Name
product
- Type
- typing.Optional[str]
- Default
- = None
- Description
- Name
interface
- Type
- typing.Optional[str]
- Default
- = None
- Description
__post_init__(self) -> None
__repr__(self) -> None
Attributes
- Name
device
- Type
- str
- Value
= None
- Description
- Name
name
- Type
- str
- Value
= None
- Description
- Name
description
- Type
- typing.Optional[str]
- Value
= None
- Description
- Name
hwid
- Type
- typing.Optional[str]
- Value
= None
- Description
- Name
vid
- Type
- typing.Optional[str]
- Value
= None
- Description
- Name
pid
- Type
- typing.Optional[str]
- Value
= None
- Description
- Name
serial_number
- Type
- typing.Optional[str]
- Value
= None
- Description
- Name
location
- Type
- typing.Optional[str]
- Value
= None
- Description
- Name
manufacturer
- Type
- typing.Optional[str]
- Value
= None
- Description
- Name
product
- Type
- typing.Optional[str]
- Value
= None
- Description
- Name
interface
- Type
- typing.Optional[str]
- Value
= None
- Description
DeviceManager
Detect, filter, and get info for connected devices.
Methods
@classmethod
@abc.abstractmethod
filter_kwargs(cls, kwargs : typing.Dict[str, str]) -> typing.Dict[str, str]Parameters
- Name
cls
- Type
- Default
- Description
- Name
kwargs
- Type
- typing.Dict[str, str]
- Default
- Description
Response
- Type
- typing.Dict[str, str]
- Description
@classmethod
@abc.abstractmethod
get_all(cls) -> list[DeviceInfo]Parameters
- Name
cls
- Type
- Default
- Description
Response
- Type
- list[DeviceInfo]
- Description
@classmethod
@abc.abstractmethod
check_device_match(- cls,
- device_info : DeviceInfo,
- **kwargs
Parameters
- Name
cls
- Type
- Default
- Description
- Name
device_info
- Type
- DeviceInfo
- Default
- Description
- Name
**kwargs
- Type
- Default
- = {}
- Description
Response
- Type
- bool
- Description
@classmethod
@abc.abstractmethod
filter(cls, **kwargs) -> list[DeviceInfo]Parameters
- Name
cls
- Type
- Default
- Description
- Name
**kwargs
- Type
- Default
- = {}
- Description
Response
- Type
- list[DeviceInfo]
- Description
SerialDeviceManager
Detect, filter, and get info for connected serial devices.
Methods
@classmethod
filter_kwargs(cls, kwargs : typing.Dict[str, str]) -> typing.Dict[str, str]Filter kwargs to those which are returned from `serial.tools.list_ports.comports`, i.e. the attributes of `DeviceInfo`. Supports the use of `port` as alternative name for `device`.
Parameters
- Name
cls
- Type
- Default
- Description
- Name
kwargs
- Type
- typing.Dict[str, str]
- Default
- Description
A dictionary of key-value pairs to filter.
Response
- Type
- typing.Dict[str, str]
- Description
The filtered dictionary.
@classmethod
get_all(cls) -> list[DeviceInfo]Get all connected devices.
Parameters
- Name
cls
- Type
- Default
- Description
Response
- Type
- list[DeviceInfo]
- Description
A list of all devices detected.
@classmethod
check_device_match(- cls,
- device_info : DeviceInfo,
- **kwargs
Determine if the `DeviceInfo` instance's attributes match the filter `**kwargs`
Parameters
- Name
cls
- Type
- Default
- Description
- Name
device_info
- Type
- DeviceInfo
- Default
- Description
The device to check for a match against.
- Name
**kwargs
- Type
- Default
- = {}
- Description
The key-value pairs, which will be filtered, and then used to evaluate the device for a match.
Response
- Type
- bool
- Description
True if the `DeviceInfo` matches (or no kwargs provided, or all kwargs have been filtered), else False.
@classmethod
filter(cls, **kwargs) -> list[DeviceInfo]Search through all detectable devices. `**kwargs` are first filtered by `filter_kwargs` based on attrs of `DeviceInfo`. This allows the number of devices detected to be pared down based on known, stable information about the device being searched for.
Parameters
- Name
cls
- Type
- Default
- Description
- Name
**kwargs
- Type
- Default
- = {}
- Description
Search criteria for finding a device.
Response
- Type
- list[DeviceInfo]
- Description
A list of devices which match all `**kwargs` provided.
Attributes
- Name
SERIAL_SEARCH_KEYS
- Type
- Value
= ['device', 'name', 'description', 'hwid', 'vid', 'pid', 'serial_number', 'location', 'manufacturer', 'product', 'interface']
- Description