Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choosing device by serial number? #130

Open
FilipDominec opened this issue Jan 24, 2021 · 3 comments
Open

Choosing device by serial number? #130

FilipDominec opened this issue Jan 24, 2021 · 3 comments

Comments

@FilipDominec
Copy link

FilipDominec commented Jan 24, 2021

In my experiment, I use X-Y positioning with two Thorlabs TDC001 servo controllers. Of course, it is essential to identify X and Y axes correctly by controller serial number, so that the program never swaps them at startup. This could lead to crashes.

But I cannot find out how to achieve this with instrumental.

In [1]: from instrumental import instrument, list_instruments

In [2]: paramsets = list_instruments()
/home/dominecf/p/210124_getting_Thorlabs_work/instrumental/instrumental/drivers/motion/ecc100.py:26: UserWarning: Driver 'instrumental.drivers.motion.ecc100' is out of date and incompatible with the current Instrumental core. Pull requests fixing this are welcome.
  "Pull requests fixing this are welcome.".format(__name__)

In [3]: paramsets
Out[3]: 
[<ParamSet[TDC001_APT] port='/dev/ttyUSB1'>,
 <ParamSet[TDC001_APT] port='/dev/ttyUSB0'>]

In [4]: dict(paramsets[0])
Out[4]: {'classname': 'TDC001_APT', 'module': 'motion.apt', 'port': '/dev/ttyUSB1'}

Apparently, there is no access to the serial numbers. Should I dig into the code and try to reimplement similar functionality regarding serial numbers as found e.g. in https://github.com/felix92/thorpy (though that module imports usb.core to read the serial number contained in the USB device descriptor)?

@FilipDominec
Copy link
Author

FilipDominec commented Jan 25, 2021

Actually there is a field called serial in the header file


But it seems that this is only used on Windows, through the module tdc_001.py. On Linux, the apt.py module is used instead, and there is no access to the serial number. (Should not this be documented?)

Another confusing attribute is this, which obviously relates to the virtual serial port over USB:

In [5]: i = instrument(list_instruments()[0])

In [5]: i._ser
Out[4]: Serial<id=0x7f8bad4b67b8, open=True>(port='/dev/ttyUSB2', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=0.2, xonxoff=False, rtscts=False, dsrdtr=False)

But the "id" number changes upon each re-connection of the device.

What I expect is the access to the 8-digit number recorded permanently into, and printed on, each Thorlabs' controller.

@FilipDominec
Copy link
Author

OK, I can see in the APT_Communication_Protocol_Rev_16.pdf that the MGMSG_HW_REQ_INFO message should provide also serial number.

But issuing a command that explicitly calls it,

i.get_info()

only gives the following result:
b'\x06\x00T\x00\x80\x00\x01\x00\x00\x83TDC001\x00\x00\x10\x00\x0b\x00\x01\x00APT DC Motor Controller \x08\x00\x01\x00\x00\x00\x01\x00'

These bytes contain no unique serial number. Both my controllers report exactly the same.

A solution for Linux: Until a fix is issued, apparently the only reliable source of serial number is in the USB descriptor. This can be filtered as such:

def list_instruments_filter(filter_serial_number=None):
    print("DEBUG: filter_serial_number = ", filter_serial_number)
    return [ParamSet(TDC001_APT, port=p.device) for p in comports() if ((p.vid, p.pid) == (0x0403, 0xfaf0) and
        (filter_serial_number is None or p.serial_number==filter_serial_number)]

@FilipDominec
Copy link
Author

The above PR fixes this simply by exposing the serial number to the end user. If the PR is merged, this issue will be solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant