我有一个UWP应用程序的问题,我正在尝试编写。我正在连接一个我已经编程的自定义嵌入式USB块设备(它实际上是Cypress半导体的开箱即用的示例)。我使用的是在设备中嵌入MS OS字符串的WinUSB.sys驱动程序,以便无需编写自定义的INF文件来调用WinUSB.sys驱动程序即可使用设备。
在我的代码中,我使用UsbDevice.GetDeviceSelector方法返回一个AQS,然后可以将它传递给DeviceInformation.FindAllAsync,以便开始与我的应用程序中的设备进行通信。我已确认该设备在设备管理器中显示时没有任何问题,并且我已检查注册表以确保它具有接口GUID。我有一个来自USBViewer的屏幕截图,用来显示设备的配置。这种查找和连接USB设备的方法来自于这个MSDN示例发现的here。
当我使用UsbDevice.GetDeviceSelector方法时,它返回一个与此设备没有关联的GUID。它返回的GUID实际上与Lumia电话(DEE824EF-729B-4A0E-9C14-B7117D33A817)相关联。因此,它找不到我的设备连接到系统。
为了解决问题,我调用了DeviceInformation.FindAllAsync,不带任何参数来查看我的设备是否已列出,并且它确实找到了该设备(在连接到我的机器的1000多个其他设备中)。然后,我在没有GetDeviceSelector方法帮助的情况下编写了一个自定义的AQS字符串,只从GUID开始。这样做会返回27个设备,但当我尝试将VID和PID添加到此AQS字符串时,没有任何返回。
我还确保我要使用的设备在应用程序清单中通过其适当的VID和PID列出,因为这是具有0xFF的自定义类的设备所必需的。我使用了自定义USB UWP设备示例,它可以找到设备,尽管它使用了与设备选取器完全不同的方法,如果需要,我将转到该选取器,但这不是我的愿望,因为它使应用程序的这一部分不是一个干净的解决方案。
我已经在MSDN论坛here上发布了这个问题,并提供了更多信息,但我在那里并没有得到太多的参与。任何帮助都将不胜感激。我知道我一定错过了一些简单的东西。
亚当
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";
}
}
发布于 2016-12-12 18:27:42
刚刚给你发了一封邮件,询问进度(我想,我不得不猜测你的邮箱地址),但现在我似乎自己找到了一个解决方案。请看我在UWP app cannot find/connect to USB device上的回答
简而言之,您必须创建一个inf来安装winusb驱动程序。我不知道为什么,但这对我(和其他人,请参见Cannot create UsbDevice from DeviceInformation.Id)成功了。
发布于 2018-12-28 14:07:42
指南DEE824EF-729B-4A0E-9C14-B7117D33A817实际上是标准的WinUSB指南。我不认为这和Lumia手机有任何关系。我不知道为什么没有任何地方的文档。我认为您指定的Guida5dcbf10-6530-11d2-901f-00c04fb951实际上是在转移注意力。我也错误地使用了这一点,但它只是将我引向了花园小路。它显示了USB接口,但我无法连接到它们。
您可能想尝试一下这个类https://github.com/MelbourneDeveloper/Device.Net/blob/master/src/Usb.Net.UWP/UWPUsbDevice.cs。
下面是它获取设备的方式:
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;
}此示例连接到一个设备,我认为您将能够以相同的方式连接到该设备:
private static async Task InitializeTrezor()
{
//Register the factory for creating Usb devices. This only needs to be done once.
UWPUsbDeviceFactory.Register();
//Register the factory for creating Usb devices. This only needs to be done once.
UWPHidDeviceFactory.Register();
//Note: other custom device types could be added here
//Define the types of devices to search for. This particular device can be connected to via USB, or Hid
var deviceDefinitions = new List<DeviceDefinition>
{
new DeviceDefinition{ DeviceType= DeviceType.Hid, VendorId= 0x534C, ProductId=0x0001, Label="Trezor One Firmware 1.6.x" },
new DeviceDefinition{ DeviceType= DeviceType.Usb, VendorId= 0x1209, ProductId=0x53C1, ReadBufferSize=64, WriteBufferSize=64, Label="Trezor One Firmware 1.7.x" },
new DeviceDefinition{ DeviceType= DeviceType.Usb, VendorId= 0x1209, ProductId=0x53C0, ReadBufferSize=64, WriteBufferSize=64, Label="Model T" }
};
//Get the first available device and connect to it
var devices = await DeviceManager.Current.GetDevices(deviceDefinitions);
var trezorDevice = devices.FirstOrDefault();
await trezorDevice.InitializeAsync();
//Create a buffer with 3 bytes (initialize)
var buffer = new byte[64];
buffer[0] = 0x3f;
buffer[1] = 0x23;
buffer[2] = 0x23;
//Write the data to the device
await trezorDevice.WriteAsync(buffer);
//Read the response
var readBuffer = await trezorDevice.ReadAsync();
}如果你以这种方式连接设备,你将获得Device.Net (https://github.com/MelbourneDeveloper/Device.Net)对Windows classic和安卓的免费支持
发布于 2021-01-29 13:29:03
使用使用.NET 5的Device.net的DeviceManager.Current.GetDevices(deviceDefinitions),我找不到任何连接到我的win10的设备,这可以通过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;
}https://stackoverflow.com/questions/40901567
复制相似问题