核心代码
public class PrinterHelper
{
/// <summary>
/// 更新线程
/// </summary>
Thread m_Thread;
/// <summary>
/// 线程阻塞
/// </summary>
AutoResetEvent m_ResetEvent = new AutoResetEvent(true);
/// <summary>
/// 是否工作
/// </summary>
bool m_ThreadIsWork = false;
/// <summary>
/// 是否阻塞
/// </summary>
bool m_ThreadIsPause = true;
/// <summary>
/// 服务器状态
/// </summary>
public delegate void PrinterStatusEventDelegate(int Status, string Message);
/// <summary>
/// 服务器状态
/// </summary>
public event PrinterStatusEventDelegate PrinterStatus;
/// <summary>
/// 打印机名称
/// </summary>
private static string m_PrinterName = string.Empty;
public PrinterHelper(string PrinterName)
{
m_PrinterName = PrinterName;
this.m_Thread = new Thread(new ThreadStart(this.WorkThreedFun));
this.m_Thread.IsBackground = true;
this.m_Thread.Start();
this.m_ThreadIsWork = true;
this.m_ThreadIsPause = false;
this.m_ResetEvent.Set();
}
[DllImport("TSCLIB.dll", EntryPoint = "about")]
public static extern int about();
[DllImport("TSCLIB.dll", EntryPoint = "openport")]
public static extern int openport(string printername);
[DllImport("TSCLIB.dll", EntryPoint = "barcode")]
public static extern int barcode(string x, string y, string type,
string height, string readable, string rotation,
string narrow, string wide, string code);
[DllImport("TSCLIB.dll", EntryPoint = "clearbuffer")]
public static extern int clearbuffer();
[DllImport("TSCLIB.dll", EntryPoint = "closeport")]
public static extern int closeport();
[DllImport("TSCLIB.dll", EntryPoint = "downloadpcx")]
public static extern int downloadpcx(string filename, string image_name);
[DllImport("TSCLIB.dll", EntryPoint = "formfeed")]
public static extern int formfeed();
[DllImport("TSCLIB.dll", EntryPoint = "nobackfeed")]
public static extern int nobackfeed();
[DllImport("TSCLIB.dll", EntryPoint = "printerfont")]
public static extern int printerfont(string x, string y, string fonttype,
string rotation, string xmul, string ymul,
string text);
[DllImport("TSCLIB.dll", EntryPoint = "printlabel")]
public static extern int printlabel(string set, string copy);
[DllImport("TSCLIB.dll", EntryPoint = "sendBinaryData")]
public static extern int sendBinaryData(byte[] content, int length);
//功能:繪製QRCODE二維條碼
//語法:
//QRCODE X, Y, ECC Level, cell width, mode, rotation, [model, mask,]"Data string”
//參數說明
//X QRCODE條碼左上角X座標
//Y QRCODE條碼左上角Y座

本文介绍了一个用于控制打印机并监测其状态的C#类库。该库通过调用TSCLIB.dll实现打印机的初始化、标签内容打印、状态查询等功能。文章详细展示了如何使用这些功能进行打印任务,并提供了具体示例。
最低0.47元/天 解锁文章
3954





