我正在维护一个用于访问 USB 设备的库,该库将自身注册为 HID 设备,并使 Mac 应用程序能够执行各种漂亮的操作(GPIO、I2C 等)。该库可以在这里找到:
https://github.com/codemercs-com/io-warrior-mac
由于我将项目升级到 MacOS 10.13 SDK,IOServiceGetMatchingServices() 在从回调调用时返回 nil 迭代器对象DeviceAdded,但不返回错误代码。
我的假设是,自从我在 2002 年左右最初编写这个库以来,IOKit 中的某些内容已经发生了根本性的变化。
我正在注册我的“设备插入”回调,如下所示:
result = IOServiceAddMatchingNotification(gNotifyPort,
kIOFirstMatchNotification, matchingDict,
IOWarriorAdded, NULL, &gIOWarriorAddedIter);
Run Code Online (Sandbox Code Playgroud)
当插入受支持的设备时,确实会调用此回调,但是当我随后调用 IOServiceGetMatchingServices 时,迭代器为零,或者,当其他设备已连接时,仅包含这些设备,而不包含新插入的设备。
io_iterator_t IOWarriorFindHIDDevices ()
{
CFMutableDictionaryRef hidMatchDictionary = IOWarriorSetUpHIDMatchingDictionary ();
// Set up matching dictionary to search the I/O Registry for HID devices we are interested in. Dictionary reference is NULL if error.
if (NULL == hidMatchDictionary) {
PrintErrMsg ("Couldn't create a matching dictionary.");
return 0;
}
io_iterator_t hidObjectIterator;
// Now search I/O Registry for matching devices.
IOReturn ioReturnValue = IOServiceGetMatchingServices (kIOMasterPortDefault, hidMatchDictionary, &hidObjectIterator);
if (ioReturnValue != kIOReturnSuccess) {
PrintErrMsgIfIOErr(ioReturnValue, "IOServiceGetMatchingServices returned error");
return 0;
}
if (hidObjectIterator == 0) {
PrintErrMsg("IOServiceGetMatchingServices returned nil hidObjectIterator");
return 0;
}
return hidObjectIterator;
}
Run Code Online (Sandbox Code Playgroud)
当应用程序启动时迭代可用设备时,所有设备都可以很好地发现。
有什么想法我可能做错了吗?
| 归档时间: |
|
| 查看次数: |
1656 次 |
| 最近记录: |