【发布时间】:2016-06-04 19:12:13
【问题描述】:
我正在尝试在 MonoLibUsb(在 Linux 上)中打开一个 USB 设备句柄,但每次打开它时,我都会在设备句柄上看到 IsInvalid == true。
USB 设备绝对与 LibUsb 兼容,因为我已将它连接到我的 Windows PC,并且可以成功使用 LibUsbDotNet 与之对话。如果我尝试在 Mono 中使用 LibUsbDotNet,则应用程序在尝试打开它时会挂起,所以我认为 LibUsbDotNet 是用于 Windows,而 MonoLibUsb 是用于 Mono(名称有点泄露)。然而,即使是 MonoLibUsb 也无法正确使用该设备。
那么为什么返回的设备句柄无效?
代码
private void UsbInit() {
var sessionHandle = new MonoUsbSessionHandle();
var profileList = new MonoUsbProfileList();
profileList.Refresh(sessionHandle);
List<MonoUsbProfile> usbList = profileList.GetList().FindAll(MyVidPidPredicate);
foreach(MonoUsbProfile profile in usbList) {
var deviceHandle = profile.OpenDeviceHandle();
if (deviceHandle.IsInvalid) {
Console.WriteLine(string.Format("IsInvalid: {0} - {1}", MonoUsbSessionHandle.LastErrorCode, MonoUsbSessionHandle.LastErrorString));
}
}
}
private bool MyVidPidPredicate(MonoUsbProfile profile) {
if (profile.DeviceDescriptor.VendorID == 0xabcd && profile.DeviceDescriptor.ProductID == 0x1234)
return true;
return false;
}
输出
IsInvalid: Success -
【问题讨论】:
标签: c# mono libusb libusbdotnet