Artem has posted 1 posts at DZone. View Full User Profile

Raw access to USB device under Mac OS X 10.6

09.07.2011
| 7487 views |
  • submit to reddit
Some time ago I had to implement Java applet for web page to access IrDA USB dongle under Windows, Linux and Mac OS X.
Windows and Linux both have IrSock implementations, so they are out of this article scope. Mac OS X differs in a way that they dropped IrDA support in 10.4. This limitation was the reason for my decision to use library JIR as 100% Java IrDA stack implementation, and access to underlying IrDA dongle hardware (chip) using native IOKit API.
IOKit API is available for C and C++ language only, and uses COM concept. I found very little samples on Internet, and they were mostly on synchronous bulk write to USB. While working with IR port employs asynchronous reading and writing, taking delays into account, putting things of puzzle together (Java interface; JIR; native methods) and making it work, took decent amount of my time. Finally, I got a clean enough Java USB access layer for Mac, so it can be reused for other USB dongle devices which don't have Mac driver such as IrDA dongles, TV tuners, custom boards, etc.

 

My library consists of 3 modules/layers:

 

1. usb-interface module (Java):
It provides abstraction for usb device modelling and its usage by client code.
Classes are:
usb.driver.DeviceDriver - base abstract class for device driver implementation;
usb.dongle.Device - model for raw USB device with methods for input-output to USB pipe;
devicemodel.* (SerialLink, SIRLink)- interfaces with contract for serial port abstraction;
usb.driver.impl.irda.MSC7780 - 100% Java device driver for Moschip MSC 7780- based IrDA dongle, based on Linux kernel C driver code.

 

2. darwin-usb module (Java):
It provides implementation classes with native methods:
usb.dongle.UsbDevice - base abstract class for USB device modelling by native wrappers for IOKit API;
usb.dongle.UsbDeviceListener - contract on raw callback listener (extended by usb.driver.DeviceDriver- subclasses);
usb.dongle.FactoryActor - singleton owner for background loop, which dispatches events from USB port hardware to device driver objects.

 

3. darwin-jni module (C):
C modules with native methods from darwin-usb Java classes.

 

The archive also contains irda-client module with entry-point main functions to test, and JIR module, which is essentially a customised version of JIR library (contains additional classes for IrCOMM protocol and necessary fixes).

 

I hope my classes could save some time and be a good start point and hardware abstraction layer for other Java developers who happen to communicate with raw USB device from Java app under Mac OS X.

 

Download darwin-usb library source code
0
Published at DZone with permission of its author, Artem Gorikov.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Kari Zimmerman replied on Thu, 2011/12/08 - 1:08pm

Hi, Artem. I'm looking to develop a Java applet to allow a webpage access to a USB device on Windows, Linux and Mac OS X operating systems.  The problem is that I don't even know where to start. Your library looks like a good starting point, but does it also include the implementations for Windows and Linux?  I have some Java experience but I'm lost with this project.  Any help you can offer to get me started in the right direction would be greatly appreciated.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.