Aadishri Aadishri - 5 months ago 33
C Question

cannot read but can write on serial port through Android Emulator

I am working on a program that is communicating with serial port over USB through Android emulator.

emulator -qemu -serial /dev/ttyUSB0

The emulator is able to open the port and write into it. However, read is not happening.

The program has a timeout for read maintained by a timer. The read happens in a separate 'read' thread. The main thread has a
fd pair to signal the read-thread that the serial port is closed post timeout. In the read-thread, polling happens(
function call) over the 2 file-descriptors: one is serial port fd, the other is one of the socketpair.

The board that I have connected to works fine with sending commands over 'cutecom'

The poll never succeeds for serial port. However, poll succeeds for 'socketpair'ed fd and the thread ends on a close-signal sent from main-thread post timeout.


  1. Are there any special settings for read as even loop-back fails

  2. Are there differences between settings for read and write on a serial port?


struct termios settings are a must with ioctl calls. The following changes got my read call working! Still unsure how write call was successful...

struct termios termios;
int ret;

tcflush(fd, TCIOFLUSH);

tcgetattr(fd, &termios);


termios.c_cflag |= (CLOCAL | CREAD | CRTSCTS | CS8);
tcsetattr(fd, TCSANOW, &termios);

/* tcgetattr(fd, &termios); */

tcflush(fd, TCIOFLUSH);