Test to see if USB Printer is ready

Test to see if USB Printer is ready

Postby Rick Lipkin » Thu May 21, 2015 4:46 pm

To All

Is there a way to test if the Default USB printer is turned on, Ready and plugged in ?

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2633
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Test to see if USB Printer is ready

Postby karinha » Thu May 21, 2015 5:37 pm

Code: Select all  Expand view

   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

   endif
 


João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7316
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Test to see if USB Printer is ready

Postby Rick Lipkin » Thu May 21, 2015 6:33 pm

Joã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 :cry:

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2633
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Test to see if USB Printer is ready

Postby karinha » Thu May 21, 2015 6:53 pm

Rick,

Code: Select all  Expand view

#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 NIL
 


João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7316
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Test to see if USB Printer is ready

Postby Rick Lipkin » Thu May 21, 2015 7:46 pm

Joã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
User avatar
Rick Lipkin
 
Posts: 2633
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Test to see if USB Printer is ready

Postby cnavarro » Thu May 21, 2015 8:05 pm

Rick

You can test the function hb_printerIsReady ("USB001")?
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6501
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Test to see if USB Printer is ready

Postby sambomb » Thu May 21, 2015 8:10 pm

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
Email: SamirSSabreu@gmail.com
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
User avatar
sambomb
 
Posts: 385
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Test to see if USB Printer is ready

Postby Rick Lipkin » Thu May 21, 2015 8:10 pm

Christobal

I get a compile error using xHarbour unresolved external.

Rick
User avatar
Rick Lipkin
 
Posts: 2633
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Test to see if USB Printer is ready

Postby Rick Lipkin » Thu May 21, 2015 8:19 pm

Samir

The result for IsPrinter() is always .t. when I test it even though the USB cable is un-plugged.

Rick
User avatar
Rick Lipkin
 
Posts: 2633
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Test to see if USB Printer is ready

Postby Rick Lipkin » Thu May 21, 2015 8:27 pm

To All

This code does not trap a printer that has the USB plug pulled and is not ready :cry:

Rick Lipkin
Code: Select all  Expand view

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)
ENDIF
 
User avatar
Rick Lipkin
 
Posts: 2633
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Test to see if USB Printer is ready

Postby dutch » Fri May 22, 2015 2:00 am

Dear Rick,

FWH Function is PrnStatus( cPrinterName ), it works for me.
Code: Select all  Expand view
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      16777216  
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
User avatar
dutch
 
Posts: 1535
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: Test to see if USB Printer is ready

Postby Rick Lipkin » Fri May 22, 2015 12:53 pm

Dutch

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:
Code: Select all  Expand view

#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)

RETURN
 


cPort = "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
User avatar
Rick Lipkin
 
Posts: 2633
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Test to see if USB Printer is ready

Postby sambomb » Fri May 22, 2015 2:37 pm

Do you have spooler service running?
Email: SamirSSabreu@gmail.com
MSN: SamirAbreu@hotmail.com
Skype: SamirAbreu
xHarbour 1.1.0 + FwXh 8.02
xHarbour 1.2.1 + Fwhh 10.6
User avatar
sambomb
 
Posts: 385
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil

Re: Test to see if USB Printer is ready

Postby Rick Lipkin » Fri May 22, 2015 3:33 pm

Samir

Yes .. the reason this thread started is that I use the same printer as our Counter computer, all I do is un-plug the Counter computers USB and insert mine.

Sometimes I forget to take my USB cable out and when we cash out customers, the Counter computer will not print because I have my cable plugged in instead of the Counter computer.

I just want to be able to test the 'ready' state of the default printer so the printer cable issue will be tested and resolved at run-time.. just to be able to throw up a MsgAlert to the user to be able to check if the cable is plugged in.

As you can see from the picture .. my default printer is faded out and is 'not ready' .. I just need some way to test for the 'ready state' before I print.

Rick Lipkin
Image
User avatar
Rick Lipkin
 
Posts: 2633
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Test to see if USB Printer is ready

Postby Bayron » Fri May 22, 2015 9:14 pm

=====>

Bayron Landaverry
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], karinha and 36 guests