标签打印机:TSC TTP-244 Pro
打印机驱动:file:///C:/Users/admin/Downloads/tsc_2022.1_m-2.exe_1.zip
官方文档预览下载: https://fs.chinatsc.cn/system/files/tspl_tspl2_programming_2018_5_17_scjiantizhongwen.pdf
官方给出的参考案例:file:///C:/Users/admin/Downloads/tsc_java-example.zip
官方资料下载地址:https://www.chinatsc.cn/zh-CN/downloads
官方案例
package com.tscsdk; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.util.Arrays; import com.sun.jna.Library; import com.sun.jna.Native; public class JavaTest { public interface TscLibDll extends Library { TscLibDll INSTANCE = (TscLibDll) Native.loadLibrary("\\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) { String WT1 = "TSC Printers"; String B1 = "20080101"; //unicode format byte[] result_unicode = new byte[1024]; String word_unicode = "简体中文测试123123繁體測試"; result_unicode = word_unicode.getBytes(StandardCharsets.UTF_16LE); //utf-8 format byte[] result_utf8 = new byte[1024]; String word_utf8 = "TEXT 40,620,\"ARIAL.TTF\",0,12,12,\"utf8 test Wörter auf Deutsch\""; result_utf8 = word_utf8.getBytes(StandardCharsets.UTF_8); //TSCLIB_DLL.about(); byte status = TscLibDll.INSTANCE.usbportqueryprinter();//0 = idle, 1 = head open, 16 = pause, following <ESC>!? command of TSPL manual TscLibDll.INSTANCE.openport("TSC TE210"); TscLibDll.INSTANCE.sendcommand("SIZE 100 mm, 120 mm"); TscLibDll.INSTANCE.sendcommand("SPEED 4"); TscLibDll.INSTANCE.sendcommand("DENSITY 12"); TscLibDll.INSTANCE.sendcommand("DIRECTION 1"); TscLibDll.INSTANCE.sendcommand("SET TEAR ON"); TscLibDll.INSTANCE.sendcommand("CODEPAGE UTF-8"); TscLibDll.INSTANCE.clearbuffer(); TscLibDll.INSTANCE.downloadpcx("\\UL.PCX", "UL.PCX"); TscLibDll.INSTANCE.windowsfont(40, 490, 48, 0, 0, 0, "Arial", "Windows Font Test"); TscLibDll.INSTANCE.windowsfontUnicodeLengh(40, 550, 48, 0, 0, 0, "Arial", result_unicode,word_unicode.length()); TscLibDll.INSTANCE.sendcommand("PUTPCX 40,40,\"UL.PCX\""); TscLibDll.INSTANCE.sendBinaryData(result_utf8, result_utf8.length); TscLibDll.INSTANCE.barcode("40", "300", "128", "80", "1", "0", "2", "2", B1); TscLibDll.INSTANCE.printerfont("40", "440", "0", "0", "15", "15", WT1); TscLibDll.INSTANCE.printlabel("1", "1"); TscLibDll.INSTANCE.closeport(); } }
使用案例
1、连续打印条码,条码流水号递增
public static void demo() { // 支持中文 System.setProperty("jna.encoding","GBK"); TscLibDll.INSTANCE.openport(printInfo.getName()); TscLibDll.INSTANCE.clearbuffer(); TscLibDll.INSTANCE.sendcommand("SIZE 70mm,70mm"); TscLibDll.INSTANCE.sendcommand("GAP 3mm, 0mmn"); TscLibDll.INSTANCE.sendcommand("DIRECTION 1"); // 打印机有61个计数器(@0 ~ @60),使用@1计数器,每次递增 1 TscLibDll.INSTANCE.sendcommand("SET COUNTER @1 1"); TscLibDll.INSTANCE.sendcommand("@1 =\"01-XT01-2303220001\""); TscLibDll.INSTANCE.sendcommand("CLS"); TscLibDll.INSTANCE.sendcommand("BARCODE 100,50,\"128\",100,1,0,2,2,@1"); TscLibDll.INSTANCE.sendcommand("PRINT 1,5); TscLibDll.INSTANCE.closeport(); }
打印结果
01-XT01-2303220001
01-XT01-2303220002
01-XT01-2303220003
01-XT01-2303220004
01-XT01-2303220005
2、打印二维码
TscLibDll.INSTANCE.sendcommand("QRCODE 10,10,H,4,A,0,\"ABCabc123\"");
标签:打印机,Java,String,int,标签,INSTANCE,TscLibDll,byte,sendcommand From: https://www.cnblogs.com/shycnblogs/p/17243454.html