[newbie] problem with usbtmc-communication

wrw at mac.com wrw at mac.com
Tue Dec 4 09:33:49 EST 2012


On Dec 4, 2012, at 7:14 AM, Jean Dubois <jeandubois314 at gmail.com> wrote:

> The following test program which tries to communicate with a Keithley
> 2200 programmable power supply using usbtmc in Python does not work as
> expected. I have connected a 10 ohm resistor to its terminals and I
> apply 0.025A, 0.050A, 0.075A en 0.1A,
> I then measure the current and the voltage en write them in a file
> De data produced looks like this:
> 0.00544643 0.254061; first current value is wrong, voltage value is
> correct
> 0.0250807 0.509289; second current value is wrong, but it corresponds
> to the first, second voltage is correct
> 0.0501099 0.763945; 3rd current value is wrong, but it corresponds to
> the second, 3rd voltage is right
> 0.075099 1.01792; 4th current value is wrong,  it corresponds to the
> 3rd, 4th voltage is right
>                            4th correct current value is missing
> 
> But is should be (numerical inaccuracy taking into account)(these data
> were produced by a similar octave-program):
> 0.0248947 0.254047
> 0.0499105 0.509258
> 0.0749044 0.764001
> 0.0998926 1.01828
> 
> Here is the python-program:
> #!/usr/bin/python
> import time
> import os
> import sys
> measurementcurr=''
> measurementvolt=''
> timesleepdefault=1
> filename ='mydata.txt'
> usbkeith = open('/dev/usbtmc1','r+')
> usbkeith.flush()
> usbkeith.write("*IDN?\n")
> #strip blank line:
> identification=usbkeith.readline().strip()
> print 'Found device: ',identification
> usbkeith.write("SYST:REM" + "\n")
> usbkeith.write(":SENS:VOLT:PROT 1.5\n")
> keithdata = open(filename,'w')
> #start first measurement
> usbkeith.write(":SOUR:CURR 0.025\n")
> usbkeith.write(":OUTP:STAT ON\n")
> time.sleep(timesleepdefault)
> usbkeith.write(":MEAS:CURR?\n")
> time.sleep(timesleepdefault)
> measurementcurr=usbkeith.readline()
> print 'Measured current 1: ',measurementcurr
> usbkeith.write("MEAS:VOLT?\n")
> time.sleep(timesleepdefault)
> measurementvolt=usbkeith.readline()
> print 'Measured voltage 1: ',measurementvolt
> keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> #start second measurement
> usbkeith.write("SOUR:CURR 0.050\n")
> time.sleep(timesleepdefault)
> usbkeith.write("MEAS:CURR?\n")
> time.sleep(timesleepdefault)
> measurementcurr=usbkeith.readline()
> print 'Measured current 2: ',measurementcurr
> usbkeith.write("MEAS:VOLT?\n")
> time.sleep(timesleepdefault)
> measurementvolt=usbkeith.readline()
> print 'Measured voltage 2: ',measurementvolt
> keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> #start 3rd measurement
> time.sleep(timesleepdefault)
> usbkeith.write("SOUR:CURR 0.075\n")
> time.sleep(timesleepdefault)
> usbkeith.write("MEAS:CURR?\n")
> time.sleep(timesleepdefault)
> measurementcurr=usbkeith.readline()
> print 'Measured current 3: ',measurementcurr
> usbkeith.write("MEAS:VOLT?\n")
> time.sleep(timesleepdefault)
> measurementvolt=usbkeith.readline()
> print 'Measured voltage 3: ',measurementvolt
> keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> #start 4th measurement
> time.sleep(timesleepdefault)
> usbkeith.write("SOUR:CURR 0.1\n")
> time.sleep(timesleepdefault)
> usbkeith.write("MEAS:CURR?\n")
> time.sleep(timesleepdefault)
> measurementcurr=usbkeith.readline()
> print 'Measured current 4: ',measurementcurr
> usbkeith.write("MEAS:VOLT?\n")
> time.sleep(timesleepdefault)
> measurementvolt=usbkeith.readline()
> print 'Measured voltage 4: ',measurementvolt
> keithdata.write(measurementcurr.strip()+' '+measurementvolt)
> usbkeith.write(":OUTP:STAT OFF\n")
> print "Goodbye, data logged in file:"
> print filename
> usbkeith.close()
> keithdata.close()
> 
> can anyone here what is going wrong and how to get it right?
> 
> thanks
> jean
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Just guessing here - it looks as though you are setting the current and THEN turning the output on.  That might be the correct sequence or it might not.  If not, it would explain the offset between that and the subsequent readings.

This is really a Keithley problem, not a Python problem.

-Bill



More information about the Python-list mailing list