Author Topic: Plot (non-touch screen) SMUs measurements in real time?  (Read 3695 times)

0 Members and 1 Guest are viewing this topic.

Offline ivayloTopic starter

  • Frequent Contributor
  • **
  • Posts: 661
  • Country: us
Plot (non-touch screen) SMUs measurements in real time?
« on: May 29, 2014, 04:17:14 am »
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...
« Last Edit: May 29, 2014, 04:22:50 am by ivaylo »
 

Offline TiN

  • Super Contributor
  • ***
  • Posts: 4543
  • Country: ua
    • xDevs.com
Re: Plot (non-touch screen) SMUs measurements in real time?
« Reply #1 on: May 29, 2014, 04:48:06 am »
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 instruments
and 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.
« Last Edit: May 29, 2014, 04:52:32 am by TiN »
YouTube | Metrology IRC Chat room | Let's share T&M documentation? Upload! No upload limits for firmwares, photos, files.
 

Offline ivayloTopic starter

  • Frequent Contributor
  • **
  • Posts: 661
  • Country: us
Re: Plot (non-touch screen) SMUs measurements in real time?
« Reply #2 on: May 29, 2014, 06:02:09 am »
Yup, shouldn't be that difficult to talk to the instrument and just plot. Thanks for confirming...
 

Offline ivayloTopic starter

  • Frequent Contributor
  • **
  • Posts: 661
  • Country: us
Re: Plot (non-touch screen) SMUs measurements in real time?
« Reply #3 on: July 07, 2014, 07:23:01 am »
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: [Select]
#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()
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf