*** Listing 3 *** /* * try to get a character from a scale; allow 1 to 2 sec. */ int get_response(hn_port *p) { int c; long int t; t = time(NULL) + 2; while (time(NULL) < t) if ((c = hn_pgetc(p)) != EOF) return c; return hn_pgetc(p); } /* * write a command packet to a scale */ int write_command(unsigned si, unsigned fc, hn_port *p) { char buf[7]; char *s; sprintf(buf, "%c%.2u%.2u%c", EOT, si, fc, ENQ); for (s = buf; *s != '\0'; ++s) if (hn_pputc(*s, p) == EOF) return EOF; if (hn_pflush(p) == EOF) return EOF; return 0; }