Quantcast
Channel: Instrument Control (GPIB, Serial, VISA, IVI) topics
Viewing all articles
Browse latest Browse all 5565

PyVISA with Keithley 2400 SCPI

$
0
0

Hi, I'm trying to ask a Keithley 2440 to loop through relatively fast sets of 4 wire measurements, report the data, and repeat.  I have tried RS232 serial communications with pyserial, which worked alright but was not able to communicate quickly and therefore had a low duty cycle of time collecting data vs. not, so I switched to GPIB (NI GPIB-USB-HS with PyVISA in Python 2.7).  Now I have managed to get the Keithley set up for the right current for the 4 wire measurement, but often have errors of the output not turning off after a given period of time and the Keithley has not successfully reported any values back to my computer with my recent attempts at these controls.  I got most of the SCPI commands from a coworker who was using a LabVIEW program to control his Keithley a couple of years ago.  Current code looks like this:

 

import visa
import numpy as np
from pylab import *
import matplotlib.pyplot as plt
import time

number_loops = 20
count = 10
DIVoutput = np.zeros((count*number_loops,5)) # make sure this is at least larger than loops*trig count!!!!
NPLC = 6
COUNT = 10

rm = visa.ResourceManager()
rm.list_resources()
('ASRL1::INSTR', 'ASRL2::INSTR', 'GPIB0::24::INSTR')
inst = rm.open_resource('GPIB0::24::INSTR')
inst.timeout = 25000 # in milliseconds

time.sleep(0.001)

print(inst.query("*IDN?"))
print(inst.query(':ROUT:TERM?'))

inst.write(':ROUT:TERM FRON')
print(inst.query(':ROUT:TERM?'))

inst.write('*RST')

inst.write(':FORM:ELEM VOLT,CURR,TIME;DATA SREAL;BORD NORM')
inst.write('Smiley FrustratedENSE:AVER:TCON MOV OFF')
inst.write('Smiley FrustratedYSTEM:AZEROSmiley FrustratedTAT OFF')
inst.write(':TRIGSmiley Very HappyEL 0.0')
inst.write('Smiley FrustratedOURCESmiley Very HappyELAY 0.0')
inst.write('Smiley FrustratedYST:AZERO OFF')
inst.write('Smiley Very HappyISP:ENAB OFF')
inst.write('Smiley FrustratedYST:BEEPSmiley FrustratedTAT OFF')
inst.write(':AVER OFF')
inst.write('Smiley FrustratedYST:RSEN ON')
inst.write('Smiley FrustratedYST:AZERO ONCE')


for i in range(number_loops):
#START OF LOOP

inst.write(':CURR:NPLC '+str(NPLC)+';')
inst.write('Smiley FrustratedOUR:FUNC CURR')
inst.write('Smiley FrustratedOUR:CURR 1e-3')
inst.write("Smiley FrustratedENS:FUNC 'VOLTSmiley Very HappyC'")
inst.write(':VOLTSmiley TongueROT 5')
inst.write('Smiley SurprisedUTP ON')
inst.write(':ARM:COUN 1;:TRIG:COUN '+str(count)+';Smiley FrustratedOUR:CURR:MODE FIX;')
inst.write(':ARMSmiley FrustratedOUR IMM;:ARM:TIME 0.01;:TRIGSmiley FrustratedOUR IMM;:TRIGSmiley Very HappyEL 0')
inst.write(':TRIG:CLE;:INIT')
inst.write('Smiley SurprisedUTP OFF')

b=inst.query_ascii_values('FETC?')
a=(inst.read())

inst.close()

 

I get errors like "UnicodeDecodeError: 'ascii' codec can't decode byte 0xb3 in position 3: ordinal not in range(128)" when I do this.  

 

 

Does anyone have an example of code that effectively gets 4 wire measurements out of a Keithley at faster than 1 Hz?  I'd be happy with anything that pretty much works and has a higher than 50% "up" time of actually taking measurements.  

 

Thanks in advance for any help.  


Viewing all articles
Browse latest Browse all 5565

Trending Articles