老師要給招生辦寫一個藝術招生考試評分系統,以下是打印條形碼部分,這一部分就是我昨晚奮戰一晚的結晶啊!網上找不到任何資料,僅憑打印機器附送的一份兒幫助文檔。沒有完全是從無到有,從零開始的啊!一步一步都是試出來的,光標簽紙都浪費了三四米!
現在回頭想,其實也沒什么深奧的東西,只是比較偏重於硬件底層。做完這個打印機的工作原理我倒了解了不少!主要的還是對打印機進行二次開發!
首先,你需要三個新北洋的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包的基礎上能有一份幫助文檔的話,介就是如虎添翼啊!
------------------------------------------------------------------------完了-------------------------------------------------------------------
