Connecting to the Device
Connecting to a USB device follows the same, familiar pattern as the other types of devices:
async Task<UsbDevice > GetUsbDevice(uint vendorId, uint productId) { foreach (DeviceInformation deviceInfo in await DeviceInformation.FindAllAsync(UsbDevice .GetDeviceSelector( vendorId, productId))) { // Return the first one (null if user doesn't consent) // Be sure to call FromIdAsync on the UI thread! return await UsbDevice .FromIdAsync(deviceInfo.Id); } return null; }
UsbDevice
’s version of GetDeviceSelector
has three overloads: one that lets you specify a vendor ID and product ID, one that lets you specify a Guid
representing the WinUSB ...
Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.