Math55 <magelord@t-online.de> wrote:[color=blue]
> hi, i have this piece of code:[/color]
Which is full of non-standard function, include file etc. Thus you're
unfortunately rather off-topic in comp.lang.c, where only the standard
C language is the topic, but not system-specific extensions. I would
strongly recommend that you take this to e.g. comp.unix.programmer.
<mostly OT>[color=blue]
> #define MODEMDEVICE "/dev/ttyS1"[/color]
[color=blue]
> volatile int STOP=FALSE;[/color]
No reason to make this a volatile and global variable.
[color=blue]
> main()[/color]
You better declare main() as returning int or you might get into
trouble with a C99 compliant compiler.
[color=blue]
> {
> char buf[255];[/color]
<snipped>
[color=blue]
> while (STOP==FALSE) {
> res = read(fd,buf,255);
> buf[res]=0;[/color]
This will fail badly when a) read() returns a negative number,
indicating failure, or b) you get exactly 255 chars, in which
cases you would be writing outside the boundaries of your buffer.
[color=blue]
> printf(":%s:%d\n", buf, res);
> if (buf[0]=='z') STOP=TRUE;
> }[/color]
Why not simply write it as
do
{
res = read(fd, buf, 254)
...
} while ( buf[0] != 'z' );
[color=blue]
> /* restore the old port settings */
> tcsetattr(fd,TCSANOW,&oldtio);
> }[/color]
You're missing a return statement - even if you didn't explicitely
wrote that main() returns an int a C89 compiler will automatically
default to this type.
[color=blue]
> it prints the data that comes from the ttyS0 port. now i have 2[/color]
No, you're reading from /dev/ttyS1, see your #define of MODEMDEVICE.
[color=blue]
> questions:[/color]
[color=blue]
> 1. can it be that this code does not get all data from the port and[/color]
Yes. But you don't even check yet for all possible errors.
[color=blue]
> 2. anyone good at decoding such signals?[/color]
What signals?
</mostly OT>
Regards, Jens
--
_ _____ _____
| ||_ _||_ _|
Jens.Toerring@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | |
http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring