博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TSC条码打印机C#例程(tsclib.dll调用) 【转】
阅读量:6259 次
发布时间:2019-06-22

本文共 5450 字,大约阅读时间需要 18 分钟。

//----  program.cs

using System;

using System.Collections.Generic;
using System.Windows.Forms;

using System.Runtime.InteropServices;

public class TSCLIB_DLL
{
 [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 = "sendcommand")]

    public static extern int sendcommand(string printercommand);

 [DllImport("TSCLIB.dll", EntryPoint = "setup")]

    public static extern int setup(string width, string height,
              string speed, string density,
              string sensor, string vertical,
              string offset);

 [DllImport("TSCLIB.dll", EntryPoint = "windowsfont")]

    public static extern int windowsfont(int x, int y, int fontheight,
     int rotation,  int fontstyle, int fontunderline,
                    string szFaceName, string content);
  
}

namespace TSCLIB_DLL_IN_C_Sharp
{
    static class Program
    {
        /// <summary>
        /// 應用程式的主要進入點。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

 

 

//----Form1.cs

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TSCLIB_DLL_IN_C_Sharp

{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)

        {
            //TSCLIB_DLL.about();                                                                //Show the DLL version
            TSCLIB_DLL.openport("TSC TTP-344M Plus");                                          //Open specified printer driver
            TSCLIB_DLL.setup("100", "63.5", "4", "8", "0", "0", "0");                          //Setup the media size and sensor type info
            TSCLIB_DLL.clearbuffer();                                                          //Clear image buffer
            TSCLIB_DLL.barcode("100", "100", "128", "100", "1", "0", "2", "2", "Barcode Test"); //Drawing barcode
            TSCLIB_DLL.printerfont("100", "250", "3", "0", "1", "1", "Print Font Test");       //Drawing printer font
            TSCLIB_DLL.windowsfont(100, 300, 24, 0, 0, 0, "ARIAL", "Windows Arial Font Test"); //Draw windows font
            TSCLIB_DLL.downloadpcx("UL.PCX", "UL.PCX");                                        //Download PCX file into printer
            TSCLIB_DLL.sendcommand("PUTPCX 100,400,"UL.PCX"");                               //Drawing PCX graphic
            TSCLIB_DLL.printlabel("1", "1");                                                   //Print labels
            TSCLIB_DLL.closeport();                                                            //Close specified printer driver
           
        }
    }
}

 

 

//------ 另例

  [System.Runtime.InteropServices.DllImport("tsclib.dll")]

  private static extern void windowsfont(int a, int b, int c,int d,int e ,int f, string g ,string h);
  [System.Runtime.InteropServices.DllImport("tsclib.dll")]
  private static extern void openport(string printername);
  [System.Runtime.InteropServices.DllImport("tsclib.dll")]
  private static extern void closeport();
  [System.Runtime.InteropServices.DllImport("tsclib.dll")]
  private static extern void sendcommand(string command);
  [System.Runtime.InteropServices.DllImport("tsclib.dll")]
  private static extern void setup(string width,string height,string speed,string density,string sensor,string vertical,string offset);
  [System.Runtime.InteropServices.DllImport("tsclib.dll")]
  private static extern void clearbuffer();
  [System.Runtime.InteropServices.DllImport("tsclib.dll")]
  private static extern void printlabel(string Set,string Copy);

  private void button1_Click(object sender, System.EventArgs e)
  {
   openport("TSC TTP-343");
   setup("100","65","3","10","0","3","0");
   clearbuffer();
   windowsfont(50,30,70,0,0,0,"黑体","索书号:");
   printlabel("1", "1");
   closeport();
  }

 

 

 

#region 调用TSC打印机打印条码

        /// <summary>
        /// 调用TSC打印机打印条码
        /// </summary>
        /// <param name="title">打印的标题</param>
        /// <param name="barCode">打印的条码编号</param>
        public static void TSC(string title, string barCode)
        {
            // 打开 打印机 端口.
            TSCLIB_DLL.openport(p_port);
            // 设置标签 宽度、高度 等信息.
            // 宽 94mm  高 25mm
            // 速度为4
            // 字体浓度为8
            // 使用垂直間距感測器(gap sensor)
            // 两个标签之间的  间距为 3.5mm
            TSCLIB_DLL.setup("94", "25", "4", "8", "0", "3.5", "0");
            // 清除缓冲信息
            TSCLIB_DLL.clearbuffer();
            // 发送 TSPL 指令.
            // 设置 打印的方向.
            TSCLIB_DLL.sendcommand("DIRECTION 1");
            // 打印文本信息.
            // 在 (176, 16) 的坐标上
            // 字体高度为34
            // 旋转的角度为 0 度
            // 2 表示 粗体.
            // 文字没有下划线.
            // 字体为 黑体.
            // 打印的内容为:title
            TSCLIB_DLL.windowsfont(176, 16, 34, 0, 2, 0, "宋体", title);
            // 打印条码.
            // 在 (176, 66) 的坐标上
            // 以 Code39 的条码方式
            // 条码高度 130
            // 打印条码的同时,还打印条码的文本信息.
            // 旋转的角度为 0 度
            // 条码 宽 窄 比例因子为 7:12
            // 条码内容为:barCode
            TSCLIB_DLL.barcode("176", "66", "39", "130", "1", "0", "7", "12", barCode);
            // 打印.
            TSCLIB_DLL.printlabel("1", "1");
            // 关闭 打印机 端口
            TSCLIB_DLL.closeport();
        }
#endregion

 

转载于:https://www.cnblogs.com/liujianshe1990-/p/10676388.html

你可能感兴趣的文章
飞舞的蝴蝶
查看>>
Linux环境下C语言模拟内存负载测试
查看>>
专栏《轻松玩转ELK海量可视化日志分析系统》已完结【附代码下载】
查看>>
新手IT人员,如何找到适合自己专业书籍的6个问题?
查看>>
初学者学习linux运维的几个问题及老鸟建议
查看>>
Server 2008 R2 AD RMS完整部署:RMS部署篇
查看>>
SFB 项目经验-45-用培训课件当运维文档,聪明
查看>>
使用Kubernetes创建PHP留言板系统
查看>>
时间管理,从洗碗开始
查看>>
我用EDM卖约会秘籍的半个月
查看>>
运营这个职业的诞生缘由「社区运营入门系列④」
查看>>
在VMM2012R2中使用二代虚拟机创建的模板无法创建虚拟机的解决方法
查看>>
大道至简 电话号码重新成为O2O新宠
查看>>
Office 365离线安装
查看>>
jar包与was版本不兼容怎么办
查看>>
将Windows Server 2008 R2网络升级到Windows Server 2012
查看>>
修改计算机名的注意事项
查看>>
WIN7关闭共享后怎样去掉图标上的小锁
查看>>
SRV记录注册不成功的可能的原因
查看>>
一步完成 MySQL 向 Redis 迁移
查看>>