Usb device programming windows

Overview of developing Windows client drivers for USB devices

Purpose

This section describes Universal Serial Bus (USB) support in the Windows operating system, so that you can develop USB device drivers that are interoperable with Windows.

Where applicable

USB devices are peripherals, such as mouse devices and keyboards, that are connected to a computer through a single port. A USB client driver is the software installed on the computer that communicates with the hardware to make the device function. If the device belongs to a device class supported by Microsoft, Windows loads one of the Microsoft-provided USB drivers (in-box class drivers) for the device. Otherwise, a custom client driver must be provided by the hardware manufacturer or a third party vendor. The user installs the client driver for the device when the device is first detected by Windows. After successful installation, Windows loads the client driver every time the device is attached and unloads the driver when the device is detached from the host computer.

You can develop a custom client driver for a USB device by using the Windows Driver Frameworks (WDF) or the Windows Driver Model (WDM). Instead of communicating with the hardware directly, most client drivers send their requests to the Microsoft-provided USB driver stack that makes hardware abstraction layer (HAL) function calls to send the client driver’s request to the hardware. The topics in this section describe the typical requests that a client driver can send and the device driver interfaces (DDIs) that the client driver must call to create those requests.

Developer audience

A client driver for a USB device is a WDF or WDM driver that communicates with the device through DDIs exposed by the USB driver stack. This section is intended for use by C/C++ programmers who are familiar with WDM. Before you use this section, you should understand basic driver development. For more information, see Getting Started with Windows Drivers. For WDF drivers, the client driver can use Kernel-Mode Driver Framework (KMDF) or User-Mode Driver Framework (UMDF) interfaces designed specifically to work with USB targets. For more information about the USB-specific interfaces, see WDF USB Reference and UMDF USB I/O Target Interfaces.

Development tools

The Windows Driver Kit (WDK) contains resources that are required for driver development, such as headers, libraries, tools, and samples.

USB programming reference

Gives specifications for I/O requests, support routines, structures, and interfaces used by USB client drivers. Those routines and related data structures are defined in the WDK headers.

USB driver samples

Use these samples to get started with USB client driver programming.

Related standards and specifications

You can download official USB specifications from the Universal Serial Bus Documents website. This website contains links to the Universal Serial Bus Revision 3.0 Specification and the Universal Serial Bus Revision 2.0 specification.

Documentation sections

Introduces you to USB driver development. Provides information about choosing the most appropriate model for providing a USB driver for your device. Write, build, and install your first skeleton user-mode and kernel-mode USB drivers by using the USB templates included with Microsoft Visual Studio.

Provides an overview of the USB driver stack architecture.

Learn how a client driver builds a variable-length data structure called a USB Request Block (URB) to submit requests to the USB driver stack.

Learn how a client driver builds a variable-length data structure called a USB Request Block (URB) to submit requests to the USB driver stack.

Device configuration refers to the tasks that the client driver performs to select a USB configuration and an alternate interface in each interface. The section shows the methods calls required to select a USB configuration.

Describes USB pipes, URBs for I/O requests, and how a client driver can use the device driver interfaces (DDIs) to transfer data to and from a USB device.

USBDeview для Windows

Оценка:
  • 1
  • 2
  • 3
  • 4
  • 5

4.21 /5 голосов — 62

Лицензия:Бесплатная
Версия:3.01 | Сообщить о новой версии
Обновлено:10.09.2020
ОС:Windows 10, 8.1, 8, 7, XP
Интерфейс:Английский
Разработчик:
Категория:Внешние устройства
Загрузок (сегодня/всего):25 / 164 060 | Статистика
Размер:97 Кб
СКАЧАТЬ

USBDeview — небольшая программка, которая выведет список всех USB устройств (флеш-карта, мобильный телефон, фотоаппарат, принтер и т.д.), когда-либо подключаемых к Вашему компьютеру.

При этом по каждому устройству, подключено оно в данный момент или нет, USBDeview предоставит исчерпывающую информацию: дату и время, когда устройство было добавлено и время последнего подключения, наименование/описание устройства, тип, серийный номер, идентификационные номера продукта и производителя и многое другое. Полученную информацию можно экспортировать в Text/HTML или XML файл.

Кроме этого, USBDeview также может деинсталлировать USB устройства, которые вы использовали ранее, или отключить те, что подключены к вашему компьютеру в данный момент.

BlueSoleil — одно из наиболее популярных приложений, которое при помощи Bluetooth поможет соединить.

USBDeview — небольшая программка, которая выведет список всех USB устройств (флеш-карта.

AutoHotkey — приложение для автоматизации процессов до одного клика. Настраивайте клавиатуру и.

MediaKey — утилита для переназначения клавиш абсолютно любых клавиатур. Позволяет управлять.

ScanLite — небольшая бесплатная утилита, с помощью которой можно быстро и легко осуществлять.

Fast Mouse — небольшая утилита для автоматического нажатия кнопки мыши с определенной.

Отзывы о программе USBDeview

Марат про USBDeview 3.01 [17-09-2020]

а как руссификатор установить на эту прогу
| 3 | Ответить

Admin в ответ Марат про USBDeview 3.01 [20-09-2020]

Распаковать в ту же папку, где находится сама программа
1 | 3 | Ответить

Ян про USBDeview 2.85 [28-11-2019]

Угу. эта прога только для просмотра. Если вы с ее помощью удалите историю подключений, в реестре следы все равно остаются, только их уже ручками УДАЛИТЬ НЕЛЬЗЯ. Так что очистка истории только вручную
3 | 8 | Ответить

Катя про USBDeview 2.80 [31-05-2019]

Спасибо большое, оочень помогло:)))
2 | 2 | Ответить

Андрик 96 про USBDeview 2.71 [30-10-2017]

А есть русификатор ? Или как убрать все пути выставления флешку в комп
3 | 4 | Ответить

Слон в ответ Андрик 96 про USBDeview 2.71 [31-10-2017]

А слона то мы и не заметили. Глаза открой. Внизу описания есть «Дополнительные файлы к программе:», клацаешь и грузится русификатор.
3 | 3 | Ответить

AlexI про USBDeview 2.61 [12-08-2016]

замечательная вещь, рекомендую!
3 | 2 | Ответить

Write a Windows desktop app based on the WinUSB template

The easiest way to write a Windows desktop app that communicates with a USB device, is by using the C/C++ WinUSB template. For this template, you need an integrated environment with the Windows Driver Kit (WDK) (with Debugging Tools for Windows) and Microsoft Visual Studio (Professional or Ultimate). You can use the template as a starting point.

Prerequisites

  • To set up the integrated development environment, first install Microsoft Visual Studio Ultimate 2019 or Microsoft Visual Studio Professional 2019 and then install the WDK. You can find information about how to set up Visual Studio and the WDK on the WDK download page.
  • Debugging Tools for Windows are included when you install the WDK. For more information, see Download and Install Debugging Tools for Windows.

Creating a WinUSB application

To create an application from the template:

In the New Project dialog box, in the search box at the top, type USB.

In the middle pane, select WinUSB Application (Universal).

Select Next.

Enter a project name, choose a save location, and select Create.

The following screenshots show the New Project dialog box for the WinUSB Application (Universal) template.

This topic assumes that the name of the Visual Studio project is USB Application1.

Visual Studio creates one project and a solution. You can see the solution, the project, and the files that belong to the project in the Solution Explorer window, as shown in the following screen shot. (If the Solution Explorer window is not visible, choose Solution Explorer from the View menu.) The solution contains a C++ application project named USB Application1.

The USB Application1 project has source files for the application. If you want to look at the application source code, you can open any of the files that appear under Source Files.

Add a driver package project to the solution. Select and hold (or right-click) the solution (Solution ‘USB Application1’), then select Add > New Project as shown in the following screenshot.

In the New Project dialog box, in the search box at the top, once again type USB.

In the middle pane, select WinUSB INF Driver Package.

Select Next.

Enter a project name, then select Create.

The following screenshots show the New Project dialog box for the WinUSB INF Driver Package template.

This topic assumes that the name of the Visual Studio project is USB Application1 Package.

The USB Application1 Package project contains an INF file that is used to install Microsoft-provided Winusb.sys driver as the device driver.

Your Solution Explorer should now contain both projects, as shown in the following screenshot.

In the INF file, USBApplication1.inf, locate this code: %DeviceName% =USB_Install, USB\VID_vvvv&PID_pppp

Replace VID_vvvv&PID_pppp with the hardware ID for your device. Get the hardware ID from Device Manager. In Device Manager, view the device properties. On the Details tab, view the Hardware Ids property value.

In the Solution Explorer window, select and hold (or right-click) Solution ‘USB Application1’ (2 of 2 projects), and choose Configuration Manager. Choose a configuration and platform for both the application project and the package project. In this exercise, we choose Debug and x64, as shown in the following screen shot.

Building, deploying and debugging the project

So far in this exercise, you’ve used Visual Studio to create your projects. Next you need to configure the device to which the device is connected. The template requires that the Winusb driver is installed as the driver for your device.

Your testing and debugging environment can have:

Two computer setup: the host computer and the target computer. You develop and build your project in Visual Studio on the host computer. The debugger runs on the host computer and is available in the Visual Studio user interface. When you test and debug the application, the driver runs on the target computer.

Single computer setup: Your target and host run on one computer. You develop and build your project in Visual Studio, and run the debugger and the application.

You can deploy, install, load, and debug your application and the driver by following these steps:

Two computer setup

  1. Provision your target computer by following the instructions in Provision a computer for driver deployment and testing. Note: Provisioning creates a user on the target machine named, WDKRemoteUser. After provisioning is complete you will see the user switch to WDKRemoteUser.
  2. On the host computer, open your solution in Visual Studio.
  3. In main.cpp add this line before the OpenDevice call.

The line causes the application to pause when launched. This is useful in remote debugging.

  1. In pch.h, include this line:

This include statement is required for the system() call in the preceding step.

In the Solution Explorer window, select and hold (or right-click) USB Application1 Package, and choose Properties.

In the USB Application1 Package Property Pages window, in the left pane, navigate to Configuration Properties > Driver Install > Deployment, as shown in the following screen shot.

Check Remove previous driver versions before deployment.

For Remote Computer Name, select the name of the computer that you configured for testing and debugging. In this exercise, we use a computer named dbg-target.

Select Install/Reinstall and Verify. Select Apply.

In the property page, navigate to Configuration Properties > Debugging, and select Debugging Tools for Windows – Remote Debugger, as shown in the following screen shot.

Select Build Solution from the Build menu. Visual Studio displays build progress in the Output window. (If the Output window is not visible, choose Output from the View menu.) In this exercise, we’ve built the project for an x64 system running Windows 10.

Select Deploy Solution from the Build menu.

On the target computer, you will see driver install scripts running. The driver files are copied to the %Systemdrive%\drivertest\drivers folder on the target computer. Verify that the .inf, .cat, test cert, and .sys files, and any other necessary files, are present %systemdrive%\drivertest\drivers folder. The device must appear in Device Manager without errors.

On the host computer, you will see this message in the Output window.

To debug the application

On the host computer, navigate to x64 > Win8.1Debug in the solution folder.

Copy the application executable, UsbApplication1.exe to the target computer.

On the target computer launch the application.

On the host computer, from the Debug menu, select Attach to process.

In the window, select Windows User Mode Debugger (Debugging Tools for Windows) as the transport and the name of the target computer, in this case dbg-target, as the qualifier as shown in this image.

Select the application from the list of Available Processes and select Attach. You can now debug using Immediate Window or by using the options in Debug menu.

The preceding instructions debug the application by using Debugging Tools for Windows – Remote Debugger. If you want to use the Remote Windows Debugger (the debugger that is included with Visual Studio), then follow these instructions:

  1. On the target computer, add msvsmon.exe to the list of apps allowed through Firewall.
  2. Launch Visual Studio Remote Debugging Monitor located in C:\DriverTest\msvsmon\msvsmon.exe.
  3. Create a working folder, such as, C:\remotetemp.
  4. Copy the application executable, UsbApplication1.exe to the working folder on the target computer.
  5. On the host computer, in Visual Studio, right-click the USB Application1 Package project, and select Unload Project.
  6. Select and hold (or right-click) the USB Application1 project, in project properties expand the Configuration Properties node and select Debugging.
  7. Change Debugger to launch to Remote Windows Debugger.
  8. Change the project settings to run the executable on a remote computer by following the instructions given in Remote Debugging of a Project Built Locally. Make sure that Working Directory and Remote Command properties reflect the folder on the target computer.
  9. To debug the application, in the Build menu, select Start Debugging, or press F5.

    Single computer setup:

    To build your application and the driver installation package, choose Build Solution from the Build menu. Visual Studio displays build progress in the Output window. (If the Output window is not visible, choose Output from the View menu.) In this exercise, we’ve built the project for an x64 system running Windows 10.

    To see the built driver package, navigate in Windows Explorer to your USB Application1 folder, and then navigate to x64 > Debug > USB Application1 Package. The driver package contains several files: MyDriver.inf is an information file that Windows uses when you install the driver, mydriver.cat is a catalog file that the installer uses to verify the test signature for the driver package. These files are shown in the following screen shot.

    Note There is no driver file included in the package. That is because the INF file references the in-box driver, Winusb.sys, found in Windows\System32 folder.

    Manually install the driver. In Device Manager, update the driver by specifying the INF in the package. Point to the driver package located in the solution folder, shown in the preceding section. Note If you see the error DriverVer set to a date in the future , set INF Package project settings > Inf2Cat > General > Use Local Time > Yes.

    Select and hold (or right-click) the USB Application1 project, in project properties expand the Configuration Properties node and select Debugging.

    Change Debugger to launch to Local Windows Debugger.

    Select and hold (or right-click) the USB Application1 Package project, and select Unload Project.

    To debug the application, in the Build menu, select Start Debugging, or press F5.

    Template code discussion

    The template is a starting point for your desktop application. The USB Application1 project has source files device.cpp and main.cpp.

    The main.cpp file contains the application entry point, _tmain. The device.cpp contains all helper functions that open and close the handle to the device.

    The template also has a header file named device.h. This file contains definitions for the device interface GUID (discussed later) and a DEVICE_DATA structure that stores information obtained by the application. For example, it stores the WinUSB interface handle obtained by OpenDevice and used in subsequent operations.

    Getting the instance path for the device — see RetrieveDevicePath in device.cpp

    To access a USB device, the application creates a valid file handle for the device by calling CreateFile. For that call, the application must obtain the device path instance. To obtain the device path, the app uses SetupAPI routines and specifies the device interface GUID in the INF file that was used to install Winusb.sys. Device.h declares a GUID constant named GUID_DEVINTERFACE_USBApplication1. By using those routines, the application enumerates all devices in the specified device interface class and retrieves the device path of the device.

    In the preceding function, the application gets the device path by calling these routines:

    SetupDiGetClassDevs to get a handle to the device information set, an array that contains information about all installed devices that matched the specified device interface class, GUID_DEVINTERFACE_USBApplication1. Each element in the array called a device interface corresponds to a device that is installed and registered with the system. The device interface class is identified by passing the device interface GUID that you defined in the INF file. The function returns an HDEVINFO handle to the device information set.

    SetupDiEnumDeviceInterfaces to enumerate the device interfaces in the device information set and obtain information about your device interface.

    This call requires the following items:

    • An initialized caller-allocated SP_DEVICE_INTERFACE_DATA structure that has its cbSize member set to the size of the structure.
    • The HDEVINFO handle from step 1.
    • The device interface GUID that you defined in the INF file.

    SetupDiEnumDeviceInterfaces looks up the device information set array for the specified index of the device interface and fills the initialized SP_DEVICE_INTERFACE_DATA structure with basic data about the interface.

    Note To enumerate all the device interfaces in the device information set, call SetupDiEnumDeviceInterfaces in a loop until the function returns FALSE and the error code for the failure is ERROR_NO_MORE_ITEMS. The ERROR_NO_MORE_ITEMS error code can be retrieved by calling GetLastError. With each iteration, increment the member index.

    Alternately, you can call SetupDiEnumDeviceInfo that enumerates the device information set and returns information about device interface elements, specified by the index, in a caller-allocated SP_DEVINFO_DATA structure. You can then pass a reference to this structure in the DeviceInfoData parameter of the SetupDiEnumDeviceInterfaces function.

    SetupDiGetDeviceInterfaceDetail to get detailed data for the device interface. The information is returned in a SP_DEVICE_INTERFACE_DETAIL_DATA structure. Because the size of the SP_DEVICE_INTERFACE_DETAIL_DATA structure varies, SetupDiGetDeviceInterfaceDetail is called twice. The first call gets the buffer size to allocate for the SP_DEVICE_INTERFACE_DETAIL_DATA structure. The second call fills the allocated buffer with detailed information about the interface.

    1. Calls SetupDiGetDeviceInterfaceDetail with DeviceInterfaceDetailData parameter set to NULL. The function returns the correct buffer size in the requiredlength parameter. This call fails with the ERROR_INSUFFICIENT_BUFFER error code. This error code is expected.
    2. Allocates memory for a SP_DEVICE_INTERFACE_DETAIL_DATA structure based on the correct buffer size that is retrieved in the requiredlength parameter.
    3. Calls SetupDiGetDeviceInterfaceDetail again and passes it a reference to the initialized structure in the DeviceInterfaceDetailData parameter. When the function returns, the structure is filled with detailed information about the interface. The device path is in the SP_DEVICE_INTERFACE_DETAIL_DATA structure’s DevicePath member.

    Creating a file handle for the device

    See OpenDevice in device.cpp.

    To interact with the device, the needs a WinUSB interface handle to the first (default) interface on the device. The template code obtains the file handle and the WinUSB interface handle and stores them in the DEVICE_DATA structure.

    1. The app calls CreateFile to create a file handle for the device by specifying the device path retrieved earlier. It uses the FILE_FLAG_OVERLAPPED flag because WinUSB depends on this setting.
    2. By using the file handle for the device, the app creates a WinUSB interface handle. WinUSB Functions use this handle to identify the target device instead of the file handle. To obtain a WinUSB interface handle, the app calls WinUsb_Initialize by passing the file handle. Use the received handle in the subsequent calls to get information from the device, and to send I/O requests to the device.

    Release the device handles — see CloseDevice in device.cpp

    The template code implements code to release the file handle and the WinUSB interface handle for the device.

    • CloseHandle to release the handle that was created by CreateFile, as described in the Create a File Handle for the Device section of this walkthrough.
    • WinUsb_Free to release the WinUSB interface handle for the device, which is returned by WinUsb_Initialize.

    Next steps

    Next, read these topics to send get device information and send data transfers to the device:

    Learn about querying the device for USB-specific information such as device speed, interface descriptors, related endpoints, and their pipes.

    Transfer data to and from isochronous endpoints of a USB device.

    Читайте также:  Драйвер для китайского ресивера xbox 360 для windows 10
Оцените статью