Send and Receive Data on USB Port via Android App

11,003

This answer was written 2011 in the context of a question about historic Android versions before application-level USB Host APIs were added. Contemporary readers should instead see the many other questions about host mode on modern Android versions

You need to have the appropriate usb-serial device driver compiled into your kernel or loaded into it as a module, and either manually create a /dev/ttyUSB0 device file or have something that automatically creates it.

And we are assuming your converter is plugged into a working USB host port that supplies power and has a host-mode driver backing it.

Essentially this works the same way as on a desktop linux - and you may want to try the converter on a desktop linux to figure out which driver it is using.

If it's not working out of the box on your tablet, most likely you will need to root it, in order to load the driver module (or change kernels), create the node (file) in /dev and set permissions so that programs can access it.

Access would be by opening the device file, calling some ioctl's to configure it, and then just reading and writing. The opening and configuring may need to be jni native code (though you can probably do it from java), after that you should be able to read and write from java.

Another option that may be worth looking into is using a bluetooth-serial adapter - this is more device independent and probably does not require rooting.

Share:
11,003
Neha
Author by

Neha

Updated on June 04, 2022

Comments

  • Neha
    Neha almost 2 years

    I am trying to build an android app which will fetch some data from a URL and send it on the USB port of my android tablet. The USB port is connected to a USB-Serial Port Converter.

    I am not able to figure out the part where you send data on USB port. After lot of googling I found ADB, http://code.google.com/p/microbridge/ etc but none of them have a java library that can be used.

    Any suggestions?

  • Neha
    Neha almost 13 years
    Thanks @chris for the detailed answer. I finally opted for the Bluetooth Serial Adapter option since I needed something that will work out of the box and not require kernel changes. Android 3.1 has released APIs for USB but it supports tablets and not mobile phones.
  • Admin
    Admin over 6 years
    It's still fresh way to use? I mean what if i need to convert electrical signals received through usb it's will be the same? or what?