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