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

Error in discover_stages #22

Open
aveekchandra opened this issue May 10, 2021 · 1 comment
Open

Error in discover_stages #22

aveekchandra opened this issue May 10, 2021 · 1 comment

Comments

@aveekchandra
Copy link

aveekchandra commented May 10, 2021

I have been trying to interface Thorlabs APT controller (TDC001) using thorpy_master. I have plugged and unplugged the device but I still get the same error message (see below) in the discovery_stages inside thorpy.comm.
I have printed the serial ports (<print(serial_ports)>) in discovery_stages and you can see the controller has been detected as 'Brushed Motor Controller'. However, when I do print port_candidates it gives a null array. While trying several times, once or twice it returned the correct port_candidates at the print-out but returned null soon after. Please advise.

Output messages with error:
[('/dev/ttyS4', 'n/a', {}), ('/dev/ttyUSB0', 'Brushed Motor Controller', {'VID:PID': '0403:FAF0', 'SER': '27003927', 'LOCATION': '1-1'})] ---> <print(serial_ports)>
[] ----> print(port_candidates)
Traceback (most recent call last):
File "test.py", line 6, in
stages = list(discover_stages())
File "/home/qitlab/anaconda3/lib/python3.7/site-packages/thorpy/comm/discovery.py", line 28, in discover_stages
assert len(port_candidates) == 1
AssertionError

@isildur7
Copy link

replace the discover.py file with this code:

    from .port import Port
    from serial.tools.list_ports import comports
    import platform

    serial_ports = [
        (x[0], x[1], dict(y.split("=", 1) for y in x[2].split(" ") if "=" in y))
        for x in comports()
    ]

    if platform.system() == "Linux":
        port_candidates = [
            x
            for x in serial_ports
            if x[1] == "Brushed Motor Controller - Brushed Motor Controller"
        ]
        print(port_candidates)
    else:
        raise NotImplementedError(
            "Implement for platform.system()=={0}".format(platform.system())
        )

    assert len(port_candidates) == 1

    port = port_candidates[0]

    p = Port.create(port[0], port[2].get("SER", None))
    for stage in p.get_stages().values():
        yield stage


if __name__ == "__main__":
    print(list(discover_stages()))


# iManufacturer           1 Thorlabs
#    iProduct                2 APT DC Motor Controller
#    iSerial                 3 83856536

This works for me.

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

2 participants