Example #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();
            }
        }
Example #2
0
        private void btCutMarkBack_Click(object sender, EventArgs e)
        {
            bool printpoint   = false; // 切/撕纸位置
            bool front        = false;
            int  resultLength = int.Parse(tbCutMarkBack.Text);

            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))
            {
                byte[] cmddata1 = { 0X1D, 0X54 };
                byte[] cmddata2 = { 0X1D, 0X28, 0x46, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00 };

                if (printpoint == true)
                {
                    cmddata2[5] = 0x01;
                }
                else
                {
                    cmddata2[5] = 0x02;
                }

                if (front == true)
                {
                    cmddata2[6] = 0x00;
                }
                else
                {
                    cmddata2[6] = 0x01;
                }

                cmddata2[7] = (byte)Math.Round((resultLength / 0.176) % 256);
                cmddata2[8] = (byte)((resultLength / 0.176) / 256);
                LoadPOSDll.POS_WriteFile(PosPrint.POS_IntPtr, cmddata2, (uint)cmddata2.Length);

                PosPrint.ClosePrinterPort();
            }
        }
Example #3
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();
            }
        }