Mac Porting HID code from Linux to OS X

Starfox

macrumors 6502
Original poster
Apr 7, 2011
256
8
I have some HID code that writes output reports to a device using write() that I'm trying to port to OS X - The closest match I found it IOHIDDeviceSetReport(), but how do I translate the parameters for write (a buffer and a length) to the set of parameters requested by IOHIDDeviceSetReport()?
 

Starfox

macrumors 6502
Original poster
Apr 7, 2011
256
8
Because as far as I know OS X doesn't support hidraw and accessing HID devices using a file descriptor.
 

KnightWRX

macrumors Pentium
Jan 28, 2009
15,046
4
Quebec, Canada
So, did you look at the documentation then ? IOHIDDevice.setReport() takes 3 parameters according to the reference :

https://developer.apple.com/library/mac/#documentation/Kernel/Reference/IOHIDDevice_reference/translated_content/IOHIDDevice.html#//apple_ref/doc/uid/TP40011784

The first one is a pointer to a IOMemoryDescription class which is said to be your "report" (i'd wager, your bytes to write here). Looking at that class, it has both an initWithOptions method to create a report and a writeBytes method to actually write bytes in there (which would be the bytes and count parameters of your standard write() syscall) :

https://developer.apple.com/library/mac/#documentation/Kernel/Reference/IOMemoryDescriptor_reference/translated_content/IOMemoryDescriptor.html

If you want to know how a IOMemoryDescriptor works, the full source code to the implementation is available in the Darwin sources of course :

http://www.opensource.apple.com/source/xnu/xnu-1699.26.8/iokit/Kernel/IOMemoryDescriptor.cpp