Exemple #1
0
        public static bool Print(byte[] bytes, string ip, int port)
        {
            bool           result = false;
            Connection_TCP conn   = null;

            try
            {
                DocumentDPL   docDPL   = new DocumentDPL();
                ParametersDPL paramDPL = new ParametersDPL();
                docDPL.ColumnOffset = 65;
                docDPL.RowOffset    = 0;
                MemoryStream ms = new MemoryStream();
                ms.Write(bytes, 0, bytes.Length);
                Bitmap anImage = new Bitmap(ms);
                anImage.RotateFlip(RotateFlipType.Rotate90FlipX);
                docDPL.WriteImage(anImage, DocumentDPL.ImageType.Other, 0, 0, paramDPL);
                byte[] printData = docDPL.GetDocumentImageData();

                conn = Connection_TCP.CreateClient(ip, port);

                conn.Open();

                uint bytesWritten   = 0;
                uint bytesToWrite   = 1024;
                uint totalBytes     = (uint)printData.Length;
                uint remainingBytes = totalBytes;
                while (bytesWritten < totalBytes)
                {
                    if (remainingBytes < bytesToWrite)
                    {
                        bytesToWrite = remainingBytes;
                    }
                    conn.Write(printData, (int)bytesWritten, (int)bytesToWrite);
                    bytesWritten  += bytesToWrite;
                    remainingBytes = remainingBytes - bytesToWrite;
                }
                conn.WaitForEmptyBuffer(5000);
                conn.Close();
                Thread.Sleep(1000);
                result = true;
            }
            catch
            {
                // ignore
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }

            return(result);
        }
Exemple #2
0
        static void SendDPLCommandsToPrinter()
        {
            ConnectionBase conn =
                (Connection_Bluetooth32Feet)Connection_Bluetooth32Feet.CreateClient("84253f441544", true);

            //ConnectionBase conn = (Connection_Serial)Connection_Serial.CreateClient("COM21", 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One, System.IO.Ports.Handshake.None);
            conn.Open();

            LanguageFiles_DPL langdpl   = new LanguageFiles_DPL(conn);
            PrinterStatus_DPL statusdpl = new PrinterStatus_DPL(conn);
            Images_DPL        imagedpl  = new Images_DPL(conn);
            DocumentDPL       dpl       = new DocumentDPL();

            //Document doc = new Document();
            //byte[] by = doc.GetDocumentData();

            Console.WriteLine("Enter 1 to start printing...");
            var input = Console.ReadLine();
            int count = 1;

            if (input == "1")
            {
                while (input == "1" && count <= 3)
                {
                    char SOH = (char)0x01;
                    char STX = (char)0x02;
                    char CR  = (char)0x0D;

                    string send_text = STX + "L" + CR;
                    send_text += "D11" + CR;
                    send_text += "1Y11000002000451_Monochrome.DIM" + CR;
                    //send_text += "1911A1200200020HOW ARE YOU" + CR;
                    //send_text += "4911A1200200160HONEYWELL IS DOING GOOD" +
                    //    " 000000" + CR;
                    //send_text += "1A9304001300180123456" + CR;
                    //send_text += "2A9304001200520789" + CR;
                    send_text += "E" + CR;
                    conn.Write(send_text);
                    //conn.Write(ImageToByteArray(@"C:\Users\h387014\Documents\Cases\1_Monochrome.bmp"), 1, 10000);
                    conn.Write(PDFToByteArray(@"C:\Users\h387014\Downloads\DPL PatronTicket__POSTickets.pdf"), 1, 10000);

                    statusdpl.Update(3000);
                    List <string> printerstatusstring = statusdpl.QueryResults();

                    count = count + 1;
                    foreach (string item in printerstatusstring)
                    {
                        Console.WriteLine(item.ToString());
                    }
                    Console.ReadLine();
                }
                conn.Close();
            }
        }