|
Home > Archive > Unix Programming > April 2006 > lag from /dev/ttyS0 to printf() & screen
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
lag from /dev/ttyS0 to printf() & screen
|
|
| purple_stars 2006-04-27, 7:55 am |
| hi folks,
need a little help.
problem is that i'm opening /dev/ttyS0 and reading characters off of it
and trying to print them directly to stdout ... trouble is that due to
buffering (i am guessing) they aren't being sent to the screen in
anything approaching real time. i'm fflush()'ing stdout, but that's
not doing the job, i'm still not getting them to the screen as they are
transmitted. i know they are being transmitted in something like real
time because when i use kermit to watch for them it sees them just
fine, but for some reason my code isn't seeing them, or maybe it is
seeing them and just isn't printing them, i don't know. it does
EVENTUALLY print them, i mean, they aren't getting lost, it's just not
happening on the fly. here's the code i'm using ... as you can see
i've even tried to setvbuf to a NULL buffer in the hopes that i would
be forcing a conclusion ... and i've tried fflushing stdout as i said.
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
int main(int argc, char **argv)
/**
function-- main()
**/
{
int i;
int s;
unsigned char c;
char buf[100];
int len;
setvbuf(stdout,(char *)NULL,_IONBF,0);
if((s = open("/dev/ttyS0",O_RDWR | O_NDELAY)) < (int)0)
{ fprintf(stderr,"open(): < (int)0\n"); exit((int)-1); }
len = (int)0;
for(;i = read(s,&c,1);usleep(200))
if(i > (int)0)
{
printf(" %02x ",c&0xff);
if((c & 0xff) == 0xfd)
printf("\n");
fflush(stdout);
}
close(s);
exit((int)0);
}
what's going on ? i feel like my data is just getting stuck in a
buffer somewhere, but where, and how do i get it unstuck ? is it in
the driver for the serial port waiting to build up characters to send
to my code ? or is it stuck in stdin somewhere waiting ? or is it
being processed by my code and it's stuck in stdout somewhere ? i even
tried changing the code over to O_NDELAY and polling instead of waiting
and that didn't help the situation at all.
thanks for any help you can give, it's really kind of irritating me at
this point haha. 
| |
| purple_stars 2006-04-27, 7:55 am |
| nevermind, i discovered the "linux serial port programming how-to" by
Peter H. Baumann and learned about termio's ... problem solved. thank
you peter h baumann whoever you are ... you da bomb.
purple_stars wrote:
> hi folks,
>
> need a little help.
>
> problem is that i'm opening /dev/ttyS0 and reading characters off of it
> and trying to print them directly to stdout ... trouble is that due to
> buffering (i am guessing) they aren't being sent to the screen in
> anything approaching real time. i'm fflush()'ing stdout, but that's
> not doing the job, i'm still not getting them to the screen as they are
> transmitted. i know they are being transmitted in something like real
> time because when i use kermit to watch for them it sees them just
> fine, but for some reason my code isn't seeing them, or maybe it is
> seeing them and just isn't printing them, i don't know. it does
> EVENTUALLY print them, i mean, they aren't getting lost, it's just not
> happening on the fly. here's the code i'm using ... as you can see
> i've even tried to setvbuf to a NULL buffer in the hopes that i would
> be forcing a conclusion ... and i've tried fflushing stdout as i said.
[snip]
> what's going on ? i feel like my data is just getting stuck in a
> buffer somewhere, but where, and how do i get it unstuck ? is it in
> the driver for the serial port waiting to build up characters to send
> to my code ? or is it stuck in stdin somewhere waiting ? or is it
> being processed by my code and it's stuck in stdout somewhere ? i even
> tried changing the code over to O_NDELAY and polling instead of waiting
> and that didn't help the situation at all.
>
> thanks for any help you can give, it's really kind of irritating me at
> this point haha. 
|
|
|
|
|