如何以编程方式访问打印机的墨水量? [英] How can I access ink levels of printers programmatically?

查看:63
本文介绍了如何以编程方式访问打印机的墨水量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是一个特定于 Windows 的问题.

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.

我意识到每台打印机(或至少是打印机公司)的情况可能会有所不同,但我在哪里可以找到有关它们如何向 PC 显示墨水量的信息.另外,阅读此信息的最佳语言是什么?

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... :-)

如果打印机不是很便宜的型号,它将内置对 SNMP(简单网络管理协议).SNMP 查询可以从存储在其 MIB(管理信息库)中的网络设备返回当前值.

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).

对于打印机,定义了一个标准,称为打印机 MIB.打印机 MIB 定义了标准名称和树位置(ASN 中的 OID == 对象标识符.1 个符号)用于 prtMarkerSuppliesLevel,在油墨标记打印机的情况下,它映射到油墨水平.

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.

请注意,SNMP 还允许对标准 MIB 进行私有扩展.大多数打印机供应商确实在他们的私有 MIB"中隐藏了许多额外的信息,尽管标准信息应该始终可以通过打印机 MIB OID 的查询获得.

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.

几乎每种编程语言都有标准库,可以帮助您从自己的应用程序中进行特定的 SNMP 查询.

Practically every programming language has standard libraries which can help you to make specific SNMP queries from your own application.

一个这样的实现是开源的,称为Net-SNMP,它还附带了一些强大的命令行工具来运行 SNMP 查询.

One such implementation is Open Source, called Net-SNMP, which also comes with a few powerfull commandline tools to run SNMP queries.

认为查询所有墨水的所有级别的 OID 是 .1.3.6.1.2.1.43.11.1.1.9 (此网页 证实了我的看法)但我现在无法验证,因为我周围没有打印机目前在我的局域网中.所以 Net-SNMP 的 snmpget 命令来查询墨水量应该是这样的:

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's snmpget command to query ink levels should be something like:

snmpget                       \
  -c public                   \
   192.168.222.111            \
   ".1.3.6.1.2.1.43.11.1.1.9"

其中 public 是标准的社区字符串192.168.222.111 您打印机的 IP 地址.

where public is the standard community string and 192.168.222.111 your printer's IP address.

这篇关于如何以编程方式访问打印机的墨水量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆