Open MassiliaHamdani opened 9 months ago
Hi!
It looks like the ID you use to connect (104390055
) is different from the one reported by the list_kinesis_devices
function (103390054
).
Hi Alex, I have been trying this command after seeing the controller is visible in kinesis software, but getting this error repeatedly, I can't connect the BBD 302 controller to the MLS stages too. Everytime I run this code, the controller is not visible by the kinesis software anymore, I have to restart the device again, is there any way to establish this connection and not lose it due after every run?
My code: from pylablib.devices import Thorlabs Thorlabs.list_kinesis_devices() [('103387864', 'Kinesis Benchless Motor')] stage = Thorlabs.KinesisMotor("103387864", is_rack_system=True) stage = Thorlabs.KinesisMotor("103387864")
The error:
D2XXException Traceback (most recent call last) File ~\AppData\Roaming\Python\Python311\site-packages\pylablib\core\devio\comm_backend.py:809, in FT232DeviceBackend.init(self, conn, timeout, term_write, term_read, open_retry_times, datatype, reraise_error) 808 try: --> 809 self.instr=self._open_instr(port,conn_dict) 810 self.opened=True
File ~\AppData\Roaming\Python\Python311\site-packages\pylablib\core\devio\comm_backend.py:821, in FT232DeviceBackend._open_instr(self, port, params) 820 if "serial_number" in sig.arg_names: # pyft232 v0.11 signature change --> 821 return ft232.Ft232(serial_number=port,**params) 822 else:
File ~\AppData\Roaming\Python\Python311\site-packages\ft232\d2xx.py:127, in D2xx.init(self, port, serial_number, description, baudrate, bytesize, parity, stopbits, timeout, xonxoff, rtscts, writeTimeout) 125 status = d2xx.FT_OpenEx(serial, FT_OPEN_BY_SERIAL_NUMBER, 126 c.byref(self.handle)) --> 127 if status != FT_OK: raise D2XXException(status) 128 elif description:
D2XXException: Device Not Opened
The above exception was the direct cause of the following exception:
ThorlabsBackendError Traceback (most recent call last) Cell In[16], line 4 2 Thorlabs.list_kinesis_devices() 3 [('103387864', 'Kinesis Benchless Motor')] ----> 4 stage = Thorlabs.KinesisMotor("103387864", is_rack_system=True) 5 stage = Thorlabs.KinesisMotor("103387864")
File ~\AppData\Roaming\Python\Python311\site-packages\pylablib\devices\Thorlabs\kinesis.py:1102, in KinesisMotor.init(self, conn, scale, default_channel, is_rack_system) 1101 def init(self, conn, scale="step", default_channel=1, is_rack_system=False): -> 1102 super().init(conn,default_channel=default_channel,is_rack_system=is_rack_system) 1103 self.add_background_comm(0x0464) # move completed 1104 self.add_background_comm(0x0466) # move stopped
File ~\AppData\Roaming\Python\Python311\site-packages\pylablib\devices\Thorlabs\kinesis.py:277, in KinesisDevice.init(self, conn, timeout, default_channel, is_rack_system) 276 def init(self, conn, timeout=3., default_channel=1, is_rack_system=False): --> 277 super().init(conn,timeout=timeout,is_rack_system=is_rack_system,default_axis=default_channel) 278 self._remove_device_variable("axes") 279 self._add_info_variable("channel",self.get_all_channels)
File ~\AppData\Roaming\Python\Python311\site-packages\pylablib\devices\interface\stage.py:34, in IMultiaxisStage.init(self, default_axis, *args, kwargs) 33 def init(self, *args, default_axis="all", *kwargs): ---> 34 super().init(args,kwargs) 35 self._original_axis_parameter=None 36 self._default_axis=default_axis
File ~\AppData\Roaming\Python\Python311\site-packages\pylablib\devices\Thorlabs\kinesis.py:44, in BasicKinesisDevice.init(self, conn, timeout, is_rack_system) 42 def init(self, conn, timeout=3., is_rack_system=False): 43 defaults={"serial":{"baudrate":115200,"rtscts":True}, "ft232":{"baudrate":115200,"rtscts":True}} ---> 44 instr=comm_backend.new_backend(conn,backend=("auto","ft232"),term_write=b"",term_read=b"",timeout=timeout, 45 defaults=defaults,reraise_error=ThorlabsBackendError) 46 instr.setup_cooldown(write=0.003) 47 try:
File ~\AppData\Roaming\Python\Python311\site-packages\pylablib\core\devio\comm_backend.py:1776, in new_backend(conn, backend, defaults, kwargs) 1774 if defaults is not None and backend_name is not None and backend_name in defaults: 1775 conn=backend.combine_conn(conn,defaults[backend_name]) -> 1776 return backend(conn,kwargs)
File ~\AppData\Roaming\Python\Python311\site-packages\pylablib\core\devio\comm_backend.py:816, in FT232DeviceBackend.init(self, conn, timeout, term_write, term_read, open_retry_times, datatype, reraise_error) 814 self._conn_params=(port,conn_dict,timeout) 815 except self.BackendError as e: --> 816 raise self.Error(e) from e
ThorlabsBackendError: backend exception: D2XXException(3) ('Device Not Opened')
stage = Thorlabs.KinesisMotor("103387864", is_rack_system=True)
C:\Users\nusratc2\AppData\Roaming\Python\Python311\site-packages\pylablib\devices\Thorlabs\kinesis.py:1230: UserWarning: can't recognize motor model BBD302; setting all scales to internal units warnings.warn("can't recognize motor model {}; setting all scales to internal units".format(self._model))
Can you please help me with it. I am stuck for days. Please help me.
Hello!
Every time after opening the device, you need to close it again:
stage = Thorlabs.KinesisMotor("103387864", is_rack_system=True)
# ... do some work ...
stage.close()
This signals the OS that other software (e.g., Kinesis) can connect to it. In order to ensure that the device gets closed even when an error occurs, you can use the context manager approach:
with Thorlabs.KinesisMotor("103387864", is_rack_system=True) as stage:
# ... do some work ...
# the stage closes automatically when the execution is done
Also, keep in mind that only one connection can be opened at a time, which means that the code you have right now definitely won't work: it tries to connect to the same device 2 times in a row, so the second line will raise an error.
Hello, I can't establish a connection with the Thorlabs ML203 board (BBD302 controller).
When I run the following code :
import pylablib.devices.Thorlabs.kinesis
Connection and list devices connected
from pylablib.devices import Thorlabs print(Thorlabs.list_kinesis_devices(filter_ids=False))
stage_xy = Thorlabs.KinesisMotor("104390055")
I get this error :
C:\Users\massi_1xn8v1g\PycharmProjects\pythonProject\venv9\Scripts\python.exe C:\Users\massi_1xn8v1g\PycharmProjects\pythonProject\main_stage.py [('103390054', 'Brushless Motor Controller')] Traceback (most recent call last): File "C:\Users\massi_1xn8v1g\PycharmProjects\pythonProject\venv9\lib\site-packages\pylablib\core\devio\comm_backend.py", line 809, in init self.instr=self._open_instr(port,conn_dict) File "C:\Users\massi_1xn8v1g\PycharmProjects\pythonProject\venv9\lib\site-packages\pylablib\core\devio\comm_backend.py", line 821, in _open_instr return ft232.Ft232(serial_number=port,**params) File "C:\Users\massi_1xn8v1g\PycharmProjects\pythonProject\venv9\lib\site-packages\ft232\d2xx.py", line 127, in init if status != FT_OK: raise D2XXException(status) ft232.d2xx.D2XXException: Device Not Found
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\massi_1xn8v1g\PycharmProjects\pythonProject\main_stage.py", line 9, in
stage_xy = Thorlabs.KinesisMotor("104390055")
File "C:\Users\massi_1xn8v1g\PycharmProjects\pythonProject\venv9\lib\site-packages\pylablib\devices\Thorlabs\kinesis.py", line 1102, in init
super().init(conn,default_channel=default_channel,is_rack_system=is_rack_system)
File "C:\Users\massi_1xn8v1g\PycharmProjects\pythonProject\venv9\lib\site-packages\pylablib\devices\Thorlabs\kinesis.py", line 277, in init
super().init(conn,timeout=timeout,is_rack_system=is_rack_system,default_axis=default_channel)
File "C:\Users\massi_1xn8v1g\PycharmProjects\pythonProject\venv9\lib\site-packages\pylablib\devices\interface\stage.py", line 34, in init
super().init(*args,kwargs)
File "C:\Users\massi_1xn8v1g\PycharmProjects\pythonProject\venv9\lib\site-packages\pylablib\devices\Thorlabs\kinesis.py", line 44, in init
instr=comm_backend.new_backend(conn,backend=("auto","ft232"),term_write=b"",term_read=b"",timeout=timeout,
File "C:\Users\massi_1xn8v1g\PycharmProjects\pythonProject\venv9\lib\site-packages\pylablib\core\devio\comm_backend.py", line 1776, in new_backend
return backend(conn,kwargs)
File "C:\Users\massi_1xn8v1g\PycharmProjects\pythonProject\venv9\lib\site-packages\pylablib\core\devio\comm_backend.py", line 816, in init
raise self.Error(e) from e
pylablib.devices.Thorlabs.base.ThorlabsBackendError: backend exception: D2XXException(2) ('Device Not Found')
Process finished with exit code 1