The Abstraction Layer
Once the prototype works and could establish a great communication between the Xoom and the FT232 IC, I decided to separate the project in order to let anyone creates a VCP Driver adding just a few methods.
The Abstraction Layer is present in the USB VCP Library for Android. It consists of 5 classes as you can see in the following picture:
It is the main class. It represents the driver which lets the user connect and disconnect from the device. It also handles the low level connection and disconnection from the USB Device, and provides 5 abstract methods.
The user should call “connect” with a valid RS232 Configuration and a (may be null) object that implements the Async. Receveiver Interface. The “disconnect” method should be used in order to de-initialize variables but must call VCPDriver.closeDevice() in order to release all the USB stack.
“transfer” is a generic method that lets the user do synchronised transactions. The user can call this method in order to send and/or receive a package from the device.
“initialize” should be called from “connect” and will perform several controlTransfer commands in order to setup the device (including the RS232 configuration).
Finally, the AsyncReceiver is an interface with a very simple method. If your class implements this interface, you will receive async information from the driver.
As the VCPDriver has some abstract methods, all the class is abstract. So for every IC manufacturer, you should create a specialised Driver class, as I have created the FT232Driver class.
(Un)fortunately I have just signed a NDA (Non-Disclosure Agreement) with FTDI Chip in order to develop the Android version of their FT(2)232 chip.
This agreement was approved by FTDI so I cannot publish either the documentation I have just received, or the source code I develop based on that documentation.
I will go on writing about my experience developing the USB VCP driver for Android entirely on Java, and may be as a result of the project an obfuscate binary will be published in order to communicate with the FT(2)232 family.
One more thing to mention: FTDI writes very clear and nice documentation.
I have connected a USB device that creates a USB VCP profile to my Motorola Xoom in order to enable my Xoom apps to interface with RS232 devices.
My small test program shows the following details for the USB device:
Model: /dev/bus/usb/002/002 Id: 2002 Class: 0 SubClass: 0 Protocol: 0 VendorId: 1659 ProductId: 8963 Number of Interfaces: 1 >> Interface 0 -> 3 Endpoints
With all the information we can tell the device to open a custom application when the USB device is attached. To do so, the following information should be added to the ‘activity’ tag in the Manifest.
<intent-filter> <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /> </intent-filter> <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/usb_device_filter" />
The XML file is a resource file that contains information about the USB Device, that should be placed in /res/xml
<resources> <usb-device vendor-id="1659" product-id="8963" class="0" subclass="0" protocol="0"/> </resources>
When the activity starts, it can retrieve the USB Device information by calling:
device = (UsbDevice)getIntent().getParcelableExtra(UsbManager.EXTRA_DEVICE);