Answering my own question here. Finally got time to play with this and a quick and dirty Python (pylab) script which does what I wanted is bellow. Not "for commercial use" by any measure, just in case someone is looking for something like this and is wondering where to start from. Works perfectly under Linux, reads from SMU but doesn't plot properly under Win7 using Anaconda (may look into it a bit more later, pylab.plot was supposed to work under Win7 but who knows)...
#source voltage measure current with parameters, should work on any Keithley 2600
#if you are measuring very low currents don't set smua.measure.rangei bellow to autorange
script = """
smua.reset()
smua.source.func = smua.OUTPUT_DCVOLTS
smua.source.autorangev = smua.AUTORANGE_ON
smua.source.levelv = %s
smua.source.limiti = %s
smua.measure.rangei = smua.AUTORANGE_ON
smua.source.output = smua.OUTPUT_ON
print(smua.measure.i())
"""
from time import sleep
def write_read_sock( s, f, message ): #using raw sockets
s.send(message+'\n')
sleep(.005) # 5mS delay #give it some time, increase this if it skips
try:
return f.readline()
except socket.error: #not all commands return data
return '' #so taking care of those
def run_script( s, f, script ): #this function runs a Keithley script until it gets data back
lines = script.split('\n') #if more than one command returns data, split your script
for line in lines:
if line == '':
continue
res = write_read_sock( s, f, line )
if res:
return res #script interrupts at the very first data returned
while True:
try:
return f.readline() #loop until something comes back
except socket.error:
pass #if no command in your script returns data this will block!
def clear_instrument_buffer(f): #if you skip/miss a read from the socket there will be
while True: #garbage in the buffer, so this function cleans it
try:
f.readline() #loop until there is stuff in the buffer
except socket.error:
return
import socket
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
s.connect(("192.168.1.81", 5025)) #change to your instrument IP address
s.setblocking(0)
ff = s.makefile()
clear_instrument_buffer( ff )
QUEUE_SIZE = 100 #this is how many points we are showing at the same time
TIME_INCREMENT = .1 #we are reading once every TIME_INCREMENT
import Queue
dq = Queue.Queue()
from pylab import *
time_vect = linspace( 0, QUEUE_SIZE * TIME_INCREMENT, QUEUE_SIZE, endpoint=False ) #generate the X axis
def add_to_fifo( dq, datum ):
if dq.qsize() >= QUEUE_SIZE:
dq.get() #remove a value if above queue size
dq.put(datum) #add a value
for i in range(QUEUE_SIZE):
add_to_fifo( dq, 0 )
d = run_script( s, ff, script % ( '15', '100e-3' ) ) #source 15V, read in the 100mA range
add_to_fifo( dq, float(d) ) #add first reading
ion()
line, = plot( time_vect, dq.queue )
while True:
sleep(TIME_INCREMENT)
d = write_read_sock( s, ff, 'print(smua.measure.i())' ) #get next value
try:
d = float(d) #sometimes it barfs at conversion
print d #play with the sleep interval in write_read_sock
except ValueError:
print d
d=0
add_to_fifo( dq, d )
line.set_ydata( dq.queue )
line.axes.relim() #this makes the plot autoscaling
line.axes.autoscale_view()
draw()