700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > java 调用TSC打印机

java 调用TSC打印机

时间:2020-04-13 08:28:03

相关推荐

java 调用TSC打印机

JNA 依赖

<dependency><groupId>com.sun.jna</groupId><artifactId>jna</artifactId><version>3.0.9</version></dependency>

demo

// 定义接口CLibrary,继承自com.sun.jna.Library

public interface TscLibDll extends Library {

// msvcrt为dll名称,msvcrt目录的位置为:C:\Windows\System32下面,

TscLibDll INSTANCE = (TscLibDll) Native.loadLibrary(“TSCLIB”, TscLibDll.class);

/*** 显示dll版本* @return*/int about();int openport(String pirnterName);int closeport();int sendcommand(String printerCommand);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 formfeed();int nobackfeed();int windowsfont(int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, String szFaceName, String content);}public static void main(String[] args) {// 调用printf打印信息// TscLibDll.INSTANCE.about();TscLibDll.INSTANCE.openport("TSC TTP-243E Pro");System.setProperty("jna.encoding", "GBK");// 支持中文SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String time = df.format(new Date());String qrCode = "PD10";//TscLibDll.INSTANCE.about();// TscLibDll.INSTANCE.downloadpcx("C:\\Users\\Administrator\\Desktop\\cs\\CS3.PCX", "CS3.PCX");TscLibDll.INSTANCE.setup("55","85","5","8","0","2","0");TscLibDll.INSTANCE.clearbuffer();// TscLibDll.INSTANCE.sendcommand("PUTPCX 200,250,\"CS3.PCX\"");String command = "QRCODE 200,250,Q,8,A,0,M2,S7,\"" + qrCode+"\""; //打印二维码的参数和内容TscLibDll.INSTANCE.sendcommand(command); //传送指令TscLibDll.INSTANCE.windowsfont(260, 100, 36, 180, 0, 0, "arial", "办公耗材-标签纸");TscLibDll.INSTANCE.windowsfont(350, 150, 32, 180, 0, 0, "arial", time);TscLibDll.INSTANCE.nobackfeed();TscLibDll.INSTANCE.printlabel("1", "1");TscLibDll.INSTANCE.closeport();}tspl指令运用 已经验证/*** 打印二维码* @param x x轴* @param y y轴* @param ecc 纠错等级 L M Q H 7%~30%* @param width 高度 1~10* @param mode A自动 M手动* @param rotation 旋转 0~270* @param model 版本 M1 , M2* @param mask S0~S8 默认S7* @param content 内容*/public void setQucode(int x,int y,String ecc,int width,String mode,int rotation,String model,String mask,String content){String command = "QRCODE " +x+","+y+","+ecc+","+width+","+mode+","+rotation+","+model+","+mask+ ",\"" + content+"\"\n"; //打印二维码的参数和内容// TscLibDll.INSTANCE.sendcommand(command);txt = txt + command;}/*** 绘制RSS条码* @param x* @param y* @param sym 条码类型 RSS14,RSS14T* @param rotate 0~270* @param pixMult 模组宽度 1~10* @param sepHt 分隔符高度 1,2* @param segWidth 分段宽度 2~22 偶数* @param linHeight 高度 单位DOT 1~500* @param content 内容*/public void setRss(int x,int y,String sym,String rotate,String pixMult,String sepHt,String segWidth,String linHeight,String content){String command = "RSS " +x+","+y+",\""+sym+"\","+pixMult+","+segWidth+","+linHeight+ ",\"" + content+"\"\n";// TscLibDll.INSTANCE.sendcommand(command);txt = txt + command;}/*** 打印一段文字 (打中文 会打不出)* @param x* @param y* @param font 字体 0~8* @param rotation 文本旋转方向* @param x_mult 水平发大比例 1~10* @param y_mult 垂直放大比例 1~10* @param content 内容*/public void setText(int x,int y,String font,int rotation,int x_mult,int y_mult,String content){String command = "TEXT "+x+","+y+",\""+font+"\","+rotation+","+x_mult+","+y_mult+ ",\"" + content+"\"\n";txt = txt + command;}

本萌新第一次和硬件对接,

折腾了几天 对tsc打印机还不是很熟,打图片死活打不出,如果有大佬研究出了 望教教我,救救孩子吧 (╯‵□′)╯︵┻━┻

DLL 文件 和打印机驱动可以到官网下载

我这就提供下找的其他资料吧 TSPL 指令 的文档等,感兴趣的小伙伴自己研究吧!!!

百度云

链接: /s/1EgErSoK80ncZs3k3K7NaDA 提取码: x8nf

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