| Version 92 (modified by pbatard, 3 years ago) (diff) |
|---|
Windows backend
About
The aim of this project is to bring a Windows backend to the mainline libusb 1.0 branch, so that libusb 1.0 can easily be used on Windows platforms.
Status
The Windows backend is now in pre-release stages. As of 2010.02.17, it include all of the main libusb v1.0 features, for both HID and WinUSB devices, apart from isochronous transfers (which is a limitation from the WinUSB Microsoft API).
It currently supports all Windows platforms from Windows XP, including 64 bit versions of Windows, excluding the following:
- Windows 2003
- Windows XP 64 bit
Supported development environments
The following development environments are currently supported for libusb 1.0 on Windows:
- MinGW (32 bit) or MinGW-w64. If using MinGW-w64, make sure you use a recent version (> 2010.03), as earlier ones had a bug preventing libusb from working.
- Microsoft Visual C++ (Visual Studio), either Express or full version, from version 6.0. You should be able to produce both win32 and x64 binaries with Visual C++. Take note the free Express version of Visual C++ can not produce 64bit binaries.
- Windows DDK build environment, which is freely available, through the use of the 'ddk_build.cmd' file. This will also produce both 32 and 64 bits binaries.
- Cygwin. Take note that Cygwin currently can not produce 64bit binaries.
Source
The current development Windows backend is available in the libusb main git repository under libusb-pbatard.git.
For those not familiar with git, here are the git commands you can use retrieve and compile the Windows branch:
git clone git://git.libusb.org/libusb-pbatard.git ; retrieve development branch (this only needs to be done once) git pull ; keep in sync with the remote tree
On Windows, if you don't want to use git on the commandline, you can use TortoiseGit to access and keep in sync with the git repository.
Note that before you can install TortoiseGit you need to install MSysGit and make sure that, during the installation of MSysGit, when prompted to adjust the PATH environment, you select "Run Git from the Windows Command Prompt" (2nd option). Also, in the general settings of TortoiseGit, the MSysGit path must point to the MSysGit bin directory (eg: C:Program Files (x86)Gitin")
Also note that, for MinGW and cygwin, as with the original libusb 1.0 development tree, you need to run './autogen.sh' in order to have configure and Makefile created for you.
Creating applications using libusb
To create projects relying on libusb 1.0, please refer to how the example executables (lusb, xusb) are compiled.
Please note that, on Windows, libusb depends on the SetupAPI and ole32 libraries, so you must either add "-lsetupapi -lole32" in your Makefile (if using MinGW/Cygwin) or add SetupAPI.lib and OLE32.lib to your as linker dependencies in your project files (MS).
.NET support
A .NET version of libusb, called LibUsbDotNet, based on libusb 1.0 and the Windows backend has also been developed by Travis Robinson.
If you plan to use libusb in a .NET project, please make sure you check http://libusbdotnet.sourceforge.net or http://sourceforge.net/projects/libusbdotnet/
Driver Installation
To access your USB devices with the Windows backend, if the device is not HID compliant, you will need to install the relevant driver. Two options are available:
- The easiest option is to use the most recent version of our Automated Driver Installer GUI: zadig.exe (BETA), which is part of the Windows Driver Installer library, libwdi.
The current version, which is compatible with both 32 and 64 bit Windows platforms should be able to install a WinUSB driver for any USB device.
Note that because the installer needs to run with administrative privileges, it is recommended to check the md5 checksum after download (or recompile your own version from the source)
- zadig.exe (2010.06.08): 5.2 MB, md5sum: 2c230bf9024f34e2196886da599a68fd, compiled with DDK 7600.16385.0 from w74.
NB: Zadig also allows the installation of the (unsigned) libusb0.sys driver from libusb-win32 (v.1.1.14.0).
- zadig.exe (2010.06.08): 5.2 MB, md5sum: 2c230bf9024f34e2196886da599a68fd, compiled with DDK 7600.16385.0 from w74.
- Or you can download the WinUSB driver files, then customize the .inf for your device and install the driver by following the instructions that are either provided here or in the README file that comes with the driver archive.
Latest binary snapshots
The following binary snapshots are provided for your convenience, generated for the following environments:
- Microsoft Visual Studio and DDK/SDK: DLL, static lib and examples -> MS32 and MS64 directories
- MinGW: DLL and static lib -> MinGW32 directory
Cygwin users should be able to use the MinGW library with the option -mno-cygwin
Note that these archives are provided in the 7z format. If you need a decompressor, you can install 7-zip.
- 2010.05.24 (pbr281)
- 2010.05.21 (pbr279)
- 2010.05.17 (pbr277)
- 2010.04.27 (r272)
- 2010.04.21 (r268)
- 2010.04.19 (r264)
Development Considerations
- For the first release, only WinUSB and HID access will be supported, with provisions for other access modes to be included later. This should cover most devices however.
- Windows' handling of composite devices is done with multiple drivers (VID_####&PID_####&MI_##), descendants of the usbccgp.sys driver (Composite Generic Parent). For more info, see "2. How Windows handles a composite device" at http://www.cygnal.org/ubb/Forum9/HTML/001050.html.
- Because Windows does not provide a native poll() function, and cygwin is the only development environment that provides such a call, the use of libusb file descriptors with poll() on cygwin is NOT supported. We should provide native Windows events, to use with WaitForSingleObject/WaitForMultipleObjects?, in a future version of libusb.
Known Restrictions
- Neither WinUSB or HID can be used to send an actual reset command to an USB device. This is a limitation of the Microsoft drivers.
- Neither WinUSB or HID can be used to set a device configuration that is different from the default one. This is a limitation of the Microsoft drivers.
- WinUSB does not support multiple concurrent applications (as per the WinUSB Howto whitepaper).
- WinUSB does not support isochronous transfers.
- HID keyboards and mice will not have read or write access. This is because Windows requires an exclusive access to them, and uses a driver that prevent generic access.
- Likewise, HID devices or interfaces for which the OS has a specific Windows driver different from the generic HID one cannot be accessed (eg. HID audio devices).
- Multiple HID top level collections are currently not supported (only the first top level collection will be used).
- HID vendor requests are not implemented.
- Because there is no native poll on Windows, the ability to return externally pollable file descriptors on Windows (libusb_pollfd) has been disabled.
To Do
- automated driver installation (in progress)
- multithread sample application
- libusb0.sys integration
- hotplug detection
Done
- full pthread-win32 dependency removal
- multithreading/concurrent access
- HID
- device enumeration
- descriptors retrieval
- composite devices & interface selection
- poll and pipe
- control transfers
- bulk/interrupt transfers
- device reset
- transfer cancellation
- MSVC compatibility
Development's status log
Please consult the git log or the raw Activity Log.
NB: Previous development occurred on the Google Code SVN Repository but this is no longer maintained.
Development Links
- How to Use WinUSB to Communicate with a USB Device.
Note that the inf file given in the howto has a typo. If you don't change SourceDisksFiles?.NTamd64 to SourceDisksFiles?.amd64, the driver installation will fail to copy the required DLLs on 64 bit systems... - Using WinUSB for User-Mode to USB Device Communication
- WinUSB User-Mode Client Support Routines
- HID Class Support Routines
- Microsoft's USB Core Team Blog (including resources on instrumenting the USB stack in Windows 7)
- additional information about Windows Co-Installers
- Enabling Memory Leak Detection in Visual C++
- HID implementation example (C#)
Mailing list
The libusb-devel mailing list exists for the users of the library, plus developers interested in contributing to the library itself.
Attachments
-
pthread-win32_libusb.zip
(145.1 KB) -
added by pbatard 3 years ago.
Precompiled version of pthread-win32, for 32 and 64 bit platforms, /MT and /MD versions, with 64 bit patch applied (Orin Eman)
-
mingw-w64-libusb-pbatard-1ebd8c90-2010-06-28.zip
(345.5 KB) -
added by stuge 3 years ago.
libusb-pbatard.git 1ebd8c90 cross-compiled using x86_64-w64-mingw32
Download all attachments as: .zip