UsbDevice.GetDeviceClassSelector(UsbDeviceClass) Method

Definition

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.

public:
 static Platform::String ^ GetDeviceClassSelector(UsbDeviceClass ^ usbClass);
 static winrt::hstring GetDeviceClassSelector(UsbDeviceClass const& usbClass);
public static string GetDeviceClassSelector(UsbDeviceClass usbClass);
function getDeviceClassSelector(usbClass)
Public Shared Function GetDeviceClassSelector (usbClass As UsbDeviceClass) As String

Parameters

usbClass
UsbDeviceClass

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

Returns

String

Platform::String

winrt::hstring

String formatted as an AQS query.

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

}

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.

Applies to