home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_07_08
/
v7n8109a.txt
< prev
next >
Wrap
Text File
|
1989-10-02
|
681b
|
37 lines
*** 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;
}