LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   UART Polling/Interrupt (https://www.linuxquestions.org/questions/linux-software-2/uart-polling-interrupt-277756/)

jdhar 01-14-2005 11:47 AM

UART Polling/Interrupt
 
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)
{
int fd;
fd = open("/dev/ttyS0",O_RDWR | O_NOCTTY | O_NDELAY);
if (fd==-1)
{
perror("open_port: Unable to open /dev/ttyS0 - ");
}
else
{
printf("Serial Port 1 Open\n");
fcntl(fd,F_SETFL,0);
}

//configure port
configure_port(fd);
return fdopen(fd,"r+");
}


void configure_port(int fd)
{
struct termios newtio;

printf("Configuring Port\n");
newtio.c_cflag = CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
newtio.c_lflag = 0;

cfsetospeed(&newtio,B19200);
cfsetispeed(&newtio,B19200);
tcsetattr(fd,TCSANOW,&newtio);
fcntl(fd,F_SETFL,FNDELAY);
}


Thx.

raedbenz 06-10-2010 02:55 PM

any hints???

how to go and read dev/ttyS0 or /dev/rfcomm0 only when data is available rather than polling?

thanks


All times are GMT -5. The time now is 04:38 AM.