Sabrina
Sabrina

Reputation: 11

PyVISA RS232 Timeout Error (Agilent Power Supply)

I am working on opening communication with an Agilent power supply using PyVISA, and I keep getting a timeout error when I query for the instrument Id.

My code is:

import visa 

rm = visa.ResourceManager()
res = rm.list_resources()
print("Find following resources: ")
print(res)
print("Opening " + res[-1])

inst = rm.open_resource(res[-1])
inst.timeout = 100000 # timeout 100s
inst.write_termination = '\n'
inst.read_termination = '\n'

print(inst.query('*IDN?'))

The output I am getting is:

Find following resources: 
(u'ASRL5::INSTR',)
Opening ASRL5::INSTR
Traceback (most recent call last):

File "<ipython-input-10-66ffef23c46a>", line 1, in <module>
    runfile('C:/Users/Sabri/Anaconda2/untitled0.py', wdir='C:/Users/Sabri     /Anaconda2')

File "C:\Users\Sabri\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
    execfile(filename, namespace)

File "C:\Users\Sabri\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 86, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)

File "C:/Users/Sabri/Anaconda2/untitled0.py", line 20, in <module>
    print(inst.query('*IDN?'))

File "C:\Users\Sabri\Anaconda2\lib\site-packages\pyvisa\resources\messagebased.py", line 564, in query
    return self.read()

File "C:\Users\Sabri\Anaconda2\lib\site-packages\pyvisa\resources\messagebased.py", line 413, in read
    message = self._read_raw().decode(enco)

File "C:\Users\Sabri\Anaconda2\lib\site-packages\pyvisa\resources\messagebased.py", line 386, in _read_raw
    chunk, status = self.visalib.read(self.session, size)

File "C:\Users\Sabri\Anaconda2\lib\site-packages\pyvisa\ctwrapper\functions.py", line 1584, in read
    ret = library.viRead(session, buffer, count, byref(return_count))

File "C:\Users\Sabri\Anaconda2\lib\site-packages\pyvisa\ctwrapper\highlevel.py", line 188, in _return_handler
    raise errors.VisaIOError(ret_value)

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

I have tried specifying the terminating character as \n for both the read and write commands, specifying the baud rate, changing the timeout to 'None', and declaring the instrument as inst = rm.open_resource('ASRL5::INSTR') rather than inst = rm.open_resource(res[-1]). Nothing has worked so far. Any suggestions would be greatly appreciated!

Upvotes: 1

Views: 1589

Answers (2)

paul hu
paul hu

Reputation: 1

I use Ruby to control Agilent(keysight) power supply e3631a via RS232 port. I believe I had similiar issue. The symptom was the query commands (like *IDN?) yield no reply and an error code 410 would show up on the device. The issue was that the device cannot send out the data via serial port and so the buffer cannot be cleared up. The fix was that in DCB structure you need to set "DTR_CONTROL_ENABLE". In my case the line control part of dcb looks like "0x00000011". Note that for serial commnication without flow control, normally you do not need to set that. This issue has costed me two days and I hope it will help others.

Upvotes: 0

Zircatron
Zircatron

Reputation: 146

Try using the Keysight(formally Agilent) connection expert.

This is contained in the IO Libraries Suite: https://www.keysight.com/main/software.jspx?cc=GB&lc=eng&ckey=2175637&nid=-33330.977662&id=2175637

Once installed, you will be able to add instruments and check the status of the power supply.

Which power supply model is it?

Side Note: I've had situations where the the PC recognises the serial COM port but would only work after I had manually updated the driver.

Upvotes: 0

Related Questions