文档章节

PPLB条码打印

深圳大道
 深圳大道
发布于 2016/12/29 15:39
字数 1815
阅读 6
收藏 0
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;//This is about DllImport.

namespace VCsharp_2005
{
    public partial class Form1 : Form
    {
        const uint IMAGE_BITMAP = 0;
        const uint LR_LOADFROMFILE = 16;
        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType,
           int cxDesired, int cyDesired, uint fuLoad);
        [DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern int DeleteObject(IntPtr ho);
        const string szSavePath = "C:\\Argox";
        const string szSaveFile = "C:\\Argox\\PPLB_Example.Prn";
        const string sznop1     = "nop_front\r\n";
        const string sznop2     = "nop_middle\r\n";
        [DllImport("Winpplb.dll")]
        private static extern int B_Bar2d_Maxi(int x, int y, int cl, int cc, int pc, string data);
        [DllImport("Winpplb.dll")]
        private static extern int B_Bar2d_PDF417(int x, int y, int w, int v, int s, int c, int px, 
            int py, int r, int l, int t, int o, string data);
        [DllImport("Winpplb.dll")]
        private static extern int B_Bar2d_PDF417_N(int x, int y, int w, string para, string data);
        [DllImport("Winpplb.dll")]
        private static extern void B_ClosePrn();
        [DllImport("Winpplb.dll")]
        private static extern int B_CreatePrn(int selection, string filename);
        [DllImport("Winpplb.dll")]
        private static extern int B_Del_Form(string formname);
        [DllImport("Winpplb.dll")]
        private static extern int B_Del_Pcx(string pcxname);
        [DllImport("Winpplb.dll")]
        private static extern int B_Draw_Box(int x, int y, int thickness, int hor_dots, 
            int ver_dots);
        [DllImport("Winpplb.dll")]
        private static extern int B_Draw_Line(char mode, int x, int y, int hor_dots, int ver_dots);
        [DllImport("Winpplb.dll")]
        private static extern int B_Error_Reporting(char option);
        [DllImport("Winpplb.dll")]
        private static extern IntPtr B_Get_DLL_Version(int nShowMessage);
        [DllImport("Winpplb.dll")]
        private static extern int B_Get_DLL_VersionA(int nShowMessage);
        [DllImport("Winpplb.dll")]
        private static extern int B_Get_Graphic_ColorBMP(int x, int y, string filename);
        [DllImport("Winpplb.dll")]
        private static extern int B_Get_Graphic_ColorBMPEx(int x, int y, int nWidth, int nHeight,
            int rotate, string id_name, string filename);
        [DllImport("Winpplb.dll")]
        private static extern int B_Get_Graphic_ColorBMP_HBitmap(int x, int y, int nWidth, int nHeight,
           int rotate, string id_name, IntPtr hbm);
        [DllImport("Winpplb.dll")]
        private static extern int B_Get_Pcx(int x, int y, string filename);
        [DllImport("Winpplb.dll")]
        private static extern int B_Initial_Setting(int Type, string Source);
        [DllImport("Winpplb.dll")]
        private static extern int B_WriteData(int IsImmediate, byte[] pbuf, int length);
        [DllImport("Winpplb.dll")]
        private static extern int B_ReadData(byte[] pbuf, int length, int dwTimeoutms);
        [DllImport("Winpplb.dll")]
        private static extern int B_Load_Pcx(int x, int y, string pcxname);
        [DllImport("Winpplb.dll")]
        private static extern int B_Open_ChineseFont(string path);
        [DllImport("Winpplb.dll")]
        private static extern int B_Print_Form(int labset, int copies, string form_out, string var);
        [DllImport("Winpplb.dll")]
        private static extern int B_Print_MCopy(int labset, int copies);
        [DllImport("Winpplb.dll")]
        private static extern int B_Print_Out(int labset);
        [DllImport("Winpplb.dll")]
        private static extern int B_Prn_Barcode(int x, int y, int ori, string type, int narrow, 
            int width, int height, char human, string data);
        [DllImport("Winpplb.dll")]
        private static extern void B_Prn_Configuration();
        [DllImport("Winpplb.dll")]
        private static extern int B_Prn_Text(int x, int y, int ori, int font, int hor_factor, 
            int ver_factor, char mode, string data);
        [DllImport("Winpplb.dll")]
        private static extern int B_Prn_Text_Chinese(int x, int y, int fonttype, string id_name, 
            string data);
        [DllImport("Winpplb.dll")]
        private static extern int B_Prn_Text_TrueType(int x, int y, int FSize, string FType, 
            int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut, string id_name, 
            string data);
        [DllImport("Winpplb.dll")]
        private static extern int B_Prn_Text_TrueType_W(int x, int y, int FHeight, int FWidth, 
            string FType, int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut, 
            string id_name, string data);
        [DllImport("Winpplb.dll")]
        private static extern int B_Select_Option(int option);
        [DllImport("Winpplb.dll")]
        private static extern int B_Select_Option2(int option, int p);
        [DllImport("Winpplb.dll")]
        private static extern int B_Select_Symbol(int num_bit, int symbol, int country);
        [DllImport("Winpplb.dll")]
        private static extern int B_Select_Symbol2(int num_bit, string csymbol, int country);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_Backfeed(char option);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_BMPSave(int nSave, string strBMPFName);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_Darkness(int darkness);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_DebugDialog(int nEnable);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_Direction(char direction);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_Form(string formfile);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_Labgap(int lablength, int gaplength);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_Labwidth(int labwidth);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_Originpoint(int hor, int ver);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_Prncomport(int baud, char parity, int data, int stop);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_Prncomport_PC(int nBaudRate, int nByteSize, int nParity, 
            int nStopBits, int nDsr, int nCts, int nXonXoff);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_Speed(int speed);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_ProcessDlg(int nShow);
        [DllImport("Winpplb.dll")]
        private static extern int B_GetUSBBufferLen();
        [DllImport("Winpplb.dll")]
        private static extern int B_EnumUSB(byte[] buf);
        [DllImport("Winpplb.dll")]
        private static extern int B_CreateUSBPort(int nPort);
        [DllImport("Winpplb.dll")]
        private static extern int B_ResetPrinter();
        [DllImport("Winpplb.dll")]
        private static extern int B_GetPrinterResponse(byte[] buf, int nMax);
        [DllImport("Winpplb.dll")]
        private static extern int B_TFeedMode(int nMode);
        [DllImport("Winpplb.dll")]
        private static extern int B_TFeedTest();
        [DllImport("Winpplb.dll")]
        private static extern int B_CreatePort(int nPortType, int nPort, string filename);
        [DllImport("Winpplb.dll")]
        private static extern int B_Execute_Form(string form_out, string var);
        [DllImport("Winpplb.dll")]
        private static extern int B_Bar2d_QR(int x, int y, int model, int scl, char error, 
            char dinput, int c, int d, int p, string data);
        [DllImport("Winpplb.dll")]
        private static extern int B_GetNetPrinterBufferLen();
        [DllImport("Winpplb.dll")]
        private static extern int B_EnumNetPrinter(byte[] buf);
        [DllImport("Winpplb.dll")]
        private static extern int B_CreateNetPort(int nPort);
        [DllImport("Winpplb.dll")]
        private static extern int B_Prn_Text_TrueType_Uni(int x, int y, int FSize, string FType, 
            int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut, string id_name, 
            byte[] data, int format);
        [DllImport("Winpplb.dll")]
        private static extern int B_Prn_Text_TrueType_UniB(int x, int y, int FSize, string FType, 
            int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut, string id_name, 
            byte[] data, int format);
        [DllImport("Winpplb.dll")]
        private static extern int B_GetUSBDeviceInfo(int nPort, byte[] pDeviceName, 
            out int pDeviceNameLen, byte[] pDevicePath, out int pDevicePathLen);
        [DllImport("Winpplb.dll")]
        private static extern int B_Set_EncryptionKey(string encryptionKey);
        [DllImport("Winpplb.dll")]
        private static extern int B_Check_EncryptionKey(string decodeKey, string encryptionKey, 
            int dwTimeoutms);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Test code start
	        // open port.
            int nLen, ret, sw;
            byte[] pbuf = new byte[128];
	        string strmsg;
            IntPtr ver;
            System.Text.Encoding encAscII = System.Text.Encoding.ASCII;
            System.Text.Encoding encUnicode = System.Text.Encoding.Unicode;

	        // dll version.
	        ver = B_Get_DLL_Version(0);

	        // search port.
	        nLen = B_GetUSBBufferLen() + 1;
            strmsg = "DLL ";
            strmsg += Marshal.PtrToStringAnsi(ver);
            strmsg += "\r\n";
	        if (nLen > 1)
	        {
                byte[] buf1, buf2;
		        int len1 = 128, len2 = 128;
                buf1 = new byte[len1];
                buf2 = new byte[len2];
		        B_EnumUSB(pbuf);
		        B_GetUSBDeviceInfo(1, buf1, out len1, buf2, out len2);
                sw = 1;
                if (1 == sw)
                {
                    ret = B_CreatePrn(12, encAscII.GetString(buf2, 0, len2));// open usb.
                }
                else
                {
                    ret = B_CreateUSBPort(1);// must call B_GetUSBBufferLen() function fisrt.
                }
		        if (0 != ret) {
                    strmsg += "Open USB fail!";
		        }
		        else {
                    strmsg += "Open USB:\r\nDevice name: ";
                    strmsg += encAscII.GetString(buf1, 0, len1);
                    strmsg += "\r\nDevice path: ";
                    strmsg += encAscII.GetString(buf2, 0, len2);
                    //sw = 2;
                    if (2 == sw)
                    {
                        //Immediate Error Report.
                        B_WriteData(1, encAscII.GetBytes("^ee\r\n"), 5);//^ee
                        ret = B_ReadData(pbuf, 4, 1000);
                    }
		        }
	        }
	        else
	        {
                System.IO.Directory.CreateDirectory(szSavePath);
                ret = B_CreatePrn(0, szSaveFile);// open file.
                strmsg += "Open ";
                strmsg += szSaveFile;
		        if (0 != ret) {
                    strmsg += " file fail!";
		        }
		        else {
                    strmsg += " file succeed!";
		        }
	        }
            MessageBox.Show(strmsg);
	        if (0 != ret)
		        return;

	        // sample setting.
	        B_Set_DebugDialog(1);
	        B_Set_Originpoint(0,0);
	        B_Select_Option(2);
	        B_Set_Darkness(8);
	        B_Del_Pcx("*");// delete all picture.
            B_WriteData(0, encAscII.GetBytes(sznop2), sznop2.Length);
            B_WriteData(1, encAscII.GetBytes(sznop1), sznop1.Length);

	        //draw box.
	        B_Draw_Box(20, 20, 4, 760, 560);
	        B_Draw_Line('O', 400, 20, 4, 540);

	        //print text, true type text.
	        B_Prn_Text(30, 40, 0, 2, 1, 1, 'N', "PPLB Lib Example");
	        B_Prn_Text_TrueType(30,100,30,"Arial",1,400,0,0,0,"AA","TrueType Font");//save in printer.
	        B_Prn_Text_TrueType_W(30,160,20,20,"Times New Roman",1,400,0,0,0,"AB","TT_W: 多字元測試");
	        B_Prn_Text_TrueType_Uni(30,220,30,"Times New Roman",1,400,0,0,0,"AC",Encoding.Unicode.GetBytes("TT_Uni: 多字元測試"),1);//UTF-16
            encUnicode.GetBytes("\xFEFF", 0, 1, pbuf, 0);//UTF-16.//pbuf[0]=0xFF,pbuf[1]=0xFE;
            encUnicode.GetBytes("TT_UniB: 多字元測試", 0, 14, pbuf, 2);//copy mutil byte.
            encUnicode.GetBytes("\x0000", 0, 1, pbuf, 30);//null.//pbuf[30]=0x00,pbuf[31]=0x00;
	        B_Prn_Text_TrueType_UniB(30,280,30,"Times New Roman",1,400,0,0,0,"AD",pbuf,0);//Byte Order Mark.

	        //barcode.
	        B_Prn_Barcode(420, 100, 0, "3", 2, 3, 40, 'B', "1234<+1>");//have a counter
	        B_Bar2d_QR(420, 200, 1, 3, 'M', 'A', 0, 0, 0, "QR CODE");

	        //picture.
            B_Get_Graphic_ColorBMP(420, 280, "bb.bmp");// Color bmp file.
            B_Get_Graphic_ColorBMPEx(420, 320, 200, 150, 2, "bb1", "bb.bmp");//180 angle.
            IntPtr himage = LoadImage(IntPtr.Zero, "bb.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
            B_Get_Graphic_ColorBMP_HBitmap(630, 280, 250, 80, 1, "bb2", himage);//90 angle.
            if (IntPtr.Zero != himage)
                DeleteObject(himage);

	        // output.
	        B_Print_Out(2);// copy 2.

	        // close port.
	        B_ClosePrn();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //PPLBDLL Test code start
            //B_CreatePrn(0, null);

            /*
                int B_CreatePrn(int selection, LPCTSTR filename);             
                參數:
                selection;
                  選擇輸出埠或檔案。
                  0 -> print to file.
                  1 -> lpt1, 2 -> lpt2, 3 -> lpt3
                  4 -> com1, 5 -> com2, 6 -> com3
                  10 -> pipe, 11 -> USBXXX, 12 -> USB
                  13 -> LAN Client(TCP/IP)
                filename;
                  當 selection 是 0 時,資料則輸出至檔案,filename 為檔案名稱,可含路徑。
                  當 selection 是 10 時,filename 為輸出路徑或機碼(裝置路徑)。
                  當 selection 是 11 時,filename 指的是想開啟的USB之index, index由1開始;
                  當 selection 是 12 時,filename 指的是想開啟的USB機碼(裝置路徑), 
                  和nPort = 10的使用方法一樣
                  當 selection 內容是 13 時, filename 指的是想開啟的IP Address, 使用TCP/IP去開啟; 
                  預設的port值為9100, 若要指定port值, 如80, 則在IPAddress後加上字串":80".   
             * 
                int B_CreateUSBPort(int nPort);
                參數:
                    nPort;
                      USB 傳輸埠 ; nPort由1開始.
             */
            // USB Port Open
            int nUSBDataLen;
            byte[] pbuf;
            nUSBDataLen = B_GetUSBBufferLen()+1;
            pbuf = new byte[nUSBDataLen];
            B_EnumUSB(pbuf);
            B_CreateUSBPort(1);


            // Open com3
            //B_CreatePort(1, 3, null);
            //B_Set_Darkness(8);
            //B_Select_Option(1);
            //B_Set_Labgap(50,24);
            //B_Set_Labwidth(816);
            //B_Set_Speed(2);
            //B_Error_Reporting('S');

            B_Prn_Text(100, 200, 0, 3, 1, 1, 'N', "FONT 3");    //Get a text string.
            // B_Prn_Text(200,10,1,3,1,1,'N',"Text 3<+1>");
            B_Prn_Barcode(20, 20, 0, "1", 3, 3, 75, 'B', "079-305"); //Get a bar code.
            //Get a PDF-417 2D bar code.
            //B_Bar2d_PDF417(50, 150, 400, 300, 0, 0, 3, 7, 10, 2, 0, 0, "ARGOXINFO");
            //Get a Maxi Code 2D bar code.
            B_Bar2d_Maxi(400, 10, 300, 400, 93065, "This MaxiCode");
            B_Draw_Line('E', 380, 200, 100, 10);  //Line Draw by Exclusive or operation.
            //B_Draw_Line('O', 400, 180, 10, 100);  //Line draw by or operation.
            //B_Draw_Line('W', 380, 220, 100, 10); //Draw white line.
            //B_Draw_Line('E', 450, 180, 20, 110);  //Line Draw by Exclusive or operation.
            //B_Draw_Box(0, 0, 5, 815, 300);     //Draw a box.
            // B_Get_Pcx(50,55,"phone.pcx"); //Print Graphics of .PCX.
            //B_Get_Pcx(400,0,"test1.pcx");
            B_Prn_Text_TrueType(450, 20, 40, "Times New Roman", 1, 400, 0, 0, 0, "AA", "Library Test");
            // Get a truetype text
            //B_Prn_Text_TrueType(30,50,20,"Arial",4,400,0,0,0,"AB","TrueType Font");
            B_Print_Out(1);
            B_ClosePrn();
            //PPLBDLL Test code end
        }
    }
}

本文转载自:http://blog.csdn.net/smartsmile2012/article/details/36675171

深圳大道
粉丝 3
博文 877
码字总数 0
作品 0
深圳
架构师
私信 提问
免费在线生成QR-Code 名片

QR-Code 名片:使用二维条码自动管理联系人! 您可以使用此款免费条码名片生成器来制作“电子化”名片!您只需要输入您的数据,打印名片并用您的智能手机扫描二维条码即可。完成 — 无需打字...

夜莺的歌
2014/10/27
1K
0
Label mx条码软件导入Excel处理异常解决方法

Excel表格是最常用的存储数据资料的文件之一。比如说客户信息、产品信息等等这类资料信息。在印刷、防伪行业中,也经常用Txt文本和Excel表格来存储信息,实现批量打印。在条码打印软件《Lab...

张米娜
2013/05/29
1K
0
GoodMES云标签亮相2017第九届深圳国际物联网博览会

8月16-18日,2017第九届深圳国际物联网博览会(IOTE)在深圳会展中心盛大开幕。作为国内制造业信息化和工业智能制造领域的专业供应商,上海因致信息科技有限公司携旗下核心产品GoodMES云标签...

玄学酱
2018/03/07
0
0
生产制造追溯系统-再说条码打印

前言 在之前的博客中我介绍了如何实现生产现场的条码打印,我们的生活中到处都是条码,一维码、二维码随处可见,更别说一家从事生产制造加工的工厂了,而条码种类繁多、离线打印等情况就直接...

无 影
05/03
0
0
Lodop是什么?

有人说她是Web打印控件,因为她能打印、在浏览器中以插件的形式出现,用简单一行语句就把整个网页打印出来; 有人说她是打印编程接口,因为她介于浏览器和打印设备之间,是个通道和桥梁,几乎...

淡定的米哥
2014/05/06
789
1

没有更多内容

加载失败,请刷新页面

加载更多

一、docker 入坑(win10和Ubuntu 安装)

前言 终究还是绕不过去了,要学的知识真的是太多了,好在我们还有时间,docker 之前只闻其声,不曾真正的接触过,现在docker 越来越火,很多公司也都开始使用了。所以对于我们程序员而言,又...

quellanan2
12分钟前
4
0
AutoCompleteTextView

小技巧按菜单键 当菜单打开之前会调用onMenuOpened(int featereId,Menu menu),可以重写这个方法,弹出对话框或者Popmenu 再布局中添加控件AutoCompleteTextView. <AutoCompleteTextVie...

逆天游云
15分钟前
4
0
谷歌软件商店:推出5美元会员 可用数百个软件

腾讯科技讯,谷歌和苹果是全球两大智能手机操作系统的运营者,两家公司旗下分别拥有占据行业垄断地位的谷歌软件商店和苹果软件商店。据外媒最新消息,手机软件商店的商业模式正在发生一些变化...

linuxCool
38分钟前
3
0
RocketMQ 多副本前置篇:初探raft协议

Raft协议是分布式领域解决一致性的又一著名协议,主要包含Leader选举、日志复制两个部分。 温馨提示: 本文根据raft官方给出的raft动画进行学习,其动画展示地址:http://thesecretlivesofda...

中间件兴趣圈
38分钟前
2
0
elasticsearch 6.8.0 添加认证

1. 修改elasticsearch-6.8.0/config/elasticsearch.yml 最后添加一行:xpack.security.enabled: true 2. 初始化用户和密码 ./bin/elasticsearch-setup-passwords interactive 我这里初始化为......

coord
40分钟前
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部