From: c8591@aol.com (C8591) Subject: Re: Testing Pinter Status Date: 20 Jan 1999 00:00:00 GMT Message-ID: <19990119191605.01667.00000909@ng-fw1.aol.com> Content-Transfer-Encoding: 8bit References: <916763447.110160@nurn.esoterica.pt> Content-Type: text/plain; charset=ISO-8859-1 X-Admin: news@aol.com Organization: AOL http://www.aol.com Mime-Version: 1.0 Newsgroups: comp.lang.pascal.delphi.misc >Does anybody knows how to get the printer status to find out if the printer >is 'ONLINE' ? > >Mário Bernardo > > Below is code for a component I wrote for checking the printer status, save it as PrinterStatus.pas and install into delphi. Example use: if not PrinterStatus1.PrinterReady(0) then //0 = current printerport ShowMessage(PrinterStatus1.StatusMsg) else {print print print} ; ---- start of file -------------------------------------------------------------------------- { PrinterStatus unit TPrinterStatus Chris Willig 1/15/99 Code hacked together from SWAG **************************************************************************** SWAG WEB Site : http://www.gdsoft.com/swag/swag.html SWAG FTP Site : ftp://gdsoft.com/pub/swag About SWAG : SWAG is a collection of source code and program examples for the PASCAL program language. The material has been donated by various PASCAL programmers from around the world, interested in the continued advancement of one of the finest programming platforms available today. ***************************************************************************** } unit PrinterStatus; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type TPrinterStatus = class(TComponent) private { Private declarations } FPort : Word; FStatusStr : string; protected { Protected declarations } public { Public declarations } function PrinterReady(LPT: Word): boolean; published { Published declarations } property StatusMsg: string read FStatusStr; end; procedure Register; implementation uses Printers; procedure Register; begin RegisterComponents('Win95', [TPrinterStatus]); end; const PrnReady = $90; OffLine = $00; OffLine2 = $10; {NEW LINE} PaperOut = $20; PaperOut2 = $30; {NEW LINE} HookedButOff = $80; {NEW LINE} NoConnect = $B0; {MODIFIED LINE} {NOCONNECT = $30 FOR SOME COMPUTERS BY STU} function TPrinterStatus.PrinterReady(LPT: Word): boolean; var ErrorCode, C : BYTE; code, x : integer; s : string; function GetPrinterStatus (LPT: Word): Byte; {Pass 1 in LPT for LPT1} begin asm mov ah,2 mov dx,LPT dec dx int $17 mov @Result,ah end; end; {GetPrinterStatus} begin result := false; //assume not FPort := LPT; if FPort = 0 then begin {if no port specified then try to set port to current printer port} {printer name} s := Printer.Printers[Printer.PrinterIndex]; if Pos('FPort',s) <> 0 then begin s := Copy(s, Pos('FPort',s) +3, 1); Val(s,x,code); if code <> 0 then FPort := 1 else FPort := x; end else FPort := 1; {default to LPT1} end; {valid LPT is 1..4} if (FPort > 4) or (FPort < 1) then begin raise ERangeError.CreateFmt( 'LPT%d is not within the valid range of %d..%d', [FPort, 1, 4]); exit; end; ErrorCode := GetPrinterStatus(FPort); ErrorCode := ErrorCode and $B0; {NEW LINE} C := ERRORCODE shl 6; {ALWAYS MEANS NOTHING CONNECTED} if C > 0 then ERRORCODE := $B0; {ELEMINATES NO LPT3 AND NOTHING CONNECTED} case ErrorCode of PrnReady : begin FStatusStr := 'Printer Ready'; result := true; end; NoConnect : FStatusStr := 'Printer not connected'; Offline,OffLine2 : FStatusStr := 'Printer off line'; {Modified} PaperOut,PaperOut2 : FStatusStr := 'Printer out of paper'; {Modified} HookedButOff : FStatusStr := 'Printer connected but turned off'; {New} else FStatusStr := 'Printer error code: ' + IntToStr(ErrorCode); end; end; end. ------------- end of file ------------------------------------------------------------------- Chris c8591@aol.com