我正在尝试开发一个应用程序,将使用标签打印机(霍尼韦尔个人电脑42T)作为其主要打印机。这台特定的打印机没有针对android的特定SDK,所以我不得不绕过它,直接使用它的语言直接向这台打印机发送命令。根据示例代码here和here,我编写了一段代码在上面打印。
代码如下:
Thread thread = new Thread(() -> {
try
{
Socket sock = new Socket("192.168.199.106", 9100);
PrintWriter oStream = new PrintWriter(sock.getOutputStream());
oStream.println("PP 25,35"); // Command to set print starting position
oStream.println("PT This is a test"); // Command to set text
oStream.println("PF"); // Command to feed the label after printing
oStream.println("PRINT KEY OFF"); // Command to finish printing
oStream.close();
sock.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
});
thread.start();此代码将输入标签,但不会在标签上打印。
以前有没有人有过这方面的经验?谢谢。
发布于 2020-08-14 21:32:46
我和你有同样的问题,也许你想试试ZPL,因为在PC42t的描述中提到这台打印机与ZPL兼容。
得益于诸如直接协议(DP)、ZSim (ZPL-II)、ESim (EPL)等众多模拟功能,
与现有和新的打印环境的集成速度特别快,特别是因为打印机语言是自动识别的,并且无需任何预设置。
您可以看看这个Java库(归功于创建者w3blogfr):https://github.com/w3blogfr/zebra-zpl
我已经使用了这个库,并且工作正常。
https://stackoverflow.com/questions/58072488
复制相似问题