【问题标题】:Raw access to HID devices in OS X在 OS X 中对 HID 设备的原始访问
【发布时间】:2011-09-22 13:44:31
【问题描述】:

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

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

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

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

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

Python 支持将是一个不错的加分项

【问题讨论】:

    标签: device-driver hid osx-snow-leopard


    【解决方案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 api 上的包装库。使用这些库的好处是它们抽象了大多数低级调用,从而使它们更易于使用。

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-29
      • 2013-11-24
      • 1970-01-01
      • 2011-11-04
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      相关资源
      最近更新 更多