11-11-2009 01:14 AM
Hi everyone,
I want to enable communication between my PC and Keithley 2602A SourceMeter Instrument so that I can send commands to the SMI without using Test Script Builder (TSB) - a scripting/remote controlling program that enables communication between itself and the host computer.
The reason why I want to do this is because I want to program in Python to carry out a series of tasks involving other hardwares and adjusting the voltage on the SMI at the same time. I can't use TSB to do this because TSB is solely for controlling the SMI and not other hardwares. I need to use Python scripts to consolidate all the hardware control. So far, communicating with other hardwares from my PC using Python scripts is not a problem because I have readily available libraries for them.
I have found PyVisa which I thought could solve the communication problem. So I installed PyVisa and wrote the following code to test the communication.
import visa
keithley = visa.instrument("COM1") #SMI connected to COM1keithley.write("smua.source.output = smua.OUTPUT_ON") #send this command to SMI
However, the communication was not successful as I got the error message as shown below:
C:\Documents and Settings\cho\Desktop\Python Ex>keithley_test.py
Traceback (most recent call last):
File "C:\Documents and Settings\cho\Desktop\Python Ex\keithley_test.py", line 2, in <module>
keithley = visa.instrument("COM1")
File "C:\Python26\Lib\site-packages\pyvisa\visa.py", line 292, in instrument
return SerialInstrument(resource_name, **keyw)
File "C:\Python26\Lib\site-packages\pyvisa\visa.py", line 680, in __init__
"delay", "send_end", "values_format")))
File "C:\Python26\Lib\site-packages\pyvisa\visa.py", line 358, in __init__
"lock")))
File "C:\Python26\Lib\site-packages\pyvisa\visa.py", line 132, in __init__
keyw.get("lock", VI_NO_LOCK))
File "C:\Python26\Lib\site-packages\pyvisa\vpp43.py", line 753, in open
byref(vi))
File "C:\Python26\Lib\site-packages\pyvisa\vpp43.py", line 398,in check_status raise visa_exceptions.VisaIOError, status
pyvisa.visa_exceptions.VisaIOError: VI_ERROR_RSRC_BUSY: The resource is valid, but VISA cannot currently access it.
Can anyone tell me what went wrong? How can I control the Keithley 2602A using a Python script run from my PC?
11-11-2009 09:06 AM
Are you sure no other application has COM Port 1 open?
11-11-2009 10:03 AM
Also as this is serial you must append a linefeed to the end of every command sent.
11-11-2009 07:28 PM
05-20-2010 03:30 AM
HI,
I succeeded in establishing communication between my computer and the Keithely using Python.
Here what I did:
The computer is a labtop so I used a USB-GPIB (keithley KUSB-488) cable to the K2602.
First I installed the cable driver given by Keithley. Then I checked if the GPIB is recognized (GPIB Diagnostic: test passed)
Then I downloaded and installed NI-VISA 4.1 from the NI website. I don't know if newer version of NI-Visa are OK.
I downloaded pyvisa from SourceForge and installed it in the Python directory as specified.
Before launching pyvisa I tested again the GPIB using GPIB Diagnostic. If OK, I start Python and write the small program below which looks like yours:
import visa
keithley = visa.instrument("GPIB::26")
keithley.write("smua.source.levelv = 0.5")
keithley.write("display.smua.measure.func = display.MEASURE_DCAMPS")
keithley.write("smua.source.output = smua.OUTPUT_ON")
And everything went OK.
However I got trouble getting the data from the K2062 to my computer. I don't like much the syntax using nvbuffer.1.
If you had a chance try to get the data from the instrument to your computer, please let me know.
Bye!
08-19-2013 05:14 PM
Hi DavItron, this is a very old thread but it's one of the top google results when I looked up info on how to implement some Python code with PyVISA to drive the Keithley 2602A so I will post this response so that other searchers can find the info.
You can store data in named variables in the Keithely 2602A and then "print" them to the remote interface using something like the following:
import visa
ps = visa.Instrument("GPIB::Address of your instrument")
ps.write("smua.source.levelv=10")
ps.write("smua.source.output=smua.OUTPUT_ON")
ps.write("currenta, voltagea = smua.measure.iv()")
ps.write("smua.source.output=smua.OUTPUT_OFF")
current = ps.ask("print(currenta)")
voltage = ps.ask("print(voltagea)")
For what I do which is mostly setting and measuring a bias point, then holding that while I trigger a measurement on another instrument, this is fine for me. If you want to do sweeps with a lot of data points it's probably more efficient to use the buffers directly, but I haven't needed that yet.
Hope that helps somebody!