- USB printer status - Windows XP
- Posted by Guillaume on April 6th, 2005
Dear All,
I would like to retrieve the status of an USB printer under Windows XP
so that it be possible to know *before* printing whether the printer is
operational.
I had a look at the Microsoft article "How To Get the Status of a
Printer and a Print Job" Q160129 but it is not what I require as the
actual status of the printer is refreshed only during the despool of
print jobs (i.e. after printing).
Thus, I figured out that I had to:
- Communicate directly to the printer driver (bypassing the spooler)
using the "USB Device Class for Printing Devices". (DDK usbprint.h
header file.)
- Request the ieee 1284-like device id (probably using
IOCTL_USBPRINT_GET_1284_ID request).
- Retrieve the printer status information from the printer device id.
I used DDK to retrieve the USB devices (using SetupDiGetClassDevs with
GUID_DEVINTERFACE_USB_DEVICE guid), to find device interfaces (using
SetupDiGetInterfaceDevice) and to find the printer's device path (using
SetupDiGetInterfaceDetails). Then I tried to open the USB device using
CreateFile as follow:
HANDLE hUsbDevice = CreateFile(
DeviceInterfaceDetailData->DevicePath,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
(LPSECURITY_ATTRIBUTES)NULL,
OPEN_EXISTING,
0,
NULL);
But this failed returning "A device attached to the system is not
functioning." (Which is weird as the printer is connected and
works...).
- Did I follow the right method? Does Windows provide easier method to
retrieve the actual printer status? How to use the
IOCTL_USBPRINT_GET_1284_ID function included in the usbprint.h?
- How to use CreateFile to open my device? Can someone provide me with
sample code?
What am I missing? Please help! I am stuck for days on this issue.
Thanking you in advance,
Guillaume.
- Posted by Manfred Wilner on April 7th, 2005
Guillaume you need to develop a Language Monitor for this purpose.
To start with you can take a look at DDK's pjlmon.
You need to modify all the code related to your printer.
e.g. delete all PJL code if you have a raster printer, etc.
\Manfred
"Guillaume" <guillaume.gerard@gmail.com> wrote in message
news:1112798530.942669.111780@l41g2000cwc.googlegr oups.com...
- Posted by Guillaume on April 7th, 2005
Thanks a lot Manfred! I'll have a look at DDK's pjlmon.
Guillaume.
Manfred Wilner wrote:
- Posted by Guillaume on April 7th, 2005
Thanks again for your answer.
I had a look to the sample. But, supposing I develop a language
monitor, how can I use it from an application? For instance, how can I
send PJL commands to a printer (via pjlmon) and get an answer from an
application?
- Posted by Manfred Wilner on April 7th, 2005
You aren't unless you want to build a custom function into your Language
Monitor.
The Language Monitor has to have a read thread where it reads the feedback
from the printer.
This you can store in the registry and then you provide a customized
GetPrinterDataFromPort function in you Language Monitor and then you can get
these registry entries with GetPrinterData.
\Manfred
"Guillaume" <guillaume.gerard@gmail.com> wrote in message
news:1112869731.387707.159930@z14g2000cwz.googlegr oups.com...
- Posted by Guillaume on April 11th, 2005
Once again, thank you for your answer.
My point is now how to manage to send/receive PJL request to/from a
printer in a Language Monitor?
Guillaume.
- Posted by Guillaume on April 11th, 2005
Once again, thanks for your reply.
Have you ever try to use the GDI Bidi Communication Support? Can I
avoid developing a Language Monitor if I use this with a PJL printer?
- Posted by Guillaume on April 27th, 2005
I managed to send PJL data to a specific USB Lexmark E321 printer
following thoses steps:
=> Get device ID from printer name. (using GDI)
* using OpenPrinter and GetPrinterDataEx to obtain
DeviceInstanceId value of the PnPData registry key.
=> Get printer symbolic path from device ID. (using Setupapi)
* using SetupDiOpenDeviceInfo to retrieve SP_DEVINFO_DATA
struct from device ID
* then using SetupDiGetClassDevs and
SetupDiEnumDeviceInterfaces to retrieve USB device interfaces. The
right USB device is retrieved comparing device ID.
* the SetupDiGetDeviceInterfaceDetail provides the symbolic
path.
=> Open the device and write/read data to/from it.
* This is performed using CreateFile / ReadFile / WriteFile
from communication API.
This works well with the USB Lexmark printer.
The CreateFile fails when trying to use my program with a USB HP
Laserjet 1320. (Error: ERROR_GEN_FAILURE "A device attached to the
system is not functioning.")
Any idea?