Re: [iPAQ] [Serial programming]read(fd,buf, 0) doesn't return zero .. .

From: Achille Fouilleul <achille.fouilleul.a.t.gambro.com>
Date: Wed Mar 24 2004 - 08:42:14 EST

At first sight, many problems in this source:

> #define _POSIX_SOURCE 1 /* code source conforme à POSIX */
This should be placed *before* any #include or better, as a gcc option
(e.g. -D_POSIX_SOURCE=1).
> buf = (char *) malloc (10*sizeof(char));
> answ = (char *) malloc (10*sizeof(char));

What for? If the size of the buffers is fixed, "char buf[10]; char
answ[10];" is preffered (particularly if you don't free() them afterwards).

>
> bzero(&newtio, sizeof(newtio));
> newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
> newtio.c_iflag = IGNPAR;
> newtio.c_oflag = 0;
>
> /* positionne le mode de lecture (non canonique, sans echo, ...) */
> newtio.c_lflag = 0;
>
> newtio.c_cc[VTIME] = 0; /* timer inter-caractères non utilisé */
> newtio.c_cc[VMIN] = 0; /* read bloquant jusqu'à ce que 5 */
> /* caractères soient lus */

Bad, bad, don't set up serial flags this way. Use tcgetattr() to get
their status, then use statements like "newtio.c_cflag |= " and
"newtio.c_cflag &= ~" to modify them, finally apply these changes with
tcsetattr(). The glibc manual is your friend here, there are several
useful examples in it.

Bonne chance pour la suite,

Achille

** Confidentiality Statement and Disclaimer **
Proprietary or confidential information belonging to Gambro AB or to one of
its affiliated companies may be contained in this message. If you are not
the addressee indicated in this message (or responsible for the delivery of
the message to such person), please do not copy or deliver this message to
anyone. In such case, please destroy this message and notify the sender by
reply e-mail. Please advise the sender immediately if you or your employer
do not consent to Internet e-mail for messages of this kind.
Opinions, conclusions and other information in this message that pertain to
the sender's employer and its products and services represent the opinion of
the sender and do not necessarily represent or reflect the views and
opinions of the employer.
** End of Statement **
Received on Wed Mar 24 13:28:27 2004

This archive was generated by hypermail 2.1.8 : Tue May 04 2004 - 09:45:09 EDT