Android IDE (AIDE) Support Forum

Serial Port Comminacation

Hi,
I have got Digital Signage A-10 model Android tablet. It’s mcu 2017032083, DS83X, UlraOcta-A83, 4.4.4 Android. And It has got one RS232 Com Port.
In order to make serial communication over com port (ttyS3) using c ++, I wrote and run the following program;

#include
#include
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <stdio.h>

using namespace std;

int main()
{
std::cout << “seri port read/write 26.09.2019 by kako” << std::endl;
int serial_port=open("/dev/ttyS3",O_RDWR | O_NOCTTY | O_NDELAY); // ttys1 com3 secildi
if (serial_port < 0){
std::cout<<“not open” << std::endl;
}
struct termios tty;
memset(&tty,0,sizeof tty);
if(tcgetattr(serial_port, &tty) != 0){
std::cout<<“error1” << std::endl;
}
//SETUP SERI PORT
tty.c_lflag &= ~PARENB; /* no parity */
tty.c_lflag &= ~CSTOPB; //one stop bit
tty.c_lflag |= CS8; //8 bit
tty.c_lflag &= ~CRTSCTS; //disable flow control
tty.c_lflag &= ~ICANON; //Canonical mode
tty.c_lflag &= ~ECHO; //echo off
tty.c_lflag &= ~ISIG; //
tty.c_iflag &= ~(IXON | IXOFF | IXANY); //s/w flow dsb
tty.c_cc[VTIME] = 10; //
tty.c_cc[VMIN] = 0; //
cfsetispeed(&tty,B9600); // in baud rate
cfsetospeed(&tty,B9600); // out baud rate
// save setting
if(tcsetattr(serial_port, TCSANOW, &tty) != 0){
std::cout<<“error setup save” << std::endl;
}
//writing
unsigned char msg1[] = {‘M’,‘E’,‘R’,‘H’,‘A’,‘B’,‘A’,’\n’};
write(serial_port, msg1, sizeof(msg1));
// reading
char readBuf [16];
memset(&readBuf, ‘\0’, sizeof(readBuf));
tcflush(serial_port, TCIFLUSH);
int n=0;
int m=0;
while(m<1){
n = read(serial_port, &readBuf, 32);
if(n>0){
printf("%c",readBuf[0]);
if(readBuf[0]==’\n’){
break;
}
n=0;
}
}

close(serial_port);

printf("son");

}

How do I make this code a android app.
Thanks,