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.