2013/10/29 Johannes Stezenbach <j...@sig21.net>:
> On Tue, Oct 29, 2013 at 12:16:51PM -0200, Wander Lairson Costa wrote:
>> 2013/10/29 Johannes Stezenbach <j...@sig21.net>:
>> >
>> > One remark: The "Let's get it started" example in
>> > docs/tutorial.rst looks confusing, why does it do this:
>> >
>> >     cfg = dev.get_active_configuration()
>> >     interface_number = cfg[(0,0)].bInterfaceNumber
>> >     alternate_setting = usb.control.get_interface(dev, interface_number)
>> >     intf = usb.util.find_descriptor(
>> >         cfg, bInterfaceNumber = interface_number,
>> >         bAlternateSetting = alternate_setting
>> >     )
>> >
>> > instead of just this:?
>> >
>> >     intf =  cfg[(0,0)]
>> >
>>
>> The code above finds the interface by its interface number, not its
>> index inside the configuration (they are not necessarily the same
>> thing).
>
> Well, I guess the intention is to show how to look up interface
> by bInterfaceNumber, but if you take cfg[(0,0)].bInterfaceNumber
> and look it up then you end with cfg[(0,0)], right?
>

What if cfg[0,0].bInterfaceNumber == 2?

>
>> > Also, the code lacks an
>> >
>> >     intf.set_altsetting()
>> >
>>
>> set_altsetting is only needed by device with alternate settings.
>>
>> > otherwise the EPs are not reset which might lead to errors
>> > (e.g. STALL is not cleaared from previous use), and Linux complains:
>> >
>>
>> Stalled endpoints are not something expected in normal cases.
>
> set_altsetting() is always required before using an interface since it
> resets it into a known state.  I mean the tutorial should just work
> and not cause new users to wonder if pyusb is broken...
>

IIRC, according to USB spec, a device that receives a SET_INTERFACE request and
does not have additional alternate settings is allowed to return an error.

>
>> > [2249737.372143] usb 1-1.1: usbfs: process 32478 (python) did not claim 
>> > interface 0 before use
>> >
>>
>> Interface claiming, in another hand, is handled internally by PyUSB,
>> this might be a bug.
>
> usb.control.get_interface() does not claim the interface.
>

Ah, no because control requests against endpoint 0 does not need
interface claiming.


-- 
Best Regards,
Wander Lairson Costa

------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to