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


Groups > comp.lang.python > #28084

Re: Sending USB commands with Python

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: Sending USB commands with Python
Date 2012-08-29 22:07 -0400
Organization > Bestiaria Support Staff <
References <eq3t38542luf3dmula4k92islpa9lh0opk@invalid.netcom.com> <20120829222932.GA18700@cskk.homeip.net> <mailman.3947.1346280975.4697.python-list@python.org> <ad907349-042b-4ddf-aef7-043d7dfb1f9a@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3952.1346292474.4697.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, 29 Aug 2012 16:45:10 -0700 (PDT), "Adam W."
<AWasilenko@gmail.com> declaimed the following in
gmane.comp.python.general:

> 
> Huzzah!  I am indeed using 3.x, and slapping on an .encode('utf-8') made my printer try to spit paper at me! Progress.
> 
> Also, astute observation about the endpoint needing to be an input, with the following modification I get:
> 
> >>> ep.write('\x1BA'.encode('utf-8'))
> 2

	I'm a tad curious if using the notation

		b'\x1bA'

without the .encode() would work.

	My concern is that you may encounter some "string" of data for
printing which the .encode() ends up /changing/ (don't UTF-8 strings use
a high-bit to signal a multi-byte encoding of what had been a single
character?). A pure byte string shouldn't have that problem.

> >>> ep = usb.util.find_descriptor(
>     intf,
>     custom_match = \
>     lambda e: \
>         usb.util.endpoint_direction(e.bEndpointAddress) == \
>         usb.util.ENDPOINT_IN
> )

	Seems tedious to keep swapping -- does USB support bidirectional
connections?

> >>> ep.read(1)
> array('B', [163])
> >>> 
> 
> Anyone want to venture a guess on how I should interpret that?  It seems the [163] is the byte data the manual is talking about, but why is there a 'B' there?  If I put paper in it and try again I get: array('B', [3])

	Per documentation (section 8.6 in Python 2.7.2 library) of "array"
module:

'b' signed char int 1 
'B' unsigned char int 1 


>>> import array
>>> array.array("B", "\x1bB")
array('B', [27, 66])
>>> 
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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