How to control a serial device on Android?
Asked Answered
S

4

12

I want to develop an application whitch control the serial device over usb, on Linux Android.
An Android OS is 3.1 that supports USB host.

Q1: Please let me know how to get which port the serial device is mounted .

I got likely USB device information when I got "Dump Device State" on Dalvik Debug Monitor.
And, I checked /dev/tty* on android device by using adb.
I don't know which one(/dev/tty??) the serial device is.

adb shell
$ ls /dev/tty*
/dev/tty
/dev/ttyFIQ0
/dev/ttyHS0
/dev/ttyHS2
/dev/ttyHS3
/dev/ttyHS4
/dev/ttyS0
/dev/ttyS1
/dev/ttyS2
/dev/ttyS3

Q2: Please let me know how to control the serial device on Android without root permission.

I have a application(exe) that can control the serial device on linux.
I tried to do on android , but I couldn't do for permission denied.

And, I tried redirect to the serial port(maybe)
$ ls > /dev/ttyS0
But I couldn't.
cannot create /dev/ttyS0: permission denied.

Please let me know anything how to control and access to the serial device.

Schuman answered 21/7, 2011 at 6:35 Comment(2)
To do this utilizing the Android USB host capability and its corresponding API, You must implement the USB-serial driver code in userspace within your Application. No kernel "serial" driver or device ends up being involved.Declinatory
Which serial device? There can be hundreds! Please specify what exactly you want to do.Cross
C
4

There is a great review of this in the XDA forum thread:

How to talk to the Modem with AT commands.

That thread show you how to send AT commands (ATC) with a remote terminal (USB connected to you PC), but it has not yet solved the problem of how to use a local (phone) terminal to talk to the phone Modem.

BTW. You need a terminal application/program to do any talking to the modem (remember, its a 2-way communication). So that's why you need a rooted device, since the root kit usually come with Busybox (that includes a microcom terminal program). Otherwise you have to write your own program.

Cross answered 31/1, 2012 at 16:9 Comment(2)
This addresses a very different question from the one actually asked.Declinatory
The above question is ambiguous since any android can have hundreds of "serial" devices. Just check with: cat /proc/tty/drivers.Cross
X
4

in next step, you can test tty* port by couple of command: $ cat /dev/tty* /for receive the characters from tty and $ echo 'text string' > /dev/tty* /for send characters to tty

good luck!

Xeniaxeno answered 13/6, 2014 at 16:44 Comment(0)
A
0

Try on a rooted device?? In researching the same thing I've read that only a few 3.1 / 2.3.4 devices allow non-root access to the usb port.

This is what I get on my HTC Desire unrooted, 2.2:

$ ls /dev/tty*
ls /dev/tty*
/dev/tty
/dev/ttyHS0
/dev/ttyHSUSB0
/dev/ttyHSUSB1
/dev/ttyHSUSB2
/dev/ttyMSM0

My Asus Transformer, unrooted, 3.2:

$ ls /dev/tty*
ls /dev/tty*
/dev/tty
/dev/ttyHS1
/dev/ttyHS2
/dev/ttyS0
/dev/ttyS1
/dev/ttyS2
/dev/ttyS3

I get exactly the same list when docked with the Keyboard Dock installed (It as 2 x USB ports).

Hope it helps, please let me know I'd love to be able to do the same.

Abound answered 3/8, 2011 at 11:9 Comment(2)
These all presume the presence of a kernel driver, which you are very unlikely to have unless the device is rooted (not the case here) or there's already a driver in the installation (unlikely unless the device is not an ordinary phone/tablet). The proper answer is to implement the USB-serial logic in userspace against the Android USB host API.Declinatory
@ChrisStratton But while connecting through USB Host API and connected with windows PC , does not get USB device object .Whitney
G
0

If you are familiar with android development, definitely you should try usb-serial-for-android and its example. It will tell you which device is connected to your Android type-C port and more.

Gave answered 22/11, 2023 at 9:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.