Closed jonnojohnson closed 9 years ago
Yes. I have seen that in certain cases you need an extra:
self.usb_dev.set_configuration()
but not sure why. Is the original exception failing in line 158 or 159?
By the way, you can do:
python -c "from pyvisa import util; util.get_debug_info()"
and you will get a nicely printed debug info. (Still needs to be improved but is a start)
What do you mean by the original exception?
Machine Details: Platform ID: Linux-3.13.0-37-generic-x86_64-with-debian-jessie-sid Processor: x86_64
Python: Implementation: CPython Executable: /home/mj-ubuntu/anaconda/bin/python Version: 2.7.8 Compiler: GCC 4.4.7 20120313 (Red Hat 4.4.7-1) Bits: 64bit Build: Aug 21 2014 18:22:21 (#default) Unicode: UCS4
PyVISA Version: 1.6.1.dev0
Backends: ni: Version: 1.6.1.dev0 (bundled with PyVISA) Binary library: Not found py: Version: 0.1.dev0 ASRL INSTR: Available TCPIP INSTR: Available USB INSTR: Available
Full traceback:
Exception Traceback (most recent call last)
And can you try the following command:
import usb
print(usb.__version__)
print(usb.core.find()._ctx.backend.__class__.__module__.__name__.split('.')[-1])
(I am adding this to the debug info)
Sorry, the right command is:
usb.core.find()._ctx.backend.__class__.__module__.split('.')[-1]
or just update to the most recent (2 seconds ago) pyvisa-py
and then:
python -c "from pyvisa import util; util.get_debug_info()"
I was looking at the PyUSB code and found that alt_setting should be optional. Can you try now?
Machine Details: Platform ID: Linux-3.13.0-37-generic-x86_64-with-debian-jessie-sid Processor: x86_64
Python: Implementation: CPython Executable: /home/mj-ubuntu/anaconda/bin/python Version: 2.7.8 Compiler: GCC 4.4.7 20120313 (Red Hat 4.4.7-1) Bits: 64bit Build: Aug 21 2014 18:22:21 (#default) Unicode: UCS4
PyVISA Version: 1.6.1.dev0
Backends: ni: Version: 1.6.1.dev0 (bundled with PyVISA) Binary library: Not found py: Version: 0.1.dev0 ASRL INSTR: Available via PySerial (N/A) TCPIP INSTR: Available USB INSTR: Available via PyUSB (1.0.0b1). Backend: libusb1
If install the current version from github (just pushed 10 min ago), does it still fails? With the same error?
Yes I just did: pip install -U https://github.com/hgrecco/pyvisa-py/zipball/master Then tried again & got the same failed to set configuration error.
Can you check /var/log/messages
. Do you find something like usbfs: process NNNN (XYZ) did not claim interface 0 before use
? If you do, it is likely a permission problem. This is something that was written some time ago by Florian Forster in the Lantz mailing list.
Yes, you need the right udev rules to interact with the device. For
example, I created the file /etc/udev/rules.d/70-usbtmc.rules which
contains
# Agilent 34410A
SUBSYSTEM=="usb", ACTION=="add", ATTRS{idVendor}=="0957",
ATTRS{idProduct}=="0607", GROUP="plugdev", MODE="0660"
This grants read and write access to my Agilent 34410A (identified by
the vendor and product ids) for all users inside the "plugdev" group.
You can get the ids needed by the dmesg output or by lsusb (look for
ID:XXXX:YYYY where X=vendor and Y=product id).
For this, it is obviously crucial that your user is a member of plugdev
group (you can of course choose any group you see fit, for example
create a new group usbtmc; remember that you have to log out and log in
to refresh the group configurations).
If this is the case, we should find a way to achieve the same thing without manually putting each device into the rules. But it would be good to confirm that this is really the solution first.
Here is some more info: http://unix.stackexchange.com/questions/44308/understanding-udev-rules-and-permissions-in-libusb http://stackoverflow.com/questions/3738173/why-does-pyusb-libusb-require-root-sudo-permissions-on-linux
You might also try to run you python script using sudo, just for testing.
When I run IPython as sudo I now get this when trying to open the usb resource:
/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa-py/usb.pyc in after_parsing(self) 86 for name in 'SEND_END_EN,TERMCHAR,TERMCHAR_EN'.split(','): 87 attr = getattr(constants, 'VIATTR' + name) ---> 88 self.attrs[attr] = attr.default 89 90 def read(self, count):
AttributeError: 'int' object has no attribute 'default'
Repeated the attempt to open_resource (still as sudo) & got: /home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa-py/protocols/usbtmc.pyc in init(self, vendor, product, serial_number, device_filters, timeout, **kwargs) 158 self.usb_dev.set_configuration() #self.CONFIGURATION 159 except usb.core.USBError as e: --> 160 raise Exception('failed to set configuration') 161 162 try:
Exception: failed to set configuration
I solved the AttributeError: 'int' object has no attribute 'default'
But still cannot reproduce failed to set configuration
. I will check on a linux computer, because I suspect that this might be the problem.
For example, this is the output with an osci on my mac:
>>> import visa
>>> rm = visa.ResourceManager('@py')
>>> rm.list_resources()
('USB0::6833::1416::Unknown::0::INSTR',)
>>> inst = rm.open_resource('USB0::6833::1416::Unknown::0::INSTR')
>>> inst.query('*IDN?')
'Rigol Technologies,DS1052E,DS1ED122105695,00.02.04.00.01'
and using the ni backend:
>>> import visa
>>> rm = visa.ResourceManager()
>>> rm.list_resources()
('USB0::0x1AB1::0x0588::DS1K00005888::INSTR', 'ASRL1::INSTR', 'ASRL2::INSTR')
>>> inst = rm.open_resource('USB0::0x1AB1::0x0588::DS1K00005888::INSTR')
>>> inst.query('*IDN?')
'Rigol Technologies,DS1052E,DS1ED122105695,00.02.04.00.01'
Notice the only problem in this snippet with the py backend is that the resource name is malformed (this is due to a change in PyUSB) and that the serial ports are not listed.
And this are my debug info:
Machine Details:
Platform ID: Darwin-10.8.0-x86_64-i386-64bit
Processor: i386
Python:
Implementation: CPython
Executable: /Users/grecco/envs/pyvisadev/bin/python3.4
Version: 3.4.1
Compiler: GCC 4.2.1 (Apple Inc. build 5666) (dot 3)
Bits: 64bit
Build: May 18 2014 00:54:21 (#v3.4.1:c0e311e010fc)
Unicode: UCS4
PyVISA Version: 1.6.1.dev0
Backends:
ni:
Version: 1.6.1.dev0 (bundled with PyVISA)
#1: /Library/Frameworks/visa.framework/visa:
found by: auto
bitness: 32
py:
Version: unknown
USB INSTR: Available via PyUSB (1.0.0b2). Backend: libusb0
ASRL INSTR: Available via PySerial (10.8.0)
TCPIP INSTR: Available
Ok I updated PyVISA-py just now and re-tried (using sudo) and now I can create the instrument:
In [4]: rm.list_resources()
Out[4]:
(u'ASRL/dev/ttyS31::INSTR',
u'ASRL/dev/ttyS30::INSTR',
u'ASRL/dev/ttyS29::INSTR',
u'ASRL/dev/ttyS28::INSTR',
u'ASRL/dev/ttyS27::INSTR',
u'ASRL/dev/ttyS26::INSTR',
u'ASRL/dev/ttyS25::INSTR',
u'ASRL/dev/ttyS24::INSTR',
u'ASRL/dev/ttyS23::INSTR',
u'ASRL/dev/ttyS22::INSTR',
u'ASRL/dev/ttyS21::INSTR',
u'ASRL/dev/ttyS20::INSTR',
u'ASRL/dev/ttyS19::INSTR',
u'ASRL/dev/ttyS18::INSTR',
u'ASRL/dev/ttyS17::INSTR',
u'ASRL/dev/ttyS16::INSTR',
u'ASRL/dev/ttyS15::INSTR',
u'ASRL/dev/ttyS14::INSTR',
u'ASRL/dev/ttyS13::INSTR',
u'ASRL/dev/ttyS12::INSTR',
u'ASRL/dev/ttyS11::INSTR',
u'ASRL/dev/ttyS10::INSTR',
u'ASRL/dev/ttyS9::INSTR',
u'ASRL/dev/ttyS8::INSTR',
u'ASRL/dev/ttyS7::INSTR',
u'ASRL/dev/ttyS6::INSTR',
u'ASRL/dev/ttyS5::INSTR',
u'ASRL/dev/ttyS4::INSTR',
u'ASRL/dev/ttyS3::INSTR',
u'ASRL/dev/ttyS2::INSTR',
u'ASRL/dev/ttyS1::INSTR',
u'ASRL/dev/ttyS0::INSTR',
u'USB0::10893::36894::MY53240105::0::INSTR')
In [5]: scope = rm.open_resource('USB0::10893::36894::MY53240105::0::INSTR')
However I'm getting a timeout error when querying for idn.
In [6]: scope.query('*IDN?')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-6-9571613806bc> in <module>()
----> 1 scope.query('*IDN?')
/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa/resources/messagebased.pyc in query(self, message, delay)
382 if delay > 0.0:
383 time.sleep(delay)
--> 384 return self.read()
385
386 # Kept for backwards compatibility.
/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa/resources/messagebased.pyc in read(self, termination, encoding)
307 if termination is None:
308 termination = self._read_termination
--> 309 message = self.read_raw().decode(enco)
310 else:
311 with self.read_termination_context(termination):
/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa/resources/messagebased.pyc in read_raw(self, size)
281 logger.debug('%s - reading %d bytes (last status %r)',
282 self._resource_name, size, status)
--> 283 chunk, status = self.visalib.read(self.session, size)
284 ret += chunk
285 except errors.VisaIOError as e:
/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa-py/highlevel.pyc in read(self, session, count)
289 # from the session handle, dispatch to the read method of the session object.
290 try:
--> 291 return self.sessions[session].read(count)
292 except KeyError:
293 return constants.StatusCode.error_invalid_object
/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa-py/usb.pyc in read(self, count)
100 term_char, _ = self.get_attribute(constants.VI_ATTR_TERMCHAR)
101 while True:
--> 102 ret += self.interface.read(1)
103 if ret[-1:] == term_char:
104 # TODO: What is the correct success code??
/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa-py/protocols/usbtmc.pyc in read(self, size)
311 req = BulkInMessage.build_array(self._btag, recv_chunk, None)
312
--> 313 raw_write(req)
314
315 resp = raw_read(recv_chunk)
/home/mj-ubuntu/anaconda/lib/python2.7/site-packages/pyvisa-py/protocols/usbtmc.pyc in write(self, data)
202 return self.usb_send_ep.write(data)
203 except usb.core.USBError as e:
--> 204 raise ValueError(str(e))
205
206 def read(self, size):
ValueError: [Errno 110] Operation timed out
If I try to read the current timeout value I get a Runtime error:
RuntimeError: maximum recursion depth exceeded while calling a Python object
And if I try to set the timeout I also get and error:
Exception: Unknown attribute 1073676314
Timeout was not implemented for usb (I just did), but in any case this should not be the problem as the default is 2 seconds. I am surprised that is not working, I will install a linux and check. (The ASRL list looks horrible on linux, I am opening another issue for that)
I think this is solved. Feel free to reopen if necessary.
hgrecco, I have the same timeout problem working with Keysight b2912a unit. Could you please tell me if you solved this problem ? If yes, how ?
Thanks in advance!
I'm having a similar problem with an Agilent 34411A multimeter. The stack trace looks like this. Last week I was able to get about one '*IDN?' query out of the machine and then all subsequent writes and queries failed until I unplugged/replugged/reconnected. It seems there is some bug deep in USB protocol handler. The same code works for a Keithley 2110 multimeter, so it must be some small difference in how they interact over USB which is tripping up pyvisa-py.
Traceback (most recent call last):
File "
Here's an example where the first query succeeded but then it fails thereafter. Maybe there is a pyvisa-py problem in releasing the USB bus? Below, I query the DC range, I get 100mV as a response, but then I query it again and it fails due to a Pipe Error. Immediately prior, I set up i = rm.open_resource(
i.query('SENS:VOLT:DC:RANG?') u'+1.00000000E-01\n' i.query('SENS:VOLT:DC:RANG?') Traceback (most recent call last): File "
", line 1, in File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 407, in query return self.read() File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 332, in read message = self.read_raw().decode(enco) File "/usr/local/lib/python2.7/dist-packages/pyvisa/resources/messagebased.py", line 306, in read_raw chunk, status = self.visalib.read(self.session, size) File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/highlevel.py", line 253, in read return self.sessions[session].read(count) File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/usb.py", line 102, in read usb.USBError) File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/sessions.py", line 313, in _read current = reader() File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/usb.py", line 96, in return self._read(lambda: self.interface.read(1), File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/protocols/usbtmc.py", line 307, in read raw_write(req) File "/usr/local/lib/python2.7/dist-packages/pyvisa-py/protocols/usbtmc.py", line 204, in write raise ValueError(str(e)) ValueError: [Errno 32] Pipe error
Did this ever get solved? I have a Keysight 34461A that is locking up frequently and needs to be disconnected and reconnected all the time.
The problem we had with the Keithley 2230-3 has been resolved by sending a special (non-conforming) command upon connecting, to put the instrument in remote mode and clear its remote interface. It is unlike any other instrument I have used. I have also made small local customizations to pyvisa-py and pyusb to make them work with all our instruments now, so if anyone is looking for help I could publish some minor suggestions to GitHub. If I recall correctly, I bypassed the "language selection" portion and defaulted automatically to English, since it was causing problems with one Agilent instrument.
Paul
On Jul 7, 2017 01:04, "brandonrwin" notifications@github.com wrote:
@nat45928 https://github.com/nat45928 I had a similar problem with a 33500B. After locking up, the NI tools would report a protocol error for the next few reads and then eventually work, so perhaps it was partially equipment related. Updating the 33500B to the latest firmware fixed it for me.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pyvisa/pyvisa-py/issues/3#issuecomment-313542649, or mute the thread https://github.com/notifications/unsubscribe-auth/APcbhXNHHC1QzrFpAc2IIvFJFmp0KbqEks5sLWflgaJpZM4CyYiP .
Hi nat45928,
Sorry, my last response was a bit off topic; I sent it by replying to an email on my phone :0. Have a look at https://github.com/pyvisa/pyvisa-py/issues/96. With some local customizations to pyvisa-py and pyusb, we are able to get reliable 34411A operation. I'm assuming the 34461A is a similar instrument. I can send you the changes I made if you want to diff them against your local copy of pyvisa-py and pyusb.
I can not find the Keithley instrument 2230G-60-3 using Pyvisa in Linux. When I run rm.list_resources(), there only appear an ASRL, no USB device. The specific information is as follow:
lili@ubuntu:/$ python3 -c "from pyvisa import util; util.get_debug_info()" Machine Details: Platform ID: Linux-5.4.0-42-generic-x86_64-with-glibc2.29 Processor: x86_64
Python: Implementation: CPython Executable: /usr/bin/python3 Version: 3.8.5 Compiler: GCC 9.3.0 Bits: 64bit Build: Jul 28 2020 12:59:40 (#default) Unicode: UCS4
PyVISA Version: 1.11.3
Backends: ivi: Version: 1.11.3 (bundled with PyVISA)
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.5.1 ASRL INSTR: Available via PySerial (3.5) 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'
lili@ubuntu:/$ python3 Python 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information.
import pyvisa rm=pyvisa.ResourceManager('@py') rm.list_resources() ('ASRL/dev/ttyS0::INSTR',)
I'm on: Anaconda 2.1.0 (64 bit), Python 2.7.8 on Ubuntu 14.04 pyvisa 1.6.1.dev0 (updated today) pyvisa-py 0.1.dev0 pyusb 1.0.0b1
I have a Keysight scope connected over USB.
Exception: failed to set configuration
Any thoughts?