k34386t@kaira.HUT.FI (Petri Kruiseri Suominen) (06/22/88)
Does anyone know how to check for printer line status with TP4,
I've tried the following, but the result is just the same as with
no check at all, PC just waits for the printer to become online.
function checkprn:boolean;
var
lst:text;
begin
assign(lst,'LPT1');
{$I-}
rewrite(lst);
{$I+}
if IOresult<>0 then
checkprn:=false
else
checkprn:=true;
end;taylorj@byuvax.bitnet (06/24/88)
The following code fragment should get you started. E-mail me if you have
any questions.
{Determines if parallel printer is connected and ready to print}
{Warns if printer is off or off line}
{Printer number can be 1 - 3}
function lptready(portnum: integer) :boolean;
begin
reg.ah := 2; {read printer status}
reg.dx := portnum - 1;
intr($17, reg);
if ((reg.ah and $80) = $80)
or ((reg.ah and $08) = $08) then begin {not busy or I/O error}
lptready := true;
case reg.ah of
$08: begin
warning(2, 'Your printer is off line. Press the "on-line" or "select"
button.');
waitkey;
end;
$C8: begin
warning(2, 'Your printer is off. Please turn it on.');
waitkey;
end;
end;
end else begin
lptready := false;
end;
end;
{Determines if com port exists}
{Port number can be 1 or 2}
function comready(portnum: integer) :boolean;
begin
reg.ah := 3; {read com port status}
reg.dx := portnum - 1;
intr($14, reg);
if reg.ah = 96 then begin
comready := true;
end else begin
comready := false;
end;
end;
You probably need to be slightly familiar with interrupts from Turbo to
have the appropriate register type.
Jim Taylor
Microcomputer Support for Curriculum, Brigham Young University
taylorj@byuvax.bitnetweijers@cwi.nl (Eric Weijers) (06/25/88)
In article <13936@santra.UUCP> k34386t@kaira.UUCP (Petri Kruiseri Suominen) writes: > > >Does anyone know how to check for printer line status with TP4, >I've tried the following, but the result is just the same as with >no check at all, PC just waits for the printer to become online. > > >function checkprn:boolean; >var > lst:text; >begin > assign(lst,'LPT1'); > {$I-} > rewrite(lst); > {$I+} > if IOresult<>0 then > checkprn:=false > else > checkprn:=true; >end; You should use DOS interrupt $17 (HEX). Define a variable of type registers and set AH to 2 and DX to the number of the printer you want to test. If you have only one printer, DX should be 0. If the interrupt returns, the AH register contains the printer status byte. This byte is build up as follows: bit 0 : time out bit 1 : unused bit 2 : unused bit 3 : I/O error (if set) bit 4 : selected (if set) bit 5 : out of paper (if set) bit 6 : acknowledge (if set) bit 7 : not busy (if set) The code should look like this: uses DOS; var Regs : registers; i : byte; begin i := 1; Regs.AH := 2; Regs.DX := 0; repeat Intr($17,Regs); inc(i); until ((Regs.AH <> 2) or i=10); { here you should test on the value of Regs.AH } end; Eric Weijers weijers@cwi.nl
leonard@bucket.UUCP (Leonard Erickson) (06/26/88)
In article <13936@santra.UUCP> k34386t@kaira.UUCP (Petri Kruiseri Suominen) writes:
<Does anyone know how to check for printer line status with TP4,
<I've tried the following, but the result is just the same as with
<no check at all, PC just waits for the printer to become online.
<
<function checkprn:boolean;
<var
< lst:text;
<begin
< assign(lst,'LPT1');
< {$I-}
< rewrite(lst);
< {$I+}
< if IOresult<>0 then
< checkprn:=false
< else
< checkprn:=true;
<end;
This has been discussed on the Borland SIG on CIS for the last month or two.
The only solution is to use the "printer status" call from the BIOS and see
what the result byte is. $90 is printer ready on *most* printers, but not
all. They have been trying to get a universally applicable routine and have
essentially given up. They've got a routine, but no matter what value they
test for, there are *some* printers that that value will be wrong for.
Aren't "standards" wonderful?
--
Leonard Erickson ...!tektronix!reed!percival!bucket!leonard
CIS: [70465,203]
"I used to be a hacker. Now I'm a 'microcomputer specialist'.
You know... I'd rather be a hacker."Michael_Krause.ROCH@xerox.com (06/29/88)
Try this one on for size. I put it together about a year ago and have found it
to work well in all situations I find myself in. I'm currently using Turbo
Pascal 4.0
Function PrinterReady : Boolean;
Var
Ch : Char;
IOStatus : Integer;
Begin
{$I-} Write (Lst,#0); {$I+}
IOStatus := IOResult;
If IOStatus <> 0 Then
Begin
GotoXY (1,25); ClrEol;
Write ('Printer not ready !! (Press any key to Abort)');
End;
Repeat
{$I-} Write (Lst,#0); {$I+}
IOStatus := IOResult;
Until (IOStatus = 0) Or Keypressed;
GotoXY (1,25); ClrEol;
PrinterReady := IOStatus = 0;
End; { PrinterStatus }
The routine is be called something like this :
.
.
.
If PrinterReady Then
PrintReports;
.
.
.
Good luck
Mike Krause
716-483-9752