Discussion:
[pyusb-users] Controlling LED on wired xbox 360 gamepad
Mike Lawrence
2016-07-20 01:28:22 UTC
Permalink
Hi all,

I wonder if anyone might be able to help with this one. I'm looking to use
pyusb to interact with a wired xbox 360 gamepad. So far I can read just
fine but I'd also like to write so I can make the LED stop blinking.

Looking here (
http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/UsbInfo), I
should be able to do it, but no matter what messages I try sending, I'm not
having any luck controlling the LED. Below is the code I have thus far, any
suggestions?

import usb
dev = usb.core.find(idVendor=1118, idProduct=654)
dev.set_configuration()
readEP = dev[0][(0,0)][0] #endpoint to read from
writeEP = dev[0][(0,0)][1] #endpoint to write to

print readEP #should be: <ENDPOINT 0x81: Interrupt IN>
print writeEP #should be: <ENDPOINT 0x1: Interrupt OUT>

##read the startup messages
for i in range(4): #usually only 4 messages
data = dev.read(readEP.bEndpointAddress,readEP.wMaxPacketSize,100)
print len(data) #should be 3

##get initial button/axes state
data = dev.read(readEP.bEndpointAddress,readEP.wMaxPacketSize,100)
print len(data) #should be 20

##Try to set the LED to illuminate just one element (message 0x06).
##Each of the following commented-out attempts fails to leave only the first
##element illuminated and subsequent attempts at reading or writing yields
##"usb.core.USBError: [Errno 5] Input/Output Error"
dev.write(writeEP,'010306',100)
# dev.write(writeEP,'0\x010306',100)
# dev.write(writeEP,'66310',100) #decimal value of 0x010306

##attempt to read again
while True:
data = dev.read(readEP.bEndpointAddress,readEP.wMaxPacketSize,100)
Mike Lawrence
2016-07-20 15:08:27 UTC
Permalink
Nevermind, solved it! The proper write message is:

dev.write(writeEP,"\x01\x03\x06",0)


--
Mike Lawrence
Graduate Student
Department of Psychology & Neuroscience
Dalhousie University

~ Certainty is (possibly) folly ~

On Tue, Jul 19, 2016 at 10:28 PM, Mike Lawrence <***@gmail.com>
wrote:

> Hi all,
>
> I wonder if anyone might be able to help with this one. I'm looking to use
> pyusb to interact with a wired xbox 360 gamepad. So far I can read just
> fine but I'd also like to write so I can make the LED stop blinking.
>
> Looking here (
> http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/UsbInfo),
> I should be able to do it, but no matter what messages I try sending, I'm
> not having any luck controlling the LED. Below is the code I have thus far,
> any suggestions?
>
> import usb
> dev = usb.core.find(idVendor=1118, idProduct=654)
> dev.set_configuration()
> readEP = dev[0][(0,0)][0] #endpoint to read from
> writeEP = dev[0][(0,0)][1] #endpoint to write to
>
> print readEP #should be: <ENDPOINT 0x81: Interrupt IN>
> print writeEP #should be: <ENDPOINT 0x1: Interrupt OUT>
>
> ##read the startup messages
> for i in range(4): #usually only 4 messages
> data = dev.read(readEP.bEndpointAddress,readEP.wMaxPacketSize,100)
> print len(data) #should be 3
>
> ##get initial button/axes state
> data = dev.read(readEP.bEndpointAddress,readEP.wMaxPacketSize,100)
> print len(data) #should be 20
>
> ##Try to set the LED to illuminate just one element (message 0x06).
> ##Each of the following commented-out attempts fails to leave only the
> first
> ##element illuminated and subsequent attempts at reading or writing yields
> ##"usb.core.USBError: [Errno 5] Input/Output Error"
> dev.write(writeEP,'010306',100)
> # dev.write(writeEP,'0\x010306',100)
> # dev.write(writeEP,'66310',100) #decimal value of 0x010306
>
> ##attempt to read again
> while True:
> data = dev.read(readEP.bEndpointAddress,readEP.wMaxPacketSize,100)
>
>
Hermann Hamann
2016-08-13 07:34:15 UTC
Permalink
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. http://sdm.link/zohodev2dev
Wander Lairson Costa
2016-08-13 13:02:14 UTC
Permalink
Hi,

PyUSB relies on ctypes for finding libraries, which relies on Windows
library search policy, if it finds libusb1 first, then that's what it
assumes as the backend. backend parameter was designed for cases like
yours, when the default backend discovery policy doesn't apply.
Anyway, you code may be helpful to improve the search code, would you
mind opening a issue?

2016-08-13 4:34 GMT-03:00 Hermann Hamann <hermann-***@web.de>:
> Dear maintainers,
> my client and I have the same USB-Device. I have written a program for it.
> It runs fine on both Linux systems. It runs fine on my Windows but crashes
> on my client's.
> Both have installed the driver with inf-wizard and the system control shows
> libusb0.dll on
> both machines.
>
> However, pyusb1 does not care about it; there is no single line related to
> the registry in the code.
> Instead pyusb started searching with pyusb1 backend and finds some libusb1
> in some private direcory
> of some other device. And crashed.
>
> This is not acceptable.
> I have written a demo to fetch the correct service from the registry, it
> follows here:
> -------------------------------------------------------------------------------------
> from __future__ import print_function
> # call this only on Windows
> try:
> from _winreg import *
> except:
> from winreg import *
> def getService(vid,pid):
> vidpid = r"\VID_%04x&PID_%04x" % (vid,pid)
> path = r"SYSTEM\ControlSet002\ENUM\USB" + vidpid
> key = OpenKey(HKEY_LOCAL_MACHINE,path,0,KEY_READ)
> try:
> i = 0
> enumkey = EnumKey(key,i)
> i = i + 1
> except Exception as message:
> pass # print("enumkey",message)
>
> newkey = OpenKeyEx(key,enumkey,0,KEY_READ)
> service,Size = QueryValueEx(newkey,"Service")
> return service
> if __name__ == "__main__":
> print ("service for 0x5656 0x0834 is",getService(0x5656,0x0834))
> -----------------------------------------------------------------------------------------
> The output is
> "service for 0x5656 0x0834 is libusb0"
>
> I am aware of the backend=xxx switches and the findlibrary hooks.
> They are useful to override defaults in special cases.
>
> However this does not answer the question which defaults are appropiate in
> the normal case.
> On Windows the registry entry is the most appropriate default.
>
> I hope this can help you to amend pyusb1 (which is a great tool anyway).
>
> Sincerely Hermann Hamann
>
>
>
> ------------------------------------------------------------------------------
> What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
> patterns at an interface-level. Reveals which users, apps, and protocols are
> consuming the most bandwidth. Provides multi-vendor support for NetFlow,
> J-Flow, sFlow and other flows. Make informed decisions using capacity
> planning reports. http://sdm.link/zohodev2dev
> _______________________________________________
> pyusb-users mailing list
> pyusb-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyusb-users
>



--
Best Regards,
Wander Lairson Costa
Hermann Hamann
2016-08-17 07:31:20 UTC
Permalink
------------------------------------------------------------------------------
chris clark
2016-08-17 14:17:04 UTC
Permalink
On Wed, Aug 17, 2016 at 12:31 AM, Hermann Hamann <hermann-***@web.de>
wrote:

> Hi
> < would you mind opening a issue?
> I will do so, but it may take some time.
> I have absolutely no background in Windows and there will be a lot of
> googling before
> I can present hard facts.
>
> Therefore I ask the Window gurus among the users to answer me some
> questions:
> 1. What is the registry for?
> 2. Is it valid programming style to disregard registry entries?
> 3. Has anyone succesfully used a non registered driver?
>

Can you clarify #3? I've always had to install the driver, is that what you
mean by registered?

I've some rough notes on Windows usage at
https://bitbucket.org/clach04/coldtears_clock/wiki/Windows

On creating issues, it is worth creating it as a place holder and
incrementally adding details when you have them.

Chris
Hermann Hamann
2016-08-18 09:10:56 UTC
Permalink
------------------------------------------------------------------------------
Xiaofan Chen
2016-08-18 12:00:03 UTC
Permalink
On Wed, Aug 17, 2016 at 3:31 PM, Hermann Hamann <hermann-***@web.de> wrote:
> Hi
> < would you mind opening a issue?
> I will do so, but it may take some time.
> I have absolutely no background in Windows and there will be a lot of
> googling before I can present hard facts.
>
> Therefore I ask the Window gurus among the users to answer me some
> questions:
> 1. What is the registry for?
> 2. Is it valid programming style to disregard registry entries?
> 3. Has anyone succesfully used a non registered driver?
>

I see. If you have no background in Windows, maybe you
want to step back and debug the real problem and forget
about the registry thingy for a while.

As for 3), you can use Zadig which will take care of the
digital signature requirement under Windows.


--
Xiaofan

------------------------------------------------------------------------------
Hermann Hamann
2016-08-20 09:19:15 UTC
Permalink
------------------------------------------------------------------------------
Jeffrey Nichols
2016-08-20 12:11:06 UTC
Permalink
Your real problem is that you don't know beforehand which driver your
device will be using. If you're doing the driver install as part of an
installer (e.g. using wdi-simple.exe) or instructing your users to use
zadig.exe then you should already know which driver has been installed.
I would say it's highly unusual to not know the driver for a device you
control, which is one of the reasons why everyone has rejected the
registry idea.

And since you'll know which driver has been installed, you'll know which
backend to use.

You can include a libusb dll with your program and add its directory to
the front of the PATH, like so:

os.environ['PATH'] = get_main_dir() + ';' + os.environ['PATH']

Which will guarantee that you're using the DLL you think you are.

P.S. all these can be put together nicely with cx_freeze and inno setup
to create a "real program" for your users.

Best Regards,
Jeff

On 8/20/2016 5:19 AM, Hermann Hamann wrote:
> Hi
> > ..and debug the real problem
> What is my real problem?
> H.H.
>
>
> ------------------------------------------------------------------------------
>
>
> _______________________________________________
> pyusb-users mailing list
> pyusb-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyusb-users
Hermann Hamann
2016-08-23 09:23:58 UTC
Permalink
------------------------------------------------------------------------------
Jeffrey Nichols
2016-08-23 13:13:11 UTC
Permalink
On 8/23/2016 5:23 AM, Hermann Hamann wrote:
> Hi, thank you
> <Iwould say it's highly unusual to not know the driver for a device
> you control, which is one of the reasons why everyone
> <has rejected the registry idea.
>
> Well, why then the library search? It is completely superfluous if I
> fix anything at installation.
> Sincerely
> Hermann
I believe the automatic backend selection is to make scripts that run on
only your computer simpler and interactive python shells more
convenient. For anything that's going to be run on other people's
computers you should definitely be specifying the backend. Moreover, you
should be altering the PATH so you know which dll is being used.

So yes, in *your* application it is superfluous. It is convenient for
other sorts of situations, though.

Jeff
Hermann Hamann
2016-08-24 09:34:43 UTC
Permalink
------------------------------------------------------------------------------
Xiaofan Chen
2016-08-17 14:26:29 UTC
Permalink
On Sat, Aug 13, 2016 at 3:34 PM, Hermann Hamann <hermann-***@web.de> wrote:
> Dear maintainers,
> my client and I have the same USB-Device. I have written a program for it.
> It runs fine on both Linux systems. It runs fine on my Windows but crashes
> on my client's.
> Both have installed the driver with inf-wizard and the system control shows
> libusb0.dll on both machines.
>
> However, pyusb1 does not care about it; there is no single line related to
> the registry in the code.

Why do you think registry access is needed?

> Instead pyusb started searching with pyusb1 backend and finds some libusb1
> in some private directory of some other device. And crashed.
>
> This is not acceptable.

What do you mean by private directory of some other device? Why it crashed?

If you want to use libusb-1.0 backend, you need to have libusb-1.0.dll in
the system and better use WinUSB driver for your device.


--
Xiaofan

------------------------------------------------------------------------------
Hermann Hamann
2016-08-18 09:07:15 UTC
Permalink
------------------------------------------------------------------------------
Xiaofan Chen
2016-08-18 11:57:32 UTC
Permalink
On Thu, Aug 18, 2016 at 5:07 PM, Hermann Hamann <hermann-***@web.de> wrote:
>
> Hi
>
> <Why do you think registry access is needed?
> I have read so in the internet. I will post reference later.
>
> <What do you mean by private directory of some other device?
>
> If it helps you:
>
> C:\Program Files\RTLSDR Scanner>dir lib*.*
> Volume in Laufwerk C: hat keine Bezeichnung.
> Volumeseriennummer: ECEC-C891
>
> Verzeichnis von C:\Program Files\RTLSDR Scanner
>
> 12.04.2013 20:04 68.608 libusb-1.0.dll
> 1 Datei(en), 68.608 Bytes
> 0 Verzeichnis(se), 70.811.631.616 Bytes frei
>
> C:\Program Files\RTLSDR Scanner>

This again has nothing to do with libusb or pyusb.

> < Why it crashed?
> I don't know.

You need to figure that out.

> <If you want to use libusb-1.0 backend, you need to have libusb-1.0.dll in
> <the system and better use WinUSB driver for your device.
>
> I want the backend that is in the registry.

The registry thingy has nothing to do with your problem.


--
Xiaofan

------------------------------------------------------------------------------
Xiaofan Chen
2016-08-18 12:07:59 UTC
Permalink
On Thu, Aug 18, 2016 at 7:57 PM, Xiaofan Chen <***@gmail.com> wrote:
> On Thu, Aug 18, 2016 at 5:07 PM, Hermann Hamann <hermann-***@web.de> wrote:
>>
>> Hi
>>
>> <Why do you think registry access is needed?
>> I have read so in the internet. I will post reference later.
>>
>> <What do you mean by private directory of some other device?
>>
>> If it helps you:
>>
>> C:\Program Files\RTLSDR Scanner>dir lib*.*
>> Volume in Laufwerk C: hat keine Bezeichnung.
>> Volumeseriennummer: ECEC-C891
>>
>> Verzeichnis von C:\Program Files\RTLSDR Scanner
>>
>> 12.04.2013 20:04 68.608 libusb-1.0.dll
>> 1 Datei(en), 68.608 Bytes
>> 0 Verzeichnis(se), 70.811.631.616 Bytes frei
>>
>> C:\Program Files\RTLSDR Scanner>
>
> This again has nothing to do with libusb or pyusb.

I mean why your program finds this very old version of
libusb Windows dll? You probably want to use the latest
version of libusb Windows release and put the dll in the
right directory.

>> < Why it crashed?
>> I don't know.
>
> You need to figure that out.
>
>> <If you want to use libusb-1.0 backend, you need to have libusb-1.0.dll in
>> <the system and better use WinUSB driver for your device.
>>
>> I want the backend that is in the registry.
>
> The registry thingy has nothing to do with your problem.
>



--
Xiaofan

------------------------------------------------------------------------------
Hermann Hamann
2016-08-19 09:05:09 UTC
Permalink
------------------------------------------------------------------------------
Tormod Volden
2016-08-18 18:40:18 UTC
Permalink
On Thu, Aug 18, 2016 at 11:07 AM, Hermann Hamann wrote:
> <What do you mean by private directory of some other device?
>
> If it helps you:
>
> C:\Program Files\RTLSDR Scanner>dir lib*.*
> 12.04.2013 20:04 68.608 libusb-1.0.dll

Probably "C:\Program Files\RTLSDR Scanner" is in the global %PATH%, so
it is not so "private".

> < Why it crashed?
> I don't know.

I believe the crash probably happened when libusb1 accessed the device
through the libusb0.sys driver (which in theory could work but the
different drivers have their subtleties). libusb1 might have worked
better if it could access the device through the WinUSB driver. Since
the libusb-win32 library / libusb0 driver combination seems to work
you have likely encountered a bug in the libusb1/libusb0.sys
combination. It would be nice if you can file a bug and supply more
detail, if not to get the bug fixed, at least warn others about the
issue.

> <If you want to use libusb-1.0 backend, you need to have libusb-1.0.dll in
> <the system and better use WinUSB driver for your device.
>
> I want the backend that is in the registry.

pyusb by default looks for libusb1 first, using the path, like how
most applications loads DLLs. If you have the libusb1 DLL installed in
the path but don't want to have it selected, you must select backend
explicitly.

I suppose libusb1 (somewhere through the Windows API layers) uses the
registry to know which driver to use. It is however not obvious how
pyusb should interpret the registry to choose its backend library.
Flexibility comes at a cost.

For instance, libusb-win32 ships both a library (DLL) and a driver
(SYS) and the former always uses the latter to access the device,
whereas libusb1 is just a library and can use various drivers (WinUSB,
HID, libusb0.sys, libusbK) to access the device. The Windows driver
registry will point to which driver is in charge of a device, and the
application must perform requests to this driver, but the application
(or developer) must itself select its libraries. And the pyusb
application currently uses a DLL search to select default library
backend, regardless of the device.

If libusb1 would only support WinUSB, and we had a strict
driver<->libusb relation, heuristics based on the registered driver
could make more sense. Add more possible backends and drivers, try to
make things consistent across platforms, and it all becomes more
complex.

Hermann, in your case you are probably better off selecting the
libusb0 backend in your python application, if you know that your
device requires libusb0.sys. Otherwise, register the device for WinUSB
(with .inf file or Zadig), make sure a known good libusb1.dll is
installed in the path (before any third party libusb1.dll) and select
the libusb1 backend in your python application for good measure.

BTW, Hermann's example patch hardcodes "ControlSet002" which I believe
should be "CurrentControlSet", unless there are better ways to find
the "Service" associated with a device. I also think device instances
(e.g. different serial numbers but same vid/pid) can have different
Service values, and I am not sure how the patch deals with that.

Regards,
Tormod

------------------------------------------------------------------------------
Hermann Hamann
2016-08-19 08:50:34 UTC
Permalink
------------------------------------------------------------------------------
Tormod Volden
2016-08-22 21:03:06 UTC
Permalink
On Fri, Aug 19, 2016 at 10:50 AM, Hermann Hamann <hermann-***@web.de> wrote:
> Hi Tormod,
> thank you for your expertise; now I see clearer.
>
>> < Why it crashed?
>> I don't know.
>
> I will send you a crash dump later.

Great, thanks.

>
>> <If you want to use libusb-1.0 backend, you need to have libusb-1.0.dll in
>> <the system and better use WinUSB driver for your device.
>>
>> I want the backend that is in the registry.
>
>>pyusb by default looks for libusb1 first
>
> < .... you must select backend explicitly.
>
> Well how can I? I do not know which backend is available on my clients'
> machines.

You should know! The application that you deliver to your client is
your.py + pyusb + libusb backend. If your application is "taking care"
of a device you ship this bundle + hardware driver (libusb0.sys or inf
declaring WinUSB for the device). If your application is just an extra
tool and an existing application already installed a hardware driver
that you don't want to interfere with, you better know the application
which "owns" the device and which hardware driver it uses, but as you
already are aware of, you can also read out the registered hardware
driver from the registry. If the existing hardware driver can be
either libusb0.sys or winusb.sys, you must bundle all appropriate
backends to handle all cases. As I said before, the libusb1 backend
should handle both, but due the bug you encounter it seems you will
need to bundle both libusb1 and libusb-win32 for now and your
application must choose between either as function of the hardware
driver, as a workaround for this bug. Again, only if you cannot decide
the hardware driver for this device...

And whether the client may have other applications using some variety
of libusb or not, that is not something you should speculate about,
because the other "private" libusb libraries can be modified versions
for what you know. If the machine is well administrated, it might have
a relatively recent, official libusb installed in the system32 folder,
but you probably shouldn't rely on that. Your installation
program/instructions should install the libusb DLL that you need.

> I can only rely on the driver that was installed for my device and which is
> displayed
> in the control panel. I suppose the control panel gets it through the
> registry.

>
> << Flexibility comes at a cost.
> And what is the cost of reliability?

The cost of reliability here is that you shouldn't rely on the
convenience auto-detection of already installed libusb backends that
pyusb offers as an option. It is provided as a convenience, but as an
application programmer you don't have to rely on it. As any other
application programmer you should know what is the hardware driver
used for the device, and assure the existence of libraries that your
program needs. pyusb has the flexibility of working with many backends
and thus with many hardware drivers so it gives many possibilities.
The cost of flexibility is that is you have choose between all these
possibilities, and make sure your choice is implemented.

It would be very normal for a program or library to depend on one
specific hardware driver. Here pyusb is very flexible. The cost of
this flexibility is paid by the pyusb developers, and only your choice
of relying on the autodetection convenience is adding to your bill.

The client's flexibility to use different hardware drivers will cost
you as the application programmer. On the other hand if you know that
the device uses the libusb0.sys hardware driver, and you know that the
libusb-win32 backend works well with your device, you just select this
backend in your application and bundle libusb-win32 with it. You also
make sure that this libusb0.dll is the one picked up by pyusb by
having it first in the path that pyusb uses for DLL discovery. This is
how other Windows applications make sure they have the right DLL's
(and version) loaded, for instance by throwing them into the directory
where the executable is. Or you follow the suggestion in the pyusb
manual https://github.com/walac/pyusb/blob/master/docs/tutorial.rst#specifying-libraries-by-hand
(with the only catch that you might have to find out if the host is 32
or 64 bit).

>
> <And the pyusb application currently uses a DLL search to select default
> library
> <backend, regardless of the device.
>
> Well I rank the registry higher in authority than the library search order.

It looks like you are mixing up library backend and driver. The
registry will tell you which driver (part of OS) is handling the
device. The OS doesn't dictate what DLL's you make up your application
from. From the OS point of view, your application includes pyusb and
libusb backend. The libusb backend is not a driver or service, it is a
piece of code linked into your application (linked at run-time in the
case of pyusb).

>
>
> <Hermann, in your case you are probably better off selecting the
> <libusb0 backend in your python application, if you know that your
> <device requires libusb0.sys. Otherwise, register the device for WinUSB
> <(with .inf file or Zadig), make sure a known good libusb1.dll is
> <installed in the path (before any third party libusb1.dll) and select
> <the libusb1 backend in your python application for good measure.
>
> Well I am a bit confused when regarding recommendations for driver
> installation.
> The tutorial recommends the inf-wizard and libusb0 and so I did and it works
> fine.

Which exact tutorial? That must be for the libusb-win32 backend.

> Well I can instruct my clients to do the same and hardcode pyusb0 into my
> program.

BTW, do you actually mean pyusb0 (0.4) or libusb0? It actually gets
really fun if you have a pyusb 0.4 program, that either runs through
pyusb 0.4 (and its possible backends) or through the pyusb 1.0 legacy
mode (and thus the backend selection we have talked about) - a lot
more combinations possible and auto-selections that the poor 0.4
program wouldn't know about. I remember trying to draw a chart of
these once... This gets even more complicated with Linux factored in,
where many supported distributions still have pyusb 0.4 so making one
pyusb application that works everywhere is challenging, at least
without bundling your own pyusb, and python, and libusb - for each
platform...

> So much about flexibility.

Flexibility is not the same as autodetection. And the autodetection
actually works as intended. Just the above mentioned bug may have
ruined the result. Or the 3rd party libusb1.dll that was first in your
path is somehow broken - let us know if you can reproduce with the
official, latest libusb.

>
> <BTW, Hermann's example patch hardcodes "ControlSet002" which I believe
> <should be "CurrentControlSet", unless there are better ways to find
>
> I found this with a registry editor search. I do not understand enough to
> judge the generality of this approach.
>
> <(e.g. different serial numbers but same vid/pid) can have different
> <Service values, and I am not sure how the patch deals with that.
> I would not care, nobody will have two same oscilloscopes on its computer.

The Windows registry contains different instances for each serial
number. If the oscilloscopes have no USB serial number, there will be
a new instance for every USB hardware port address used. In theory you
can have different drivers associated depending on which USB port it
is plugged into :)

>
> Thank you again for your effort, this makes my issue obsolete an I will not
> open it.

Glad I could help. Your issue is at a level higher than pyusb.

Tormod

>
> Sincerely Hermann

------------------------------------------------------------------------------
Hermann Hamann
2016-08-19 09:15:40 UTC
Permalink
------------------------------------------------------------------------------
Tormod Volden
2016-08-22 21:20:19 UTC
Permalink
On Fri, Aug 19, 2016 at 11:15 AM, Hermann Hamann wrote:
> Hi, Tormod
>
> This is the crashdump :
>
>
> C:\Portable\wdso>python wdso.py
>
> wdso 0.9.8
> found productId 0x0834
> [Errno 5] Input/output error
> Process USB_server:
> Traceback (most recent call last):
> File "C:\Python27\lib\multiprocessing\process.py", line 258, in _bootstrap
> self.run()
> File "C:\Python27\lib\multiprocessing\process.py", line 114, in run
> self._target(*self._args, **self._kwargs)
> File "C:\Portable\wdso\wdso.py", line 5019, in createUSBProcess
> USBProcess = USB(USBQ,ScopeQ,DiagQ,PID,BUS,DEV)
> File "C:\Portable\wdso\wdso.py", line 3563, in __init__
> self.device_init()
> File "C:\Portable\wdso\wdso.py", line 3631, in device_init
> self.device.ctrl_transfer(0x42,0xb1,0xdc,0,None); sleep(0.02)
> File "C:\Python27\lib\site-packages\usb\core.py", line 1043, inctrl_transfer
> self.__get_timeout(timeout))
> File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 883,in <hermann-***@web.de>
> ctrl_transfer timeout))
> File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 595,
> in _check
> raise USBError(_strerror(ret), ret, _libusb_errno[ret])
> USBError: [Errno 5] Input/output error
> finished
>

The interesting parts are probably in libusb and not in pyusb. You can
run with the LIBUSB_DEBUG environment variable set to a number to get
more info, e.g.:
LIBUSB_DEBUG=4

You can also set these from within python, like in the example of
PYUSB_DEBUG here:
os.environ['PYUSB_DEBUG'] = 'debug'

Now when it comes to the libusb <-> kernel hardware driver interaction
on Windows, it is not easy to get the full overview of possibilities,
requirements and failure modes. Quoting from
https://github.com/libusb/libusb/wiki/Windows :
"libusb0.sys access is done through the libusbK DLL, therefore, if you
plan to use the libusb-win32/libusb0.sys driver in libusb, you must
have that library installed. If using a recent version of Zadig, you
should not have to do anything, at it will install the library for
you."

Whether this was always (or still!) true I am not sure.

Tormod

------------------------------------------------------------------------------
Xiaofan Chen
2016-08-25 01:33:29 UTC
Permalink
On Tue, Aug 23, 2016 at 5:20 AM, Tormod Volden <***@gmail.com> wrote:

>
> Now when it comes to the libusb <-> kernel hardware driver interaction
> on Windows, it is not easy to get the full overview of possibilities,
> requirements and failure modes. Quoting from
> https://github.com/libusb/libusb/wiki/Windows :
> "libusb0.sys access is done through the libusbK DLL, therefore, if you
> plan to use the libusb-win32/libusb0.sys driver in libusb, you must
> have that library installed. If using a recent version of Zadig, you
> should not have to do anything, at it will install the library for
> you."
>
> Whether this was always (or still!) true I am not sure.
>

Yes Zadig will install libusbk.dll when installing libusb0.sys
or libusbk.sys driver. However, it is not recommended to use
libusb0.sys (device driver mode or filter driver mode) with
libusb Windows (libusb-1.0 API).

Ref: https://github.com/libusb/libusb/issues/94

In general, you should use WinUSB driver to use libusb
Windows (libusb-1.0 API).


--
Xiaofan

------------------------------------------------------------------------------
Hermann Hamann
2016-08-27 07:03:18 UTC
Permalink
------------------------------------------------------------------------------
Xiaofan Chen
2016-08-28 10:03:48 UTC
Permalink
On Thu, Aug 25, 2016 at 9:33 AM, Xiaofan Chen <***@gmail.com> wrote:
> On Tue, Aug 23, 2016 at 5:20 AM, Tormod Volden <***@gmail.com> wrote:
>
>>
>> Now when it comes to the libusb <-> kernel hardware driver interaction
>> on Windows, it is not easy to get the full overview of possibilities,
>> requirements and failure modes. Quoting from
>> https://github.com/libusb/libusb/wiki/Windows :
>> "libusb0.sys access is done through the libusbK DLL, therefore, if you
>> plan to use the libusb-win32/libusb0.sys driver in libusb, you must
>> have that library installed. If using a recent version of Zadig, you
>> should not have to do anything, at it will install the library for
>> you."
>>
>> Whether this was always (or still!) true I am not sure.
>>
>
> Yes Zadig will install libusbk.dll when installing libusb0.sys
> or libusbk.sys driver. However, it is not recommended to use
> libusb0.sys (device driver mode or filter driver mode) with
> libusb Windows (libusb-1.0 API).
>
> Ref: https://github.com/libusb/libusb/issues/94
>
> In general, you should use WinUSB driver to use libusb
> Windows (libusb-1.0 API).
>

I have edited libusb wiki to warn against using libusb0.sys
with libusb Windows.

https://github.com/libusb/libusb/wiki/Windows#Driver_Installation

--
Xiaofan

------------------------------------------------------------------------------
Hermann Hamann
2016-08-31 07:28:48 UTC
Permalink
------------------------------------------------------------------------------
Hermann Hamann
2016-09-14 11:05:01 UTC
Permalink
------------------------------------------------------------------------------
Wander Lairson Costa
2016-09-18 21:19:06 UTC
Permalink
2016-09-14 8:05 GMT-03:00 Hermann Hamann <hermann-***@web.de>:
> Hi,
> I am preparing an Installation Guide for my DSO program.
> I do not want to do obsolete or redundant work.
> Therfore I ask the following:
> * Are there plans for a new version of pyusb1 in the near future?

Maybe a minor bug fix version, but not big changes.

> * Are there plans for a Windows Installation Guide?

If you find the information in readme not enough, we can talk about
improving it, a pull request is very welcome :)

> Sincerely Hermann
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> pyusb-users mailing list
> pyusb-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyusb-users
>



--
Best Regards,
Wander Lairson Costa

------------------------------------------------------------------------------
Hermann Hamann
2016-09-20 12:14:06 UTC
Permalink
------------------------------------------------------------------------------
Hermann Hamann
2016-09-23 07:18:23 UTC
Permalink
------------------------------------------------------------------------------
Wander Lairson Costa
2016-09-23 12:23:12 UTC
Permalink
It feels like your problem was more about pyusb dependencies than
pyusb itself. Windows is a pain, because the way it works. Maybe the
solution is just an updated README file with more detaild instructions
about dependencies installation.

2016-09-23 4:18 GMT-03:00 Hermann Hamann <hermann-***@web.de>:
> Hi,
>
> To install or to not install, that is the question.
>
> I was recently bitten by some lethal errors using pyusb. These were not in
> the pyusb code but came from lower layers as a consequence of misusing them.
> The following correspondence with the maintenance crew was unsuccessful
> because the service aspect was not realized.
> It turned out that the errors were a consequence of different installation
> requirements of the different services.
> I confess guilty of having too long ignored the features of the winusb
> service.
> I have learned that DLLs need not be installed with winusb.
> I have learned too that DLLs must be installed with the libusb0 service and
> the installed library must be used.
> And it was the hard way to learn (using an apparently widely unknown
> technique called testing).
> And that installation requirement is what you still have to learn!
> I have enough logfiles to prove that.
> This has consequences for the structure of pyusb, the features that can
> safely be provided, and the necessary restrictions that must be documented.
> The good news is that for winusb served devices no changes are required.
> Well, to proceed with my work on the installation guide, I need a formal
> agreement of the service thesis because that will dominate the bugfix
> procedure.
> Who ever objects to this thesis should talk now or be silent for ever.
> I agree [ ] I disagree [ ]
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> pyusb-users mailing list
> pyusb-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyusb-users
>



--
Best Regards,
Wander Lairson Costa

------------------------------------------------------------------------------
Hermann Hamann
2016-09-24 07:33:05 UTC
Permalink
------------------------------------------------------------------------------
Hermann Hamann
2016-10-11 09:27:28 UTC
Permalink
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Wander Lairson Costa
2016-10-11 10:03:50 UTC
Permalink
Hi Hermann,

Thanks for digging on this. I didn't have free time to update docs yet, but
will do.

2016-10-11 6:27 GMT-03:00 Hermann Hamann <hermann-***@web.de>:

> Hi,
> The use of the pyusb0 service is a bit troublesome, because you have to
> specify the desired library by hand.
> I always had the dream of automatically use the installed library.
> Well, here is how.
> You must know the Vid and Pid of your device. With that you can look up
> the registry for the installed service.
> If it is winusb you need not care.
> If it is pyusb0 then you get the device descriptor and extract the device
> name.
> With it you go to the driverstore and scan the filerepository directory
> for a directory file name
> that starts with the device name.
> Then you walk under this tree until you find a dll name.
> This is the installed library.
> Was not so hard.
> I want to thank Xiaofan for his encouraging advice to dig deeper in this
> registry thingens.
> Now there is no more any need to pick a wrong library.
>
>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> pyusb-users mailing list
> pyusb-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyusb-users
>
>


--
Best Regards,
Wander Lairson Costa
Jeffrey Nichols
2016-10-11 12:55:49 UTC
Permalink
Don't forget to indicate in the documentation that not knowing which
driver to use is a VERY unusual situation, and that anyone going down
that path will need to install both libusb DLLs in the application's PATH.

Jeff

On 10/11/2016 6:03 AM, Wander Lairson Costa wrote:
> Hi Hermann,
>
> Thanks for digging on this. I didn't have free time to update docs
> yet, but will do.
>
> 2016-10-11 6:27 GMT-03:00 Hermann Hamann <hermann-***@web.de
> <mailto:hermann-***@web.de>>:
>
> Hi,
> The use of the pyusb0 service is a bit troublesome, because you
> have to specify the desired library by hand.
> I always had the dream of automatically use the installed library.
> Well, here is how.
> You must know the Vid and Pid of your device. With that you can
> look up the registry for the installed service.
> If it is winusb you need not care.
> If it is pyusb0 then you get the device descriptor and extract the
> device name.
> With it you go to the driverstore and scan the filerepository
> directory for a directory file name
> that starts with the device name.
> Then you walk under this tree until you find a dll name.
> This is the installed library.
> Was not so hard.
> I want to thank Xiaofan for his encouraging advice to dig deeper
> in this registry thingens.
> Now there is no more any need to pick a wrong library.
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> pyusb-users mailing list
> pyusb-***@lists.sourceforge.net
> <mailto:pyusb-***@lists.sourceforge.net>
> https://lists.sourceforge.net/lists/listinfo/pyusb-users
> <https://lists.sourceforge.net/lists/listinfo/pyusb-users>
>
>
>
>
> --
> Best Regards,
> Wander Lairson Costa
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>
>
> _______________________________________________
> pyusb-users mailing list
> pyusb-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyusb-users
Hermann Hamann
2016-10-13 09:28:38 UTC
Permalink
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Hermann Hamann
2016-10-13 09:47:32 UTC
Permalink
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Hermann Hamann
2016-08-24 10:27:22 UTC
Permalink
------------------------------------------------------------------------------
Continue reading on narkive:
Loading...