Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.

hi,

I'm trying to program two separate instruments that are connected by GPIB cable using GPIB prologix. When I try to control each instrument separately, the code run separately but when I the full code, I got the following error:

VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.

 

I tried to increase time.sleep but it doesn't help. Any advice would be appreciated!


import pyvisa as visa
import time
import datetime

#setting up the power meter Newport 1830C
rm = visa.ResourceManager()
# print(rm.list_resources())
pwm = rm.open_resource('ASRL3::INSTR')
pwm.write("++mode 1\n")
pwm.write("++addr 4\n") #GPIB address
pwm.write("++auto 1\n")
# print("connected to: "+pwm.query("*IDN?\n"))
# pwm.baud_rate = 9600
pwm.write("C") #Clear Status Byte Register
pwm.write("O") #Auto-Calibration
pwm.write('F2') 


#setting up the laser Agilent 8163A with tunable laser HP 81689A in slot 1
lsr = rm.open_resource('ASRL3::INSTR')
lsr.write("++mode 1\n")
lsr.write("++addr 20\n")
lsr.write("++auto 1\n")
lsr.write("*RST")
time.sleep(20)
# print("connected to: "+lsr.query("*IDN?\n"))
lsr.write("sour2:pow:stat 1") #turns laser on
lsr.write("sour2:pow 100uW") # sets laser power
time.sleep(20)
# lsr.baud_rate = 38400

file_path = "...."
data= open(file_path+"/"+"power_data_"+datetime.datetime.fromtimestamp(
time.time()).strftime('%Y-%m-%d %H_%M_%S')+".txt", 'w',buffering=1)
data.write('wavelength [nm], power [W]\n')


wavelen_1 = 1530
wavelen_2 = 1576
for i in range(wavelen_1, wavelen_2):
wavelength = i
lsr.write('sour2:wav %s' %str(i*1e-9)) #sets laser wavelength in nm
time.sleep(5)
pwm.write("W"+str(i))
data.write(str(wavelength) +', ')
time.sleep(5)
power = pwm.query('D?\n')
pwm.timeout(5000)
data.write(power)
lsr.write("sour2:pow:stat 0") #turns laser off
data.close

0 Kudos
Message 1 of 3
(7,452 Views)

I get the same error when trying to get data from a Keithley 2182A instrument via LabView functions/NI VISA. 

 

 

I have not completely figured it out, but one thing I was going to try for myself was increasing the timeout time in the GPIB IO settings. In my case, NI MAX > VISA interface leads to a place where I can edit the "timeout" time. I think it actually re-writes the timeout of the GPIB-instrument interface. In case of PyVisa too I am sure there is somewhere you can redefine the timeout time. If this is actually a legit way to increase/modify timeout time, I think it can help. 

 

Maybe someone more experienced/knowledgeable on this can comment on whether it is even possible/okay to increase timeout period of a instrument-GPIB connection this way... 

timeout expire error even after resetting timeout.PNG

0 Kudos
Message 2 of 3
(7,359 Views)