12

在 OS X 上获取对 HID 设备的原始访问权限的最简单方法是什么?

我一直在查看 IOKit 示例,但即使打开设备似乎也不必要地复杂,涉及多个回调并包含来自六个库的内容。
libusb 可用于 OS X,但内核抓取所有 HID 设备以进行独占访问,并且在尝试使用无代码 .kext 阻止它与我的设备关联时,我遇到了奇怪的行为(它阻止内核抓取设备最初,但任何配置设备的调用似乎都会导致内核从我正在测试的小 python libusb 脚本下抓取设备)。

基本上,我有一个只是流式传输数据的 HID 设备。我想打开它以进行(理想情况下是独占的)访问,并获取数据流。

我在 IOKit 文档中找到的所有示例都非常复杂,与 libusb 中大约 8 行相比。必须有一种更简单的方法,它不是第 3 方库。

值得注意的是,我完全不熟悉任何功能的 OS X 编程。

Python支持将是一个不错的选择

4

2 回答 2

4

不幸的是,除了使用 api 之外别无他法HID Manager。不支持在 OS X 中对 HID 设备的原始访问。

文档清楚地表明:

HID family. Through the HID Manager, the HID family provides a device
interface for accessing a variety of devices, including joysticks and other 
game devices, audio devices, non-Apple displays, and UPS (uninterruptible 
power supply) devices. 

通过 POSIX api 进行原始访问,仅适用于存储、网络和串行设备:

Using POSIX APIs
For each storage, network, and serial device the I/O Kit dynamically
creates a device file in the file system’s /dev directory when it discovers 
a device and finds a driver for it, either at system startup or as part of 
its ongoing matching process. If your device driver is a member of the I/O 
Kit’s Storage, Network, or Serial families, then your clients can access your 
driver’s services by using POSIX I/O routines.

因此,您可以HID Manager直接使用 apis,也可以使用libusb或(如其他答案所述)hidapi,它们只不过是HID Managerapis 上的包装库。使用这些库的好处是它们抽象了大多数低级调用,从而使它们更易于使用。

于 2015-02-09T08:04:05.080 回答
1

看看 hidapi mac 后端

http://www.signal11.us/oss/hidapi/

https://github.com/signal11/hidapi

于 2011-07-02T05:14:00.897 回答