Porting HID code from Linux to OS X

Discussion in 'Mac Programming' started by Starfox, Aug 19, 2012.

  1. Starfox macrumors regular

    Joined:
    Apr 7, 2011
    #1
    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()?
     
  2. KnightWRX macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #2
    write() is a Unix syscall, why not use write() ?
     
  3. Starfox thread starter macrumors regular

    Joined:
    Apr 7, 2011
    #3
    Because as far as I know OS X doesn't support hidraw and accessing HID devices using a file descriptor.
     
  4. KnightWRX macrumors Pentium

    KnightWRX

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

    https://developer.apple.com/library...HIDDevice.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...ce/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
     
  5. Starfox thread starter macrumors regular

    Joined:
    Apr 7, 2011
  6. bigwiz macrumors newbie

    Joined:
    Sep 12, 2012
    #6
    Elan touchpad

    We are trying to do something similar for the Elan touchpad.
     

Share This Page