Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'subject:Python': 0.05; 'binary': 0.05; 'sequences.': 0.07; 'utf-8': 0.07; 'encode': 0.09; 'encodes': 0.09; 'expected.': 0.09; 'skip:e 80': 0.09; 'such.': 0.09; 'cc:addr:python-list': 0.10; 'library': 0.15; '127': 0.16; 'adam': 0.16; 'ah,': 0.16; 'command)': 0.16; 'command:': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'hex': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'received:202.125.174': 0.16; 'received:202.125.174.133': 0.16; 'received:boardofstudies.nsw.edu.au': 0.16; 'received:cskk.homeip.net': 0.16; 'received:edu.au': 0.16; 'received:harvey.boardofstudies.nsw.edu.au': 0.16; 'received:homeip.net': 0.16; 'received:nsw.edu.au': 0.16; 'simpson': 0.16; 'translation': 0.16; 'wrote:': 0.17; 'byte': 0.17; 'bytes': 0.17; '>>>': 0.18; 'cheers,': 0.23; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'looks': 0.26; 'values': 0.26; 'all.': 0.28; 'trouble': 0.28; 'arthur': 0.29; 'concern': 0.29; 'i/o': 0.29; 'prints': 0.29; 'subject:Sending': 0.29; 'character': 0.29; '"the': 0.29; 'thursday,': 0.30; 'code': 0.31; 'getting': 0.33; '11,': 0.33; 'text,': 0.33; 'changed': 0.34; 'whatever': 0.35; 'but': 0.36; 'received:au': 0.36; 'subject:with': 0.36; 'charset :us-ascii': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'instead': 0.39; 'short': 0.39; 'claim': 0.60; 'content-disposition:inline': 0.60; '30,': 0.62; 'more': 0.63; 'august': 0.66; 'million': 0.72; 'celebrated': 0.84; 'howard': 0.84; 'subject:commands': 0.84; 'dennis': 0.91; 'story,': 0.91 Date: Fri, 31 Aug 2012 08:47:56 +1000 From: Cameron Simpson To: "Adam W." Subject: Re: Sending USB commands with Python MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20c77648-7b1f-4a45-82de-c8721c834394@googlegroups.com> User-Agent: Mutt/1.5.21 (2010-09-15) References: <20c77648-7b1f-4a45-82de-c8721c834394@googlegroups.com> Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1346366887 news.xs4all.nl 6975 [2001:888:2000:d::a6]:55747 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28148 On 30Aug2012 05:51, Adam W. wrote: | On Thursday, August 30, 2012 12:55:14 AM UTC-4, Dennis Lee Bieber wrote: | > How many bytes did it claim to send? | | 11, which is what I expected. But I changed the byte value to 16 | (because I was having trouble getting single digit hex values working | in the command) and sent this command: | | >>> for x in range(0,500): | ep.write(b'\x16\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF') | | it respond with 500 17's and prints a black bar! So it looks like whatever concern you had with using encode was coming to fruition. Yeah. Try 'iso8859-1' instead of 'utf-8'. You want to be not translating the byte values at all. UTF-8 encodes character values over 127 as multibyte sequences. ISO8859-1 is a 256 code set that does no translation - character codes in go directly to byte values out. You're speaking a binary protocol, not text, so you want a one to one mapping. Better still would be to be using a bytes I/O layer instead of one with a text->byte translation; I do not know if the USB library you're using offers such. So try 'iso8859-1'; at least the translation is a no-op. Cheers, -- Cameron Simpson B1FF is an archetype, and all you're showing us is one of the more amusing of his many instantiations. - Howard E. Motteler Ah, perhaps Arthur Clarke anticipated this in his celebrated short story, "The Nine Million Names Of B1FF"? - Nosy