Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34428

Re: problem with usbtmc-communication

From Terry Reedy <tjreedy@udel.edu>
Subject Re: problem with usbtmc-communication
Date 2012-12-06 15:28 -0500
References <05927d41-f73f-4fef-9a6d-4133e5c7d86a@n8g2000vbb.googlegroups.com> <mailman.471.1354650937.29569.python-list@python.org> <5a264830-225a-4321-add4-edda89bfa82c@u19g2000yqj.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.588.1354825729.29569.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[newbie] problem with usbtmc-communication Jean Dubois <jeandubois314@gmail.com> - 2012-12-04 04:14 -0800
  Re: [newbie] problem with usbtmc-communication wrw@mac.com - 2012-12-04 09:33 -0500
    Re: problem with usbtmc-communication Jean Dubois <jeandubois314@gmail.com> - 2012-12-04 08:12 -0800
      Re: problem with usbtmc-communication wrw@mac.com - 2012-12-05 10:26 -0500
        Re: problem with usbtmc-communication Jean Dubois <jeandubois314@gmail.com> - 2012-12-05 12:38 -0800
          Re: problem with usbtmc-communication wrw@mac.com - 2012-12-05 17:21 -0500
            Re: problem with usbtmc-communication Jean Dubois <jeandubois314@gmail.com> - 2012-12-06 05:50 -0800
              Re: problem with usbtmc-communication wrw@mac.com - 2012-12-06 09:50 -0500
                Re: problem with usbtmc-communication Jean Dubois <jeandubois314@gmail.com> - 2012-12-06 11:41 -0800
                Re: problem with usbtmc-communication Dave Angel <d@davea.name> - 2012-12-06 15:10 -0500
                Re: problem with usbtmc-communication wrw@mac.com - 2012-12-06 15:15 -0500
                Re: problem with usbtmc-communication Jean Dubois <jeandubois314@gmail.com> - 2012-12-07 05:46 -0800
                Re: problem with usbtmc-communication Jean Dubois <jeandubois314@gmail.com> - 2012-12-10 05:31 -0800
                Re: problem with usbtmc-communication wrw@mac.com - 2012-12-10 10:34 -0500
                Re: problem with usbtmc-communication Jean Dubois <jeandubois314@gmail.com> - 2012-12-10 22:58 -0800
                Re: problem with usbtmc-communication wrw@mac.com - 2012-12-11 09:34 -0500
                Re: problem with usbtmc-communication Jean Dubois <jeandubois314@gmail.com> - 2012-12-11 12:48 -0800
                Re: problem with usbtmc-communication wrw@mac.com - 2012-12-11 21:21 -0500
                Re: problem with usbtmc-communication Jerry Hill <malaclypse2@gmail.com> - 2012-12-11 19:49 -0500
                Re: problem with usbtmc-communication Jean Dubois <jeandubois314@gmail.com> - 2012-12-12 08:16 -0800
          Re: problem with usbtmc-communication Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-12-05 18:08 -0500
  Re: [newbie] problem with usbtmc-communication Terry Reedy <tjreedy@udel.edu> - 2012-12-04 14:55 -0500
    Re: problem with usbtmc-communication Jean Dubois <jeandubois314@gmail.com> - 2012-12-06 06:05 -0800
    Re: problem with usbtmc-communication Jean Dubois <jeandubois314@gmail.com> - 2012-12-06 07:44 -0800
      Re: problem with usbtmc-communication Terry Reedy <tjreedy@udel.edu> - 2012-12-06 15:28 -0500
        Re: problem with usbtmc-communication Jean Dubois <jeandubois314@gmail.com> - 2012-12-07 05:51 -0800

csiph-web