【问题标题】:Is there a way to get the status of a thermal printer using ESC commands?有没有办法使用 ESC 命令获取热敏打印机的状态?
【发布时间】:2019-10-01 10:50:20
【问题描述】:

我正在向库escpos-coffee添加一个方法,它返回热敏打印机的状态,即是否在线/离线,是否正在结束纸张或纸张已完成,或者钱箱是否打开/关闭。

我在 escpos-coffee 库中添加了一个方法“showPrinterStatus”,它基于ESC c 3 命令,它以字节形式将命令发送到打印机。该方法据说启用了卷纸即将用完传感器,以及卷纸用完传感器。此外,我添加了另一种方法“transmitStatus”,基于GS r 命令,它传输 n=1 和 n=49 的纸张传感器状态,以及 n=2 和 n=50 的现金抽屉状态。代码如下:

 /**
     *
     * @param nSignal
     * @return
     * @throws IOException
     * Method decides whether the printer should return an output paper-end signal to a parallel interface or not
     * input 1,2 4,8 to enable, 0 to disable
     */

    public EscPos showPrinterStatus(int nSignal)  throws IOException {
        write(27);
        write('c');
        write('3');
        write(nSignal);
        return this;
    }

    /**
     *
     * @param n
     * @return
     * @throws IOException
     * returns the status of the printer, 1 or 49 returns paper sensor status, 2 or 50 returns drawer kick-out connector status
     */
    public EscPos transmitStatus(int n) throws IOException{
      write(29);
      write('r');
      return this;
    }

我正在使用 Device Monitoring Studio,预计会有一些可见的通信。看起来 showPrinterStatus 方法正在向热敏打印机发送信号,但 transmitStatus 方法似乎根本没有引起任何通信。此外,如果我检查现金抽屉状态并让现金抽屉保持打开状态,则根本没有通信,请求只是排队。一旦我推回现金抽屉,打印机执行命令需要 5-10 分钟,而打印机一直在队列中。

在我的实现中是否有什么我忘记了,或者有没有比 Device Monitoring Studio 更好的方法来显示打印机状态?

【问题讨论】:

    标签: java printing thermal-printer epson escpos


    【解决方案1】:

    我有同样的问题,但我是通过 USB 连接的,尝试使用串行端口,然后从中读取。我不是 Java 开发人员,但这是我在 python 中的解决方案

    from serial import Serial
    serial = Serial('/dev/ttyUSB0', 115200, timeout=.03)
    serial.write(b'\x10\x04\x01')
    serial.read()
    

    另一种方法是通过终端(如果您使用的是 linux)

    echo -n '\x10\x04\x01' > /dev/usb/lp0 #assuming lp0 is your printer 
    
    cat /dev/usb/lp0 
    

    它输出缓冲区中的数据,而不是打印在纸上

    【讨论】:

      【解决方案2】:

      如果您使用的是usb接口,您可以尝试使用usb4java lib,然后您可以从打印机读取字节,对我来说它适用于linux并显示门打开或纸张结束...,但我还没有在windows上测试过...

      UsbEndpoint endpointIn = iface.getUsbEndpoint(endpointAddressIn);
      UsbPipe pipeIn = endpointIn.getUsbPipe();
      pipeIn.open();
      byte[] data = new byte[1024];
      int received;
      received = pipeIn.syncSubmit(data);
      pipeIn.close();
      

      完整代码在github上:Usb Printer Status

      【讨论】:

        猜你喜欢
        • 2020-09-22
        • 1970-01-01
        • 1970-01-01
        • 2011-06-19
        • 2015-08-20
        • 1970-01-01
        • 2012-07-19
        • 2014-06-27
        • 2019-08-15
        相关资源
        最近更新 更多