Skip to main content
UsbDevice.GetDeviceClassSelector | getDeviceClassSelector method

Gets an Advanced Query Syntax (AQS) string that the app can pass to DeviceInformation.FindAllAsync in order to find a specific type of USB device.

Syntax


var string = Windows.Devices.Usb.UsbDevice.getDeviceClassSelector(usbClass);

public static string GetDeviceClassSelector(
  UsbDeviceClass usbClass
)

Public Shared Function GetDeviceClassSelector(
  usbClass As UsbDeviceClass 
) As String

public:
static String^ GetDeviceClassSelector(
  UsbDeviceClass^ usbClass
)

Parameters

usbClass

Type: UsbDeviceClass

A UsbDeviceClass object for the device class specified by the app.

Return value

Type: String [JavaScript] | System.String [.NET] | Platform::String [C++]

String formatted as an AQS query.

Remarks

You can search for a UsbDevice in the enumerated collection of devices by specifying class code, sub class code, or protocol code. To do this,

  1. Create a UsbDeviceClass object by specifying ClassCode, SubclassCode, and ProtocolCode property values. Alternatively, you can call the constructor by specifying a particular UsbDeviceClasses property.
  2. Call GetDeviceClassSelector and pass that new class. The call retrieves an AQS string.
  3. Call FindAllAsync and pass the string to get the UsbDevice object.

Examples


protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
    byte deviceClass = 0xf0;
    byte deviceSubclass = 0x01;
    
    var myDevices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(
                          UsbDevice.GetDeviceClassSelector(
                          new UsbDeviceClass() {
                          Class = deviceClass, Subclass = deviceSubclass }));

    UsbDevice device = null;

    foreach (var device in myDevices)
    {
        if (IsMyDevice(device))
        {
            device = await UsbDevice.FromIdAsync(device.Id);
        }
    }

    if (device == null)
    {
        ShowError("Usb device not found");
        return;
    }

}

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Devices.Usb
Windows::Devices::Usb [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

None supported

Namespace

Windows.Devices.Usb
Windows::Devices::Usb [C++]

Metadata

Windows.winmd

See also

UsbDevice