thorlabs_elliptec.helper module

thorlabs_elliptec.helper.find_device(vid: int = None, pid: int = None, manufacturer: str = None, product: str = None, serial_number: str = None, location: str = None)[source]

Search attached serial ports for a specific device.

The first device found matching the criteria will be returned. Because there is no consistent way to identify serial devices, the default parameters do not specify any selection criteria, and thus the first serial port will be returned. A specific device should be selected using a unique combination of the parameters.

The USB vendor (vid) and product (pid) IDs are exact matches to the numerical values, for example vid=0x067b or vid=0x2303. The remaining parameters are strings specifying a regular expression match to the corresponding field. For example serial_number="83" would match devices with serial numbers starting with 83, while serial_number=".*83$" would match devices ending in 83. A value of None means that the parameter should not be considered, however an empty string value ("") is subtly different, requiring the field to be present, but then matching any value.

Be aware that different operating systems may return different data for the various fields, which can complicate matching when attempting to write cross-platform code.

To see a list of serial ports and the relevant data fields:

import serial
for p in list_ports.comports():
    print(f"{p.device}, {p.manufacturer}, {p.product}, {p.vid}, {p.pid}, {p.serial_number}, {p.location}")
Parameters:
  • vid – Numerical USB vendor ID to match.

  • pid – Numerical USB product ID to match.

  • manufacturer – Regular expression to match to a device manufacturer string.

  • product – Regular expression to match to a device product string.

  • serial_number – Regular expression to match to a device serial number.

  • location – Regular expression to match to a device physical location (eg. USB port).

Returns:

First ListPortInfo device which matches given criteria.

thorlabs_elliptec.helper.list_devices() str[source]

Return a string listing all detected serial devices and any associated identifying properties.

The manufacturer, product, vendor ID (vid), product ID (pid), serial number, and physical device location are provided. These can be used as parameters to find_device() or the constructor of a device class to identify and select a specific serial device.

Returns:

String listing all serial devices and their details.