using serial port RS-232 in android?

63,956

Solution 1

I just ported the JavaCOMM ( GNU RXTX ) library to the Android. Here is the link http://v-lad.org/projects/gnu.io.android/

You still might need to rebuild your kernel and maybe recompile the shared library for your environment. But this should get you started.

Solution 2

As noted above, you'll need to come up with device drivers for whatever USB<->Serial device you have. Many of these devices use the Prolific PL2303 chip:

http://www.qbik.ch/usb/devices/showdr.php?id=175

which the stock linux kernel has support for, and has had for a long time. I've used this and it works fine, so I would recommend you stick with USB<->Serial devices that use this chip.

Beyond that, with udev these devices normally show up as /dev/ttyUSB#. How that happens with Android, I don't know, so you'll need to figure that out.

Finally, you will need to build the RxTx native code. This code is pretty crufty - I had problems building it on a fairly modern Angstrom, and I was not trying to cross-compile at all.

Solution 3

Unlike the regular PCs, most of the stock kernels for the android devices come with minimum compiled modules. You need to recompile the kernel with enabled drivers for USB to serial converters. You luck depends on the specific device that you using. A lot of manufactures violate GPL, by not providing the kernel source code. Some manufactures like Motorola with the Droid 2 require signed kernel. Which makes it impossible to load custom kernel on the device.

Also, although many devices have USB host mode you have to jump through the hoops to switch the device mode. For example Motrola droid requires a special dongle to be plugged in into the USB port before powering on to switch into the host mode.

Here are some links for you that explain what you need to do:

  1. “More on Droid host mode,” http://www.tombom.co.uk/blog/?p=134.

  2. “USB Host mode on Motorola Droid,” http://www.tombom.co.uk/blog/?p=124.

Solution 4

Yes, it's definitely a mess to use the serial devices from the phone side on the Android. The problem is that the various devices present on the AOS is not documented, and rarely coincides with standard Linux ones. Thus you are never sure what/who you are actually talking to, some device, abstraction layer (HAL, UART,PCI etc). Here is a tutorial on how to talk to a serial device (the modem) from an externally USB connected PC.

In any case, if your phone does support USB host mode, there have to be another way to reach your serial port/devices using that. After all, backward compatibility does often insure some kind of FAX, telephony or external modem support from your USB cable. Also there is tehtering which may also contain some virtual serial device...

There is a tutorial for some of this here.

PS. The main problem of such programs (like that of Vlad) and applications (like serial-api) are that they make too strong assumptions on the device/port names and the permissions needed to reach (read/write) these...

Solution 5

Probably not exactly what you're looking for, but this instructable might point you in the right direction

Share:
63,956
rami
Author by

rami

Updated on October 02, 2020

Comments

  • rami
    rami over 3 years

    I want to send signals via serial port using the JavaComm API classes on an Android device, and here is how I imagine it:

    1- the Android device would be: Archos 3.2 which has android 2.2 and USB host mode.

    2- include RxTx lib package with my Android app. and include RxTx native code using Android NDK.

    3- a short cable which is usb-->serial.

    Could you explain to me where I might face problems?

  • rami
    rami over 13 years
    OK, but since the device has host mode enabled then the kernel must be equipped with drivers to do the job, right? if we think of it like a normal linux box, would I face a problem if I just plug a usb--serial adapter?
  • plaisthos
    plaisthos over 13 years
    compare it to a normal PC. Its USB Ports are in host mode. Plugging in a USB<->Serial Adapter under WIndows needs drivers. Under Linux the driver are part of the kernel. BUt Android uses a stripped down kernel where drivers which are not needed are removed. I believe the USB<-> serial drivers are removed too.
  • rami
    rami over 13 years
    thanks, I've seen those Droid thing, but at least Archos and Acer provide the kernel source
  • Vlad
    Vlad about 13 years
    so does the Droid, the original one. With Droid2 you are out of luck. Unless you get Motorolla give you the keys. :-(
  • Chris Stratton
    Chris Stratton about 13 years
    Most likely "removed" only in the sense of not selected for compilation. The source is probably still there and quite likely to build just fine if enabled in the configuration.