200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > java通过TscLibDll调用佳博热敏票据打印机(580130IVC)打印小票

java通过TscLibDll调用佳博热敏票据打印机(580130IVC)打印小票

时间:2021-11-04 17:02:20

相关推荐

java通过TscLibDll调用佳博热敏票据打印机(580130IVC)打印小票

需求说明:

在java中通过TscLibDll发送ESC指令到打印机,做一个PC端本地调用票据打印机的小插件,调整打印样式、切纸、蜂鸣,打印机通过网线连接。官方只提供了java调用标签打印机的demo,不太了解这方面,记录一下自己遇到的坑。

1.安装驱动,修改打印机IP地址

580130IVC票据打印机可以通过网线、usb等方式进行连接调用。安装驱动(USB),测试打印机。将打印机连接到路由器,通过官方提供的文档说明打印自测页,查看出厂设置的IP地址。查看电脑本地的IP,记录IP地址。修改电脑本地的IP地址,将打印机连接到电脑上,使电脑和打印机在同一网段,通过官方提供的修改IP工具修改打印机IP,修改后的IP地址和路由器在同一网段。修改完成之后,恢复电脑本地的IP,重新安驱动(网口),安装过程中填写修改后的打印机IP地址。将打印机连接到路由器,打印测试。

说明:找官方的技术支持,会提供修改打印IP地址的说明文档和工具

2.TSCLIB.DLL

TSCLIB.DLL分32位和64位

操作系统为64位放到C:\Windows\System下

操作系统为32位放到C:\Windows\System32下

我的操作系统是64位的,放到C:\Windows\System程序中会提示加载不到,放到C:\Windows\System32下就可以,不知为何,希望大神解惑。

3.调用打印机

在程序中通过打印机名称调用打印机

4.向打印机发送指令

直接上代码

package com.yuqi.utils;import com.jfinal.plugin.activerecord.Record;import com.sun.jna.Library;import com.sun.jna.Native;public class PrinterUtils {private static final String LOAD_LIBRARY="TSCLIB";//打印机private static final String print_model="58130IVC";public interface TscLibDll extends Library{TscLibDll INSTANCE = (TscLibDll) Native.load("TSCLIB", TscLibDll.class);int about ();int openport (String pirnterName);int closeport ();int sendcommand (String printerCommand);int sendBinaryData (byte[] printerCommand, int CommandLength);int setup (String width,String height,String speed,String density,String sensor,String vertical,String offset);int downloadpcx (String filename,String image_name);int barcode (String x,String y,String type,String height,String readable,String rotation,String narrow,String wide,String code);int printerfont (String x,String y,String fonttype,String rotation,String xmul,String ymul,String text);int clearbuffer ();int printlabel (String set, String copy);int windowsfont (int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, String szFaceName, String content);int windowsfontUnicode(int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, String szFaceName, byte[] content);int windowsfontUnicodeLengh(int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, String szFaceName, byte[] content, int length);byte usbportqueryprinter();}public static void main(String[] args){System.loadLibrary(LOAD_LIBRARY);System.setProperty("jna.encoding", "GBK");TscLibDll.INSTANCE.openport(print_model);TscLibDll.INSTANCE.sendcommand("--------------------------------");TscLibDll.INSTANCE.sendcommand("品名\t\t单价 数量 小记");StringBuffer detail = new StringBuffer();String productName = "啦啦啦啦啦";detail.append(productName);if(productName.length() <= 8){detail.append("\t");}detail.append("23.00"+"\t");detail.append("1"+" ");detail.append("23.00");TscLibDll.INSTANCE.sendcommand(detail.toString());TscLibDll.INSTANCE.sendcommand("--------------------------------");TscLibDll.INSTANCE.sendcommand("");TscLibDll.INSTANCE.sendcommand("");TscLibDll.INSTANCE.sendcommand("");TscLibDll.INSTANCE.sendcommand("");//切纸 TscLibDll.INSTANCE.sendBinaryData(Command.CUT_PAPER.getCommandBytes(),Command.CUT_PAPER.getCommandBytes().length);TscLibDll.INSTANCE.closeport();}/*** 蜂鸣*/public static void buzzing(Printer printer){System.loadLibrary(LOAD_LIBRARY);TscLibDll.INSTANCE.openport(printer.getPrinterName());TscLibDll.INSTANCE.sendBinaryData(Command.BUZZING.getCommandBytes(),Command.BUZZING.getCommandBytes().length);TscLibDll.INSTANCE.closeport();}}enum Command {/** 切纸 */CUT_PAPER(new byte[]{0x1D, 0x56, 1}),/** 蜂鸣 */BUZZING(new byte[]{0x1B,0x42,2,6 }),/** 水平居中 */ALINE_CENTER(new byte[]{0x1B,0x61,1 }),/** 左对齐 */ALINE_LEFT(new byte[]{0x1B,0x61,0 }),/** 右对齐 */ALINE_RIGHT(new byte[]{0x1B,0x61,2 }),/** 行间距 */LINE_HEIGHT_DEFAULT(new byte[]{0x1B,0x32}),/** 横向跳格 */SKIP_SPACE(new byte[]{0x1B,0x44,16,20,24,28 });Command(byte[] commandBytes) {mandBytes = commandBytes;}private byte[] commandBytes;public byte[] getCommandBytes() {return commandBytes;}}

到后来才明白TSCLIB.DLL的方法是和tsc指令(标签打印机)相关的,票据打印机的ESC指令需要为十六进制码,通过sendBinaryData()发送,官方有指令说明文档,例如横向跳格、设置相对位置这样的指令现在也不明白怎么用,通过制表符实现对齐

5.成果展示

大致就是这个样子

到现在自己也不是很明白TSCLIB.DLL和ESC指令其中原理,如果有路过的大神希望能指导一下,非常感谢。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。