[cups-devel] How to status/error of printer like connected or disconnected using cups

Michael Sweet msweet at apple.com
Sat Oct 1 11:56:19 PDT 2016


Shobin,

> On Sep 29, 2016, at 7:23 AM, Balakrishnan, Shobin <shobin.balakrishnan at opwglobal.com> wrote:
> 
> Hi,
> 
> 
>   I am working on linux platform.I made an application that can print a file. The application runs in realtime, I needed it to handle the printer status/error such as:
> 
> 1. Printer connected or disconnected
> 2. Printer turned off
> 3. Printer out of paper
> 4. Printer out of ink
> 
> My question is: how can I handle those status/errors above with CUPS? As I see it, there's no straightforward way to check whether a printer is out of paper or ink. So I guess I have to make another way.Please help me ASAP.

The printer state is reflected in the printer-state-reasons attribute, which is part of the destination options in the cups_dest_t structure.  Use cupsGetDests, cupsGetNamedDest, or cupsEnumDests to get the current (cached) printer state and then cupsGetOption("printer-state-reasons", dest->num_options, dest->options) to get a comma-delimited list of state strings for the print queue.  There is no reason for "printer turned off" (we cannot detect that) but the following list should be useful (may have "-error", "-report", or "-warn" appended):

- "connecting-to-device": Trying to connect to printer
- "offline-report": Unable to connect to printer (offline, disconnected, or turned off)
- "marker-supply-low": Low ink
- "marker-supply-empty": Out of ink
- "marker-waste-almost-full": Waste tank almost full
- "marker-waste-full": Waste thank full
- "toner-low": Low toner
- "toner-empty": Out of toner
- "media-low": Low paper
- "media-empty": Out of paper
- "media-needed": Paper needed to complete job

Note that this state is only updated when printing, so it can be stale compared to the actual printer.  There is no API  to update the state independent of a print job, but you can (often) print a "CUPS command" job to update things - see:

    https://www.cups.org/doc/spec-command.html#ReportLevels

for more information on CUPS command files.

_________________________________________________________
Michael Sweet, Senior Printing System Engineer




More information about the cups mailing list