Plot (non-touch screen) SMUs measurements in real time? - Page 1
Forum section: electronics / testgear

author: ivaylo
author_rank: Frequent Contributor
timestamp: May 29, 2014, 04:17:14 am
content: Noticed the new(er) source meters with touch screen interface (Agilent B2900A series, the Keithley 2450 demonstrated by robrenz, etc.) can plot measurements in real time. How do people do that with the older SMUs? Looked at Keithley's Test Script Builder, the embedded TSP Express stuff, etc. but they all seem to be capable of first running a script, collecting data in a buffer and only then plotting. I can whip up an external script to do that independent of the Keithley softwares but wanted to make sure I am not missing something obvious. Appreciate your help...

author: TiN
author_rank: Super Contributor
timestamp: May 29, 2014, 04:48:06 am
content: I'd say those instruments mostly used with custom software, rather then demo stuff which comes in bundle.Lot of SMUs and other test gear comes with LabView drivers/libraries, and support access to functions in realtime, so you can write your own software to control instrumentsand do various smart things with results. Software development environment may vary a lot, LabView, C/C++, Matlab, sorts of Basic, even python and web-apps stuff sometimes.There are plenty interfaces available, almost always GPIB, often USB/LAN or at least RS232. You can google for programming reference/guides for Keithley to check variety of functions there.Measurement to buffer and then read from there usually done if you need speed, as it takes extra time to communicate with interface.

author: ivaylo
author_rank: Frequent Contributor
timestamp: May 29, 2014, 06:02:09 am
content: Yup, shouldn't be that difficult to talk to the instrument and just plot. Thanks for confirming...

author: ivaylo
author_rank: Frequent Contributor
timestamp: July 07, 2014, 07:23:01 am
content: 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)...Code:#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 autorangescript = """smua.reset()smua.source.func = smua.OUTPUT_DCVOLTSsmua.source.autorangev = smua.AUTORANGE_ONsmua.source.levelv = %ssmua.source.limiti = %ssmua.measure.rangei = smua.AUTORANGE_ONsmua.source.output = smua.OUTPUT_ONprint(smua.measure.i())"""from time import sleepdef write_read_sock( s, f, message ): #using raw socketss.send(message+'\n')sleep(.005) # 5mS delay #give it some time, increase this if it skipstry:return f.readline()except socket.error: #not all commands return datareturn '' #so taking care of thosedef run_script( s, f, script ): #this function runs a Keithley script until it gets data backlines = script.split('\n') #if more than one command returns data, split your scriptfor line in lines:if line == '':continueres = write_read_sock( s, f, line )if res:return res #script interrupts at the very first data returnedwhile True:try:return f.readline() #loop until something comes backexcept 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 bewhile True: #garbage in the buffer, so this function cleans ittry:f.readline() #loop until there is stuff in the bufferexcept socket.error:returnimport sockets = socket.socket( socket.AF_INET, socket.SOCK_STREAM )s.connect(("192.168.1.81", 5025)) #change to your instrument IP addresss.setblocking(0)ff = s.makefile()clear_instrument_buffer( ff )QUEUE_SIZE = 100 #this is how many points we are showing at the same timeTIME_INCREMENT = .1 #we are reading once every TIME_INCREMENTimport Queuedq = Queue.Queue()from pylab import *time_vect = linspace( 0, QUEUE_SIZE * TIME_INCREMENT, QUEUE_SIZE, endpoint=False ) #generate the X axisdef add_to_fifo( dq, datum ):if dq.qsize() >= QUEUE_SIZE:dq.get() #remove a value if above queue sizedq.put(datum) #add a valuefor 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 rangeadd_to_fifo( dq, float(d) ) #add first readingion()line, = plot( time_vect, dq.queue )while True:sleep(TIME_INCREMENT)d = write_read_sock( s, ff, 'print(smua.measure.i())' ) #get next valuetry:d = float(d) #sometimes it barfs at conversionprint d #play with the sleep interval in write_read_sockexcept ValueError:print dd=0add_to_fifo( dq, d )line.set_ydata( dq.queue )line.axes.relim() #this makes the plot autoscalingline.axes.autoscale_view()draw()