Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.04; 'sys': 0.05; 'filename': 0.07; 'line:': 0.07; 'subject:skip:c 10': 0.07; '"\\n")': 0.09; '%s\\n"': 0.09; '(without': 0.09; 'loop.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:k 40': 0.09; 'terry': 0.09; '%d:': 0.16; '1):': 0.16; 'file:"': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.17; 'skip:i 40': 0.17; 'skip:u 30': 0.17; 'jan': 0.18; 'followed': 0.20; 'python?': 0.20; 'skip:= 10': 0.20; 'all,': 0.21; 'import': 0.21; 'subject:problem': 0.22; 'this:': 0.23; 'idea': 0.24; 'second': 0.24; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'values': 0.26; 'skip:m 30': 0.26; 'am,': 0.27; 'guess': 0.27; 'skip:# 10': 0.27; 'first.': 0.27; 'header:X-Complaints-To:1': 0.28; 'jean': 0.29; "skip:' 10": 0.30; 'code': 0.31; '(and': 0.32; 'suggestion': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'wrong': 0.34; 'clear': 0.35; 'protocol': 0.35; 'there': 0.35; 'received:org': 0.36; 'skip:u 20': 0.36; 'but': 0.36; 'subject:with': 0.36; 'should': 0.36; 'does': 0.37; 'two': 0.37; 'why': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'subject:-': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'first': 0.61; 'below:': 0.71; '4th': 0.78; 'received:fios.verizon.net': 0.84; 'voltage': 0.84; 'responses': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: problem with usbtmc-communication Date: Thu, 06 Dec 2012 15:28:20 -0500 References: <05927d41-f73f-4fef-9a6d-4133e5c7d86a@n8g2000vbb.googlegroups.com> <5a264830-225a-4321-add4-edda89bfa82c@u19g2000yqj.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 In-Reply-To: <5a264830-225a-4321-add4-edda89bfa82c@u19g2000yqj.googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1354825729 news.xs4all.nl 6972 [2001:888:2000:d::a6]:60089 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34428 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