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