2011-06-25 133 views
6

在OS X上獲得對HID設備的原始訪問權限的最簡單方法是什麼?對OS X中的HID設備的原始訪問權限

我一直在尋找IOKit的例子,但是即使打開一個設備似乎也是不必要的複雜,涉及多個回調幷包含來自六個庫的東西。
libusb可用於OS X,但內核抓住所有HID設備進行獨佔訪問,並且在嘗試使用無代碼.kext阻止它與我的設備關聯時(它阻止內核抓取該設備最初,但任何調用配置設備似乎導致內核抓住設備遠離我測試的小python libusb腳本)。

基本上,我有一個HID設備,只是流數據。我想打開它(理想的獨佔)訪問,並獲得數據流。

我在IOKit文檔中找到的所有示例都非常複雜,與在libusb中使用的〜8行相比非常複雜。必須有一種更簡單的方式,而不是第三方的圖書館。

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

Python支持將是一個不錯的加

回答

1

不幸的是,不是使用HID Manager的API沒有其他辦法。原始訪問OS X中的HID設備不受支持。

documentation清楚:

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,這只是available存儲,網絡和串行設備:

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 apis上的封裝庫。使用這些庫的好處是它們可以抽象出大部分低級調用,從而使它們更易於使用。