Raw access to HID devices in OS X
Asked Answered
W

2

15

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

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).

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

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.

It's worth noting that I am entirely unfamiliar with programming for OS X in any capability.

Python support would be a nice plus

Wagner answered 25/6, 2011 at 11:18 Comment(0)
P
7

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

The documentation makes it clear:

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. 

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.

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.

Palomo answered 9/2, 2015 at 8:4 Comment(0)
L
1

Take a look at the hidapi mac backend

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

https://github.com/signal11/hidapi

Lippold answered 2/7, 2011 at 5:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.