1. 程式人生 > >TSC打印機使用教程終極版(轉)

TSC打印機使用教程終極版(轉)

src 指令 快速 spl img label 如果 ins height

最近公司做一個資產采集的項目,之前做過此類項目,不過沒有整理資料,借這次機會寫一下,做個記錄。

本教程使用的打印機型號:TSC TTP-244 Plus 官方文檔

一、TSC打印機安裝

1.機器安裝

根據官方快速安裝指南安裝打印機,此處不詳細說明,也可以看視頻教程,唯一需要註意的地方就是碳帶的方向不要裝錯

產品說明書

打印機初始化、感測器校正方法

a) 兩個手指同時按住PAUSE、FEED鍵,不要松手,同時開機。

b) 待三個燈輪流閃時,只松開FEED鍵。待走紙,可松開PAUSE鍵。正常出紙是出大概2-3張標簽紙。

c) 按下FEED鍵,正常出紙為一張標簽紙高度。並停在正常撕紙位置。

2.安裝驅動

驅動下載

安裝完驅動後,在頁面設置修改下紙張大小,打印測試頁。

二、程序調用

1.準備

相關文件:TSPL2指令集(中文版) dll

註冊dll:新建bat文件,復制對應系統版本的命令,把下載的dll和bat命令文件放到同一目錄,執行bat命令。

技術分享圖片
1 set source=.
2 set target=%windir%\system32
3 echo Copy Files...
4 copy %source%\TSCActiveX.dll %target%
5 copy %source%\TSCLIB.dll %target%
6 echo 
Regist Service 7 regsvr32 %target%\TSCActiveX.dll
32位 技術分享圖片
1 set source=.
2 set target=%windir%\sysWOW64
3 echo Copy Files...
4 copy %source%\TSCActiveX.dll %target%
5 copy %source%\TSCLIB.dll %target%
6 echo Regist Service
7 regsvr32 %target%\TSCActiveX.dll
64位系統

2.JavaScript方式調用

技術分享圖片
 1 <script type=text/javascript language=javascript>
 2 var d = new Date();
 3 var time = d.toLocaleString();
 4 var TSCObj;
 5 TSCObj = new ActiveXObject("TSCActiveX.TSCLIB");//引入插件
 6 //TSCObj.ActiveXabout();
 7 TSCObj.ActiveXopenport ("TSC TTP-244 Plus");//打開打印機端口
 8 TSCObj.ActiveXsetup ("99.5","70","5","8","0","2","0");//設置初始參數
 9 //TSCObj.ActiveXformfeed();
10 //TSCObj.ActiveXnobackfeed();
11 TSCObj.ActiveXsendcommand ("SET TEAR ON");
12 TSCObj.ActiveXclearbuffer();
13 TSCObj.ActiveXwindowsfont (260, 100, 36, 0, 0, 0, "arial", "辦公耗材-標簽紙");//打印文本
14 TSCObj.ActiveXwindowsfont (450, 170, 32, 0, 0, 0, "arial", time);//打印時間
15 //BARCODE X,Y,”code type”,height,human readable,rotation,narrow,wide,[alignment,]”content“
16 TSCObj.ActiveXbarcode ("100", "300", "128", "100", "2", "0", "2", "2", "PD102011");//打印條碼
17 TSCObj.ActiveXprintlabel ("1","1");
18 TSCObj.ActiveXcloseport();//關閉端口
19 </script>
20 
21 Javascript代碼
JavaScript

3.C#調用

技術分享圖片
 1 #region 調用TSC打印機打印條碼
 2         /// <summary>
 3         /// 調用TSC打印機打印條碼
 4         /// </summary>
 5         /// <param name="title">打印的標題</param>
 6         /// <param name="barCode">打印的條碼編號</param>
 7         public static void TSC(string title, string barCode)
 8         {
 9             // 打開 打印機 端口.
10             TSCLIB_DLL.openport(p_port);
11             // 設置標簽 寬度、高度 等信息.
12             // 寬 94mm  高 25mm
13             // 速度為4
14             // 字體濃度為8
15             // 使用垂直間距感測器(gap sensor)
16             // 兩個標簽之間的  間距為 3.5mm
17             TSCLIB_DLL.setup("94", "25", "4", "8", "0", "3.5", "0");
18             // 清除緩沖信息
19             TSCLIB_DLL.clearbuffer();
20             // 發送 TSPL 指令.
21             // 設置 打印的方向.
22             TSCLIB_DLL.sendcommand("DIRECTION 1");
23             // 打印文本信息.
24             // 在 (176, 16) 的坐標上
25             // 字體高度為34
26             // 旋轉的角度為 0 度
27             // 2 表示 粗體.
28             // 文字沒有下劃線.
29             // 字體為 黑體.
30             // 打印的內容為:title
31             TSCLIB_DLL.windowsfont(176, 16, 34, 0, 2, 0, "宋體", title);
32             // 打印條碼.
33             // 在 (176, 66) 的坐標上
34             // 以 Code39 的條碼方式
35             // 條碼高度 130
36             // 打印條碼的同時,還打印條碼的文本信息.
37             // 旋轉的角度為 0 度
38             // 條碼 寬 窄 比例因子為 7:12
39             // 條碼內容為:barCode
40             TSCLIB_DLL.barcode("176", "66", "39", "130", "1", "0", "7", "12", barCode);
41             // 打印.
42             TSCLIB_DLL.printlabel("1", "1");
43             // 關閉 打印機 端口
44             TSCLIB_DLL.closeport();
45         }
46 #endregion
47 
48 C#代碼
C#代碼

4.Java調用

解壓文件,將jna.jar包添加到項目 下載地址  

本示例打印的是二維碼,由於官方文檔中沒有重寫打印二維碼的方法,我也懶得寫了,直接使用的發送命令的方式打印。

技術分享圖片
 1 package com.zmkj.momo.admin;
 2 
 3 import com.sun.jna.Library;
 4 import com.sun.jna.Native;
 5 
 6 import java.text.SimpleDateFormat;
 7 import java.util.Date;
 8 
 9 /**
10  * TSC打印機測試
11  */
12 public class TscPrint {
13     public interface TscLibDll extends Library {
14         TscLibDll INSTANCE = (TscLibDll) Native.loadLibrary("TSCLIB", TscLibDll.class);
15         int about();
16         int openport(String pirnterName);
17         int closeport();
18         int sendcommand(String printerCommand);
19         int setup(String width, String height, String speed, String density, String sensor, String vertical, String offset);
20         int downloadpcx(String filename, String image_name);
21         int barcode(String x, String y, String type, String height, String readable, String rotation, String narrow, String wide, String code);
22         int printerfont(String x, String y, String fonttype, String rotation, String xmul, String ymul, String text);
23         int clearbuffer();
24         int printlabel(String set, String copy);
25         int formfeed();
26         int nobackfeed();
27         int windowsfont(int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, String szFaceName, String content);
28     }
29 
30 
31     public static void main(String[] args) {
32         System.setProperty("jna.encoding", "GBK");// 支持中文
33         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
34         String time = df.format(new Date());
35         String qrCode = "PD102011";
36         //TscLibDll.INSTANCE.about();
37         TscLibDll.INSTANCE.openport("TSC TTP-244 Plus");
38         //TscLibDll.INSTANCE.downloadpcx("C:\\UL.PCX", "UL.PCX");
39         TscLibDll.INSTANCE.setup("99.5","70","5","8","0","2","0");
40         TscLibDll.INSTANCE.clearbuffer();
41         //TscLibDll.INSTANCE.sendcommand("PUTPCX 550,10,\"UL.PCX\"");
42         String command = "QRCODE 300,250,Q,8,A,0,M2,S7,\"" + qrCode+"\""; //打印二維碼的參數和內容
43         TscLibDll.INSTANCE.sendcommand(command); //傳送指令
44         TscLibDll.INSTANCE.windowsfont(260, 100, 36, 0, 0, 0, "arial", "辦公耗材-標簽紙");
45         TscLibDll.INSTANCE.windowsfont(450, 150, 32, 0, 0, 0, "arial", time);
46         TscLibDll.INSTANCE.printlabel("1", "1");
47         TscLibDll.INSTANCE.closeport();
48     }
49 }
50 
51 Java代碼
Java代碼

如果運行報錯UnsatisfiedLinkError: Unable to load library “TSCLIB”...可以嘗試把JDK換成32位版本。

在調用過程中有不明白的地方看TSPL2說明書,上面有詳細的指令用法以及參數說明!!!

TSC打印機使用教程終極版(轉)