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

Lakeshore 336 Driver with USB interface not connecting #5369

Open
filmartinelli opened this issue Sep 15, 2023 · 9 comments
Open

Lakeshore 336 Driver with USB interface not connecting #5369

filmartinelli opened this issue Sep 15, 2023 · 9 comments

Comments

@filmartinelli
Copy link

If you encounter a bug, use the following template.
If you have a feature request feel free to freestyle or use ideas section in the discussions
here.
If you have a question or general opinion, open your query on a relevant discussion section.

Bug report template:

The driver for the lakeshore 336 does not connect when using USB interface

Steps to reproduce

  1. Connect the device via USB and initialize the class LakeshoreModel336

Expected behaviour

The device is connected

Actual behaviour

The device runs in timeout when waiting for the *IDN?\n

System

It would be helpful to provide such information:

Windows 10

If you are using a released version of qcodes (recommended):
latest release

@jenshnielsen
Copy link
Collaborator

Hi @filmartinelli I am not sure it the driver has been tested with usb connection but normally it should work. Could you show the exact command you use to connect.

@jenshnielsen
Copy link
Collaborator

Also its usually a good idea to test if you can connect with the utility program supplied from the visa library vendor. Ni Max if you use the NI drivers etc.

@filmartinelli
Copy link
Author

Hi @jenshnielsen .

The line that I use to connect to the instrument is the following
from qcodes.instrument_drivers.Lakeshore import LakeshoreModel336
tc = LakeshoreModel336("lake", "ASRL4::INSTR")

ASRL4::INSTR is the VISA resource name that I can find on NI MAX or with PyVisa Resource manager.

I tried to connect the instrument via NI MAX and it works perfectly. However, in order to succesfully establish the connection, I need to specify proper parameters in terms of baud rate, bit number and parity. These parameters are different from the default values.

In QCodes I did not find a way to specify the parameters of the serial communication, so I guessed that the problem could come from the driver establishing a communication with default parameters which are wrong.

Serial com parameters are as follow

  • Baud Rate = 57900
  • Data bits = 7
  • Parity Odd
  • Flow control none

Thank you!

@jenshnielsen
Copy link
Collaborator

I am a bit surprised to see that it's a serial instrument and not a usb instrument https://pyvisa.readthedocs.io/en/latest/introduction/names.html

Perhaps its also possible to connect as a usb instrument.

We typically have not needed to expose these kinds of settings but if it is required, we are happy to review a pr that makes it possible to set then on the Lakeshore class.

@filmartinelli
Copy link
Author

I was surprised as well, however according to the manual the USB interface just emulates a serial port and it does not mention any way to use it as a USB instrument.

Here a screenshot of the manual

image

To my understanding, it seems that the only possible way to establish connection via USB as Serial.
Also, I do not think it is necessary to expose the setting of the baud rate etc., but just to make these number as default when calling this class.

@frankhoff
Copy link

We had that issue a while ago. The default settings for the serial connection are set to 9600 as far as I know. A workaround would be to directly use pyvisa's ResourceManager, to open the connection to the device and then create the Lakeshore336 instance.

Here's some code (in this case the port was "COM3"):

from pyvisa import ResourceManager, constants
rm = ResourceManager()
LS366 = rm.open_resource("COM3", baud_rate=57600, parity=constants.Parity.odd, data_bits=7)
lake = Model_336("lake", "COM3")

Cheers

@jenshnielsen
Copy link
Collaborator

@frankhoff I am not completely sure that would always be safe since it relies on pyvisa always reusing the resouce.
@filmartinelli I would be happy to review a pr that sets these things correctly by default.

In the mean time I have opened #5485 to allow these kwargs to be passed to open_resource

@frankhoff
Copy link

Thanks for the reply!
If this procedure is unsafe, wouldn't it be good to catch this in some way? As user, I would expect qcodes to throw an error, if the device which should be used has already been opened.

Passing kwargs to open_resource for serial devices sounds like a good idea to me 👍

@ggggggggg
Copy link

I solved this by overloading _open_resource for the instrument that needs it, in my case a Lakeshore370.

   def _open_resource(self, address: str, visalib: str | None) -> tuple[MessageBasedResource, str, ResourceManager]:
        # first call the existing _open_resource method
        resource, visabackend, resource_manager = super()._open_resource(address, visalib)
        # then set the odd communication settings that can't be passed by argument with the current api
        from pyvisa import constants
        resource.parity = constants.Parity.odd
        resource.data_bits = 7
        return resource, visabackend, resource_manager

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

4 participants