Open thombou opened 3 years ago
I am having a similar problem.
I am able to initialize the thorlabs motor directly through a shell but when I do the same sequence of commands in a script and run the script with python script_name.py
, I get the following exception
Exception: Moving velocity failed: Invalid error code.
I am baffled about why the shell vs. script should make a difference. Some insight would be much appreciated. I have added the code below for the function called in a script used to initialize a single thorlabs motor.
def initMotor() -> Motor:
"""
Defines and instantiates the mode motor.
This function finds a THORLABS motor connected to the computer and
initiates the velocity and acceleration constraints. Additionally, the
motor will be moved to the homing position.
Parameters
----------
None
Returns
-------
Motor
Motor object defined by thorlabs_apt.
"""
devices = apt.list_available_devices()
try:
motorSerialNumber = devices[0][1]
except:
raise Exception("No motor detected. Ensure the device is connected.")
# Initialize motor if detected.
modeMotor = apt.Motor(motorSerialNumber)
modeMotor.set_move_home_parameters(*modeMotor.get_move_home_parameters())
modeMotor.set_velocity_parameters(*modeMotor.get_velocity_parameters())
modeMotor.enable()
try:
modeMotor.move_home(True)
except:
raise Exception("Motor cannot be homed.")
return modeMotor
Actually, this is the same error I am facing. I think the problem is the import function. I made a post 5 minutes ago detailing the trouble shooting steps I took
When using the library in a Qt application, it is impossible to create a motor in a separate thread. Calling apt.Motor() causes the application to crash. without any error.
I am using PyQt5, Python 3.8.5 64bits on Windows 10