原始访问OS X中的HID设备 [英] Raw access to HID devices in OS X

查看:251
本文介绍了原始访问OS X中的HID设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What is the simplest way to get raw access to HID devices on OS X?

我一直在研究IOKit示例,但即使打开设备似乎

libusb可用于OS X,但内核抓住了所有HID设备以进行独占访问,而在尝试执行以下操作时,我的行为越来越奇怪:使用无代码的.kext阻止它与我的设备关联(它阻止内核最初获取设备,但是任何配置设备的调用似乎都导致内核从我是的小python libusb脚本下获取设备

I've been looking through the IOKit examples, but even opening a device seems needlessly complex, involving multiple callbacks and include things from half a dozen libraries.
libusb is available for OS X, but the kernel grabs all HID devices for exclusive access, and I have been getting strange behavior while trying to use a codeless .kext to block it from associating with my device (it prevents the kernel from grabbing the device initially, but any calls to configure the device seem to cause the kernel to grab the device away from under the little python libusb script I am testing with).

基本上,我有一个仅用于传输数据的HID设备。我想将其打开以进行(最好是排他的)访问,并仅获取数据流。

Basically, I have a HID device that just streams data. I want to open it for (ideally exclusive) access, and just get the datastream.

与相比,我在IOKit文档中发现的所有示例都非常复杂。 libusb需要约8行。必须有一个不是第三方库的简单方法。

All the examples I have found in the IOKit docs are really complex, compared to the ~8 lines it would take in libusb. There must be a simpler way that isn't a 3'rd party library.

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

Python支持将是一个不错的加

推荐答案

不幸的是,除了使用 HID Manager api之外,没有其他方法。不支持对OS X中的HID设备进行原始访问。

Unfortunately there is no other way than using HID Manager apis. Raw access to HID devices in OS X it's not supported.

文档使其清晰:

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的原始访问只是可用 用于存储,网络和串行设备:

Raw access through POSIX apis it's only available for storage, network and serial devices:

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上的包装器库。使用这些库的好处是可以抽象出大多数低级调用,从而使它们更易于使用。

So you can either use HID Manager apis directly or you can use libusb or (as the other answer mentions) hidapi which are nothing more than wrapper libraries over HID Manager apis. The benefit of using these libraries is that they abstract most of the low level calls thus making them easier to use.

这篇关于原始访问OS X中的HID设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆