home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 03 / prready.c < prev    next >
Text File  |  1992-01-14  |  2KB  |  71 lines

  1.  
  2. // prready.c -  check printer and return TRUE if ready else FALSE 
  3. #include<dos.h>  // required for prt_ready function   
  4. #include<stdio.h>  // not needed for prt_ready function 
  5. #include<stdlib.h>
  6.  
  7. unsigned char printer_status(int prt);
  8.  
  9. char *PrinterStatus[8] = // Printer Status Bits:
  10.     {
  11.     "Time Out",     // 0
  12.     "",             // 1 - (Unused)
  13.     "",             // 2 - (Unused)
  14.     "I/O Error",    // 3
  15.     "Selected",     // 4
  16.     "Out of Paper", // 5
  17.     "Acknowledged", // 6
  18.     "Not Busy"      // 7
  19.     };
  20.  
  21. void main(int argc, char **argv)
  22.     {
  23.     unsigned char status;
  24.     int printerno,i;
  25.  
  26.     printerno = atoi(argv[1]);
  27.  
  28.     if((argc != 2) || (printerno < 1) || (printerno > 3))
  29.         {
  30.         printf("Usage: PRREADY <printernumber (1-3)>\n");
  31.         exit(1);
  32.         }
  33.  
  34.     status = printer_status(printerno);
  35.     printf("Printer %d status: ",printerno);
  36.  
  37.     if(!(status & 0xf9))
  38.         printf("not available");
  39.     else
  40.         {
  41.         for( i = 0; i < 8; i++, status >>= 1)
  42.             {
  43.             if(i == 1)
  44.                 {
  45.                 status >>= 1;
  46.                 i++;
  47.                 continue;
  48.                 }
  49.             if(status & 0x01)
  50.                 printf("%s ",PrinterStatus[i]);
  51.             if(i == 7 && (!status))
  52.                 printf("Busy");
  53.             }
  54.         }
  55.     }
  56.  
  57.     // prt should be 1, 2, or 3  depending on printer to be checked 
  58. unsigned char printer_status(int prt)
  59.     {
  60.     union REGS regs;
  61.  
  62.     regs.h.ah = 2;  // request printer status 
  63.     regs.x.dx = prt-1;  // printer (0-2) 
  64.     int86(0x17, ®s, ®s);
  65.  
  66.     // if printer is ready status should be 0x90: Powered on, 
  67.     //   Selected, Not Busy 
  68.     return regs.h.ah;
  69.     }
  70.  
  71.