有没有办法使用
java套接字程序找到打印机状态?该程序需要确定打印机状态.如
>打印机开/关/ IDEAL.
>目前的工作.
>尝试纸张水平.
>碳粉离开.
我使用了javax.print API,这有助于我在打印机中打印文档并列出4个属性
> printer-is-accepting-jobs:接受工作
> printer-name:myPrinter
>排队作业计数:0
>支持颜色:不支持
有些人让我用snmp4j或LPR知道状态.
我用snmp写了一个应用程序.我无法成功.您可以在链接snmp application之后找到代码表.在此代码中(第38行SNMPManager客户端=新SNMPManager(“udp:127.0.0.1/161”);我们需要提供打印机的IP地址.所以我给了tcp / ip:127.0.0.1/161)我在线程“main”java.lang.IllegalArgumentException中遇到异常异常:地址类型tcp / ip unknown,我期待帮助解决这个问题.
PrintService printer = PrintServiceLookup.lookupDefaultPrintService();
AttributeSet att = printer.getAttributes();
for (Attribute a : att.toArray()) {
String attributeName;
String attributeValue;
attributeName = a.getName();
attributeValue = att.get(a.getClass()).toString();
String gh = (attributeName + " : " + attributeValue);
if (gh.equals("printer-is-accepting-jobs : not-accepting-jobs")) {
JOptionPane.showMessageDialog(rootPane, "Printer Not Available");
}
if (gh.equals("queued-job-count : 0")) {
JOptionPane.showMessageDialog(rootPane, gh);
}
System.out.println(gh);
}