unitelabs.bus.utils

Packages

Attributes

  • Name
    __all__
    Type
    Value

    = [ "AutoDetector", "SerialDeviceManager", "DeviceInfo" ]

    Description

Classes

  • AutoDetector

    This class is used by the `unitelabs.bus.Protocol` to cycle through possible devices until the correct device is found.

    Methods

    • __init__(
        self,
        **kwargs
      ) -> None

      Parameters

      • Name
        self
        Type
        Default
        Description

      • Name
        protocol
        Type
        Protocol
        Default
        Description

        The `unitelabs.bus.Protocol` instance to use.

      • Name
        **kwargs
        Type
        Default
        = {}
        Description

        Kwargs used to initialize the `Protocol` instance, which contains `Transport` init kwargs.

    • get_transport_type(self) -> None

      Infer the type of the transport based on the `protocol._transport_factory` which stores the `TransportFactory` used to initialize the `Protocol`. This allows the differential initialization of new transport instances based on `DeviceInfo`.

    • get_device_manager(self) -> type[DeviceManager]

      Get the correct `DeviceManager` based on the `TransportType`.

      Response

      Type
      type[DeviceManager]
      Description

    • resolve(
        self,
        validation_timeout : float,
        **validation_kwargs
      ) -> None

      User entry-point. Iterates through all available devices until a connection is successfully made, or all available devices have been tested. If no valid connection can be found, calls to `protocol.connection_lost` to pass control back to `protocol`.

      Parameters

      • Name
        self
        Type
        Default
        Description

      • Name
        validation_timeout
        Type
        float
        Default
        Description

        How long in seconds to wait for a response from `Protocol.validate`.

      • Name
        **validation_kwargs
        Type
        Default
        = {}
        Description

        kwargs from `Protocol.validate` used to validate the connection.

    • _connect(
        self,
        validation_timeout : float,
      ) -> bool

      Updates the `transport` on the `protocol` and attempts to open said `transport` and validate the connection using `Protocol.validate`.

      Parameters

      • Name
        self
        Type
        Default
        Description

      • Name
        validation_timeout
        Type
        float
        Default
        Description

        How long in seconds to wait for a response from `Protocol.validate`.

      • Name
        device
        Type
        DeviceInfo
        Default
        Description

        The device to which we wish to attempt to validate a connection.

      Response

      Type
      bool
      Description

      Whether or not the connection was successfully made and validated.

    • _update_protocol_transport(self, device : DeviceInfo) -> None

      Update the `Protocol`s underlying `Transport` to connect to the given `device`.

      Parameters

      • Name
        self
        Type
        Default
        Description

      • Name
        device
        Type
        DeviceInfo
        Default
        Description

        The `DeviceInfo` of the new device to connect the `Protocol` to.

    Attributes

    • Name
      _transport_type
      Type
      TransportType
      Value

      = None

      Description

    • Name
      protocol
      Type
      Value

      = protocol

      Description

    • Name
      _transport_kwargs
      Type
      Value

      = kwargs

      Description

    • Name
      _device_manager
      Type
      Value

      = None

      Description

    • Name
      _validation_kwargs
      Type
      Value

      = kwargs

      Description

    • Name
      _is_resolving
      Type
      Value

      = False

      Description

    • Name
      logger
      Type
      logging.Logger
      Value

      = None

      Description

    • Name
      device_manager
      Type
      type[DeviceManager]
      Value

      = None

      Description

    • Name
      is_resolving
      Type
      bool
      Value

      = None

      Description

      Whether or not we are currently trying to connect to a device

  • 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]
      ) -> None

      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

  • 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,
        **kwargs
      ) -> bool

      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

Copyright © 2024