效果图

开发、使用环境说明

  1. 安装TSC_7.3.8_M-3.exe打印机驱动,安装时选择对应的ttp 244 pro
  2. 将TSCLIB.dll复制到C:\Windows\system

驱动安装说明

选择下一步

选择安装路径,默认即可,选择下一步

选择安装打印机,选择下一步

选择其他,点击下一步

选择对应的打印机型号,点击下一步

选择USB端口,点击下一步

直接默认即可,点击下一步

驱动安装完成

TSCLIB.cs代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices; namespace WindowsFormsPrint
{
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); //打开打印机端口,并进行相关设置
public static void openportExt()
{
TSCLIB_DLL.openport("TSC TTP-244 Pro");//找打打印机端口
TSCLIB_DLL.sendcommand("SIZE 60 mm,30 mm");//设置条码大小
TSCLIB_DLL.sendcommand("GAP 2 mm,0");//设置条码间隙
TSCLIB_DLL.sendcommand("SPEED 4");//设置打印速度
TSCLIB_DLL.sendcommand("DENSITY 7");//设置墨汁浓度
TSCLIB_DLL.sendcommand("DERECTION 1");//设置相对起点
TSCLIB_DLL.sendcommand("REFERENCE 3 mm,3 mm");//设置偏移边框
TSCLIB_DLL.sendcommand("CLS");//清除记忆(每次打印新的条码时先清除上一次的打印记忆)
}
//打印在用车档案二维码
public static void printVehicleCode(string str_hetong, string str_zhengjian, string str_name)
{
char space = (char)();
string codeValue = str_hetong + space + str_zhengjian;
TSCLIB_DLL.sendcommand("CLS");//需要清除上一次的打印记忆
TSCLIB_DLL.sendcommand("QRCODE 260,20,H,7,A,0,M2,S7,\"" + codeValue + "\"");
TSCLIB_DLL.windowsfont(, , , , , , "黑体", str_hetong);
TSCLIB_DLL.windowsfont(, , , , , , "黑体", str_zhengjian);
TSCLIB_DLL.windowsfont(, , , , , , "黑体", str_name);
TSCLIB_DLL.printlabel("", "");
} //打印财务条形码
public static void printFinanceCode(string str_Date, string str_siteNo,
string str_siteName, string str_Num, string str_Name, int count)
{
for (int i = ; i < count; i++)
{
char Num = (char)(i + );
char space = (char)();
string value = str_Date + space + str_siteNo + space + str_Num + space + Num;
string txt = str_Date + space + str_siteName + space + str_Num + space + str_Name + space + Num;
TSCLIB_DLL.sendcommand("CLS");//需要清除上一次的打印记忆
TSCLIB_DLL.barcode("", "", "", "", "", "", "", "", value);
TSCLIB_DLL.windowsfont(, , , , , , "黑体", txt);
TSCLIB_DLL.printlabel("", "");
}
} //关闭打印机端口
public static void closeportExt()
{
TSCLIB_DLL.closeport();
}
}
}

打印二维码:

        private void print_Click(object sender, EventArgs e)
{
try
{
print.Enabled = false;
base.DoWork(DoPrint);
print.Enabled = true;
}
catch (Exception ex)
{
// FileLogHelper.WriteInfoLog(ex.ToString());
MessageBox.Show(ex.ToString());
} } private void DoPrint(object sender, EventArgs e)
{
DataGridViewSelectedRowCollection rows = ArchivesView.SelectedRows;
if (rows.Count <= )
{
MessageBox.Show("请先选择数据项!");
return;
}
TSCLIB_DLL.openportExt();
foreach (DataGridViewRow dr in rows)
{
TSCLIB_DLL.printVehicleCode(dr.Cells[].Value.ToString(), dr.Cells[].Value.ToString(), dr.Cells[].Value.ToString());
}
TSCLIB_DLL.closeportExt();
}

C#调用dll提示"试图加载格式不正确的程序"解决方法

程序在32位操作系统上运行正常,在64位操作系统上运行读卡功能提示”试图加载格式不正确“。

程序在64位操作系统上运行正常,在64位操作系统上运行读卡功能提示”试图加载格式不正确“。

--------------------------------------------------------------------------------------------

点击项目属性,把目标平台Any CPU 设置为X86(32位操作系统)或者X64(64位操作系统)

按照上面解决方案可能会有下面的问题:

 C# form继承问题 : 提示 无法加载基类 ;请确保已引用该程序集并已生成所有项目。 
 把 生成 - 目标平台 改成 x86或者Any CPU ,重新生成一次,Form可正常编辑。 
 

所以新的解决方案是:选择Any CPU 把下面打勾的去掉

C# TSC打印二维码和条形码的更多相关文章

  1. C#调用TSC条码打印机打印二维码

    #region 调用TSC打印机打印 /// <summary> /// 调用TSC打印机打印 /// </summary> /// <param name=" ...

  2. 使用FastReport打印二维码

    简单介绍一下该功能所在的项目背景:C#语言编写的WPF客户端应用程序,在“结账”模块中,打印出的收款小票上需要显示一个二维码,服务生拿着小票去找顾客,顾客可以选择现金.银行卡等普通支付方式,也可以直接 ...

  3. zbar+opencv检测图片中的二维码或条形码

    zbar本身自带检测二维码条形码功能,这里使用opencv只是做一些简单的读取图片,灰度图片以及显示条形码和二维码时用到一些绘制 // barcode-qrcodescanner.cpp: 定义控制台 ...

  4. 安卓四核PDA手持PDA智能POS机 打印二维码 分享

    很多项目都会用到 类似的要求  移动手持终端 通过程序 可以生成条码或二维码 打印出小票或标签纸 下面直接上代码 希望对大家有点用处 private void print(){ csys.setTex ...

  5. 【Demo】 生成二维码 和 条形码

    条形码 和 二维码 对比 一维条形码只是在一个方向(一般是水平方向)表达信息,而在垂直方向则不表达任何信息,其一定的高度通常是为了便于阅读器的对准. 在水平和垂直方向的二维空间存储信息的条形码, 称为 ...

  6. android 项目学习随笔二十一(IM、语音识别、机器人、统计、扫描二维码、条形码)

    语音识别:科大讯飞语音云 http://www.xfyun.cn/ 语音机器人模拟 public class TalkBean { public String text; public boolean ...

  7. Android二维码开源项目zxing用例简化和生成二维码、条形码

    上一篇讲到:Android二维码开源项目zxing编译,编译出来后有一个自带的測试程序:CaptureActivity比較复杂,我仅仅要是把一些不用的东西去掉,用看起来更方便,二维码和条形码的流行性自 ...

  8. Lodop打印二维码内容长度不同如何大小相同

    利用Loodop打印控件打印二维码的时候,往往传入的数值是变量,有的只有一个数字,有的却一大堆数字和字母,根据内容长度不同,二维码大小也不同,这样如果批量打印二维码标签,传入的数据是不同的,会造成有的 ...

  9. iOS - 原生的CIFilter生成二维码和条形码

    使用CIFilter可以不引入任何第三方库,就可以生成想要的二维码和条形码,今天简单的介绍一下使用CIFilter生成二维码和条形码.系统CIFilter生成的二维码和条形码的大小有时并不能满足需求, ...

随机推荐

  1. MySql的学习笔记

    良好的理解sql语句: 列:理解可以运算的成变量 where: 理解成表达式,放在行中看是否成立 查出来的结果可以当成一张表理解,select 套用select综合查询:   五种查询 where g ...

  2. pod出现include of non-modular header inside framework module 错误

    今天打包pod 的时候 出现的错误 -> AFNetworking+RX (3.1.0.18) - ERROR | [iOS] xcodebuild: Returned an unsuccess ...

  3. 机器学习:线性判别式分析(LDA)

    1.概述      线性判别式分析(Linear Discriminant Analysis),简称为LDA.也称为Fisher线性判别(Fisher Linear Discriminant,FLD) ...

  4. Python: Pandas的DataFrame如何按指定list排序

    本文首发于微信公众号“Python数据之道”(ID:PyDataRoad) 前言 写这篇文章的起由是有一天微信上一位朋友问到一个问题,问题大体意思概述如下: 现在有一个pandas的Series和一个 ...

  5. 【论文:麦克风阵列增强】An Algorithm For Linearly Constrained Adaptive Array Processing

    作者:桂. 时间:2017-06-03  15:06:37 链接:http://www.cnblogs.com/xingshansi/p/6937635.html 原文链接:http://pan.ba ...

  6. 模拟jquery底层链式编程

    //特点1:快级作用域,程序启动自动执行 //内部的成员变量,外部无法访问(除了var) //简单的函数链式调用 function Dog(){ this.run=function(){ alert( ...

  7. 【转载】SQL Server行转列,列转行

    行转列,列转行是我们在开发过程中经常碰到的问题.行转列一般通过CASE WHEN 语句来实现,也可以通过 SQL SERVER 2005 新增的运算符PIVOT来实现.用传统的方法,比较好理解.层次清 ...

  8. cms基本概念(dedecms,phpcms)

    1.什么是cms? cms是"Content Management System"的缩写,意为"内容管理系统". 内容管理系统是企业信息化建设和电子政务的新宠, ...

  9. angularJS插入html及更换iframe的src

    html: ng-bind-html <div class="tabs_content" ng-bind-html="specialHtml">&l ...

  10. salesforce零基础学习(七十四)apex:actionRegion以及apex:actionSupport浅谈

    我们在开发中,很难会遇见不提交表单的情况.常用的apex:commandButton,apex:commandLink,apex:actionFunction,apex:actionSupport.他 ...