View the Most Wanted LQ Wiki articles.
Go Back > Forums > Linux Forums > Linux - Hardware
User Name
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?


  Search this Thread
Old 07-08-2008, 10:43 AM   #1
LQ Newbie
Registered: Jun 2008
Posts: 9

Rep: Reputation: 0
Query buffer with serial port /dev/ttyS0

Hi all, I'm now 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 something like 766 bytes (or something weird like that).

This is my call:

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

I've also tried I_NREAD instead of FIONREAD, but I'm not sure what is going on. Is the value of 766 what I should be getting for the number of bytes??
Old 07-08-2008, 11:31 AM   #2
LQ Newbie
Registered: Jun 2008
Posts: 9

Original Poster
Rep: Reputation: 0
I'm been messing around with this and now think it's some kind of timing issue. As I changed the value of usleep() after my write but before my query_buffer, the value query_buffer returned changed. If I increase the amount of data sent to the serial port, it requires a longer sleep or it can't read anything.

However, the value query buffer returns just continues to rise as I increase the time sleeping. Does this mean that it's constantly sending info to the port even while it's sleeping? and even when I say to only send 10 bytes?
Old 07-08-2008, 04:24 PM   #3
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


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
writing to serial port, /dev/ttyS0 togunter Programming 2 06-08-2008 09:27 AM
How to read serial port (/dev/ttyS0) seraph-seph Linux - Hardware 4 11-01-2006 06:55 AM
How to read serial port (/dev/ttyS0) without end of transmission seraph-seph Programming 1 10-22-2006 01:03 AM
Serial Port HowTo (Cannot open /dev/ttyS0) chun-mee Linux - Hardware 2 07-14-2006 05:35 PM
Unable to communicate using serial port (COM1) /dev/ttys0 vinaybms Linux - Networking 1 03-11-2005 08:08 AM

All times are GMT -5. The time now is 11:52 PM.

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