Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-16-2009, 09:58 AM   #1
LQ Newbie
Registered: Jul 2009
Posts: 10

Rep: Reputation: 0
Reading data from serial port at 8 Kb/sec


I want to read 8Kbytes from serial port.
What I observed is "read" call blocks until I get specified no.of bytes/or less than it. (which is the expected behavior, I think.)

I as looping in a "for" loop for reading and printing the no.of bytes in each read.But I never get 8Kb in a sec.

Is it possible to read the data at this frequency ?
I am beginner in this domain.

Below is my code

#define SIZE 80*1024
int main(int argc,char *argv[])
int fd,readcount = 0,samples = 0,writecount = 0;
char buf[SIZE];

if(argc < 3)

samples = atoi(argv[2]);

fd = open(argv[1], O_RDONLY);
if (fd < 0)
fprintf(stderr,"Can't open file");

readcount = read(fd,buf,samples);

writecount = write(1,buf,readcount);


Thanks in advance.

Old 07-17-2009, 12:21 PM   #2
Registered: Jun 2009
Posts: 101

Rep: Reputation: 19
Getting 8Kb of data in a second also depends on the external tool to provide that much of data. The fact that some amount of data can be transferred doesn't mean that there is really so much data sent. It's like reading a device as a file - you need to wait for input. Not reaching the 8Kb limit is actually a good thing: it means that you have no data loss.


Last edited by jeromeNP7; 09-04-2009 at 10:19 PM.
Old 07-20-2009, 08:42 AM   #3
LQ Newbie
Registered: Jul 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks for your reply.
I have connected a modem to a serial port. The modem is able to send 8kb in a sec. I have checked it using minicom on linux and hyperterminal on windows.
But I observed a different behaviour when the modem is connected to my h/w device. The same h/w device can receive the data sent from another PC. so I don't think,ther's problem with h/w device(driver).

Any suggestions or pointers regarding this observation will be helpful.



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
the get data from serial port function read() blocks when data not available DEF. Programming 3 11-17-2014 08:11 AM
Serial port reading jayadhanesh Linux - Newbie 3 05-19-2009 07:54 PM
reading from serial port IC009562 Linux - Software 2 11-09-2007 12:25 AM
help reading data from a serial port skydemon Linux - General 1 08-10-2006 09:48 AM
reading data from a serial port mchitrakar Linux - Networking 3 12-04-2004 02:24 PM > Forums > Linux Forums > Linux - Newbie

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