04-06-2017 05:01 AM
Hi,
I'm trying to control a Keithley 2410 via python on an x86_64 linux machine (CentOS 7). I'm using python 2.7.5, NI-VISA 16 and PyVISA 1.8. The Keithley is connected to the computer via a a RS232-to-USB cable and it's configured for RS232 communication (with the parameters: baud 57600, bits 8, parity none, terminator <LF>, flow-ctrl none). When I try to query the Keithley I get a timeout error, as shown below:
>>> import visa
>>> rm = visa.ResourceManager()
>>> print(rm.list_resources())
(u'ASRL1::INSTR', u'ASRL2::INSTR')
>>> keithley = rm.open_resource("ASRL2::INSTR")
>>> print(keithley.query('*IDN?'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/pyvisa/resources/messagebased.py", line 407, in query
return self.read()
File "/usr/lib/python2.7/site-packages/pyvisa/resources/messagebased.py", line 332, in read
message = self.read_raw().decode(enco)
File "/usr/lib/python2.7/site-packages/pyvisa/resources/messagebased.py", line 306, in read_raw
chunk, status = self.visalib.read(self.session, size)
File "/usr/lib/python2.7/site-packages/pyvisa/ctwrapper/functions.py", line 1582, in read
ret = library.viRead(session, buffer, count, byref(return_count))
File "/usr/lib/python2.7/site-packages/pyvisa/ctwrapper/highlevel.py", line 188, in _return_handler
raise errors.VisaIOError(ret_value)
pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
Any suggestions as to what the problem(s) might be would be much appreciated!
Thanks
04-06-2017 09:20 AM
Not used Python but have used Visa with serial busses. You need to make sure there is a linefeed appended to the end of the command.
04-07-2017 07:05 AM
Thanks for the suggestion. When you say a linefeed I guess that you mean "\n"? It is my understanding that PyVISA adds this to the query automatically but, even if it doesn't, I tried adding the "\n" explicitly and unfortunately it didn't seem to work.
04-07-2017 08:59 AM
Well the only other things are:
Cable needs (assuming 9 pin to 9 pin) needs to be staright through. Pin 1 to Pin1, Pin 2 to Pin 2 etc
Instrument is configured for the same baud rate etc as Visa
05-03-2017 07:56 AM
Thanks for the help. It seems that I needed to explicitly set the baud rate in my python script.
rm = visa.ResourceManager()
smu = rm.open_resource("ASRL2::INSTR")
smu.baud_rate = 57600
Thanks again.