Dan*_*Dan 17 c# xaml arduino arduino-uno uwp
我试图动态列出连接到计算机的USB与某个UsbDeviceClass匹配
有关我尝试在设备管理器中列出的USB类的信息如下
理想情况下它应该能够列出Com
端口,因为我希望列出的设备特别是Arduinos.
DeviceInformationCollection usbDeviceInfoCollection = await DeviceInformation.FindAllAsync(UsbDevice.GetDeviceClassSelector(new UsbDeviceClass()
{
ClassCode = 0x02,
SubclassCode = 0x02,
ProtocolCode = 0x01
}));
Debug.WriteLineIf(usbDeviceInfoCollection.Count == 1, "1 USB device found");
Debug.WriteLineIf(usbDeviceInfoCollection.Count != 1, usbDeviceInfoCollection.Count + " USB devices found");
for (int i = 0; i < usbDeviceInfoCollection.Count; i++)
{
Debug.WriteLine("USB Device " + (i + 1));
Debug.WriteLine("ID: " + usbDeviceInfoCollection[i].Id);
Debug.WriteLine("Name: " + usbDeviceInfoCollection[i].Name);
Debug.WriteLine("Properties: " + usbDeviceInfoCollection[i].Properties);
Debug.WriteLine("");
}
Run Code Online (Sandbox Code Playgroud)
上面的代码显示了我一直在努力实现这一目标,但到目前为止,我没有运气.这是因为当程序运行时,它会在连接了设备时返回0个设备.
我也尝试使用预定义的类UsbDeviceClasses.CdcControl
,但是,也没有达到我想要的结果.
我很欣赏任何关于如何正确实现这一目标的指导.
此外,由于这是一个UWP项目,我已经包含了下面的功能,因此它应该能够检测到我想要的设备.
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort"/>
</Device>
</DeviceCapability>
Run Code Online (Sandbox Code Playgroud)
从程序的轻微变化使用Arduino的信息的示例输出DeviceInformation.FindAllAsync()
,没有UsbDeviceClass
作为jsanalytics建议.
Device 1354
EnclosureLocation: Windows.Devices.Enumeration.EnclosureLocation
ID: \\?\USB#VID_2341&PID_0243#9543231323835131B172#{86e0d1e0-8089-11d0-9ce4-08003e301f73}
IsDefault: False
IsEnabled: True
Kind: DeviceInterface
Name: Genuino Uno (COM6)
Pairing: Windows.Devices.Enumeration.DeviceInformationPairing
Properties: System.__ComObject
Run Code Online (Sandbox Code Playgroud)
注册表的图像
更新,这个页面有关于更具体的USB功能,包括name:cdcControl, classId:02 * *
.但是,我仍然无法通过像这个远程arduino应用程序那样的附加设备进行枚举; Windows Remote Arduino体验.
快速编辑以澄清.我无法连接到设备,我只能枚举02类子类02协议01的设备.可以通过指定VID和PID连接到我的设备,但在当前情况下,这可能无视点.
您可以枚举外部USB设备,首先您需要在Package.appxmanifest文件中添加此权限。
<uap:Capability Name="removableStorage" />
Run Code Online (Sandbox Code Playgroud)
然后在您的应用程序中编写此代码。
var removableDevices = KnownFolders.RemovableDevices;
var externalDrives = await removableDevices.GetFoldersAsync();
foreach (var item in externalDrives)
{
var name = item.DisplayName;
}
Run Code Online (Sandbox Code Playgroud)
现在为了刷新列表重新运行代码。
归档时间: |
|
查看次数: |
914 次 |
最近记录: |