To All
Is there a way to test if the Default USB printer is turned on, Ready and plugged in ?
Thanks
Rick Lipkin
To All
Is there a way to test if the Default USB printer is turned on, Ready and plugged in ?
Thanks
Rick Lipkin
cPorta := PrnGetPort()
cPrinter := PrinterPortToName( cPorta )
if empty(cPrinter)
cPrinter := PrinterPortToName( "USB002" )
if empty(cPrinter)
cPrinter := PrinterPortToName( "USB001" )
if empty(cPrinter)
MsgStop("No printers Installed")
return nil
endif
endif
endifJoão
Thank you for your code, unfortunately the example you provided tells me the port and printer name, but not if it is Ready or On-Line
Thanks
Rick Lipkin
Rick,
#include "Fivewin.ch"
FUNCTION Main()
LOCAL oPrn, oPrint,oFnt, cPrinter := ""
LOCAL oDlg, oBrw
LOCAL aPrn := {}
LOCAL cDef, i := 1
aPrn := GetPrinters()
IF Empty (aPrn) // Empty( oPrn:hDC )
MsgAlert ("No Printers found" )
RETURN NIL
ENDIF
cDef := GetDefaultPrinter()
DEFINE DIALOG oDlg FROM 2, 2 TO 21, 50 TITLE "Available Printers"
@ 1, 2 LISTBOX oBrw FIELDS aPrn[ i ] ;
HEADERS "Printer Array" ;
FIELDSIZES 200 ;
OF oDlg ;
SIZE 100, 100
oBrw:bGoTop = { || i := 1 }
oBrw:bGoBottom = { || i := Eval( oBrw:bLogicLen )}
oBrw:bSkip = { | nWant, nOld | nOld := i, i += nWant, ;
i := Max( 1, Min( i, Eval( oBrw:bLogicLen ) ) ),;
i - nOld }
oBrw:bLogicLen = { || Len( aPrn ) }
oBrw:cAlias = "Array" // Just put something
@ 7.8,2 SAY "DEFAULT PRINTER: " + cDef
@ 1,22 BUTTON "&Print" OF oDlg ACTION Testprint (aPrn[i])
@ 2,22 BUTTON "&End " OF oDlg ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED
RETURN NIL
//--------------------------------------------------------------
FUNCTION TestPrint(cPrn)
LOCAL oFnt, oPrint
LOCAL cText := "Printer Test - Default Printer"
IF MsgYesNo ( "Print to " + cPrn)
PRINT oPrint NAME "Formular" TO (cPrn)
DEFINE FONT oFnt NAME "ARIAL" SIZE 0,12 OF oPrint
oPrint:SetCopies (2)
oPrint:SetLandscape()
oPrint:Setup () // check the settings
PAGE
oPrint:CmSay (1,1, cText,oFnt)
ENDPAGE
ENDPRINT
oFnt:End()
ENDIF
RETURN NILJoão
Thank you again for your kind response and code .. unfortunately, your example shows me the printers loaded on the computer, but not the specific attributes of the printer such as 'being ready'
What I am really looking for is to be able to interrogate the default printer attributes and determine if the printer is 'on line' and 'ready'
Thanks
Rick Lipkin
Rick
You can test the function hb_printerIsReady ("USB001")?
IsPrinter()
Determines if print output can be processed.
Syntax
IsPrinter( [<cPrinterName>] ) --> lIsPrinter
Arguments
<cPrinterName>
An optional character string holding the name of a particular printer driver. Return
The function returns .T. (true) when the operating system can process print output, otherwise .F. (false) is returned.
Description
The IsPrinter() function is used to test if an application can pass print output to the operating system. This is usually the case when a print spooler is active. IsPrinter() cannot detect, if a physical printer is ready to print, since this is monitored by the operating system.
If a character string holding a particular printer name is passed, IsPrinter() returns .T. (true) if this printer is installed.
Note: under CA-Clipper (DOS), IsPrinter() checked the readiness of a physical printer. This is not possible with xHarbour's IsPrinter() function due to differences between DOS and modern operating systems.
Info
See also: GetDefaultPrinter(), GetPrinters(), PCol(), PRow(), SET DEVICE, SET PRINTER, SetPrc()
Category: Printer functions
Source: rtl\isprint.c
LIB: xhb.lib
DLL: xhbdll.dll
Example
// The example outlines possibilities of getting printer information
// different from CA-Clipper (DOS).
PROCEDURE Main
LOCAL aPrinter := GetPrinters()
? ValToPrg( aPrinter )
? GetDefaultPrinter()
? IsPrinter()
? IsPrinter( aPrinter[1] )
? IsPrinter( "HP LaserJet" )
RETURN
Christobal
I get a compile error using xHarbour unresolved external.
Rick
Samir
The result for IsPrinter() is always .t. when I test it even though the USB cable is un-plugged.
Rick
To All
This code does not trap a printer that has the USB plug pulled and is not ready :cry:
Rick Lipkin
PRINTER oPRINT FROM USER ;
PREVIEW MODAL ;
NAME "Gross Sales Report for "+xLOGIN
IF EMPTY( oPRINT:hDC )
MsgStop ( "Printer not Ready !" )
CLOSE DATABASES
oDlg:END()
RETURN(NIL)
ENDIFDear Rick,
FWH Function is PrnStatus( cPrinterName ), it works for me.
PrnStatus()
Retrieves the status of a printer.
Syntax:
PrnStatus( <cPrinter> ) --> nStatus
Parameters:
<cPrinter> The printer of which the status is to be retrieved.
Returns:
<nStatus> One of the following values:
#define PRINTER_STATUS_OK 0
#define PRINTER_STATUS_PAUSED 1
#define PRINTER_STATUS_ERROR 2
#define PRINTER_STATUS_PENDING_DELETION 4
#define PRINTER_STATUS_PAPER_JAM 8
#define PRINTER_STATUS_PAPER_OUT 16
#define PRINTER_STATUS_MANUAL_FEED 32
#define PRINTER_STATUS_PAPER_PROBLEM 64
#define PRINTER_STATUS_OFFLINE 128
#define PRINTER_STATUS_IO_ACTIVE 256
#define PRINTER_STATUS_BUSY 512
#define PRINTER_STATUS_PRINTING 1024
#define PRINTER_STATUS_OUTPUT_BIN_FULL 2048
#define PRINTER_STATUS_NOT_AVAILABLE 4096
#define PRINTER_STATUS_WAITING 8192
#define PRINTER_STATUS_PROCESSING 16384
#define PRINTER_STATUS_INITIALIZING 32768
#define PRINTER_STATUS_WARMING_UP 65536
#define PRINTER_STATUS_TONER_LOW 131072
#define PRINTER_STATUS_NO_TONER 262144
#define PRINTER_STATUS_PAGE_PUNT 524288
#define PRINTER_STATUS_USER_INTERVENTION 1048576
#define PRINTER_STATUS_OUT_OF_MEMORY 2097152
#define PRINTER_STATUS_DOOR_OPEN 4194304
#define PRINTER_STATUS_SERVER_UNKNOWN 8388608
#define PRINTER_STATUS_POWER_SAVE 16777216Dutch
Thank you for your code .. I did see something similar in the \Samples.. Here is my code,.. I query for the port and the name .. I run both parameters through PrnStatus() .. and the USB printer cable has been removed:
#include "Fivewin.ch"
#define PRINTER_STATUS_OK 0
#define PRINTER_STATUS_PAUSED 1
#define PRINTER_STATUS_ERROR 2
#define PRINTER_STATUS_PENDING_DELETION 4
#define PRINTER_STATUS_PAPER_JAM 8
#define PRINTER_STATUS_PAPER_OUT 16
#define PRINTER_STATUS_MANUAL_FEED 32
#define PRINTER_STATUS_PAPER_PROBLEM 64
#define PRINTER_STATUS_OFFLINE 128
#define PRINTER_STATUS_IO_ACTIVE 256
#define PRINTER_STATUS_BUSY 512
#define PRINTER_STATUS_PRINTING 1024
#define PRINTER_STATUS_OUTPUT_BIN_FULL 2048
#define PRINTER_STATUS_NOT_AVAILABLE 4096
#define PRINTER_STATUS_WAITING 8192
#define PRINTER_STATUS_PROCESSING 16384
#define PRINTER_STATUS_INITIALIZING 32768
#define PRINTER_STATUS_WARMING_UP 65536
#define PRINTER_STATUS_TONER_LOW 131072
#define PRINTER_STATUS_NO_TONER 262144
#define PRINTER_STATUS_PAGE_PUNT 524288
#define PRINTER_STATUS_USER_INTERVENTION 1048576
#define PRINTER_STATUS_OUT_OF_MEMORY 2097152
#define PRINTER_STATUS_DOOR_OPEN 4194304
#define PRINTER_STATUS_SERVER_UNKNOWN 8388608
#define PRINTER_STATUS_POWER_SAVE 16777216
//------------------------
FUNCTION Main()
Local cPort,aPrn,nStatus,aPrinter
cPort := PrnGetPort()
Msginfo( cPort )
cPrinter := GetDefaultPrinter()
msginfo( "cPrinter" )
msginfo( cPrinter )
nStatus := PrnStatus( cPrinter )
msginfo( nStatus )
nStatus := PrnStatus( cPort )
msginfo( nStatus)
RETURNcPort = "USB001"
cPrinter = "Brother HL-1440 series"
nStatus passing cPrinter = 0 ( status ok )
nStatus passing cPort = 4096 ( status un-available )
Perhaps running this on XP has some bearing ?? .. the above results retrieved the correct port and printer name .. but the status seemed to conflict each other interrogating the Port vs the printer name ..
Rick Lipkin
Do you have spooler service running?

=====>
Bayron Landaverry
xBasePHP.com
(215)2226600 Philadelphia,PA, USA
MayaBuilders@gMail.com
Guatemala
FWH25.06--Harbour 3.0.0--BCC7.7--UEstudio 10.10
Windows 10
FiveWin, One line of code and it's done...