- USB Request Blocks (URBs)
- In this section
- Overview of developing Windows applications for USB devices
- Choosing a programming model
- Driver requirement
- Code samples
- Development tools
- How to communicate with a USB device under Windows and Java?
- 4 Answers 4
- Not the answer you’re looking for? Browse other questions tagged java windows usb or ask your own question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- Is there a way to communicate with USB devices from browser?
- 6 Answers 6
- Working with USB devices in .NET
- 11 Answers 11
USB Request Blocks (URBs)
This section describes a USB Request Block (URB) and provides information about how a USB client driver can use Windows Driver Model (WDM) routines to allocate, build, and submit URBs to the USB driver stack.
A Universal Serial Bus (USB) client driver cannot communicate with its device directly. Instead, the client driver creates requests and submits them to the USB driver stack for processing. Within each request, the client driver provides a variable-length data structure called a USB Request Block (URB). The URB structure describes the details of the request and also contains information about the status of the completed request. The client driver performs all device-specific operations, including data transfers, through URBs. The client driver must initialize the URB with information about the request before submitting it to the USB driver stack. For certain types of requests, Microsoft provides helper routines and macros that allocate an URB structure and fill the necessary members of the URB structure with details provided by the client driver.
Each URB begins with a standard fixed-sized header (_URB_HEADER) whose purpose is to identify the type of operation requested. The Length member of _URB_HEADER specifies the size, in bytes, of the URB. The Function member, which must be one of a series of system-defined URB_FUNCTION_XXX constants, determines the type of operation that is requested. In the case of data transfers, for instance, this member indicates the type of transfer. Function codes URB_FUNCTION_CONTROL_TRANSFER, URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER, and URB_FUNCTION_ISOCH_TRANSFER indicate control, bulk/interrupt, and isochronous transfers respectively. The USB driver stack uses the Status member to return a USB-specific status code.
To submit an URB, the client driver uses the IOCTL_INTERNAL_USB_SUBMIT_URB request, which is delivered to the device by means of an I/O request packet (IRP) of type IRP_MJ_INTERNAL_DEVICE_CONTROL.
After the USB driver stack is done processing the URB, the driver stack uses the Status member of the URB structure to return a USB-specific status code.
NoteВ В KMDF and UMDF driver developers should use the respective framework interfaces for communicating with a USB device. For more information, see Working with USB Devices for KMDF drivers and Working with USB Interfaces in UMDF. These topics discuss the underlying WDM driver interfaces used for USB device communication.
In this section
This topic describes how a USB client driver can use Windows Driver Model (WDM) driver routines to allocate and format an URB before sending the request to the Microsoft-provided USB driver stack.
This topic describes the steps that are required to submit an initialized URB to the USB driver stack to process a particular request.
This topic describes best practices for a client driver for allocating, building, and sending an URB to the USB driver stack included with WindowsВ 8.
Overview of developing Windows applications for USB devices
Summary
- Guidelines for choosing the right programming model
- UWP app and desktop app developer experience
Important APIs
This topic provides guidelines for deciding whether you should write a UWP app or a Windows desktop app to communicate with a USB device.
Windows provides API sets that you can use to write apps that talk to a custom USB devices. The API performs common USB-related tasks such as, finding the device, data transfers.
«Custom device» in this context means, a device for which Microsoft does not provide an in-box class driver. Instead, you can install WinUSB (Winusb.sys) as the device driver.
Choosing a programming model
If you install Winusb.sys, here are the programming model options:
Windows 8.1 provides a new namespace: Windows.Devices.Usb. The namespace cannot be used in earlier version of Windows. Other Microsoft Store resources are here: UWP app.
Before Windows 8.1, apps that were communicating through Winusb.sys, were desktop apps written by using WinUSB Functions. In Windows 8.1, the API set has been extended. Other Windows desktop app resources are here: Windows desktop app.
The strategy for choosing the best programming model depends on various factors.
Will your app communicate with an internal USB device?
The APIs are primarily designed for accessing peripheral devices. The API can also access PC internal USB devices. However access to PC internal USB devices from a UWP app is limited to a privileged app that is explicitly declared in device metadata by the OEM for that PC.
Will your app communicate with USB isochronous endpoints?
If your app transmits data to or from isochronous endpoints of the device, you must write a Windows desktop app. In Windows 8.1, new WinUSB Functions have been added to the API set that allow a desktop app to send data to and receive data from isochronous endpoints.
Is your app a «control panel» type of app?
UWP apps are per-user apps and do not have the ability to make changes outside the scope of each app. For these types of apps, you must write a Windows desktop app.
Is the USB device class supported classes by UWP apps?
Write a UWP app if your device belongs to one these device classes.
- name:cdcControl, classId:02 * *
- name:physical, classId:05 * *
- name:personalHealthcare, classId:0f 00 00
- name:activeSync, classId:ef 01 01
- name:palmSync, classId:ef 01 02
- name:deviceFirmwareUpdate, classId:fe 01 01
- name:irda, classId:fe 02 00
- name:measurement, classId:fe 03 *
- name:vendorSpecific, classId:ff * *
Note If your device belongs to DeviceFirmwareUpdate class, your app must be a privileged app.
If your device does not belong to one the preceding device classes, write a Windows desktop app.
Driver requirement
Driver requirement | UWP app | Windows desktop app |
---|---|---|
Function driver | Microsoft-provided Winusb.sys (kernel-mode driver). | Microsoft-provided Winusb.sys (kernel-mode driver). |
Filter driver | If filter drivers are present, access is limited to privileged apps. The app is declared as privileged apps in device metadata by the OEM. | Filter driver can be present in the kernel mode device stack as long as it doesn’t block access to Winusb.sys. |
Code samples
Sample | UWP app | Windows desktop app |
---|---|---|
Get started with these samples |
|
|
Development tools
Development tools | UWP app | Windows desktop app |
---|---|---|
Developer environment |