[comp.lang.pascal] TurboPascal printer problem...

m84_tobbe@tekno.chalmers.se (Torbjorn Backstrom) (04/13/89)

I have problems using the printer from within a TurboPascal v5 program.
If the printer isn't on, or out of paper, any writing to it results in
the program crashing without pardon.

 I use the {$I-} - {$I+}-options when assigning/rewriting, but it does 
not seem to help. Do you have to do such a check for every single 
"writeln" directed to the printer? Or is there a better way to stop the 
Big Crash from occuring?

Thanks in advance for any pointers on how to solve this,

Tobbe

natec@infohh.rmi.de (NATEC Institut GmbH) (04/15/89)

test youtr printer status
Procedure PSt ( PrtNo : Byte ); (* Printerstatus *)
(* Part of it taken from: *)
(* Christoph Naethbohm, CHIP 87(9), 190 *)
(* and Klaus Bach, CHIP 88(11), 331 *)
Type
  Bild                       = Array[1..25,1..80] of Record Ze,At: Char end;
Var
  Inhalt                     : Bild;
  Mono_VRam                  : Bild Absolute $B000:$0000;
  OrigMode                   : Word;
  St                         : Byte;
  Weiter                     : Char;
  s,p                        : String;
  ParStat                    : Word;

Function Bit ( i,j : Byte ) : Boolean;  
begin
  if (j>=0) and (j<8) then begin
    i:= i shl (7-j);
    i:= i shr 7
  end else i:= 0;
  Bit:= (i=1)
end;
begin
  if PrtNo= 0 then p:= 'LPT1: 'else p:= 'LPT2: ';
  { insert your own status port next line }
  ParStat:= $379;
  if MEM[$0FFFF:$0E] = $FE then if PrtNo= 0 then ParStat:= $3BD;  { $FE => XT }
  St:= (Port[ParStat]);
  Inhalt:= Mono_VRam;
  OrigMode:= LastMode;
  CursorOff;
  MakeWindow (20,12,40,3);
  while not (Bit(St,7) and Bit(St,6) and Bit(St,4) and not Bit(St,5)) do begin
    Str (St,s);
    s:= ' ('+s+')';
    if Bit(St,6) and Bit(St,5) and Bit(St,4) and Bit(St,3)
      then Center(1,p+'Device not connected'+s)
      else if Bit(St,7) then Center(1,p+'Device switched off'+s)
        else if Bit(St,5) then Center(1,p+'Paper out'+s)
          else if not Bit(St,4) then Center(1,p+'Device offline'+s)
            else Center(1,p+'Device out of order'+s);
    Center(2,'Any key or (I) for ignore');
    Weiter:= ReadKey;
    if UpCase(Weiter)='I' then St:= 216 else St:= (Port[ParStat]);
    GotoXY (1,1);
    ClrEol;
  end;
  CursorOn;
  TextMode(OrigMode);
  Mono_VRam:= Inhalt
end;


Dr Gerd C Schmerse  |  natec@infohh.rmi.de     |     ___    
NATEC Institut      |  49 40 88300170 (fax)    |    /o o\   
Hamburg, W.Germany  |  49 40 88300124 (voice)  | -m-"-U-"-m-

taylorj@yvax.byu.edu (04/18/89)

You actually have two solutions to this problem:

1) (easy) call interrupt 17H and find out the printer status (out of paper,
offline, etc.)  I strongly recommend that you not use the method that was
posted  (from Germany), as it reads hardware directly and may not work on all
computers.  I have some example code I can send if you'd like.

2) (hard) send out each character one at a time, checking the printer status
first.

If you use the first method to check before you start printing, or after each
line, you may catch some errors, but you can still get hung up if any printer
problems occur while the line is being sent to the printer.  The second method
is the only way to guarantee that you will not hang up (or at least allow the
user to abort the printing at any time).

Jim Taylor
Microcomputer Support for Curriculum
101 HRCB, Brigham Young University     |   BITNET: taylorj@byuvax.bitnet
Provo, UT  84602                       |   INTERNET: taylorj@yvax.byu.edu




#! rnews  

cs3b3aj@maccs.McMaster.CA (Stephen M. Dunn) (04/21/89)

In article <527@infohh.rmi.de> natec@infohh.rmi.de (NATEC Institut GmbH) writes:
>
>test your printer status
[large subprogram deleted]

Why not just call int 17h, function 02h?  This returns the printer status.
Call with DX=printer number (0=LPT1, etc)
Returns in AH:  bit 7:  printer not busy
		bit 6:  acknowledge
		bit 5:  out of paper
		bit 4:  printer selected
		bit 3:  I/O error
		bit 2:  unused
		bit 1:  unused
		bit 0:  timed-out
These are the meanings when the bits are set.
I don't know what happens if your printer is hooked up to your serial port;
perhaps you could then use the int 14h functions to check its status.
-- 
======================================================================
! Stephen M. Dunn, cs3b3aj@maccs.McMaster.CA ! DISCLAIMER:           !
! This space left unintentionally blank - vi ! I'm only an undergrad !
======================================================================