LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 01-14-2005, 11:47 AM   #1
jdhar
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 - ");
}
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.
 
Old 06-10-2010, 02:55 PM   #2
raedbenz
Member
 
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?

thanks
 
  


Reply


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 05:36 AM.

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