Open rakansha opened 8 years ago
Did you properly set the write_termination and read_termination ? To check that the write_termination is correct try sending a command modifying the state of the instrument and check visially that it worked.
can you elaborate on how that can be done
print keysight.read_termination None
Even write commands are not working. "Operation timed out " error on those also
The manual of the instrument should specify what is the expected termination of a message when writing and reading (line feed \n, carriage return \r, both, something else...). Once you know what is/are the terminations character(s), you can set write_termination and read_termination accordingly, this pyvisa will add the write_termination to your messages and strip the read_termination from your messages.
keysight.write_termination = '\r\n'
keysight.read_termination = '\r\n
I tried all possible combinations : \n, \r, \r\n, \f nothing seems to work.
Can you communicate using NIMax ? I noticed you are using the py backend which is not yet super stable, so if you can try first to use the ni backend. Did you find anything in the instrument manual ?
actually NI VISA library is not available for my Linux version
Has this issue been solved. I am trying to connect a raspberry pi to a keysight 33511B function generator. I have tried writing a udev rule (as explained here: https://github.com/pyvisa/pyvisa-py/issues/3) and that didn't work. Seems like there is a common trend with Keysight (Agilent) instruments as it is here as well: https://github.com/pyvisa/pyvisa-py/issues/71. Trying to change the termination character also didn't work for me. You said the teledyne lecroy waveform generator worked quite well?
Not to my knowledge but apparrently python-ivi usbtmc works so it might be worth giving it a look and use it to update the current implementation. Do you want to try ? Otherwise I might have some time this week but I cannot make any promise.
I have tried today and the instrument now receives commands. part of the problem may have been the an incorrect group/user for the udev rules which i made sure to follow the instructions on the usbtmc repo: https://github.com/python-ivi/python-usbtmc However I get errors for some of the scpi commands i send. But that could be due to sending incorrect commands. i am gonna try and check the error messages in the function generator to see whats going on. Thank you for pointing me in the right direction 👍
It may be worth adding a note in the docs about the configuration of the udev. At least a note pointing to python-usbtmc. Could you do a PR updating the docs ?
Yup. I can provide a link to usbtmc and another link to explain creating user groups etc. with a small explanation of what information is where. Would it be best to create a new doc just for explaining udev rules?
To be clear only the usbtmc library worked. Not pyvisa. I still get a timeout error
Interesting in that case it is still worth investigating on the Pyvisa side. I may have some time to give a look tomorrow but in the meantime a PR about udev would still be meaningful so please go ahead with the doc PR.
Ideally the PR should be against pyvisa-py. I had no time to actually dive into the differences between pyvisa and python-usbtmc but it looks like python-usbtmc has a number of safeguards against instruments not behaving as expected, so it is probably really worth trying to adapt it here.
I am also experiencing this issue with the Tektronix MSO3014 oscilloscope using the pyvisa library. Have you investigated any further on this end?
I'm new to this so take my answer with a grain of salt, but I also had a problem with the "Operation timed out" error when using the Tektronix MSO3014 with pyvisa. I fixed it by installing the MSO3000(etc.) IVI driver v1.4 from the Tektronix website:
https://www.tek.com/oscilloscope/dpo2002-software
and following the installation instructions. Hopefully, that will help? If you need more information, please let me know what I should provide - I'm a novice.
Same problem with Keysight B2911A SMU on Linux and these versions:
Machine Details:
Platform ID: Linux-4.15.0-55-generic-x86_64-with-Ubuntu-18.04-bionic
Processor: x86_64
Python:
Implementation: CPython
Executable: /usr/bin/python3
Version: 3.6.9
Compiler: GCC 8.3.0
Bits: 64bit
Build: Nov 7 2019 10:44:02 (#default)
Unicode: UCS4
PyVISA Version: 1.10.1
Backends:
ni:
Version: 1.10.1 (bundled with PyVISA)
Binary library: Not found
py:
Version: 0.3.1
ASRL INSTR:
Please install PySerial (>=3.0) to use this resource type.
No module named 'serial'
USB INSTR: Available via PyUSB (1.0.2). Backend: libusb1
USB RAW: Available via PyUSB (1.0.2). Backend: libusb1
TCPIP INSTR: Available
TCPIP SOCKET: Available
GPIB INSTR:
Please install linux-gpib to use this resource type.
No module named 'gpib'
Any attempt to write to the device would result in usb.core.USBError: [Errno 110] Operation timed out
What worked for me: installing the full Keysight IO Libraries Suite 2020 (for Linux) (bit of a hassle, requires a specific kernel version) and explicitly instantiating visa.ResourceManager("/usr/lib/x86_64-linux-gnu/libivivisa.so")
.
Having the same issue with an Agilent (Keysight) 33521A but only after updating the firmware from v1.14 to v5.02, so that may be a clue. Times out on write and query operations for all combinations of termination characters ('\r', '\r\n', '\n')
Edited to add: everything still works fine from my windows device using the NI backend.
My pyvisa info:
Machine Details: Platform ID: Linux-4.15.0-88-generic-x86_64-with-Ubuntu-18.04-bionic Processor: x86_64
Python: Implementation: CPython Executable: /usr/bin/python3 Version: 3.6.9 Compiler: GCC 8.3.0 Bits: 64bit Build: Nov 7 2019 10:44:02 (#default) Unicode: UCS4
PyVISA Version: 1.10.1
Backends: ni: Version: 1.10.1 (bundled with PyVISA) pyvisa/pyvisa#1: /usr/lib/x86_64-linux-gnu/libvisa.so.0.0.0: found by: auto bitness: 64 Could not get more info: VI_ERROR_NSUP_ATTR (-1073807331): The specified attribute is not defined or supported by the referenced object. py: Version: 0.3.1 ASRL INSTR: Available via PySerial (3.4) USB INSTR: Available via PyUSB (1.0.2). Backend: libusb1 USB RAW: Available via PyUSB (1.0.2). Backend: libusb1 TCPIP INSTR: Available TCPIP SOCKET: Available GPIB INSTR: Please install linux-gpib to use this resource type. No module named 'Gpib'
Hi, same issue with Agilent u3606a.
Machine Details:
Platform ID: Linux-5.4.72-v8+-aarch64-with-glibc2.17
Processor:
Python:
Implementation: CPython
Executable: /home/pi/miniforge3/envs/sitesting/bin/python
Version: 3.8.6
Compiler: GCC 7.5.0
Bits: 64bit
Build: Oct 7 2020 18:25:18 (#default)
Unicode: UCS4
PyVISA Version: 1.10.1
Backends:
ni:
Version: 1.10.1 (bundled with PyVISA)
Binary library: Not found
py:
Version: 0.3.1
ASRL INSTR: Available via PySerial (3.4)
USB INSTR: Available via PyUSB (1.1.0). Backend: libusb1
USB RAW: Available via PyUSB (1.1.0). Backend: libusb1
TCPIP INSTR: Available
TCPIP SOCKET: Available
GPIB INSTR:
Please install linux-gpib to use this resource type.
No module named 'gpib'
Please update to the latest pyvisa and pyvisa-py versions and report the exact error you see (since sometimes there are slight variations between systems).
Min example with latest version of system (clean environment):
Machine Details:
Platform ID: Linux-5.4.72-v8+-aarch64-with-glibc2.17
Processor:
Python:
Implementation: CPython
Executable: /home/pi/miniforge3/envs/pyvisa_test/bin/python3.8
Version: 3.8.6
Compiler: GCC 7.5.0
Bits: 64bit
Build: Oct 7 2020 18:25:18 (#default)
Unicode: UCS4
PyVISA Version: 1.11.1
Backends:
ivi:
Version: 1.11.1 (bundled with PyVISA)
Binary library: Not found
py:
Version: 0.5.1
ASRL INSTR: Available via PySerial (3.4)
USB INSTR: Available via PyUSB (1.1.0). Backend: libusb1
USB RAW: Available via PyUSB (1.1.0). Backend: libusb1
TCPIP INSTR: Available
TCPIP SOCKET: Available
GPIB INSTR:
Please install linux-gpib (Linux) or gpib-ctypes (Windows, Linux) to use this resource type. Note that installing gpib-ctypes will give you access to a broader range of funcionality.
No module named 'gpib'
Minimal example code
import traceback
import pyvisa as visa
rm = visa.ResourceManager()
m = rm.open_resource('USB0::2391::19736::MY50099047::0::INSTR')
m.write_termination = '\n'
m.read_termination = '\n'
try:
m.query('*IDN?')
except Exception as e:
traceback.print_exc()
print('adding delay: ')
m.query_delay = .2
try:
m.query('*IDN?')
except Exception as e:
traceback.print_exc()
Output/Error:
Traceback (most recent call last):
File "test.py", line 11, in <module>
m.query('*IDN?')
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 644, in query
return self.read()
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 486, in read
message = self._read_raw().decode(enco)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 442, in _read_raw
chunk, status = self.visalib.read(self.session, size)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa_py/highlevel.py", line 519, in read
return data, self.handle_return_value(session, status_code)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa/highlevel.py", line 251, in handle_return_value
raise errors.VisaIOError(rv)
pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
adding delay:
Traceback (most recent call last):
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa_py/protocols/usbtmc.py", line 256, in write
return self.usb_send_ep.write(data)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/usb/core.py", line 406, in write
return self.device.write(self, data, timeout)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/usb/core.py", line 977, in write
return fn(
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/usb/backend/libusb1.py", line 837, in bulk_write
return self.__write(self.lib.libusb_bulk_transfer,
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/usb/backend/libusb1.py", line 938, in __write
_check(retval)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/usb/backend/libusb1.py", line 602, in _check
raise USBTimeoutError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBTimeoutError: [Errno 110] Operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 17, in <module>
m.query('*IDN?')
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 638, in query
self.write(message)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 197, in write
count = self.write_raw(message.encode(enco))
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 157, in write_raw
return self.visalib.write(self.session, message)[0]
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa_py/highlevel.py", line 543, in write
written, status_code = self.sessions[session].write(data)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa_py/usb.py", line 179, in write
count = self.interface.write(data)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa_py/protocols/usbtmc.py", line 436, in write
bytes_sent += raw_write(data)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa_py/protocols/usbtmc.py", line 258, in write
raise ValueError(str(e))
ValueError: [Errno 110] Operation timed out
Can you try to read just a single byte of the answer ? I would like to know if reading fail altogether or if we have a termination issue.
import pyvisa as visa
rm = visa.ResourceManager()
m = rm.open_resource('USB0::2391::19736::MY50099047::0::INSTR')
m.write_termination = '\n'
m.read_termination = '\n'
m.write('*IDN?')
while True:
print(m.read_bytes(1))
@MatthieuDartiailh
This is the output to your code:
Traceback (most recent call last):
File "test.py", line 10, in <module>
print(m.read_bytes(1))
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 371, in read_bytes
chunk, status = self.visalib.read(self.session, size)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa_py/highlevel.py", line 519, in read
return data, self.handle_return_value(session, status_code)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa/highlevel.py", line 251, in handle_return_value
raise errors.VisaIOError(rv)
pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
Nothing printed before the error message ?
No, that is all the output
Can you try a command that would produce a visible change in the instrument state ? We need to figure out if we cannot read the answer or if the instrument is not answering because it did not properly receive the message.
>>> import pyvisa as visa
>>>
>>> rm = visa.ResourceManager()
>>> m = rm.open_resource('USB0::2391::19736::MY50099047::0::INSTR')
>>>
>>>
>>> m.write_termination = '\n'
>>> m.read_termination = '\n'
>>> m.write('CONF:VOLT:DC')
13
>>>
Do you see the mode changing on the instrument ? If you send "OUTP 1"
does the output turn on (assuming it was off) ?
Unfortunately I am not at the lab. Will check it tomorrow. (Sorry about the inconvenience)
No problem. Debugging those kind of issues is always a pain and I would really like to make pyvisa-py better but I do not have that much open-source time those days.
Hi @MatthieuDartiailh , After a few hard-resets on the device: write works (I can see it controlling the instrument, though the ERROR REMOTE appears in the display. Also, query works but the same ERROR Remote message appears in the display. I will debug the error thrown and update you with it
`import pyvisa as visa
rm = visa.ResourceManager()
m = rm.open_resource('USB0::2391::19736::MY50099047::0::INSTR')
m.write_termination = '\n'
m.read_termination = '\n'
m.write('CONF:VOLT:DC')
m.write('sense:voltage:dc:range 10V')
print(m.query('*IDN?'))
m.write('MEAS:VOLT:DC?')
while True:
print(m.read_bytes(1))`
Produces:
Agilent Technologies,U3606A,MY50099047,02.00-03.00-03.00
Traceback (most recent call last):
File "test.py", line 16, in <module>
print(m.read_bytes(1))
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa/resources/messagebased.py", line 371, in read_bytes
chunk, status = self.visalib.read(self.session, size)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa_py/highlevel.py", line 519, in read
return data, self.handle_return_value(session, status_code)
File "/home/pi/miniforge3/envs/pyvisa_test/lib/python3.8/site-packages/pyvisa/highlevel.py", line 251, in handle_return_value
raise errors.VisaIOError(rv)
pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
This is the point where things get really complicated... I am still confused by how some USB devices works flawlessly while some other like your cannot behave properly.
If you want to keep digging, try to use Wireshark to spy on the transferred data using PyVISA-py and possibly using NI or Keysight implementation if you can install it. There must be something different. I will try to go again through the code and the USBTMC specification and see if we missed anything but it may take me some time.
I will try to sniff it, though due to the actual circumstances I will not be able to access physically the instrument everyday. Will use a normal x86 machine to use a different backend and see the differences.
In any case, thanks a lot for your support and all the work you put on the project.
You are welcome and I am sorry I cannot offer you a better solution.
Hi @MatthieuDartiailh I am back at the lab, so probably can get the wireshark traces you asked for. This issue also happens to keysight b2912a (actually, even before, on the instr.write):
pyvisa_py/protocols/usbtmc.py in write(self, data)
256 return self.usb_send_ep.write(data)
257 except usb.core.USBError as e:
--> 258 raise ValueError(str(e))
259
260 def read(self, size):
ValueError: [Errno 110] Operation timed out
can you tell me what traces you need from wireshark?
thanks!
Ideally I would like to see everything from the opening of the instrument till the error. And if you can get the same in a working environment that would be great since I could compare both.
Hi Matthieu, I am not sure if the attachment will help with this issue. I captured some traces, that I think were for this issue in November 2019. However, I did not get to discuss it before the contract that was using the Signal Generator ended in January 2020. The traces might be too old with an old version of pyvisa-py. I think there are traces of the error with pyvisa-py and no problems with usbtmc. Hope it helps and is not a distraction with it simply being too old, Michael Wilkinson Compute Thing Limited
On Mon, 2021-03-01 at 05:41 -0800, Matthieu Dartiailh wrote:
Ideally I would like to see everything from the opening of the instrument till the error. And if you can get the same in a working environment that would be great since I could compare both. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Hi Matthieu, just send you an email with the traces. Thanks
Thanks. However I cannot give you a timeline for this. I am a bit overwhelmed at the moment.
Of course, and thanks again for your time!
Maybe this helps: https://github.com/python-ivi/python-usbtmc/pull/50
Thanks for sharing @ferdymercury .I honestly do not remember of I did such changes for pyvisa-py I have a vague recollection but I am not sure. Could you make a PR ? I am a bit under water at the moment.
We are also running into this issue with a Keysight 33500B Series waveform generator. Has there been farther work on this? Is there anything we can do to help. Using python-usbtmc has no problems.
I took a look at the python-usbtmc fix but have no idea what the heck they are doing.
The problem seems to lie with these two lines: https://github.com/pyvisa/pyvisa-py/blob/main/pyvisa_py/protocols/usbtmc.py#L292 and the line right under it.
C/P here for clarity:
self.usb_dev.reset()
self.usb_dev.set_configuration()
Commenting out both of them and the timeout error disappears with the 33500B. We tested with a Keysight DMM and don't see a problem there either.
If you comment out just the reset, then you get a resource busy error. If you comment out just set_configuration, you get the time out error again. You must comment out both.
I have no idea what this impacts, but from reading some libusb docs, they say: "You cannot change/reset configuration if your application has claimed interfaces. It is advised to set the desired configuration before claiming interfaces."
I am not sure if this has anything to do with it? Maybe resetting and then trying to set configuration is going out of order. You don't reset, but set_configuration is already called once in the USBRAW class init, which USBTMC class calls https://github.com/pyvisa/pyvisa-py/blob/main/pyvisa_py/protocols/usbtmc.py#L216
I am going to test with a non-Keysight device and see if anything weird happens
I must say I have no time for PyVISA beyond answering to people issues. If you can figure out how to at least mitigate this issue I will happily review a PR.
It is perfectly possible that the logic got messed up at one point when refactoring those two classes and that a lack of deep enough understanding of libusb caused the issue. If you do make a PR, please add that kind of information as comment so that we do not regress in the future.
Ok, let me do some additional testing with non-Keysight devices and see if any weird problems occur with commenting out those two lines. If things look good, I will create a PR for this problem.
Sorry to barge in this issue, but if it helps, I was having a very similar issue with a Tektronix oscilloscope (TBS1062). Just commenting out those two lines did not work, but if I also comment lines 216 and 221 (actually, the entire try/except blocks), it worked fine, and no problem was observed with other instruments from other manufacturers.
Line 221 was:
self.usb_dev.set_interface_altsetting()
It seems there is some kind of issue with the configuration settings and some very specific instruments.
My software details for VISA are: Machine Details: Platform ID: Linux-4.4.0-28-generic-x86_64-with-Ubuntu-16.04-xenial Processor: x86_64
Python: Implementation: CPython Executable: /usr/bin/python Version: 2.7.11+ Compiler: GCC 5.3.1 20160413 Bits: 64bit Build: Apr 17 2016 14:00:29 (#default) Unicode: UCS4
PyVISA Version: 1.8
Backends: ni: Version: 1.8 (bundled with PyVISA) Binary library: Not found py: Version: 0.3.dev0 ASRL INSTR: Please install PySerial to use this resource type. No module named serial TCPIP INSTR: Available USB RAW: Available via PyUSB (1.0.0). Backend: libusb1 USB INSTR: Available via PyUSB (1.0.0). Backend: libusb1 GPIB INSTR: Please install linux-gpib to use this resource type. No module named gpib TCPIP SOCKET: Available
I am using py visa to connect to a Keysight 33500B Series waveform generator.I have already successfully used python VISA to connect to Tektronix oscilloscope as well as Teledyne LeCroy Waveform generator..But with Keysight I get an operation time out error on any query or write function..This is the what my input output session looks like: