在OS X上获取HID设备原始访问权限的最简单方法是什么?
我一直在看IOKit的例子,但即使打开一个设备似乎也不必要地复杂,涉及多个回调,并包含六个库中的内容
libusb可用于OS X,但内核会占用所有HID设备进行独占访问,当我试图使用无代码.kext来阻止它与我的设备关联时,我遇到了奇怪的行为(它阻止内核最初抓取设备,但任何配置设备的调用似乎都会导致内核在我正在测试的小python libusb脚本下抓取设备)。
基本上,我有一个HID设备,它只是流式传输数据。我想打开它进行(理想情况下是独占)访问,然后只获取数据流。
我在IOKit文档中发现的所有例子都非常复杂,与libusb中的大约8行相比。一定有一种更简单的方法,而不是三方图书馆。
值得注意的是,我对任何功能的OSX编程都完全陌生
Python支持将是一个不错的优势
不幸的是,除了使用HID Manager
api之外,没有其他方法。不支持对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
API,也可以使用libusb或(正如另一个答案所提到的)hidapi,它们只不过是HID Manager
API上的包装库。使用这些库的好处是,它们抽象了大多数低级别调用,从而使它们更易于使用。
看看hidapi mac后端
http://www.signal11.us/oss/hidapi/
https://github.com/signal11/hidapi