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


Groups > comp.lang.python > #28148

Re: Sending USB commands with Python

Date 2012-08-31 08:47 +1000
From Cameron Simpson <cs@zip.com.au>
Subject Re: Sending USB commands with Python
References <20c77648-7b1f-4a45-82de-c8721c834394@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3992.1346366887.4697.python-list@python.org> (permalink)

Show all headers | View raw


On 30Aug2012 05:51, Adam W. <AWasilenko@gmail.com> 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 <cs@zip.com.au>

B1FF is an archetype, and all you're showing us is one of the more amusing of
his many instantiations.        - Howard E. Motteler <motteler@umbc.edu>
Ah, perhaps Arthur Clarke anticipated this in his celebrated short story,
"The Nine Million Names Of B1FF"? - Nosy <ataylor@nmsu.edu>

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


Thread

Re: Sending USB commands with Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-29 18:56 -0400
  Re: Sending USB commands with Python "Adam W." <AWasilenko@gmail.com> - 2012-08-29 16:45 -0700
  Re: Sending USB commands with Python MRAB <python@mrabarnett.plus.com> - 2012-08-30 01:53 +0100
  Re: Sending USB commands with Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-29 22:07 -0400
    Re: Sending USB commands with Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-30 00:55 -0400
      Re: Sending USB commands with Python "Adam W." <AWasilenko@gmail.com> - 2012-08-30 05:51 -0700
        Re: Sending USB commands with Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-30 14:24 -0400
        Re: Sending USB commands with Python Cameron Simpson <cs@zip.com.au> - 2012-08-31 08:47 +1000

csiph-web