老师要给招生办写一个艺术招生考试评分系统,以下是打印条形码部分,这一部分就是我昨晚奋战一晚的结晶啊!网上找不到任何资料,仅凭打印机器附送的一份儿帮助文档。没有完全是从无到有,从零开始的啊!一步一步都是试出来的,光标签纸都浪费了三四米!
现在回头想,其实也没什么深奥的东西,只是比较偏重于硬件底层。做完这个打印机的工作原理我倒了解了不少!主要的还是对打印机进行二次开发!
首先,你需要三个新北洋的dll类包:bpladll.dll,ByUSBInt.dll,LabelUSBPrintDll.dll
光有这三个类包是不够的,应为这三个包不是.net语言写的,所以还要自己新建一个.net的类包当做引导层,导入bplad.dll包。以下是我自己写的一个CUST.dll包:
using System; using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CUST
{ /// <summary>
/// Bpladll 的摘要说明。
/// </summary>
public class PrinterDll
{
public const int BPLA_OK = 1000; //一切正常
public const int BPLA_COMERROR = 1001; //通讯错或者未联接打印机
public const int BPLA_PARAERROR = 1002; //参数错误
public const int BPLA_FILEOPENERROR = 1003; //文件打开错误
public const int BPLA_FILEREADERROR = 1004; //文件读错误
public const int BPLA_FILEWRITEERROR = 1005; //文件写错误
public const int BPLA_FILEERROR = 1006; //文件不合要求
public const int BPLA_NUMBEROVER = 1007; //指定的接收信息数量过大
public const int BPLA_IMAGETYPEERROR = 1008; //图象文件格式不正确
public const int BPLA_DRIVERERROR = 1009; //驱动错误
public const int BPLA_TIMEOUTERROR = 1010; //超时错误
public const int BPLA_LOADDLLERROR = 1011; //加载动态库失败
public const int BPLA_LOADFUNCERROR = 1012; //加载动态库函数失败
public const int BPLA_NOOPENERROR = 1013; //端口未打开
//static string m_dllpath = Application.StartupPath+@"\BPLADLL.dll";
//端口类型宏定义
public const int BPLA_COM_PORT = 0;
public const int BPLA_LPT_PORT = 1;
public const int BPLA_API_USB_PORT = 2;
public const int BPLA_CLASS_USB_PORT = 3;
public const int BPLA_DRIVER_PORT = 4;
public const int BPLA_NET_PORT = 5;
//打印纸张宏定义
public const int BPLA_CONTINUE_PAPER_PRINT = 0;
public const int BPLA_LABEL_PAPER_PRINT = 1;
public const int BPLA_BLACK_PAPER_PRINT = 2;
public const int BPLA_CONTINUE_PRINT = 3;
//打印应用
public const int BPLA_ADDVALUE_PRINT = 0;
public const int BPLA_ROLL_PRINT = 1;
public const int BPLA_DEEPNESS_PRINT = 2;
public const int BPLA_GRAY_PRINT = 3;
//打印内容宏定义
public const int BPLA_TEXT_PRINT = 0;
public const int BPLA_BARCODE_PRINT = 1;
public const int BPLA_IMAGE_PRINT = 2;
public const int BPLA_FIGURE_PRINT = 3;
//TrueType字体风格结构体定义
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct TrueTypeFontStyle
{
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public bool Bold;//加粗
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public bool Italic;//倾斜
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public bool Underline;//下划线
}
//将指令保存到文件
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SetSaveFile")]
public static extern int BPLA_SetSaveFile(
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.I1)]
bool bsave, string filename,
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.I1)]
bool bport);
//获取版本
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_GetVersion")]
public static extern int BPLA_GetVersion();
//打开配置串口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_OpenCom")]
public static extern int BPLA_OpenCom(string comname, int intbaudrate, int handshake);
//打开配置串口,不进行连接检查
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_OpenComEx")]
public static extern int BPLA_OpenComEx(string PortName, int Baudrate, int Handshake, int WriteTimeOut);
//关闭串口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_CloseCom")]
public static extern int BPLA_CloseCom();
//通过API打开并口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_OpenLptByAPI")]
public static extern int BPLA_OpenLptByAPI(string cLptName);
//关闭API并口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_CloseLptByAPI")]
public static extern int BPLA_CloseLptByAPI();
//打开网络端口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_OpenNetPort")]
public static extern int BPLA_OpenNetPort(string cIpAddress, int iPort);
//关闭网络端口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_CloseNetPort")]
public static extern int BPLA_CloseNetPort();
//打开驱动并口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_OpenLpt")]
public static extern int BPLA_OpenLpt(int address, int busySleep);
//关闭驱动并口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_CloseLpt")]
public static extern int BPLA_CloseLpt();
//打开USB口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_OpenUsb")]
public static extern int BPLA_OpenUsb();
//通过内部ID号打开USB口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_OpenUsbByID")]
public static extern int BPLA_OpenUsbByID(int ID);
//关闭USB口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_CloseUsb")]
public static extern int BPLA_CloseUsb();
//枚举USB类模式设备数量
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_EnumUsbPrn")]
public static extern int BPLA_EnumUsbPrn(ref int iUsbPrnNum);
//打开USB类模式端口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_OpenUsbPrn")]
public static extern int BPLA_OpenUsbPrn(int iDeviceNum);
//关闭USB类模式端口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_CloseUsbPrn")]
public static extern int BPLA_CloseUsbPrn();
//设置端口写超时时间
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SetTimeOut")]
public static extern int BPLA_SetTimeOut(int WriteTimeOut);
//设置端口读写超时时间
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SetTimeOutEx")]
public static extern int BPLA_SetTimeOutEx(int WriteTimeOut, int ReadTimeOut);
//发送指令
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SendCommand")]
public static extern int BPLA_SendCommand(string command, int commandlength);
//接收指令
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_ReceiveInfo")]
public static extern int BPLA_ReceiveInfo(int relength, string buffer, ref int length, int time);
//发送文件
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SendFile")]
public static extern int BPLA_SendFile(string filename);
//接收数据到文件
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_ReceiveFile")]
public static extern int BPLA_ReceiveFile(int relength, string filename, ref int length, int time);
//打开驱动程序
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_OpenPrinterDriver")]
public static extern int BPLA_OpenPrinterDriver(string DriverName);
//关闭驱动程序
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_ClosePrinterDriver")]
public static extern int BPLA_ClosePrinterDriver();
//开始打印作业
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_StartDoc")]
public static extern int BPLA_StartDoc();
//结束打印作业
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_EndDoc")]
public static extern int BPLA_EndDoc();
//下载位图
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_DownloadImage")]
public static extern int BPLA_DownloadImage(string imagename, int imagetype, int modeltype, string filename);
//删除存储器模块中指定的文件
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_DownErase")]
public static extern int BPLA_DownErase(int modeltype, int filetype, string filename);
//删除指定存储器模块中的全部文件
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_DownEraseAll")]
public static extern int BPLA_DownEraseAll(int modeltype);
//复位打印机
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_Reset")]
public static extern int BPLA_Reset();
//执行进/退标签
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_ForBack")]
public static extern int BPLA_ForBack(int distance, int delaytime);
//设置出纸方式、纸张类型、工作模式
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_Set")]
public static extern int BPLA_Set(int outmode, int papermode, int printmode);
//设置传感器模式
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SetSensor")]
public static extern int BPLA_SetSensor(int labelmode);
//设置连续介质打印长度
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SetPaperLength")]
public static extern int BPLA_SetPaperLength(int continuelength, int labellength);
//设置打印停止位置
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SetEnd")]
public static extern int BPLA_SetEnd(int position);
//设置灰度模式
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SetGrayMode")]
public static extern int BPLA_SetGrayMode(int mode);
//进入标签模式,设置打印区域及打印参数
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_StartArea")]
public static extern int BPLA_StartArea(int unitmode, int printwidth, int column, int row, int darkness, int speedprint, int speedfor, int speedbac);
//设置票面内某些域成镜象效果,对条码无效
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SetMirror")]
public static extern int BPLA_SetMirror();
//整体镜象
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SetAllMirror")]
public static extern int BPLA_SetAllMirror();
//启动打印标签
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_Print")]
public static extern int BPLA_Print(int pieces, int samepieces, int outunit);
//保存标签不打印
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SaveLabel")]
public static extern int BPLA_SaveLabel();
//打印已经保存的标签,不支持连续域设置
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintSaveLabel")]
public static extern int BPLA_PrintSaveLabel(int pieces);
//横向复制
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SetCopy")]
public static extern int BPLA_SetCopy(int pieces, int gap);
//整体翻转
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_SetAllRotate")]
public static extern int BPLA_SetAllRotate(int rotatemode);
//设置线段的版面位置,采用覆盖模式
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintLine")]
public static extern int BPLA_PrintLine(int startx, int starty, int endx, int endy, int linewidth);
//设置矩形的版面位置
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintBox")]
public static extern int BPLA_PrintBox(int startx, int starty, int width, int height, int horizontal, int vertical, int bitmode);
//设置圆形的版面位置
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintCircle")]
public static extern int BPLA_PrintCircle(int centerx, int centery, int radius, int linewidth, int bitmode);
//设置预下载图象的版面位置
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_LoadImage")]
public static extern int BPLA_LoadImage(string imagename, int startx, int starty, int pointwidth, int pointheight, int bitmode);
//设置直接下载图象的版面位置,支持BMP单色位图,要求位图的宽度点数为32的倍数
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintImage")]
public static extern int BPLA_PrintImage(string imagename, int startx, int starty, int bitmode);
//设置直接下载灰度图象的版面位置,支持8位BMP灰度位图
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintGrayImage")]
public static extern int BPLA_PrintGrayImage(string imagename);
//打印内部点阵字体
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintText")]
public static extern int BPLA_PrintText(string text, int startx, int starty, int rotate, int fonttype, int pointwidth, int pointheight, string addvalue, int space, int bitmode);
//打印内部点阵字体
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintTextEx")]
public static extern int BPLA_PrintTextEx(string text, int startx, int starty, int rotate, int fonttype, int pointwidth, int pointheight, int space, int bitmode, string addvalue, int iValueStartPlace, int iValueLen);
//打印外部下载到RAM或FLASH中的扩展字体。
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintOut")]
public static extern int BPLA_PrintOut(string text, int startx, int starty, int rotate, string fonttype, int pointwidth, int pointheight, string addvalue, int space, int bitmode);
//打印外部下载到RAM或FLASH中的扩展字体。
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintOutEx")]
public static extern int BPLA_PrintOutEx(string text, int startx, int starty, int rotate, string fonttype, int pointwidth, int pointheight, int space, int bitmode);
//中英文混排打印
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintMixText")]
public static extern int BPLA_PrintMixText(string text, int startx, int en_starty, int cn_starty, int rotate, int en_fonttype, string cn_fonttype, int en_width, int cn_width, int pointwidth, int pointheight, string addvalue, int space, int bitmode);
//中英文混排打印
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintMixTextBuild")]
public static extern int BPLA_PrintMixTextBuild( string text, int startx, int en_starty, int cn_starty,int rotate,int en_fonttype,string cn_fonttype,
int en_width,int cn_width,int pointwidth,int pointheight,int space,int bitmode,string addvalue,int iValueStartPlace,int iValueLen);
//中英文混排打印
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintMixTextEx")]
public static extern int BPLA_PrintMixTextEx(string text, int startx, int cn_starty, int xy_adjust, int rotate, string en_fonttype, string cn_fonttype, int pointwidth, int pointheight, string addvalue, int space, int bitmode);
//中英文混排打印
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintMixTextCmd")]
public static extern int BPLA_PrintMixTextCmd(string text, int startx, int cn_starty, int xy_adjust, int rotate, string en_fonttype, string cn_fonttype, int pointwidth, int pointheight, int space, int bitmode, string addvalue, int iValueStartPlace, int iValueLen);
//打印TRUETYPE字体
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintTruetype")]
public static extern int BPLA_PrintTruetype(string text, int startx, int starty, string fontname, int fontheight, int fontwidth);
//打印TRUETYPE字体
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintTruetypeEx")]
public static extern int BPLA_PrintTruetypeEx(string text, int startx, int starty, string fontname, int fontheight, int fontwidth, int rowrotate);
//打印TRUETYPE字体
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintTruetypeStyle")]
public static extern int BPLA_PrintTruetypeStyle(string text, int startx, int starty, string fontname, int fontheight, int fontwidth, ref TrueTypeFontStyle sStyle, int rowrotate);
//设置一维条码的版面位置
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintBarcode")]
public static extern int BPLA_PrintBarcode(string codedata, int startx, int starty, int rotate, int bartype, int height, int number, int numberbase, string addvalue);
//设置一维条码的版面位置
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintBarcodeEx")]
public static extern int BPLA_PrintBarcodeEx(string codedata, int startx, int starty, int rotate, int bartype, int height, int number, int numberbase, string addvalue, int iValueStartPlace, int iValueLen);
//设置PDF417码的版面位置
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintPDF")]
public static extern int BPLA_PrintPDF(string codedata, int startx, int starty, int rotate, int basewidth, int baseheight, int scalewidth, int scaleheight, int row, int column, int cutmode, int level, int length, string addvalue);
//设置PDF417码的版面位置
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintPDFEx")]
public static extern int BPLA_PrintPDFEx(string codedata,int startx,int starty,int rotate,int basewidth, int baseheight, int scalewidth,int scaleheight,
int row, int column,int cutmode,int level,int length,string addvalue,int iValueStartPlace,int iValueLen);
//设置Maxicode码的版面位置
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintMaxi")]
public static extern int BPLA_PrintMaxi(string codedata, int startx, int starty, string addvalue);
//设置Maxicode码的版面位置
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintMaxiEx")]
public static extern int BPLA_PrintMaxiEx(string codedata, int startx, int starty, string addvalue, int iValueStartPlace, int iValueLen);
//设置QR码的版面位置
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintQR")]
public static extern int BPLA_PrintQR(string codedata, int startx, int starty, int weigth, int symboltype, int languagemode, int number);
//设置DataMatrix码的版面位置
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_PrintDatamatrix")]
public static extern int BPLA_PrintDatamatrix(string codedata, int startx, int starty, int weigth, int reversecolor, int shape, int number);
//测试串口
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_CheckCom")]
public static extern int BPLA_CheckCom();
//测试状态
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_CheckStatus")]
public static extern int BPLA_CheckStatus(byte[] papershort, byte[] ribbionshort, byte[] busy, byte[] pause, byte[] com, byte[] headheat, byte[] headover, byte[] cut);
//测试切刀
[System.Runtime.InteropServices.DllImportAttribute("BPLADLL.dll", EntryPoint = "BPLA_CheckCut")]
public static extern int BPLA_CheckCut();
}
}
--------------------------------------------------------------------太长了,割一下,其实可以选择性导入----------------------------------------------------------------
接下来我又写了一个打印的类,没办法老师要求:
using System;
using System.Collections.Generic;
using System.Text;
using CUST;//别忘了添加引用哦
using System.Threading;
namespace YiShuPingFen
{
class Print
{
public bool Print_BQ(string bianhao)
{
try
{
int a;
#region==========打开USB==========
///int BPLA_OpenUsbPrn(int iDevID)
/*iDevID:[in] USB类模式设备编号,取值范围:> 0。
*/
a = PrinterDll.BPLA_OpenUsbPrn(1);//
if (a != PrinterDll.BPLA_OK)
throw new Exception();
#endregion
#region==========设置出纸方式==========
///int BPLA_Set(int iOutMode, int iPaperMode, int iPrintMode)
///
/*iOutMode :[in] 取值范围:0 --- 3,分别表示:切刀,剥离,撕离,回卷。
iPaperMode :[in] 取值范围:0:非连续纸,1:连续纸。
iPrintMode :[in] 取值范围:0:热敏打印,1:热转印打印。
*/
a = PrinterDll.BPLA_Set(1, 0, 1);//
if (a != PrinterDll.BPLA_OK)
throw new Exception();
#endregion
#region==========设置标签纸的大小设置==========
///int BPLA_SetPaperLength(int iContinueLength, int iLabelLength)
/*
* iContinueLength :[in] 连续纸长度,取值范围:0 --- 9999,如果为0,则不进行设置,单位:点,毫米/10,英寸/100。
iLabelLength :[in] 寻找标签的最大长度,取值范围:0 --- 9999,如果为0,则不进行设置,单位:点,毫米/10,英寸/100。
*/
a = PrinterDll.BPLA_SetPaperLength(600, 30);//
if (a != PrinterDll.BPLA_OK)
throw new Exception();
#endregion
#region==========设置停止位==========
///int BPLA_SetEnd(int iPosition)
///iPosition :[in] 取值范围:0 --- 999, 0:存在传感器和按键起作用,非0:打印机不判别是否撕掉或剥掉,直接出纸到停止位。
PrinterDll.BPLA_SetEnd(170);
#endregion
#region==========进入标签模式,设置打印区域及打印参数==========
///int BPLA_StartArea(int iUnitMode, int iPrintWidth, int iColumn, int iRow, int iDarkness, int iSpeedPrint, int iSpeedFor, int iSpeedBac) /*
* iUnitMode :[in] 单位模式,取值范围:0 --- 3 分别表示:0:默认单位,1:米制,2:点,3:英制。
iPrintWidth :[in] 打印宽度设置。取值范围:单位由参数iUnitMode决定, 0 --- 9999。
iColumn :[in] 列偏移数,取值范围:0 --- 9999。
iRow :[in] 行偏移数,取值范围:0 --- 9999。
iDarkness :[in] 打印浓度,取值范围:0 --- 30。
iSpeedPrint :[in] 打印速度,取值范围:0 --- 20。
iSpeedFor :[in] 进纸速度,取值范围:0 --- 20。
iSpeedBac :[in] 退纸速度,取值范围:0 --- 20。
*/
a = PrinterDll.BPLA_StartArea(2, 600, 11, 10, 0, 0, 0, 0);//进入标签模式,设置打印区域及打印参数
if (a != PrinterDll.BPLA_OK)
throw new Exception();
#endregion
#region==========标签头文字设置==========
///int BPLA_PrintTruetype(char *cText, int iStartX, int iStartY, char *cFontName, int iFontHeight, int iFontWidth)
/*
* cText :[in] 需要打印的文字。
iStartX :[in] 起点位置横坐标,取值范围:0 --- 9999。
iStartY :[in] 起点位置纵坐标,取值范围:0 --- 9999。
cFontName :[in] TRUETYPE字体名称,字符集依照系统默认字符集。
iFontHeight :[in] 字体高度,取值范围:>= 0
iFontWidth :[in] 字体宽度,取值范围:如果为0,则根据高度自动匹配宽度;如果不为0,则宽度为设定值,允许设置不规则字体。
*/
a = PrinterDll.BPLA_PrintTruetype("长春理工大学", 220, 220, "Arial", 25, 0);//
if (a != PrinterDll.BPLA_OK)
throw new Exception();
#endregion
#region==========标签条形码设置==========
/// int BPLA_PrintBarcode(char *cCodeData, int iStartX, int iStartY, int iRotate, int iBarType, int iHeight, int iNumber, int iNumberBase, char *cAddvalue)
/*
* cCodeData :[in] 条码数据。
iStartX :[in] 起点位置横坐标,取值范围:0 --- 9999。
iStartY :[in] 起点位置纵坐标,取值范围:0 --- 9999。
iRotate :[in] 旋转方向,取值范围:1 --- 4分别代表逆时针旋转0、90、180、270度。
iBarType :[in] 条码类型,取值范围:0 --- 19(有标记文字), 20-39(无标记文字)。参见“附录/条码说明”。
iHeight :[in] 条码高度,取值范围:0 --- 999。
iNumber :[in] 比例分子,取值范围:1 --- 24。
iNumberBase :[in] 比例分母,取值范围:1 --- 24。比例分子与分母的设置见参见“附录/条码说明”。
cAddvalue :[in] 连续域递变值,可以为字母或数字设定递变值,如果为字母,递增使用符号“>”,递减使用符号“<”,比如从“m”开始递增,每次跳一个,则可以使用“>01”,递减,每次跳一个,则使用“<01”;如果为数字,递增使用符号“+”,递减使用符号“-”,比如从“10”开始递增,每次加1,则可以使用“+01”,递减,每次减1,则使用“-01”,此项值必须是长度为3个字节的字符串,如“+10”、“-08”、“>20”、“<10”等等。如果不准备使用递变值,则必须将此项设置为“000”。
*/
a = PrinterDll.BPLA_PrintBarcode(bianhao, 150, 70, 1, 4, 100, 4, 2, "000");//
if (a != PrinterDll.BPLA_OK)
throw new Exception();
#endregion
Thread.Sleep(200);
#region==========打印==========
///int BPLA_Print(int iPieces, intiSamePieces, int iOutUnit)
/*
* iPieces :[in] 打印数量,取值范围:1 --- 9999。
iSamePieces :[in] 相同标签的打印数量,取值范围:0 --- 99。
iOutUnit :[in] 出纸单位,取值范围:1 --- 9999。
*/
PrinterDll.BPLA_Print(1, 1, 1);//
if (a != PrinterDll.BPLA_OK)
throw new Exception();
#endregion
#region==========错误信息==========
//string m_info;
//byte[] m_papershort = new byte[3],
// m_ribbionshort = new byte[3],
// m_busy = new byte[3],
// m_pause = new byte[3],
// m_com = new byte[3],
// m_headheat = new byte[3],
// m_headover = new byte[3],
// m_cut = new byte[3];
//int iState = PrinterDll.BPLA_CheckStatus(m_papershort, m_ribbionshort, m_busy, m_pause, m_com, m_headheat, m_headover, m_cut);
//if (iState != PrinterDll.BPLA_OK)
//{
// m_info = "查询状态失败,错误值 --- " + iState.ToString();
//}
//else
//{
// m_info = "";
// if (m_papershort[0] != 'N')
// {
// m_info += "缺纸";
// }
// if (m_ribbionshort[0] != 'N')
// {
// m_info += "缺色带";
// }
// if (m_busy[0] != 'N')
// {
// m_info += "解释器忙";
// }
// if (m_pause[0] != 'N')
// {
// m_info += "暂停";
// }
// if (m_com[0] != 'N')
// { // m_info += "通讯错误"; // }
// if (m_headover[0] != 'N')
// {
// m_info += "打印头抬起";
// }
// if (m_headheat[0] != 'N')
// {
// m_info += " 打印头过热";
// }
// if (m_cut[0] != 'N')
// {
// m_info += "切刀响应超时";
// }
// if (m_info == "")
// {
// m_info = "状态正常";
// }
//}
#endregion
#region==========复位打印机==========
/// int BPLA_Reset()
PrinterDll.BPLA_Reset();
#endregion
#region==========关闭USB==========
///int BPLA_CloseUsbPrn()
///
PrinterDll.BPLA_CloseUsbPrn();//
#endregion
return true;
}
catch (Exception)
{
PrinterDll.BPLA_Reset();
PrinterDll.BPLA_CloseUsbPrn();
return false;
}
}
}
}
在有打印机附送的三个.dll包的基础上能有一份帮助文档的话,介就是如虎添翼啊!
------------------------------------------------------------------------完了-------------------------------------------------------------------