Open Rromotpd opened 5 years ago
This is tough one. We know that some instruments do not implement properly the USB-TMC protocol. One thing you can try is testing https://github.com/pyvisa/pyvisa-py/pull/186 (after fixing the typo mentioned in the review). Another option you have is testing python-usbtmc (which implements a similar quirk work-around). If you find any solution please let me know, I really wish we can improve pyvisa-py.
I'm more newbie than a programmer - unfortunately I don't know how ca`n I install version you provided. I installed python-usbtmc tho, and timeout is still there.
>>> import usbtmc
>>> d1=usbtmc.Instrument("USB0::1510::8464::8008202::INSTR")
>>> d2=usbtmc.Instrument('USB0::46342::8192::003398::INSTR')
>>> d1.ask("*IDN?")
'KEITHLEY INSTRUMENTS INC.,MODEL 2110,8008202,02.02-02-01'
>>> d2.ask("*IDN?")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/.local/lib/python3.5/site-packages/usbtmc/usbtmc.py", line 629, in ask
self.write(message, encoding)
File "/home/pi/.local/lib/python3.5/site-packages/usbtmc/usbtmc.py", line 609, in write
self.write_raw(str(message).encode(encoding))
File "/home/pi/.local/lib/python3.5/site-packages/usbtmc/usbtmc.py", line 492, in write_raw
self.bulk_out_ep.write(req, timeout=int(self.timeout*1000))
File "/home/pi/.local/lib/python3.5/site-packages/usb/core.py", line 387, in write
return self.device.write(self, data, timeout)
File "/home/pi/.local/lib/python3.5/site-packages/usb/core.py", line 948, in write
self.__get_timeout(timeout)
File "/home/pi/.local/lib/python3.5/site-packages/usb/backend/libusb1.py", line 824, in bulk_write
timeout)
File "/home/pi/.local/lib/python3.5/site-packages/usb/backend/libusb1.py", line 920, in __write
_check(retval)
File "/home/pi/.local/lib/python3.5/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 110] Operation timed out
I connected SRS Lock-in with RS-232 to USB adapter, which I use with Keithley 2400 Source Meter and it works flawlessly..
>>> import visa
>>> rm=visa.ResourceManager('@py')
>>> rm.list_resources()
('ASRL/dev/ttyUSB0::INSTR', 'ASRL/dev/ttyAMA0::INSTR', 'USB0::46342::8192::003398::0::INSTR')
>>> d1=rm.open_resource('ASRL/dev/ttyUSB0::INSTR')
>>> d1.write_termination = '\r\n'
>>> d1.read_termination = '\r\n'
>>> d1.baud_rate = 9600
>>> d1.query("*IDN?")
'Stanford_Research_Systems,SR865A,003398,v1.51'
>>> d1.query("SNAPD?")
'2.0302819426e-09,4.9405222136e-09,5.3414237478e-09,67.66003418'
Good you found a workaround. Could you nonetheless test the following just in case ?
pip uninstall pyvisa-py
followed by pip install https://github.com/joedoesntgit/pyvisa-py/tarball/master
(this will install the code from the PR I mentioned earlier, but the typo has been fixed now).
I will try to test this on my end too (but those lock-in are used a lot in my lab it may take some time).
By curiosity was the Keithley you mentioned in your first message using an adapter or USBTMC ?
Thanks for the solution. I reinstalled the library but still got timeout on write command. I checked Keithley 2110 and Keithley 2100 multimeters with USB cables - they're working good with both PYVISA and USBTMC libraries on my RPi. Unfortunately I have only one lock-in in my company so I can't really check if there's problem only with this one (but, again, it works on Windows).
I will try to solve this problem if I will have some free time, for now I will just use adapter or do the measurements on Windows' PC
If you want to dive deeper you can have a look at wireshark to capture the usb packets. It may be interesting to compare the Keithley messages and the lock-in messages.
And thanks for testing !
I am having a similar issue with a Keysight device. The code from my Windows installation does not work on a Raspberry Pi installation. Another device works fine on both plattforms.
On Windows I do not use the pyvisa-py
backend and the Keysight DMM works. I would conclude that it is not a device / cable issue.
Windows 10 | Raspberry Pi | |
---|---|---|
python version | 3.8.5 (Anaconda) | 3.7.3 |
pyvisa version | 1.11.3 | 1.11.3 |
pyvisa-py version | - | 0.5.1 |
pyvisa-py backend | visa.ResourceManager('@ivi') |
visa.ResourceManager('@py') |
NTP 6531 | mansonlib.py works | pyvisa or mansonlib.py works |
Keysight 34465A | pyvisa works | does not work |
import pyvisa as visa
VISA_ADDRESS = 'USB0::0x2A8D::0x0101::MY54505614::0::INSTR'
resourceManager = visa.ResourceManager()
print(resourceManager.list_resources())
dmm = resourceManager.open_resource(VISA_ADDRESS)
dmm.write('*IDN?')
idn = dmm.read()
print(idn)
dmm.write('DISP:TEXT "Hello"')
>>> import pyvisa as visa
>>> visa.log_to_screen()
>>> resourceManager = visa.ResourceManager("@py")
2021-01-18 13:50:08,639 - pyvisa - DEBUG - Created ResourceManager with session 6689986
>>> VISA_ADDRESS = 'ASRL/dev/ttyAMA0::INSTR'
>>> dmm = resourceManager.open_resource(VISA_ADDRESS)
2021-01-18 13:50:18,937 - pyvisa - DEBUG - ASRL/dev/ttyUSB0::INSTR - opening ...
2021-01-18 13:50:18,960 - pyvisa - DEBUG - ASRL/dev/ttyUSB0::INSTR - is open with session 5702442
>>> dmm.write('*IDN?')
2021-01-18 13:51:06,553 - pyvisa - DEBUG - Serial.write b'*IDN?\r\n'
7
>>> idn = dmm.read()
2021-01-18 13:51:20,106 - pyvisa - DEBUG - ASRL/dev/ttyUSB0::INSTR - reading 20480 bytes (last status <StatusCode.success_max_count_read: 1073676294>)
2021-01-18 13:51:22,125 - pyvisa - DEBUG - ASRL/dev/ttyUSB0::INSTR - exception while reading: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
Buffer content: bytearray(b'')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/.local/lib/python3.7/site-packages/pyvisa/resources/messagebased.py", line 486, in read
message = self._read_raw().decode(enco)
File "/home/pi/.local/lib/python3.7/site-packages/pyvisa/resources/messagebased.py", line 442, in _read_raw
chunk, status = self.visalib.read(self.session, size)
File "/home/pi/.local/lib/python3.7/site-packages/pyvisa_py/highlevel.py", line 519, in read
return data, self.handle_return_value(session, status_code)
File "/home/pi/.local/lib/python3.7/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.
>>> dmm.write('DISP:TEXT "Hello"')
2021-01-18 13:51:51,421 - pyvisa - DEBUG - Serial.write b'DISP:TEXT "Hello"\r\n'
19
>>> dmm.write('DISP:TEXT "Hello"\r')
2021-01-18 13:52:02,846 - pyvisa - DEBUG - Serial.write b'DISP:TEXT "Hello"\r\r\n'
20
From your Windows example it appears that your device uses the USBTMC protocol. However on Linux, you access to it as a simple serial instrument which is incorrect. Does Pyvisa-py detects your USB devices when you list the available resources ? Did you read the documentation regarding the edition of the udev rules which is often required for USB devices on Linux ?
The examples from keysight.com use a serial class device too. How can you tell from the Windows example that it is USBTMC ?
And the resource manager finds both devices
resourceManager.list_resources()
('ASRL/dev/ttyUSB0::INSTR', 'ASRL/dev/ttyAMA0::INSTR')
where USB0
is the NTP-6531 and AMA0
is the Keysight 34465A
The fact that the VISA address on Windows is USB0::0x2A8D::0x0101::MY54505614::0::INSTR
tells me it is a USBTMC device rather than a serial emulation over USB. I do not have much experience with USBTMC on Linux but I do know tat they cannot be accessed as serial resources.
Can you use Connection Expert on Linux ? If so can you use use to communicate with your device and if yes with what address ?
Oh man.. drivers. Thanks a lot for the hint. No, I cannot even install the Connection Expert (see below).
So I assume this device (or newer Keysight devices in general) cannot be controlled with pyvisa
and USB and ARM architecture?
Does IO Libraries Suite for Linux support 32-bit Linux OSes or Linux built on the ARM CPU architecture?
No, it does not. IO Libraries Suite for Linux is only built to work on 64-bit Linux OSes and the types of these OSes are listed in the ReadMe. ARM CPU architecture is not supported and thus IO Libraries Suite cannot be installed on these examples of Linux OSes or hardware: Raspbian and other Raspberry Pi Linux OSes, Ubuntu MATE. The suggestion for using Raspberry Pi to communicate with instruments is to use the common TCP/IP-Socket based libraries with instruments that have the LAN interface.
Technically you do need a Keysight specific driver, but simply a generic USBTMC driver. However I do not know if one exists for Linux on ARM.
My suggestion to use Connection Expert was simply a possible way to debug the system.
Quick follow up. I managed to get it working with the usbtmc
python library.
import usbtmc
instr = usbtmc.Instrument(0x2a8d, 0x0101)
instr.ask("*IDN?")
So even though PyVISA-py fail to list your instrument it can still be accessed through USBTMC. Can you then try the same using pyvisa-py and the address USB::0x2A8D::0x0101::MY54505614::INSTR
which is the generic version of the address you ued on Windows ?
I just tried it again on the Raspberry Pi. Oddly enough, now the resource manager actually lists the device correctly.
This made me curious and I uninstalled usbtmc
and tried again. It still works.
import pyvisa as visa
rm = visa.ResourceManager()
rm.list_resources()
# ('ASRL/dev/ttyAMA0::INSTR', 'USB0::10893::257::MY54505614::0::INSTR')
dmm = rm.open_resource('USB0::10893::257::MY54505614::0::INSTR')
dmm.query('*IDN?')
# 'Keysight Technologies,34465A,MY54505614,A.02.14-02.40-02.14-00.49-02-01\n'
dmm.close()
dmm = rm.open_resource('USB::0x2A8D::0x0101::MY54505614::INSTR')
dmm.query('*IDN?')
# 'Keysight Technologies,34465A,MY54505614,A.02.14-02.40-02.14-00.49-02-01\n'
Did you anything special when installing the usbtmc package ? I am wondering if it may have touch a configuration file or something.
I want to control both devices: Keithley multimeter and SRS Lock-in with Raspberry Pi. The issue is that Keithley works perfect - I can write commands / read data from device, but no matter what I do, my SRS Lock-in timeout in every write command.
Any suggestions how can I establish connection? So far I've tried:
Nothing works, I'm clueless..
Connection issues are only on Raspberry - on PC with Windows and NI-VISA drivers installed, my scripts for SRS Lock-in work as they should. But it is so weird that Keithley works perfect on both Raspberry and PC.