tsc 利用dll打印 c#

函数说明

1.  openp*t(a)

说明: 指定计算机端的输出端口

参数:

a: 单机打印时,请指定打印机驱动程序名称,例如: TSC CLEVER TTP-243

   若连接打印机服务器,请指定服务器路径及共享打印机名称,例如: //SERVER/TTP243

 

2.  closep*t()

说明: 关闭指定的计算机端输出端口

参数: 无

 

3. setup(a,b,c,d,e,f,g)

说明: 设定卷标的宽度、高度、打印速度、打印浓度、感应器类别、gap/black mark 垂直间距、gap/black mark 偏移距离)

参数:

a: 字符串型别,设定卷标宽度,单位 mm

       b: 字符串型别,设定卷标高度,单位 mm

       c: 字符串型别,设定打印速度,(打印速度随机型不同而有不同的选项)

                            1.0: 每秒1.0吋打印速度

                            1.5: 每秒1.5吋打印速度

                            2.0: 每秒2.0吋打印速度

                            3.0: 每秒3.0吋打印速度

                            4.0: 每秒4.0吋打印速度

                            5.0: 每秒5.0吋打印速度

                            6.0: 每秒6.0吋打印速度

       d: 字符串型别,设定打印浓度,

0~15,数字愈大打印结果愈黑

       e: 字符串型别,设定使用感应器类别

0 表示使用垂直间距传感器(gap sens*)

1 表示使用黑标传感器(black mark sens*)

f: 字符串型别,设定gap/black mark 垂直间距高度,单位: mm

g: 字符串型别,设定gap/black mark 偏移距离,单位: mm,此参数若使用一般卷标时均设为0

 

 

4.      clearbuffer()

说明: 清除

参数: 无

 

5.      barcode(a,b,c,d,e,f,g,h,I)

说明: 使用条形码机内建条形码打印

参数:

a: 字符串型别,条形码X方向起始点,以点(point)表示。

(200 DPI,1点=1/8 mm, 300 DPI,1点=1/12 mm)

b: 字符串型别,条形码Y方向起始点,以点(point)表示。

(200 DPI,1点=1/8 mm, 300 DPI,1点=1/12 mm)

c: 字符串型别,

128 Code 128, switching code subset A, B, C

automatically

128M Code 128, switching code subset A, B, C

manually.

EAN128 Code 128, switching code subset A, B, C

automatically

                     25                        Interleaved 2 of 5

                     25C                            Interleaved 2 of 5 with check digits

                     39                        Code 39

                     39C                            Code 39 with check digits

                     93                        Code 93

                     EAN13               EAN 13

                     EAN13+2            EAN 13 with 2 digits add-on

                     EAN13+5            EAN 13 with 5 digits add-on

                     EAN8                  EAN 8

     EAN8+2             EAN 8 with 2 digits add-on

                     EAN8+5                     EAN 8 with 5 digits add-on

                     CODA                Codabar

                     POST                 Postnet

                     UPCA                 UPC-A

                     UPCA+2                     UPC-A with 2 digits add-on

                     UPCA+5                     UPC-A with 5 digits add-on

                     UPCE                 UPC-E

                     UPCE+2                     UPC-E with 2 digits add-on

                     UPCE+5                     UPC-E with 5 digits add-on

 

       d: 字符串型别,设定条形码高度,高度以点来表示

       e: 字符串型别,设定是否打印条形码码文

              0: 不打印码文

              1: 打印码文

       f: 字符串型别,设定条形码旋转角度

              0: 旋转0度

              90: 旋转90度

              180: 旋转180度

              270: 旋转270度

       g: 字符串型别,设定条形码窄bar 比例因子,请参考TSPL使用手册

       h: 字符串型别,设定条形码窄bar 比例因子,请参考TSPL使用手册

       I: 字符串型别,条形码内容

 

6.      printerfont(a,b,c,d,e,f,g)

说明: 使用条形码机内建文字打印

参数:

a: 字符串型别,文字X方向起始点,以点(point)表示。

(200 DPI,1点=1/8 mm, 300 DPI,1点=1/12 mm)

b: 字符串型别,文字Y方向起始点,以点(point)表示。

(200 DPI,1点=1/8 mm, 300 DPI,1点=1/12 mm)

      c: 字符串型别,内建字型名称,共12种。

      1: 8*/12 dots

      2: 12*20 dots

      3: 16*24 dots

      4: 24*32 dots

      5: 32*48 dots

      TST24.BF2: 繁体中文24*24

      TST16.BF2: 繁体中文16*16

      TTT24.BF2: 繁体中文24*24 (电信码)

      TSS24.BF2: 简体中文24*24

      TSS16.BF2: 简体中文16*16

      K: 韩文 24*24

      L: 韩文 16*16

d: 字符串型别,设定文字旋转角度

              0: 旋转0度

              90: 旋转90度

              180: 旋转180度

              270: 旋转270度

e: 字符串型别,设定文字X方向放大倍率,1~8

f: 字符串型别,设定文字X方向放大倍率,1~8

g: 字符串型别,打印文字内容

 

7.      sendcommand(command)

说明: 送内建指令到条形码打印机

参数: 详细指令请参考TSPL

 

8.      printlabel(a,b)

说明: 打印卷标内容

参数:

       a: 字符串型别,设定打印卷标式数(set)

       b: 字符串型别,设定打印卷标份数(copy)

 

9.      downloadpcx(a,b)

说明:下载单色PCX 格式图文件至打印机

参数:

       a: 字符串型别,文件名(可包含路径)

       b: 字符串型别,下载至打印机内存内之文件名(请使用大写档名)

 

10. f*mfeed()

说明: 跳页,该函式需在setup后使用

参数: 无

 

11. nobackfeed()

说明: 设定纸张不回吐

参数: 无

 

12. windowsfont(a,b,c,d,e,f,g,h)

说明: 使用Windows TTF字型打印文字

参数:

a: 整数型别,文字X方向起始点,以点(point)表示。

b: 整数型别,文字Y方向起始点,以点(point)表示。

c: 整数型别,字体高度,以点(point)表示。

d: 整数型别,旋转角度,逆时钟方向旋转

0 ->  0 degree

90-> 90 degree

180-> 180 degree

270-> 270 degree

e: 整数型别,字体外形

0-> 标准(N*mal)

1-> 斜体(Italic)

2-> 粗体(Bold)

3-> 粗斜体(Bold and Italic)

f: 整数型别, 底线

0-> 无底线

1-> 加底线

g: 字符串型别,字体名称。如: Arial, Times new Roman, 细名体, 标楷体

h: 字符串型别,打印文字内容。

 

13. about()

说明: 显示DLL 版本号码

TSC条码打印机C#例程(tsclib.dll调用)

//----  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();
  }

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值