Register a domain and help support LQ
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.


Closed Thread
  Search this Thread
Old 07-08-2008, 01:39 PM   #1
LQ Newbie
Registered: Jun 2008
Posts: 9

Rep: Reputation: 0
Querying serial buffer

I'm trying to query what the size of the buffer is without actually reading it. I currently write to /dev/ttyS0 then query and then read the data. I'm just writing ABC and then receiving the same thing when I read, but the value I get when I query is some random number.

This is my call:

int bytes_avaiable;
ioctl(num, FIONREAD, &bytes_available);

I've found that it may be a timing issue. As I change the time I sleep after my write, but before my query it will return more bytes the longer I wait. When I use usleep(8000) after I have written about 4 bytes to /dev/ttyS0 it will query the right amount of data. I can't use that number however because it won't work for every size written ...
Old 07-08-2008, 05:24 PM   #2
LQ Newbie
Registered: Jun 2008
Posts: 9

Original Poster
Rep: Reputation: 0

Ok, I figured it out, all the echo had to be turned off:

stty -F /dev/ttyS0 -echo -echoe -echoke .....

Echo isn't so nice for a loopback test
Old 07-09-2008, 01:43 AM   #3
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
Glad you figured it out... but for next time:

Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

Closed Thread

buffer, ioctl, query, serial

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
flush the serial buffer fizgig10 Linux - General 1 09-21-2009 04:29 AM
Serial Port Buffer Overrun damiendusha Linux - Hardware 1 06-22-2006 03:56 AM
Buffer serial input -- create new device? prell Programming 4 04-30-2005 04:52 PM
how to increase serial receive email buffer size? HZC Programming 0 02-14-2005 11:32 PM
No of bytes in the serial drivers transmit buffer igjesdal Programming 0 10-13-2004 11:58 AM

All times are GMT -5. The time now is 03:50 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