I have a question regarding reading the serial part. Currently, I have opened a serial port and configured it, and then mapped a stream to it using fdopen(). I then use the returned FILE * stream to do all my io (using fread, fwrite). Since my programming basically sits for commands on the serial port, using while fread() is very CPU intensive, taking up nearly 100%. Is there any way to use streams and have it block on reading?
This is my code to open the port.. which calls the code to configure the serial port.
FILE * open_port(void)
fd = open("/dev/ttyS0",O_RDWR | O_NOCTTY | O_NDELAY);
perror("open_port: Unable to open /dev/ttyS0 - ");
printf("Serial Port 1 Open\n");
void configure_port(int fd)
struct termios newtio;
newtio.c_cflag = CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
newtio.c_lflag = 0;