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 >
Text File  |  1989-10-02  |  681b  |  37 lines

  1.  
  2. *** Listing 3 ***
  3.  
  4. /*
  5.  * try to get a character from a scale; allow 1 to 2 sec.
  6.  */
  7. int get_response(hn_port *p)
  8.     {
  9.     int c;
  10.     long int t;
  11.  
  12.     t = time(NULL) + 2;
  13.     while (time(NULL) < t)
  14.         if ((c = hn_pgetc(p)) != EOF)
  15.             return c;
  16.     return hn_pgetc(p);
  17.     }
  18.  
  19. /*
  20.  * write a command packet to a scale
  21.  */
  22. int write_command(unsigned si, unsigned fc, hn_port *p)
  23.     {
  24.     char buf[7];
  25.     char *s;
  26.  
  27.     sprintf(buf, "%c%.2u%.2u%c", EOT, si, fc, ENQ);
  28.     for (s = buf; *s != '\0'; ++s)
  29.         if (hn_pputc(*s, p) == EOF)
  30.             return EOF;
  31.     if (hn_pflush(p) == EOF)
  32.         return EOF;
  33.     return 0;
  34.     }
  35.  
  36.  
  37.