c# 用GoDEX打印机打印条码实例.docx

上传人:b****8 文档编号:30155252 上传时间:2023-08-05 格式:DOCX 页数:20 大小:20.09KB
下载 相关 举报
c# 用GoDEX打印机打印条码实例.docx_第1页
第1页 / 共20页
c# 用GoDEX打印机打印条码实例.docx_第2页
第2页 / 共20页
c# 用GoDEX打印机打印条码实例.docx_第3页
第3页 / 共20页
c# 用GoDEX打印机打印条码实例.docx_第4页
第4页 / 共20页
c# 用GoDEX打印机打印条码实例.docx_第5页
第5页 / 共20页
点击查看更多>>
下载资源
资源描述

c# 用GoDEX打印机打印条码实例.docx

《c# 用GoDEX打印机打印条码实例.docx》由会员分享,可在线阅读,更多相关《c# 用GoDEX打印机打印条码实例.docx(20页珍藏版)》请在冰豆网上搜索。

c# 用GoDEX打印机打印条码实例.docx

c#用GoDEX打印机打印条码实例

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.Data.SqlClient;

usingSystem.Xml;

usingSystem.IO;

usingSystem.Runtime.InteropServices;

usingSystem.Collections;

namespaceDLLImport

{

publicpartialclassDLLImport:

Form

{

publicDLLImport()

{

InitializeComponent();

}

[DllImport("Trace.dll")]

publicstaticexternvoidsetup(inta,intb,intc,intd,inte,intf);

[DllImport("Trace.dll")]

publicstaticexternvoidsetbaudrate(intn);

[DllImport("Trace.dll")]

publicstaticexternvoidSetTimeOutTicks(intms);

//n=0→LPT1

//n=1→COM1

//n=2→COM2

//n=3→COM3

//n=4→COM4

//n=5→LPT2

//n=6→USB

[DllImport("Trace.dll")]

publicstaticexternvoidopenport(

[MarshalAs(UnmanagedType.LPStr)]

stringn);

[DllImport("Trace.dll")]

publicstaticexternvoidcloseport();

 

[DllImport("Trace.dll")]

publicstaticexternvoidsendcommand(

[MarshalAs(UnmanagedType.LPArray)]

byte[]command);

[DllImport("Trace.dll")]

publicstaticexternvoidsendcommand(

[MarshalAs(UnmanagedType.LPStr)]

stringcommand);

//1->Success,0->Fail

[DllImport("Trace.dll")]

publicstaticexternintisready();

 

[DllImport("Trace.dll")]

publicstaticexternvoidintloadimage(

[MarshalAs(UnmanagedType.LPStr)]

stringfilename,

[MarshalAs(UnmanagedType.LPStr)]

stringimage_name,

[MarshalAs(UnmanagedType.LPStr)]

stringimage_type);

[DllImport("Trace.dll")]

publicstaticexternvoidextloadimage(

[MarshalAs(UnmanagedType.LPStr)]

stringfilename,

[MarshalAs(UnmanagedType.LPStr)]

stringimage_name,

[MarshalAs(UnmanagedType.LPStr)]

stringimage_type);

//1->Success,0->Fail

[DllImport("Trace.dll")]

publicstaticexternintecTextOut(intx,inty,intb,

[MarshalAs(UnmanagedType.LPStr)]

stringc,

[MarshalAs(UnmanagedType.LPStr)]

stringd);

//1->Success,0->Fail

[DllImport("Trace.dll")]

publicstaticexternintecTextOutR(intx,inty,intb,

[MarshalAs(UnmanagedType.LPStr)]

stringc,

[MarshalAs(UnmanagedType.LPStr)]

stringd,inte,intf,intg);

//1->Success,0->Fail

[DllImport("Trace.dll")]

publicstaticexternintecTextDownLoad(intb,stringc,stringd,inte,intf,intg,

[MarshalAs(UnmanagedType.LPStr)]

stringname);

//1->Success,0->Fail

[DllImport("Trace.dll")]

publicstaticexternintputimage(intx,inty,

[MarshalAs(UnmanagedType.LPStr)]

stringfilename,intdegree);

//1->Success,0->Fail

[DllImport("Trace.dll")]

publicstaticexternintdownloadimage(

[MarshalAs(UnmanagedType.LPStr)]

stringfilename,intdegree,

[MarshalAs(UnmanagedType.LPStr)]

stringname);

[DllImport("Trace.dll")]

publicstaticexternvoidSelectUsbPrinter(

[MarshalAs(UnmanagedType.LPStr)]

stringID);

[DllImport("Trace.dll")]

publicstaticexternvoidSelectUsbPortNumber(intportnumber);

 

[DllImport("Trace.dll")]

publicstaticexternvoidreadusb(

[MarshalAs(UnmanagedType.LPArray)]

byte[]buff,

refintlength);

privatevoidBtn_Send_Click(objectsender,EventArgse)//发送字符串到打印机

{

stringcmd=txtCmd.Text;

openport("6");//Ex:

USB

try

{

sendcommand(cmd);

closeport();

}

catch(Exceptionerror)

{

MessageBox.Show(error.Message);

return;

}

#region语法

/*

EZPL语言可运用三种命令模式:

控制命令

设定命令

标签格式命令

控制命令以符号(~)启首,旨在要求条码机立即执行动作,如清除记忆、释出标签等。

设定命令以符号(^)启首,种类包括条码机控制指令、组态指令、图像下载指令等。

标签格式命令,旨在界定各类资料如线条、矩形、条码、文字、图像等等。

^Cx(x=1~32767设定标签复制列印张数)

^Hx(x=00~19设定黑度(列印深浅)。

值愈大,印表头温度愈高)

^L正常列印;

^Px(x=1~32767设定一次要列印的张数。

^Qx,y(,z)(x=标签长度(mm)y=区间长度(mm)z=连续纸要释出之长度(mm))

^Rx(x=0~399dots设定标签左边界起印点)

^Sx(x=2~10列印速度设定)

^Wx(x=标签宽度(单位:

mm)

~Jx(字型下载x=字型代号;从a~z或A~Z;至多26种字型)

~Q±x-上边界起印点设定(x=-100~+100(单位:

dots))

~Rx反向列印(x=所使用标签宽度(单位:

mm),可设定范围依各型号之规格而定将整张标签反转180∘印出。

若要转回原方向,设定x大于规格所定的最大宽度即可)

*

*

At,x,y,x_mul,y_mul,gap,rotationInverse,data-文字命令

t=字型(A~H支援Codepage850;fontI为ASCII字型)

Zn,n=1~9亚洲字型;具有繁体中文、简体中文、韩文、日文4种

x=文字左上角水平位置(单位:

dots,1mm=8dots或12dots)

y=文字左上角垂直位置(单位:

dots,1mm=8dots或12dots)

x_mul=水平放大可1至8倍

y_mul=垂直放大可1至8倍

gap=文字间距(单位:

dots,1mm=8dots或12dots)

rotationInverse=ASCII文字可设定旋转的参数为0~3,亚洲文字可设定旋转的参数为0~7

data=打印的字符串

*

*

*

*

ATt,x,y,w,h,g,s,d,m,data-列印已下载的TrueTypeFont字型

t=TTF字型代号,从A~Z

x=文字左下角水平位置(单位:

dots,1mm=8dots或12dots)

y=文字左下角垂直位置(单位:

dots,1mm=8dots或12dots)

w=文字宽度(8~2000dot)

h=文字高度(8~2000dot)

g=文字间距(0~200dot)

s=文字旋转及字型样式设定,文字旋转的设定范围为0~3:

00°

190°

2180°

3270°

字型样式设定则为非必需选项,可分为粗体、斜体以及底线,可单一或互相搭配进行设定:

B粗体T斜体U底线EUTF8LUTF16LOHUTF16HI

m:

m=0比例模式m=1等宽模式(请参照补充说明)

data=资料字串

*

*

*

*

*

Bt,x,y,narrow,wide,height,rotation,readable,data-条码命令

t=条码类型(参考对应表)

x=条码左上角水平位置(单位:

dots,1mm=8dots或12dots)

y=条码左上角垂直位置(单位:

dots,1mm=8dots或12dots)

narrow(xdimension)=条码窄度1~10dots(0.125~1.25mm)

**DUN14码之窄度设限为5~8dots;UPC/EAN码之窄度设限为2~4dots**

wide=条码宽度设限2~30dots(0.25~0.5mm);限CODE39、93、CODABAR&I2of5

height=条码高度设限24~1200dots

rotation=条码旋转度(0~3)0)01)902)1803)270

readable=设定码文是否显示.

0–不显示1–在条码下方,置左2–在条码上方,置左3–在条码下方,置中4–在条码上方,置中5–在条码下方,置右6–在条码上方,置右

data=条码资料

 

E-终结字元及启印设定

*

*

*

Px,y,w,h,r,c,ec,len,rotation-PDF417命令

x=条码左上角水平位置(单位:

dots)

y=条码左上角垂直位置(单位:

dots)

w=条码或空白处,最窄部份之宽度

h=条码高度

r=条码行数3~90.若键入0,印表机会统计所有行数

c=条码列数1~30.若键入0,印表机会统计所有列数

ec=错误修正度0~8

len=转为PDF417条码之内容大小,包括Return及跳行(单位:

bytes)

rotation=条码旋转角度(0~3)0)01)902)1803)270

data=转为PDF417条码之资料(大小须与"len"参数设定的值相符)

*例子

^Q50,0,0

^W70

^H15

^P1

^S2

^AD

^C1

^R0

~Q+0

^Ô0

^D0

^Ê12

~R200

^L

Dy2-me-dd

Th:

m:

s

P9,40,3,3,3,1,3,22

0123456789

0123456789

E

*

*

*

*

*

*

Wx,y,mode,type,ec,mask,mul,len,roataedata-编排QR-code及MicroQRCode

x=条码左上角水平位置(单位:

dots)

y=条码左上角垂直位置(单位:

dots)

mode=条码模式(1~5)1Numericaldatamode2Alphanumericaldatamode38-bitdatamode*

4Kanjidatamode5Mixingmode(不适用于MicroQRCode)

 

type=设定类型(1~2)1Model1(original)2Model2(enhanced)3MicroQRCode

ec=错误修正等级(L、M、Q、H)Low,Medium,Mediumhigh,High(不适用于MicroQRCode)

mask=遮罩因子(0~7or8forauto);若为列印MicroQRCode时,此值必须设为"0"

mul=放大倍数(1~8)

len=条码内容长度(包括Return及跳行)

roatae=条码旋转角度0)01)902)1803)270

data=barcode资料内容

备注:

当条码模式设定为8-bitdata模式时,barcode资料内容的前四码必须用于指定资料长度。

例如,当前4码为0015时,即表示条码内容的资料长度必须为15bytes

Q50,0,0

^L

W10,10,2,1,L,8,10,36,0

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ

E

*

*

*

*

*

*

*

*

*

*/

#endregion

#regioncode39范例

//^L

//Dy2-me-dd

//Th:

m:

s

//R8,13,631,384,8,8

//BA,30,57,2,6,80,0,1,22-.$/+%40

//AB,400,25,1,1,0,0,HumanReadable

//AD,36,300,1,1,0,0I,Code39

//E

#endregion

#regionEAN8范例

/*

^L

Dy2-me-dd

Th:

m:

s

R8,13,631,384,8,8

BB,30,57,2,5,80,0,1,22408785

BB,30,200,2,5,80,0,0,22408785

AB,400,25,1,1,0,0,HumanReadable

AB,400,170,1,1,0,0,NoHuman

Readable

AD,36,300,1,1,0,0I,EAN8

E

*/

#endregion

#region128范例

/*

^L

Dy2-me-dd

Th:

m:

s

R8,13,631,384,8,8

BQ,30,57,2,5,80,0,1,22408785Godex

BQ,30,200,2,5,80,0,0,22408785Godex

AB,400,25,1,1,0,0,HumanReadable

AB,400,170,1,1,0,0,NoHumanReadable

AD,36,300,1,1,0,0I,Code128auto

E

*/

#endregion

#regionPDF417范例

/*

^L

Dy2-me-dd

Th:

m:

s

R8,13,631,384,8,8

PC50,100,3,10,3,3,3,19

&*01234567

012&*

AD,36,300,1,1,0,0I,PDF417

E

*/

#endregion

#regionQRCODE范例

/*

^L

Dy2-me-dd

Th:

m:

s

R8,13,631,384,8,8

W100,60,1,1,M,8,7,10,0

0123456789

W400,60,1,2,M,8,7,10,0

0123456789

AB,130,230,1,1,0,0,mode1

AB,430,230,1,1,0,0,mode2

AD,36,300,1,1,0,0I,QRCode

E

*/

#endregion

#regionDataMatrix范例

/*

^L

Dy2-me-dd

Th:

m:

s

R8,13,631,384,8,8

XRB250,100,7,0,50

01234567890123456789012345678901234567890123456789

AD,36,300,1,1,0,0I,DataMatrixCodeSquare

E

*/

#endregion

}

privatevoidBtn_LoadCMD_Click(objectsender,EventArgse)//发送命令文件到打印机

{

OpenFileDialogofd=newOpenFileDialog();

ofd.Filter="CommandFiles(*.cmd)|*.cmd";

if(ofd.ShowDialog()==DialogResult.OK)

{

intlength;

byte[]sBuffer=newbyte[256];

byte[]ID=newbyte[256];

string[]stBuffer=newstring[50];

openport("6");//Ex:

USB

try

{

FileStreamfileStream=newFileStream(ofd.FileName,FileMode.Open,FileAccess.Read);

Array.Clear(sBuffer,0,sBuffer.GetUpperBound(0));

while((length=fileStream.Read(sBuffer,0,sBuffer.GetUpperBound(0)))>0)

{

sendcommand(sBuffer);

}

closeport();

}

catch(Exceptionerror)

{

MessageBox.Show(error.Message);

return;

}

}

}

privatevoidbutton1_Click(objectsender,EventArgse)

{

#region类型

/*

code128

code39

PDF417

QRCODE

DataMatrxCode(Square)

*/

#endregion

txtCmd.Text="";

strings=comboBox1.SelectedItem.ToString();

stringaa="";

switch(s)

{

case"code128":

aa="^L!

Dy2-me-dd!

Th:

m:

s!

R8,13,631,384,8,8!

BQ,30,200,2,5,80,0,0,22408785Godex!

AB,400,25,1,1,0,0,HumanReadable!

AD,36,300,1,1,0,0I,Code128auto!

E";

break;

case"code39":

aa="^L!

Dy2-me-dd!

Th:

m:

s!

R8,13,631,384,8,8!

BA,30,57,2,6,80,0,1,22-.$/+%40!

AB,400,25,1,1,0,0,HumanReadable!

AD,36,300,1,1,0,0I,Code39!

E";

break;

case"PDF417":

aa="^L!

Dy2-me-dd!

Th:

m:

s!

R8,13,631,384,8,8!

PC50,100,3,10,3,3,3,19!

&*01234567!

012&*!

AD,36,300,1,1,0,0I,PDF417!

E";

break;

case"QRCODE":

aa="^L!

Dy2-me-dd!

Th

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 书信模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1