简体   繁体   English

尝试从Mac上的HID管理器获取HID设备引用时出现不兼容的指针错误

[英]Incompatible pointer error when trying to get a HID device reference from HID manager on Mac

I'm trying to write a User-Space Device driver to pull some data from a custom HID device. 我正在尝试编写一个用户空间设备驱动程序,以从自定义HID设备中提取一些数据。 I'm do the following to store a reference of the device in the HID manage into a variable. 我执行以下操作以将HID管理中设备的引用存储到变量中。

CFSetRef device = IOHIDManagerCopyDevices(HIDManager);

after this I do the following to register my callback which is setting up the report read from the device (another area I'm struggling with.) 之后,我将执行以下操作来注册我的回调,该回调用于设置从设备读取的报告(我正在苦苦挣扎的另一个区域)。

IOHIDDeviceRegisterInputReportCallback(device, report, ReadDailyDataResonposeSize, Handle_IOHIDDeviceIOHIDReportCallback, NULL);

I'm getting an error in the above function on the reference to 'device' saying "Incompatible pointer types passing CFSetRef" 我在参考“设备”的上述功能中遇到错误,说“传递CFSetRef的指针类型不兼容”

If I try to change the type that device is when creating it though I get another saying that it needs to be a CFSetRef. 如果在创建设备时尝试更改设备的类型,尽管我又说一句,它必须是CFSetRef。 So I'm a little confused, anyone have any advice. 所以我有点困惑,任何人都有建议。 I'm very new to C as well as working on Macs. 我是C语言的新手,也是Mac上的新手。 The documentation has come off pretty terse to me thus far. 到目前为止,文档对我来说还很简洁。

EDIT: Here Is a link to the rest of my code for reference. 编辑:这是我其余代码的链接,以供参考。 http://pastebin.com/rFsHisdh http://pastebin.com/rFsHisdh

IOHIDManagerCopyDevices() returns a set of IOHIDDeviceRef elements. IOHIDManagerCopyDevices()返回一 IOHIDDeviceRef元素。 You have to get one element from the set and pass that to IOHIDDeviceRegisterInputReportCallback() . 您必须从集合中获取一个元素,并将其传递给IOHIDDeviceRegisterInputReportCallback()

This is the signature of the IOHIDDeviceRegisterInputReportCallback function according to the documentation : 根据文档,这是IOHIDDeviceRegisterInputReportCallback函数的签名:

CF_EXPORT void IOHIDDeviceRegisterInputReportCallback(
    IOHIDDeviceRef device,
    uint8_t *report,
    CFIndex reportLength,
    IOHIDReportCallback callback,
    void *context) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER;

As you can see the first argument should be a IOHIDDeviceRef and you are passing in a CFSetRef which provide[s] support for the mathematical concept of a set as Martin R answer indicates. 如您所见,第一个参数应该是IOHIDDeviceRef并且您正在传入CFSetRef ,它为Martin R答案所表示provide[s] support for the mathematical concept of a set

To get the elements of the set and pass the device (if any) you should do the following: 要获取集合的元素并传递设备(如果有),您应该执行以下操作:

CFSetRef devices = IOHIDManagerCopyDevices(HIDManager);
CFIndex size = CFSetGetCount(devices);
if(size > 0) {
    CFTypeRef array[size]; // array of IOHIDDeviceRef
    CFSetGetValues(devices, array);
    IOHIDDeviceRegisterInputReportCallback((IOHIDDeviceRef)array[0], report, ReadDailyDataResonposeSize, Handle_IOHIDDeviceIOHIDReportCallback, NULL);
}

Hope it helps. 希望能帮助到你。

I ran into this problem. 我遇到了这个问题。 You were pasting from an Apple document that is no longer correct ( https://developer.apple.com/library/archive/technotes/tn2187/_index.html ). 您是从不再正确的Apple文档中粘贴的( https://developer.apple.com/library/archive/technotes/tn2187/_index.html )。 Your report variable is allocated in the wrong format, causing an memory error during runtime. 您的报告变量分配格式错误,从而在运行时导致内存错误。 Do the following: 请执行下列操作:

uint8_t *report = (uint8_t *)malloc(reportSize);
IOHIDDeviceRegisterInputReportCallback(device, report, ReadDailyDataResonposeSize, Handle_IOHIDDeviceIOHIDReportCallback, NULL);```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM