Okay, this is a Windows specific question.
I need to be able to access the ink levels of a printer connected to a computer. Possibly direct connection, or a network connection.
I recognize that it will likely be different for each printer (or printer company at least) but where can I find the information of how they reveal ink levels to a PC. Also, what is the best language to read this information in?
Okay, this is a OS agnostic answer... :-)
If the printer isn't a very cheapo model, it will have built-in support for SNMP (Simple Network Management Protocol). SNMP queries can return current values from the network devices stored in their MIBs (Management Information Bases).
For printers there's a standard defined called Printer MIB. The Printer MIB defines standard names and tree locations (OIDs == Object Identifiers in ASN.1 notation) for
prtMarkerSuppliesLevel
which in the case of ink marking printers map to ink levels.Be aware that SNMP also allows private extensions to the standard MIBs. Most printer vendors do hide many additional pieces of information in their "private MIBs", though the standard info should always be available through the queries of the Printer MIB OIDs.
Practically every programming language has standard libraries which can help you to make specific SNMP queries from your own application.
One such implementation is Open Source, called
Net-SNMP
, which also comes with a few powerfull commandline tools to run SNMP queries.I think the OID to query all levels for all inks is
.1.3.6.1.2.1.43.11.1.1.9
(this webpage confirms my believe) but I cannot verify that right now, because I don't have a printer around in my LAN at the moment. So Net-SNMP'ssnmpget
command to query ink levels should be something like:where
public
is the standard community string and192.168.222.111
your printer's IP address.I really liked tseeling's approach!
Complementarily, I found out that the max value for the OID
... .9
is not 255 as guessed by him, but it actually varies per individual cartridge. The values can be obtained from OID.1.3.6.1.2.1.43.11.1.1.8
(the results obtained by dividing by these values match the ones obtained by running hp-inklevels command from hplip.I wrote my own script that output CSVs like below (suppose printer IP addr is 192.168.1.20):
values are in this order:
<color_name>,<level>,<maxlevel>,<percentage>
The script source (one will notice I usually prefer awk over perl when the puzzle is simple enough):
I have an SNMP-capable HP 8600 pro N911a around to do some digging, so the following commands may help you a bit. Beware that this particular model has some firmware problems, you can't query "magenta" with snmpget, but you see a value with snmpwalk (which does some kind of recursive drill-down).
OLD: You can query the names and sequence of values, but I couldn't find the "max value" to calculate a clean percentage so far ;(. I'm guessing so far the values are relative to 255, so dividing by 2.55 yields a percentage.
Update: Marcelo's hint was great! From Registers .8.* you can read the max level per cartridge, and I was totally wrong assuming the max value can only be an 8-bit value. I have updated the sample script to read the max values and calculate c
There is also some discussion over there at Cacti forums. One answer confirms that the ink levels are measured as percent (value 15 is "percent" in an enumeration):
You need to install the net-snmp package. If you're not on Linux you might need some digging for SNMP command line tools for your preferred OS.
On my Linux box I use the following script to do some pretty-printing: