Coder Social home page Coder Social logo

Comments (3)

AlexShkarin avatar AlexShkarin commented on August 25, 2024

Hi!

It looks like the ID you use to connect (104390055) is different from the one reported by the list_kinesis_devices function (103390054).

from pylablib.

nusratc2 avatar nusratc2 commented on August 25, 2024

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.

from pylablib.

AlexShkarin avatar AlexShkarin commented on August 25, 2024

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.

from pylablib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.