如何以编程方式检索墨盒墨水量(Epson StatusMonitor + Mac OS X)?

发布于 2024-07-10 07:52:28 字数 134 浏览 11 评论 0原文

我正在寻找一种方法来查询 Mac OS X 上 Epson DX 4050 的墨水量。有一些名为 EPSON StatusMonitor 的 UI 可以以图形方式显示墨盒墨水量,但我想从命令行获取它,以便它可以喂机器人。

任何想法 ?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生生不灭 2024-07-17 07:52:28

这将是一项事业。 对 StatusMonitor 应用程序进行逆向工程以了解它如何查询驱动程序以查找墨水量,或者查找一些相关文档。 或许可以深入研究 StatusMonitor 应用程序来找出其小部件的内部值(这种事情在 Windows 中是可能的,尽管很 hacky),但整个过程很可能是一个时间坑:(

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 :(

家住魔仙堡 2024-07-17 07:52:28

如果打印机支持 SNMP,您可能会幸运地使用任何 SNMP 命令行工具进行查询。 打印机有标准定义,它们包含用于查询当前和最大墨水量的 API。

以下是我如何使用简单的 unix shell 命令来完成此操作(需要安装 net-snmp)。 这不是严格意义上的 Mac,但您应该有一个想法。

#!/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);'

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);'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文