>I get $GPSRMC and a
>few other messages and then it pauses for a while and then just
>keeps outputing "buff= ". I would like to read the stream
>continuosly. Any idea what is screwed up?
> while (1)
> {
> read(fd,buf,512);
> printf("buf = %s\n" ,buf);
> }
read() does not return a C string in the buffer. It fills the array
with the bytes that were read, and doesn't modify any of the other bytes.
The %s format expects an array of non-zero bytes, followed by a 0x00.
Since the data you are reading is inconsistent with the way you are
printing it, something funny might be happening. To get a better view
of the data coming across the line, try:
while (1)
{
int x,n;
n = read(fd, buf, 512);
if (n < 0)
{
perror("read error");
break;
}
printf("%d bytes: ",n);
for (x=0; x<n; x++)
printf("%02x ",buf[x]);
printf("\n");
}
I use %02x because it is usually easier to understand serial communication
problems if you can see ALL the characters involved. You could use %c,
but then a backspace would move the cursor left instead of displaying
something you can see, ^G would make the terminal beep, etc. You can
also use something like
printf("%c", isprint(buf[x])?buf[x]:'.');
There might be some other problems, but you might as well try this to
get a better idea what is really going on.
Mark S.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|