1. 程式人生 > 其它 >c# .net 呼叫TSC印表機

c# .net 呼叫TSC印表機

TSC標籤印表機傳統的呼叫方法是利用 TSCLIB.DLL這個檔案進行列印。這個DLL檔案是C++寫的,在.NET環境中只能通過宣告DLL函式的方法進行呼叫。最近在查詢TSC官網的時候才現TSC釋出了.NET環境下用的DLL檔案,可以直接在專案中通過引用的方式實現呼叫。這個檔案比TSCLIB.DLL的優勢在於自帶處理各種字符集的方法,不用列印時各種轉碼。而且列印圖片也更簡單(沒有測試)。

DLL檔案下載地址為:https://www.chinatsc.cn/SC/support/support_download/TX200_Series/DLL--_SDK 開啟頁面後選擇[軟體開發工具包]-[DLL/SDK]-[Windows Framework DLL (32 bit & 64 bit)]

但是官網上沒有呼叫方法的範例,也沒有相關的文件,只有一個光禿禿的DLL檔案。這裡真要吐槽一下TSC的文件,其本上都是10年前寫的,產品更新文件卻不更新。自己摸索了一下,實現了一個列印二維碼,解決了直接呼叫TSCLIB.DLL時,二維碼內容含中文時掃出來有亂碼的問題。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks; using log4net; using TSCSDK; namespace CBSP { public class PrintHelpter { public static void PrintTest(dynamic bundle) { TSCSDK.driver usbprint = new driver(); if (usbprint.openport(PRINT_NAME)) {
int w= bundle.w; int h=bundle.h; int g=bundle.g; float l = bundle.l; float t = bundle.t; usbprint.clearbuffer(); // 紙回拉指定長度 //TSC_DLL.sendcommand("BACKFEED 60"); //二維碼 //需要清除上一次的列印記憶 usbprint.sendcommand("CLS"); usbprint.setup(w.ToString(), h.ToString(), "4", "15", "0", g.ToString(), "0"); string command = "QRCODE " + (int)(5) + "," + (int)(5) + ",H,8,A,0,M2,\"" + "p這是一段中文" + "\""; //System.Windows.Forms.MessageBox.Show(status); usbprint.sendcommand_utf8(command); usbprint.printlabel("1", "1"); usbprint.closeport(); } } } }