Python Forum

Full Version: Multiple instruments with python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm putting together a small, automated test system with two instruments at this time. Python errors out when I try to assign the second instrument. Will Python allow multiple instruments/addresses? Help will be greatly appreciated.
You need to provide more information. Can you post an example that works with one instrument.
(May-30-2023, 12:43 AM)thomaswfirth Wrote: [ -> ]Python errors out when I try to assign the second instrument.
This is not very helpful description of a problem. Please, post minimal reproducible example of your code and the full traceback you get.
First of all, I'm a New to the Forum, New to Python and the only programming I have done was in the 80's and 90's in GWBASIC. I managed to follow a couple YouTube tutorials and saw some progress. All three of my instruments work fine individually (Power Supply, DMM and Scope). I have full control of each individually and all SCPI commands work as expected.

When I try to put a second instruments into one script is when the issues arise. The code runs fine until it reaches a command to the second instrument.
Thanks for your help.

 import pyvisa
import time
rm = pyvisa.ResourceManager('@py')
print(rm.list_resources())
ps = rm.open_resource('ASRL8::INSTR')
dmm = rm.open_resource('ASRL10::INSTR')
print(ps.query("*IDN?"))
ps.write("*RST")                             # Runs fine up to this line

print(dmm.query("*IDN?"))              # Errors here
dmm.write("*RST")
rm.close()
Error:
PS C:\Users\thoma\Desktop\Python> c:; cd 'c:\Users\thoma\Desktop\Python'; & 'C:\Users\thoma\AppData\Local\Programs\Python\Python311\python.exe' 'c:\Users\thoma\.vscode\extensions\ms-python.python-2023.8.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '54189' '--' 'c:\Users\thoma\Desktop\Python\multiple_instruments.py' ('ASRL3::INSTR', 'ASRL1::INSTR', 'ASRL10::INSTR', 'ASRL5::INSTR', 'ASRL8::INSTR', 'ASRL4::INSTR') KORAD KWR102 V2.2 SN:000003280943 Traceback (most recent call last): File "c:\Users\thoma\Desktop\Python\multiple_instruments.py", line 9, in <module> print(dmm.query("*IDN?")) ^^^^^^^^^^^^^^^^^^ File "C:\Users\thoma\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvisa\resources\messagebased.py", line 648, in query return self.read() ^^^^^^^^^^^ File "C:\Users\thoma\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvisa\resources\messagebased.py", line 486, in read message = self._read_raw().decode(enco) ^^^^^^^^^^^^^^^^ File "C:\Users\thoma\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvisa\resources\messagebased.py", line 442, in _read_raw chunk, status = self.visalib.read(self.session, size) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\thoma\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvisa_py\highlevel.py", line 519, in read return data, self.handle_return_value(session, status_code) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\thoma\AppData\Local\Programs\Python\Python311\Lib\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. PS C:\Users\thoma\Desktop\Python>
Ok I did say I was new to Python, now let me add the code for the baud rate. I did have to install two additional modules to get to the previous point but just overlooked establishing the baud rate. So please disregard the previous post. here is where I am now.
import pyvisa
import time
rm = pyvisa.ResourceManager('@py')
print(rm.list_resources())
ps = rm.open_resource('ASRL8::INSTR')
ps.baud_rate = 115200
dmm = rm.open_resource('ASRL10::INSTR')
dmm.baud_rate = 115200
print(ps.query("*IDN?"))
ps.write("*RST")
print(dmm.query("*IDN?"))
dmm.write("*RST")
rm.close()
Output:
PS C:\Users\thoma\Desktop\Python> c:; cd 'c:\Users\thoma\Desktop\Python'; & 'C:\Users\thoma\AppData\Local\Programs\Python\Python311\python.exe' 'c:\Users\thoma\.vscode\extensions\ms-python.python-2023.8.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '54317' '--' 'c:\Users\thoma\Desktop\Python\multiple_instruments.py' ('ASRL3::INSTR', 'ASRL1::INSTR', 'ASRL10::INSTR', 'ASRL5::INSTR', 'ASRL8::INSTR', 'ASRL4::INSTR') KORAD KWR102 V2.2 SN:000003280943 OWON,XDM1041,22511669,V4.0.0,3 PS C:\Users\thoma\Desktop\Python>