Reputation: 379
I am trying to make a UWP app which connects to a USB device and then executes a series of commands, like retrieving data from the internal sensor (think of an accelerometer). I started of with following these guidelines:
https://msdn.microsoft.com/en-us/library/windows/hardware/dn303343(v=vs.85).aspx
So, I also tried making a blank app, and adjusted the manifest accordingly:
<Capabilities>
<DeviceCapability Name="usb">
<Device Id="vidpid:1CBE 0003">
<Function Type="classId:ff 00 00" />
</Device>
</DeviceCapability>
</Capabilities>
To be sure, this is how the device identifies itself in the device manager:
and then used
string aqs = UsbDevice.GetDeviceSelector(vid, pid);
var finder = await DeviceInformation.FindAllAsync(aqs);
However, without success. The problem is simple, the app cannot find any device. I then went on to modify this sample app (which uses a DeviceWatcher instead of above way of finding a connected device USB):
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CustomUsbDeviceAccess
which also did not find a USB device. Of course I tried a different PC to see if it is related to my configuration, but as you expected, no success. This led me to think that it might be related to the USB device, but what could be wrong? Or did I really make some mistake in these five lines? Is there another way I could try to connect to the USB device? Any hint is appreciated!
Related Questions:
UWP/C# - Issue with AQS and USB Devices
Upvotes: 6
Views: 4020
Reputation: 3498
In my case, the DeviceInterfaceGUID
registry entry for the device was missing, which seems to be required so that the WinUSB device can be found and instantiated.
I added the entry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_16D0&PID_0BD7\None\Device Parameters\DeviceInterfaceGUID
with a random GUID like {86529001-c433-4530-a578-9a67adf1ffa9}
(in my case 16D0
is the vendor ID, 0BD7
the product ID and None
the instance). This can be done from the command line for example, by calling reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_16D0&PID_0BD7\None\Device Paramet
ers" /v "DeviceInterfaceGUID" /t REG_SZ /d "{86529001-c433-4530-a578-9a67adf1ffa9}" /f
.
I am absolutely no expert in USB and have no idea why this is needed or why it was missing; but at least in my case adding a GUID helped, both on my Windows 10 Professional and my Windows 10 IoT Core (Raspberry PI 3B). Maybe see https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/usb-device-specific-registry-settings for more details.
Upvotes: 1
Reputation: 7692
This is how to connect to a WinUSB device on UWP.
public async Task<IEnumerable<DeviceDefinition>> GetConnectedDeviceDefinitions(uint? vendorId, uint? productId)
{
var aqsFilter = "System.Devices.InterfaceClassGuid:=\"{DEE824EF-729B-4A0E-9C14-B7117D33A817}\" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True AND " + $" System.DeviceInterface.WinUsb.UsbVendorId:={vendorId.Value} AND System.DeviceInterface.WinUsb.UsbProductId:={productId.Value}";
var deviceInformationCollection = await wde.DeviceInformation.FindAllAsync(aqsFilter).AsTask();
//TODO: return the vid/pid if we can get it from the properties. Also read/write buffer size
var deviceIds = deviceInformationCollection.Select(d => new DeviceDefinition { DeviceId = d.Id, DeviceType = DeviceType.Usb }).ToList();
return deviceIds;
}
Here is a more complete answer: https://stackoverflow.com/a/53954352/1878141
And, here is a class from the repo: https://github.com/MelbourneDeveloper/Device.Net/blob/master/src/Usb.Net.UWP/UWPUsbDeviceFactory.cs
Upvotes: 0
Reputation: 379
It seems that I found one way to resolve this, which is a bit stupid, but hey, who asks me anyway...
I came across this one here on stackoverflow: Cannot create UsbDevice from DeviceInformation.Id
And it seems that my issue is indeed resolved when I use a .inf to refer to winusb as the driver. I have no idea why, so if any of you have an explanation, please let me know.
As above answer is referring to a blogpost that does exist anymore (I used the wayback machine to get to it), I'm posting the inf here, in case it helps anyone (but it's an ordinary inf)
;
;
; Installs WinUsb
;
[Version]
Signature = "$Windows NT$"
Class = USBDevice
ClassGUID = {88BAE032-5A81-49f0-BC3D-A4FF138216D6}
Provider = %ManufacturerName%
CatalogFile = WinUSBInstallation.cat
DriverVer=12/12/2016,13.54.20.543
; ========== Manufacturer/Models sections ===========
[Manufacturer]
%ManufacturerName% = Standard,NTamd64
[Standard.NTamd64]
%DeviceName% =USB_Install, USB\VID_1267&PID_0000
; ========== Class definition ===========
[ClassInstall32]
AddReg = ClassInstall_AddReg
[ClassInstall_AddReg]
HKR,,,,%ClassName%
HKR,,NoInstallClass,,1
HKR,,IconPath,%REG_MULTI_SZ%,"%systemroot%\system32\setupapi.dll,-20"
HKR,,LowerLogoVersion,,5.2
; =================== Installation ===================
[USB_Install]
Include = winusb.inf
Needs = WINUSB.NT
[USB_Install.Services]
Include =winusb.inf
Needs = WINUSB.NT.Services
[USB_Install.HW]
AddReg=Dev_AddReg
[Dev_AddReg]
HKR,,DeviceInterfaceGUIDs,0x10000,"{9f543223-cede-4fa3-b376-a25ce9a30e74}"
; [DestinationDirs]
; If your INF needs to copy files, you must not use the DefaultDestDir directive here.
; You must explicitly reference all file-list-section names in this section.
; =================== Strings ===================
[Strings]
ManufacturerName=""
ClassName="Universal Serial Bus devices"
DeviceName="OWI-535 Robotic Arm"
REG_MULTI_SZ = 0x00010000
Note that I left an arbitrary VID and PID in the driver, but I still have to connect with the VID and PID that the device tells me.
Upvotes: 3