TSC条码打印机C#例程(tsclib.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();
  }

时间: 2024-10-25 00:37:47

TSC条码打印机C#例程(tsclib.dll调用)的相关文章

TSC条码打印机C#例程(tsclib.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")]    pu

zw版【转发&#183;台湾nvp系列Delphi例程】.NET调用HALCON COM控件内存释放模式

zw版[转发·台湾nvp系列Delphi例程].NET调用HALCON COM控件内存释放模式 ------------------------------------方法一 :Imports System.Runtime.InteropServices Marshal.ReleaseComObject(COM物件)COM 物件 = Nothing 方法二 :COM 物件 = NothingGC.Collect()GC.WaitForPendingFinalizers() 方法三 :Import

DLL放在指定目录 以及设置dll调用路径

一.DLL放在指定目录 在编写C# winform程序中,不免一个项目会有多个工程文件,而这些工程文件之间是相互引用的,所以不想将工程的生成结果(exe或者dll)放在当前工程bin目录下的Debug目录或者Release目录,而是放在一个公共的目录下,比如DLLImport目录下,如何实现这个工程呢,我们知道,如果是C++,我们可以使用cmake来部署我的项目,同样在c#中也可以实现这样的功能,我们只需在每个工程的“属性”----“生成事件”----“生成后事件命令行”写入如下代码即可: IF

[blog 项目实战派]csharp通过dll调用opencv函数,图片作为参数

?一直想做着方面的研究,但是因为这个方面的知识过于小众,也是由于自己找资料的能力比较弱,知道今天才找到了比较好的资料.一个是thinimage,一个是basework,里面都实现了这里的“csharp通过dll调用opencv函数,并且采用图片作为参数”.这里小结如下. 关于如何“csharp通过dll调用opencv函数”,请参考前面博文,这里主要说如何“采用图片为参数”. 在编写图像识别/增强/机器视觉等项目的时候,一般会将算法打包成dll文件给客户,如果界面是用mfc写的话,是很好实现这个

[blog 项目实战派]csharp通过dll调用opencv函数

[blog 项目实战派]opencv通过dll调用matlab函数,图片作为参数 前文介绍了如何“csharp通过dll调用opencv函数,图片作为参数”.而在实际的代码编写过程中,很多时候想把已经写好的matlab函数融合进去,但是依然是将图片作为参数传递比较成为问题.这里我经过一段时间的研究解决了这个问题(目前只解决了灰度图片下的图片传递问题).这个问题包含几个难点,一个是mxmatrix的使用,一个是matlab和opencv对于图片的格式处理是不一样的. 本次这个项目,是opencv通

使用Visual Studio,几步实现Python C++扩展,以及DLL调用

在网上搜了下Python扩展教程,很多提到第三方开源库,而官方推荐的是用setup.py.其实用Visual Studio很简单!来看一下如何一步步编写一个Python扩展,以及如何通过扩展来调用DLL. 参考原文:Wrapping C/C++ Methods of Dynamsoft Barcode SDK for Python Visual Studio环境配置 在Visual Studio中创建一个Win32工程DynamsoftBarcodeReader.打开工程属性,添加头文件和库文件

C++ dll调用-动态(显式)

C++ dll调用-动态(显式) 废话不说上代码, dll 头文件 j_test.h #pragma once extern "C"_declspec(dllexport) void maopao(int *p, int count); extern "C"_declspec(dllexport) int test(int *p, char* count); extern "C"_declspec(dllexport) int sum(int i

C#中dll调用方法

一.      DLL与应用程序 动态链接库(也称为DLL,即为“Dynamic Link Library”的缩写)是Microsoft Windows最重要的组成要素之一,打开Windows系统文件夹,你会发现文件夹中有很多DLL文件,Windows就是将一些主要的系统功能以DLL模块的形式实现. 动态链接库是不能直接执行的,也不能接收消息,它只是一个独立的文件,其中包含能被程序或其它DLL调用来完成一定操作的函数(方法.注:C#中一般称为“方法”),但这些函数不是执行程序本身的一部分,而是根

c#解决dll调用的问题

在做一个c#中间程序时,调用第三方的dll安装路径"Program Files" 和"Program Files (x86)"的问题,经过一段时间的研究,找到了下面的解决方案: 思路: 1.配置dll的加载路径 2.监控dll 3.dll加载失败判断操作系统位数(x86.x64) 4.动态加载dll 解决方案: 1.在config中添加dll引用配置: <runtime> <assemblyBinding xmlns="urn:schem