Beispiel #1
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (serialPort1 == null)
            {
                serialPort1           = new SerialPort();
                serialPort1.RtsEnable = true;
            }
            if (serialPort1.IsOpen)
            {
                serialPort1.Close();
            }
            serialPort1.PortName        = "COM1";
            serialPort1.BaudRate        = 19200;
            serialPort1.Parity          = (Parity)Enum.Parse(typeof(Parity), "None");
            serialPort1.DataBits        = 8;
            serialPort1.StopBits        = (StopBits)Enum.Parse(typeof(StopBits), "One");
            serialPort1.ReadBufferSize  = 100;
            serialPort1.WriteBufferSize = 2048;
            serialPort1.ReadTimeout     = 100;
            serialPort1.WriteTimeout    = 10000;
            LoadPOSDll PosPrint = new LoadPOSDll();

            if (PosPrint.OpenComPort(ref serialPort1))
            {
                LoadPOSDll.POS_Reset();
                PosPrint.PrintBmpInFlash(1, 0, 0x00);
                PosPrint.PrintBmpInFlash(2, 0, 0x00);
                PosPrint.PrintBmpInFlash(3, 0, 0x00);
                PosPrint.PrintBmpInFlash(4, 0, 0x00);
                PosPrint.ClosePrinterPort();
            }
        }
Beispiel #2
0
        private void btPrintGoNextCut_Click(object sender, EventArgs e)
        {
            if (serialPort1 == null)
            {
                serialPort1           = new SerialPort();
                serialPort1.RtsEnable = true;
            }
            if (serialPort1.IsOpen)
            {
                serialPort1.Close();
            }
            serialPort1.PortName        = "COM1";
            serialPort1.BaudRate        = 9600;
            serialPort1.Parity          = (Parity)Enum.Parse(typeof(Parity), "None");
            serialPort1.DataBits        = 8;
            serialPort1.StopBits        = (StopBits)Enum.Parse(typeof(StopBits), "One");
            serialPort1.ReadBufferSize  = 100;
            serialPort1.WriteBufferSize = 2048;
            serialPort1.ReadTimeout     = 100;
            serialPort1.WriteTimeout    = 10000;
            LoadPOSDll PosPrint = new LoadPOSDll();

            if (PosPrint.OpenComPort(ref serialPort1))
            {
                LoadPOSDll.POS_Reset();

                byte[] data1 = System.Text.Encoding.Default.GetBytes("开始打印");
                byte[] data2 = System.Text.Encoding.Default.GetBytes("然后走纸到下一个/撕纸位置");
                LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, data1, (uint)data1.Length);
                LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, new byte[] { 0x0a }, 1);
                LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, data2, (uint)data2.Length);

                LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, new byte[] { 0x1B, 0x64, 0x05, 0x0A }, 4);       //打印并进纸 n 行(0x05行)
                LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, new byte[] { 0x1D, 0x54, 0x1D, 0x56, 0x30 }, 5); //一种切纸模式并切纸(1D 56)30 31
                LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, new byte[] { 0x0D }, 1);                         //把打印起始位置设置为该行的开始

                PosPrint.ClosePrinterPort();
            }
        }