Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 01-14-2005, 11:47 AM   #1
LQ Newbie
Registered: Jan 2005
Posts: 17

Rep: Reputation: 0
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 - ");
printf("Serial Port 1 Open\n");

//configure port
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;


Old 06-10-2010, 02:55 PM   #2
Registered: Dec 2007
Posts: 93

Rep: Reputation: 15
any hints???

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



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
UART : Unknown iceman911 Linux - Hardware 1 06-23-2005 10:14 PM
uart pantera Programming 5 05-21-2005 06:50 PM
Mouse polling rates Diminished7th Linux - Hardware 2 05-11-2005 06:08 PM
about device polling wangjinyi Fedora 0 04-27-2005 02:22 AM
<0>Kernel panic: Aiee, killing interrupt handler! In interrupt handler - not syncing mrb Linux - Newbie 2 01-09-2005 09:47 AM

All times are GMT -5. The time now is 01:37 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration