UsbDevice.GetDeviceClassSelector(UsbDeviceClass) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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 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,
- Create a UsbDeviceClass object by specifying ClassCode, SubclassCode, and ProtocolCode property values. Alternatively, you can call the constructor by specifying a particular UsbDeviceClasses property.
- Call GetDeviceClassSelector and pass that new class. The call retrieves an AQS string.
- Call FindAllAsync and pass the string to get the UsbDevice object.