Using UART in Android


#1

i want to use UART in Android but don’t know where i gonna make changes to enable it. can i enable it inside android or i must build it from scratch and make some changes there? is it possible to send command using android apks written in JAVA without need to android NDK?


#2

What’s the version of your system? You can refer to the demo to control UART when your system is newer than VIM_Nougat_V170901.
Have a try, Thanks


#3

I am using Vim_Nougat_Root_170612. I will try your demo as soon as possible.
There is another question: is it possible to control UART from android shell ? ( like Raspberry Pi )
Thanks


#4

It is possible to control UART from android shell. But you need to create a executable file for it with Program C.
You can hava a try . Thanks.


#5

can you mention any tutorial for controlling UART using C program in Android?
Thanks a lot.


#6

I couldn’t install the apk you provided.There was a conflict error.
even couldn’t build it using Android Studio.


#7

I created this demo on eclipse and not studio. You can refer to those source code and create yourself project.


#8

I created a project in Studio and successfully built it. now there is another problem: the problem is that I couldn’t receive anything from UART. is there another step to make it work, which i have missed?
Thanks.


#9

Did you can open the UART device( /dev/ttyS4 )?

mFd = open(device.getAbsolutePath(), baudrate);
if (mFd == null) {
    Log.e(TAG, "native open returns null");
    throw new IOException();
}
mFileInputStream = new FileInputStream(mFd);
mFileOutputStream = new FileOutputStream(mFd);

#10

There is no error log in Android studio logcat. It seems there is no problem opening UART device.


#11

What’s the model did you connect Uart port with? How did you control UART with app demo?
You can try to connect UART_RX_AO_B to UART_TX_AO_B with Line.
Firstly, you need to click the ‘Open SerialPort’ button. Then click ‘Send Message’ button. Finally, You can see the ‘Hello’ message on EditText.
More about how to control Uart on Android app, You need to seach for it on google. :smile:


#12

I could control UART using this app.
Thanks for your help terry


#13

I am facing a problem, I am able to receive data using /dev/ttsS4 but I am not able to send the data.
When I send the data it gets stored in the buffer at /dev/ttsS4 and when I retrieve the same data comes back, I know this because I am sending data to Arduino which in response sends the counter.
And I get this Error :

type=1400 audit(0.0:72): avc: denied { read } for name=“ttyS4” dev=“tmpfs” ino=7123 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:serial_device:s0 tclass=chr_file permissive=1

type=1400 audit(0.0:73): avc: denied { write } for name=“ttyS4” dev=“tmpfs” ino=7123 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:serial_device:s0 tclass=chr_file permissive=1

type=1400 audit(0.0:74): avc: denied { open } for path="/dev/ttyS4" dev=“tmpfs” ino=7123 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:serial_device:s0 tclass=chr_file permissive=1

type=1400 audit(0.0:75): avc: denied { ioctl } for path="/dev/ttyS4" dev=“tmpfs” ino=7123 ioctlcmd=5401 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:serial_device:s0 tclass=chr_file permissive=1