UsbDevice.GetDeviceClassSelector | getDeviceClassSelector method

Applies to Windows only

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);

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

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

 

 

Show:
© 2014 Microsoft