On 12/6/2012 10:44 AM, Jean Dubois wrote:

I followed your suggestion an now the code looks like this:
#!/usr/bin/python
import time
import os
import sys
measurementcurr=''
measurementvolt=''
timesleepdefault=2
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')
usbkeith.write(":OUTP:STAT ON\n")
for number, current_in in enumerate(('0.025', '0.050', '0.075',
'0.100'), 1):
    usbkeith.write(":SOUR:CURR %s\n" % current_in)
    time.sleep(timesleepdefault)
    usbkeith.write(":MEAS:CURR?\n")
    measurementcurr=usbkeith.readline()
    print 'Measured current %d: ' % number, measurementcurr
    usbkeith.write(":MEAS:VOLT?\n")
    measurementvolt=usbkeith.readline()
    print 'Measured voltage %d: ' % number, measurementvolt
    keithdata.write(measurementcurr.strip()+' '+measurementvolt)
usbkeith.write(":OUTP:STAT OFF\n")
print "Goodbye, data logged in file:"
print filename
usbkeith.close()
keithdata.close()

Still there is a "buffer-problem" as you can see in the output below:
0.00639725 0.0104065; these values are completely wrong
0.0248976 0.262959; these should have been be the first values
0.0500431 0.516602: these should been the second values
0.0749168 0.772616; these are the 3rd values
                      4th values are missing

any idea why this does what it does in Python?

I am not familiar with the protocol at all, but my guess (without looking at the octave code) is that two of these three commands

> usbkeith.write("SYST:REM" + "\n")
> usbkeith.write(":SENS:VOLT:PROT 1.5\n")
> usbkeith.write(":OUTP:STAT ON\n")

before the loop have responses that you need to read (and toss?)

usbkeith.readline(); usbkeith.readline()

so that the first values you read in the loop are the one that should be first. In other words, make sure the read buffer is clear before the loop.

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to