UWP/C# - AQS 和 USB 设备问题 [英] UWP/C# - Issue with AQS and USB Devices

查看:14
本文介绍了UWP/C# - AQS 和 USB 设备问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试编写的 UWP 应用程序出现问题.我正在连接到我已编程的自定义嵌入式 USB 批量设备(它实际上是赛普拉斯半导体的开箱即用示例).我正在使用 WinUSB.sys 驱动程序,在设备中使用嵌入式 MS 操作系统字符串,以便无需编写自定义 INF 文件即可使用该设备来调用 WinUSB.sys 驱动程序.

I have an issue with a UWP app that I am trying to write. I am connecting to a custom embedded USB Bulk device that I have programmed (it is actually an out of the box example from Cypress Semiconductor). I am using the WinUSB.sys driver using the embedded MS OS string in the device to allow the device to be used with out having to write a custom INF file to call the WinUSB.sys driver.

在我的代码中,我使用 UsbDevice.GetDeviceSelector 方法返回一个 AQS,然后可以将其传递到 DeviceInformation.FindAllAsync 以开始与我的应用程序中的设备进行通信.我已经确认设备在设备管理器中显示没有任何问题,并且我已经检查了注册表以确保它具有接口 GUID.我有一个来自 USBViewer 的屏幕截图来显示设备的配置.这种查找和连接 USB 设备的方法是从这个 MSDN 示例中找到的 此处.

In my code, I am using the UsbDevice.GetDeviceSelector method to return an AQS that can then be passed into DeviceInformation.FindAllAsync to begin communicating with the device in my app. I have confirmed that the device shows up in the device manager without any issues, and I have checked in the registry to ensure that it has an Interface GUID. I have a screenshot from USBViewer to show the configuration of the device. This method for finding and connecting with USB devices is from this MSDN example found here.

当我使用 UsbDevice.GetDeviceSelector 方法时,它返回一个与此设备无关的 GUID.它返回的 GUID 实际上与 Lumia Phones (DEE824EF-729B-4A0E-9C14-B7117D33A817) 相关联.因此,它找不到我的设备连接到系统.

When I use the UsbDevice.GetDeviceSelector method, it returns a GUID that is not associated with this device. The GUID that it returns is actually associated with Lumia Phones (DEE824EF-729B-4A0E-9C14-B7117D33A817). Because of this, it does not find my device connected to the system.

为了进行故障排除,我都调用了 DeviceInformation.FindAllAsync 并且不带任何参数来查看我的设备是否已列出,并且它确实找到了该设备(在曾经连接到我的机器的 1000 多个其他设备中).然后,我在没有 GetDeviceSelector 方法帮助的情况下编写了一个自定义 AQS 字符串,仅从 GUID 开始.这样做会返回 27 个设备,但是当我尝试将 VID 和 PID 添加到此 AQS 字符串时,没有返回任何内容.

To troubleshoot, I have both called the DeviceInformation.FindAllAsync with out any arguments to see if my device is listed, and it does find the device (amongst over 1000 other devices that have been connected ever to my machine). I then wrote a custom AQS string without the help of the GetDeviceSelector method, starting with just the GUID. Doing this returned 27 devices, but when I tried to add the VID and PID to this AQS string, nothing returned.

我还确保我要使用的设备按其适当的 VID 和 PID 列在应用清单中,因为这是自定义类别为 0xFF 的设备所必需的.我使用了自定义 USB UWP 设备示例,它可以找到该设备,尽管它使用了一种完全不同的方法和设备选择器,如果需要,我会去,但这不是我的愿望,因为它成为应用程序的一部分没有那么干净的解决方案.

I have also made sure that the device that I want to use is listed in the app manifest by its appropriate VID and PID as this is required for a device with a Custom Class of 0xFF. I have used the Custom USB UWP device example and it can find the device, though it uses a completely different method with a device picker, which I will go to if needed, but this is not my desire as it makes that part of the app not as clean of a solution.

我已经在 MSDN 论坛上发布了这个问题 这里 提供更多信息,但我在那里没有得到很多参与.任何帮助,将不胜感激.我知道我一定遗漏了一些简单的东西.

I have posted this question over in the MSDN forums here with more information, but I have not gotten a lot of engagement there. Any help would be appreciated. I know that I must be missing something simple.

亚当

private async void button_Click(object sender, RoutedEventArgs e) 
{
  //UInt32 vid = 0x04B4;
  //UInt32 pid = 0x00F0;

  UInt32 vid = uint.Parse(textBox1.Text, System.Globalization.NumberStyles.HexNumber);
  UInt32 pid = UInt32.Parse(textBox2.Text, System.Globalization.NumberStyles.HexNumber);
  Guid winusbInterfaceGuid = new Guid("a5dcbf10-6530-11d2-901f-00c04fb951ed");
  //string aqs = UsbDevice.GetDeviceSelector(vid, pid);
  string aqs = UsbDevice.GetDeviceSelector(winusbInterfaceGuid);



  var myDevices = await DeviceInformation.FindAllAsync(aqs, null);
  //var myDevices = await DeviceInformation.FindAllAsync();

  var myDevicesCount = myDevices.Count;

  if (myDevicesCount >= 1) 
  {
    textBlock2.Text = "Device Found";
  } else 
  {
    textBlock2.Text = "Searching";
    await Task.Delay(1000);
    textBlock2.Text = "looking for device";
  }
}

推荐答案

使用 Device.net 的 DeviceManager.Current.GetDevices(deviceDefinitions) using .NET 5 我找不到任何连接到我的 win10 的设备,可以轻松选择通过管理对象搜索器:

With Device.net's DeviceManager.Current.GetDevices(deviceDefinitions) using .NET 5 I can't find any device connected to my win10, which can be easily selected by ManagementObjectSearcher:

public List<ManagementBaseObject> GetLogicalDevices()
{
   List<ManagementBaseObject> devices = new List<ManagementBaseObject>();
   ManagementObjectCollection collection;
   ManagementObjectSearcher seacher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM CIM_LogicalDevice");
   collection = seacher.Get();

   foreach (var device in collection)
   {
       devices.Add(device);
   }

   return devices;
}

这篇关于UWP/C# - AQS 和 USB 设备问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆