Hi All
Can anyone help, I need to be able to query the printer and know whether it is offline or out of paper or a jam etc.
How do i do this, using PB2017r2/3 currently
regards and thanks in advance
Andrew
Hi All
Can anyone help, I need to be able to query the printer and know whether it is offline or out of paper or a jam etc.
How do i do this, using PB2017r2/3 currently
regards and thanks in advance
Andrew
Roland
The function is nearly there - I get the default printer
I have a generic text printer which is showing with an exclamation mark on the windows printers ie showing as error then it returns status =2 which is great
However my HP laserjet is showing on its screen out of paper ( I pulled the paper tray out ) - but the function still says ready - I tried putting the printer offline and it still says ready - even though there are several jobs in the queue
Any ideas ?
as always any help is truly appreciated.
Andrew
Great stuff Roland, very usefull!
Here is a window which I think will work, I am still testing. The case statement is meant to convert the value constants to a string.
forward
global type w_main from window
end type
type cb_process from commandbutton within w_main
end type
type cb_cancel from commandbutton within w_main
end type
type printer_info_6 from structure within w_main
end type
end forward
type printer_info_6 from structure
unsignedlong dwstatus
unsignedlong reserved
end type
global type w_main from window
integer width = 2098
integer height = 1460
boolean titlebar = true
string title = "Printer Status"
boolean controlmenu = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
cb_process cb_process
cb_cancel cb_cancel
end type
global w_main w_main
type prototypes
Function boolean GetDefaultPrinter ( &
Ref string pszBuffer, &
Ref ulong pcchBuffer ) &
Library "winspool.drv" Alias For "GetDefaultPrinterW"
Function boolean OpenPrinter ( &
string pPrinterName, &
Ref long phPrinter, &
ulong pDefault ) &
Library "winspool.drv" Alias For "OpenPrinterW"
Function boolean ClosePrinter ( &
long hPrinter ) &
Library "winspool.drv"
Function boolean GetPrinter ( &
long hPrinter, &
ulong Level, &
Ref structure pPrinter, &
ulong cbBuf, &
Ref ulong pcbNeeded ) &
Library "winspool.drv" Alias For "GetPrinterW"
end prototypes
type variables
Constant ULong PRINTER_STATUS_BUSY = 512 // 0x00000200
Constant ULong PRINTER_STATUS_DOOR_OPEN = 4194304 // 0x00400000
Constant ULong PRINTER_STATUS_ERROR = 2 // 0x00000002
Constant ULong PRINTER_STATUS_INITIALIZING = 32768 // 0x00008000
Constant ULong PRINTER_STATUS_IO_ACTIVE = 256 // 0x00000100
Constant ULong PRINTER_STATUS_MANUAL_FEED = 32 // 0x00000020
Constant ULong PRINTER_STATUS_NO_TONER = 262144 // 0x00040000
Constant ULong PRINTER_STATUS_NOT_AVAILABLE = 4096 // 0x00001000
Constant ULong PRINTER_STATUS_OFFLINE = 132 // 0x00000080
Constant ULong PRINTER_STATUS_OUT_OF_MEMORY = 2097152 // 0x00200000
Constant ULong PRINTER_STATUS_OUTPUT_BIN_FULL = 2048 // 0x00000800
Constant ULong PRINTER_STATUS_PAGE_PUNT = 524288 // 0x00080000
Constant ULong PRINTER_STATUS_PAPER_JAM = 8 // 0x00000008
Constant ULong PRINTER_STATUS_PAPER_OUT = 16 // 0x00000010
Constant ULong PRINTER_STATUS_PAPER_PROBLEM = 64 // 0x00000040
Constant ULong PRINTER_STATUS_PAUSED = 1 // 0x00000001
Constant ULong PRINTER_STATUS_PENDING_DELETION = 4 // 0x00000004
Constant ULong PRINTER_STATUS_POWER_SAVE = 16777216 // 0x01000000
Constant ULong PRINTER_STATUS_PRINTING = 1024 // 0x00000400
Constant ULong PRINTER_STATUS_PROCESSING = 16384 // 0x00004000
Constant ULong PRINTER_STATUS_READY = 0 // 0x00000000
Constant ULong PRINTER_STATUS_SERVER_UNKNOWN = 8388608 // 0x00800000
Constant ULong PRINTER_STATUS_TONER_LOW = 131072 // 0x00020000
Constant ULong PRINTER_STATUS_USER_INTERVENTION = 1048576 // 0x00100000
Constant ULong PRINTER_STATUS_WAITING = 8192 // 0x00002000
Constant ULong PRINTER_STATUS_WARMING_UP = 65536 // 0x00010000
end variables
on w_main.create
this.cb_process=create cb_process
this.cb_cancel=create cb_cancel
this.Control[]={this.cb_process,&
this.cb_cancel}
end on
on w_main.destroy
destroy(this.cb_process)
destroy(this.cb_cancel)
end on
type cb_process from commandbutton within w_main
integer x = 73
integer y = 64
integer width = 370
integer height = 132
integer taborder = 10
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Process"
end type
event clicked;PRINTER_INFO_6 lstr_info
Boolean lb_return
Long ll_hPrinter
String ls_null, ls_DefaultPrinter, ls_Status
ULong lul_buffer, lul_needed
// Size the buffer
SetNull(ls_null)
GetDefaultPrinter(ls_null, lul_buffer)
ls_DefaultPrinter = Space(lul_buffer)
// Get the Windows default printer
lb_return = GetDefaultPrinter(ls_DefaultPrinter, lul_buffer)
// open the printer
lb_return = OpenPrinter(ls_DefaultPrinter, ll_hPrinter, 0)
// get the printer status
lb_return = GetPrinter(ll_hPrinter, 6, lstr_info, 8, lul_needed)
choose case lstr_info.dwStatus
case PRINTER_STATUS_READY
ls_Status = "Ready"
case else
ls_Status = "Unknown Status Code: " + String(lstr_info.dwStatus)
end choose
// close the printer
ClosePrinter(ll_hPrinter)
end event
type cb_cancel from commandbutton within w_main
integer x = 1682
integer y = 1216
integer width = 334
integer height = 100
integer taborder = 10
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Cancel"
boolean cancel = true
end type
event clicked;Close(Parent)
end event
Hi Andrew
I think you would need to make a windows API call,
try looking at this article https://docs.microsoft.com/en-us/windows/desktop/printdocs/printing-and-print-spooler-functions
Hope that helps
Regards
David
To communicate with the printer you would have to use a totally different method. A post I found on StackOverflow suggest using SNMP but that may be for more high end printers. Each printer manufacturer should have there own API for that.