jxgn
jxgn

Reputation: 321

How to access the serial port in a development kit for Android?

I have a development board for Android. I want to send data serially through the available com port through an app. Is this possible? If so can anyone show how it is done? Am searching for a week but couldn't find anything proper. Thanks in advance.

Upvotes: 2

Views: 1915

Answers (1)

Chris Stratton
Chris Stratton

Reputation: 40337

First you must make sure the serial port hardware is functional and an appropriate linux kernel driver is linked or loaded as a module - this would be the same as for any other embedded linux, and you probably want to test it at this point with a command line tool or test program.

Then you need to make it accessable to applications. There are, broadly, three ways of doing this.

  • You could make the serial port's device file available to all users. This is simple, but it's up to you to decide if it could be a problem for arbitrary apps to have full access to the serial port.

  • You could create a new unix group and a corresponding Android permission, set the package manager to assign membership in the group based on the permission, and assign the device file to that group. That's how things like writing to the sdcard are handled.

  • You could leave access to the serial port restricted and create a privileged daemon which will manage the serial port and perform communications on behalf of android applications which contact it through some means of supported IPC, such as Binder, unix sockets, etc. Likely (at least if using Binder) you will have this require the client application to hold an Android permission which you create for serial port access. This would vaguely resemble how things like sending SMS messages work.

The first two methods would let (at least ndk code in) client applications use the normal posix serial APIs linux programmers would be familiar with. The third method would present the serial port as an Android style communication resource.

Before you write any code, do some web searching. I'd be very surprised if this problem hasn't already been solved several times.

Upvotes: 2

Related Questions