Subject: Testing printer status 15. ***** Q: How can I test that the printer is ready? A: Strictly speaking there is no guaranteed way to detect the printer status on a PC. As Brian Key Brian@fantasia.demon.co.uk wrote "Any book dealing with the PC BIOS support of a printer will quickly show you that there is no hardware definition which deals with the printer power status. It simply wasn't designed (and I use the word loosely!) into the IBM hardware specs." The usually advocated method in Turbo Pascal is to test the status of regs.ah after a call to interrupt 17 Hex (the parallel port driver interrupt), service 02: regs.dx := PrinterNumber; (* LPT1 = 0 *) regs.ah := $02; (* var regs : registers, uses DOS *) Intr ($17,regs); (* Interrupt 17 Hex *) status := regs.ah (* var status : byte *) But this is not a good method since the combinations of the status bits which indicate a ready state can vary from printer to printer and PC to PC. If you want a list of the status bits, see e.g. Ray Duncan (1988), Advanced MS-DOS Programming, p. 587. For an example of a code using interrupt 17 Hex see Douglas Stivison (1986), Turbo Pascal Library, pp. 118-120. Also see Michael Yester (1989), Using Turbo Pascal, pp. 494-495. The more generic alternative is to try to write a #13 to the printer having the i/o checking off, that is, while {$I-} is in effect, and testing the IOResult. But then you must first alter the printer retry times default (and restore it afterwards). Else the method can take up to a minute instead of an immediate response. Also, you must have set the FileMode for LPT1 appropriately (and restore it afterwards). Sounds a bit complicated, but you don't have to do all this yourself. There is a boolean function "LPTONLFN Get the online status of the first parallel printer" for this purpose in my ftp://garbo.uwasa.fi/pc/ts/tspa3470.zip (or whatever version number is the latest) Turbo Pascal units collection available by anonymous FTP or mail server from garbo.uwasa.fi. A2: One potential, somewhat advanced solution is to use the Device Driver Control (IOCTL) information. Here is the code. uses Dos; function PRNSTAFN : boolean; var regs : registers; handle : ^word; f : file; begin prnstafn := false; if swap(Dosversion) < $0200 then exit; { At least MS-DOS 2.0 } Assign (f, 'prn'); { Printer } Reset (f); FillChar (regs, SizeOf(regs), 0); { Just to make sure } regs.ah := $44; { Function $44 } regs.al := $07; { Subfunction $07 } handle := @f; { Establish a file handle } regs.bx := handle^; Msdos (regs); { Call interrupt $21 } Close (f); if regs.flags and FCarry <> 0 then exit; { Is the carry flag set? } if regs.al <> $FF then exit; { regs.al = $FF signals success} prnstafn := true; end; (* prnstafn *) {} begin if PRNSTAFN then writeln ('Printer ready') else writeln ('Printer not ready'); readln; end. A3: Another advanced method is using ports. This solution is based on a posting by Joerg Kunze joerg@ang-physik.uni-kiel.de. A warning. Do not experiment with the port parameters unless you know exactly what you are doing. A serious loss of data might follow. function PRNON : boolean; var dr : word absolute $40:$08; begin prnon := port[dr+1] and $18=$18; end; --------------------------------------------------------------------