How to retrieve cartridges ink level programmatically (Epson StatusMonitor + Mac OS X)?

StackOverflow https://stackoverflow.com/questions/314054

  •  10-07-2019
  •  | 
  •  

Question

I'm looking for a way to query the ink level for my Epson DX 4050 on Mac OS X. There is some UI called EPSON StatusMonitor to display cartridges levels graphically, but I'd like to get it from the command-line so it can feed a robot.

Any idea ?

Was it helpful?

Solution

This is going to be an undertaking. Either reverse engineer the StatusMonitor application to find out how it queries the drivers to find the ink level or look for some documentation for it. It may be possible to poke into the StatusMonitor application to find out internal values for its widgets (such a thing is possible with Windows, though hacky), but the entire process is likely to be a sinkhole for time :(

OTHER TIPS

If the printer supports SNMP you might be lucky to query with any SNMP command-line tool. There are standard definitions for printers and they contain APIs to query the current and max ink levels.

Here's how I do it with simple unix shell commands (requires net-snmp installed). This is not strictly Mac but you should get an idea.

#!/bin/sh

me="${0##*/}"

host="${1:-wp4535}"

base=1.3.6.1.2.1.43.11.1.1

name="WP-4535"

type=$(snmpget -v1 -c public ${host} SNMPv2-MIB::sysDescr.0)

case "$type" in
"SNMPv2-MIB::sysDescr.0 = STRING: EPSON"*)
    type=epson
    ofs=1
;;
*)
    echo "! unknown printer type" 1>&2
    exit 1
;;
esac
echo "# $host $type $name"

# get current ink levels
eval $(snmpwalk -v1 -Ov -OQ -c public ${host} ${base}.6.${ofs} |
perl -ne 'print "c[",++$c,"]=$1\n" if(m!"(\w+) ink!i);')

# get max ink level per cartridge
eval $(snmpwalk -v1 -Ov -OQ -c public ${host} ${base}.8.${ofs} |
perl -ne 'print "max[",++$c,"]=$1\n" if(m!(\d+)!i);')

snmpwalk -v1 -Ov -OQ -c public ${host} ${base}.9.${ofs} |
perl -ne '
    my @c=("","'${c[1]}'","'${c[2]}'","'${c[3]}'","'${c[4]}'");
    my @max=("","'${max[1]}'","'${max[2]}'","'${max[3]}'","'${max[4]}'");
    my $v=$c[++$c];
    printf"# $v=$1 (%.0f)\n",$1/$max[$c]*100 if(m!(\d+)!i);'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top