public void GetStatusTest_ErrorStatus()
        {
            // Tests may run in parallel and since we are using a serial port
            // we should just run all queries in one test to avoid access issues.
            var printer = new ReliancePrinter(TEST_PORT);

            var status = printer.GetStatus(StatusTypes.ErrorStatus);

            Assert.IsNotNull(status);

            // Only these should be set
            Assert.IsNotNull(status.IsCutterOkay);
            Assert.IsNotNull(status.HasFatalError);
            Assert.IsNotNull(status.HasRecoverableError);

            // All the rest must be null
            Assert.IsNull(status.IsOnline);
            Assert.IsNull(status.IsPaperPresent);
            Assert.IsNull(status.IsPaperLevelOkay);
            Assert.IsNull(status.IsTicketPresentAtOutput);
            Assert.IsNull(status.IsCoverClosed);
            Assert.IsNull(status.IsPaperMotorOff);
            Assert.IsNull(status.IsDiagButtonReleased);
            Assert.IsNull(status.IsHeadTemperatureOkay);
            Assert.IsNull(status.IsCommsOkay);
            Assert.IsNull(status.IsPowerSupplyVoltageOkay);
            Assert.IsNull(status.IsPaperPathClear);
            Assert.IsNull(status.IsNormalFeed);
            Assert.IsNull(status.HasError);
        }
        public void REL_RealHardwareTest2DBarcodes()
        {
            var printer = new ReliancePrinter(TEST_PORT);

            Assert.IsNotNull(printer);

            printer.Print2DBarcode("0123456789AMANO");
            printer.FormFeed();
        }
        public void RelianceEffectsTest()
        {
            var printer = new ReliancePrinter(TEST_PORT);

            Assert.IsNotNull(printer);

            Assert.AreEqual(FontEffects.None, printer.Effects);

            // Set some effects
            printer.AddEffect(FontEffects.Bold);
            Assert.AreEqual(FontEffects.Bold, printer.Effects);

            printer.AddEffect(FontEffects.Italic);
            Assert.AreEqual(FontEffects.Bold | FontEffects.Italic, printer.Effects);

            printer.AddEffect(FontEffects.Underline);
            Assert.AreEqual(FontEffects.Bold | FontEffects.Italic | FontEffects.Underline, printer.Effects);

            printer.AddEffect(FontEffects.Rotated);
            Assert.AreEqual(FontEffects.Bold | FontEffects.Italic | FontEffects.Underline | FontEffects.Rotated,
                            printer.Effects);

            printer.AddEffect(FontEffects.Reversed);
            Assert.AreEqual(FontEffects.Bold | FontEffects.Italic | FontEffects.Underline | FontEffects.Rotated | FontEffects.Reversed,
                            printer.Effects);

            // Clear them out
            printer.ClearAllEffects();
            Assert.AreEqual(FontEffects.None, printer.Effects);

            // Set some effects
            printer.AddEffect(FontEffects.Bold | FontEffects.Italic | FontEffects.Underline | FontEffects.Rotated | FontEffects.Reversed);
            Assert.AreEqual(FontEffects.Bold | FontEffects.Italic | FontEffects.Underline | FontEffects.Rotated | FontEffects.Reversed, printer.Effects);

            printer.RemoveEffect(FontEffects.Bold);
            Assert.AreEqual(FontEffects.Italic | FontEffects.Underline | FontEffects.Rotated | FontEffects.Reversed, printer.Effects);

            printer.RemoveEffect(FontEffects.Italic);
            Assert.AreEqual(FontEffects.Underline | FontEffects.Rotated | FontEffects.Reversed, printer.Effects);

            printer.RemoveEffect(FontEffects.Underline);
            Assert.AreEqual(FontEffects.Rotated | FontEffects.Reversed,
                            printer.Effects);

            printer.RemoveEffect(FontEffects.Rotated);
            Assert.AreEqual(FontEffects.Reversed, printer.Effects);

            printer.RemoveEffect(FontEffects.Reversed);
            Assert.AreEqual(FontEffects.None, printer.Effects);
        }
        public void RelianceScalarTest()
        {
            // Test ctor
            var printer = new ReliancePrinter(TEST_PORT);

            Assert.IsNotNull(printer);

            // Ensure defaults are set
            Assert.AreEqual(FontWidthScalar.w1, printer.Width);
            Assert.AreEqual(FontHeighScalar.h1, printer.Height);

            // Set to something else and make sure the properties are messed up
            printer.SetScalars(FontWidthScalar.w8, FontHeighScalar.h2);

            Assert.AreEqual(FontWidthScalar.w8, printer.Width);
            Assert.AreEqual(FontHeighScalar.h2, printer.Height);
        }
        public void TestPrintJob()
        {
            // TODO enter the name of your printer
            var printerName = "Reliance (Copy 1)";


            var printer = new ReliancePrinter(printerName);

            var lineOfText = string.Format("Today is {0}\n", DateTime.Now.ToLongDateString());

            // TODO There is an open task for bold, italics, etc.
            var receiptContent = new TextContent();

            receiptContent.SetTabStops(0, new [] { 100.0f, 50.0f, 50.0f, 50.0f });

            receiptContent.TextBuilder.Append("\n");
            receiptContent.TextBuilder.Append("Item\tPrice\tQuantity\tTotal\n");
            receiptContent.TextBuilder.Append("Lettuce\t$4.99\t3\t$14.97\n");
            receiptContent.TextBuilder.Append("Seedless Bun\t$1.99\t3\t$5.97\n");
            receiptContent.TextBuilder.Append("\n\n");
            receiptContent.TextBuilder.Append(new string('-', 78));
            receiptContent.TextBuilder.Append("\n\tTotal");
            receiptContent.TextBuilder.AppendFormat("\t\t$20.94\n\n");

            var welcomeFont = new Font("Tahoma", 22);
            var trailerFont = new Font("Courier Mono", 12);

            var content = new List <IContent>
            {
                new ImageContent(Resources.small_lettuce_burgers),
                new TextContent("Welcome", welcomeFont, StringAlignment.Center),

                receiptContent,

                new TextContent(lineOfText, trailerFont),
                new TextContent("Ticket #007", justification: StringAlignment.Far),
            };

            var document = new Document
            {
                DocumentContent = content,
                AutoSize        = true,
            };

            printer.PrintDocument(document);
        }
        public void RelianceJustificationTest()
        {
            var printer = new ReliancePrinter(TEST_PORT);

            Assert.IsNotNull(printer);

            Assert.AreEqual(FontJustification.JustifyLeft, printer.Justification);

            // Set some justification
            printer.SetJustification(FontJustification.JustifyCenter);
            Assert.AreEqual(FontJustification.JustifyCenter, printer.Justification);

            printer.SetJustification(FontJustification.JustifyRight);
            Assert.AreEqual(FontJustification.JustifyRight, printer.Justification);

            printer.SetJustification(FontJustification.JustifyLeft);
            Assert.AreEqual(FontJustification.JustifyLeft, printer.Justification);
        }
        public void RelianceCtorTest()
        {
            var printer = new ReliancePrinter("TEST");

            Assert.IsNotNull(printer);
        }
        public void REL_RealHardwareTests()
        {
            var printer = new ReliancePrinter(TEST_PORT);

            Assert.IsNotNull(printer);

            printer.Reinitialize();

            printer.PrintASCIIString("No effects - Left");
            printer.PrintNewline();

            printer.AddEffect(FontEffects.Bold);
            printer.PrintASCIIString("This is bold");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Bold);
            printer.AddEffect(FontEffects.Italic);
            printer.PrintASCIIString("This is italic");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Italic);
            printer.AddEffect(FontEffects.Underline);
            printer.PrintASCIIString("This is underline");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Underline);
            printer.AddEffect(FontEffects.Rotated);
            printer.PrintASCIIString("This is rotated");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Rotated);
            printer.AddEffect(FontEffects.Reversed);
            printer.PrintASCIIString("This is reversed");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Reversed);
            printer.AddEffect(FontEffects.UpsideDown);
            printer.PrintASCIIString("This is upsideDown");
            printer.PrintNewline();

            printer.Reinitialize();
            printer.SetJustification(FontJustification.JustifyCenter);
            printer.PrintASCIIString("No effects - Center");
            printer.PrintNewline();

            printer.AddEffect(FontEffects.Bold);
            printer.PrintASCIIString("This is bold");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Bold);
            printer.AddEffect(FontEffects.Italic);
            printer.PrintASCIIString("This is italic");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Italic);
            printer.AddEffect(FontEffects.Underline);
            printer.PrintASCIIString("This is underline");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Underline);
            printer.AddEffect(FontEffects.Rotated);
            printer.PrintASCIIString("This is rotated");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Rotated);
            printer.AddEffect(FontEffects.Reversed);
            printer.PrintASCIIString("This is reversed");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Reversed);
            printer.AddEffect(FontEffects.UpsideDown);
            printer.PrintASCIIString("This is upsideDown");
            printer.PrintNewline();

            printer.Reinitialize();
            printer.SetJustification(FontJustification.JustifyRight);
            printer.PrintASCIIString("No effects - Right");
            printer.PrintNewline();

            printer.AddEffect(FontEffects.Bold);
            printer.PrintASCIIString("This is bold");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Bold);
            printer.AddEffect(FontEffects.Italic);
            printer.PrintASCIIString("This is italic");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Italic);
            printer.AddEffect(FontEffects.Underline);
            printer.PrintASCIIString("This is underline");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Underline);
            printer.AddEffect(FontEffects.Rotated);
            printer.PrintASCIIString("This is rotated");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Rotated);
            printer.AddEffect(FontEffects.Reversed);
            printer.PrintASCIIString("This is reversed");
            printer.PrintNewline();

            printer.RemoveEffect(FontEffects.Reversed);
            printer.AddEffect(FontEffects.UpsideDown);
            printer.PrintASCIIString("This is upsideDown");
            printer.PrintNewline();

            printer.Reinitialize();
            printer.PrintASCIIString("Scalars");
            printer.PrintNewline();

            printer.PrintASCIIString("WH1x");
            printer.SetScalars(FontWidthScalar.w2, FontHeighScalar.h2);
            printer.PrintASCIIString("WH2x");
            printer.SetScalars(FontWidthScalar.w3, FontHeighScalar.h3);
            printer.PrintASCIIString("WH3x");
            printer.SetScalars(FontWidthScalar.w4, FontHeighScalar.h4);
            printer.PrintASCIIString("WH4x");
            printer.SetScalars(FontWidthScalar.w5, FontHeighScalar.h5);
            printer.PrintASCIIString("WH5x");
            printer.SetScalars(FontWidthScalar.w6, FontHeighScalar.h6);
            printer.PrintASCIIString("WH6x");
            printer.SetScalars(FontWidthScalar.w7, FontHeighScalar.h7);
            printer.PrintASCIIString("WH7x");
            printer.SetScalars(FontWidthScalar.w8, FontHeighScalar.h8);
            printer.PrintASCIIString("WH8x");
            printer.PrintNewline();

            printer.PrintASCIIString("H1x");
            printer.SetScalars(FontWidthScalar.w1, FontHeighScalar.h2);
            printer.PrintASCIIString("H2x");
            printer.SetScalars(FontWidthScalar.w1, FontHeighScalar.h3);
            printer.PrintASCIIString("H3x");
            printer.SetScalars(FontWidthScalar.w1, FontHeighScalar.h4);
            printer.PrintASCIIString("H4x");
            printer.SetScalars(FontWidthScalar.w1, FontHeighScalar.h5);
            printer.PrintASCIIString("H5x");
            printer.SetScalars(FontWidthScalar.w1, FontHeighScalar.h6);
            printer.PrintASCIIString("H6x");
            printer.SetScalars(FontWidthScalar.w1, FontHeighScalar.h7);
            printer.PrintASCIIString("H7x");
            printer.SetScalars(FontWidthScalar.w1, FontHeighScalar.h8);
            printer.PrintASCIIString("H8x");
            printer.PrintNewline();

            printer.PrintASCIIString("W1x");
            printer.SetScalars(FontWidthScalar.w2, FontHeighScalar.h1);
            printer.PrintASCIIString("W2x");
            printer.SetScalars(FontWidthScalar.w3, FontHeighScalar.h1);
            printer.PrintASCIIString("W3x");
            printer.SetScalars(FontWidthScalar.w4, FontHeighScalar.h1);
            printer.PrintASCIIString("W4x");
            printer.SetScalars(FontWidthScalar.w5, FontHeighScalar.h1);
            printer.PrintASCIIString("W5x");
            printer.SetScalars(FontWidthScalar.w6, FontHeighScalar.h1);
            printer.PrintASCIIString("W6x");
            printer.SetScalars(FontWidthScalar.w7, FontHeighScalar.h1);
            printer.PrintASCIIString("W7x");
            printer.SetScalars(FontWidthScalar.w8, FontHeighScalar.h1);
            printer.PrintASCIIString("W8x");
            printer.PrintNewline();


            printer.PrintNewline();
            printer.FormFeed();
        }
Example #9
0
        static void Main(string[] args)
        {
            const string phoenixPort  = "COM1";
            const string reliancePort = "COM12";

            const int captureRate = 10; // number of seconds between capture

            Console.WriteLine("Starting Security Camera Sample");


            // Setup the header with double width, double height, center justified
            var header = new StandardSection()
            {
                Justification = FontJustification.JustifyCenter,
                HeightScalar  = FontHeighScalar.h2,
                WidthScalar   = FontWidthScalar.w2,
                Font          = ThermalFonts.A,
                AutoNewline   = true,
            };



            // Setup timestamp at normal scalar with bold, underline, and centered
            var timestamp = new StandardSection()
            {
                Justification = FontJustification.JustifyCenter,
                HeightScalar  = FontHeighScalar.h1,
                WidthScalar   = FontWidthScalar.w1,
                Effects       = FontEffects.Italic | FontEffects.Underline,
                Font          = ThermalFonts.B,
                AutoNewline   = true,
            };

            // Print Status is shown as a JSON object
            var printStatus = new StandardSection()
            {
                Justification = FontJustification.JustifyLeft,
                HeightScalar  = FontHeighScalar.h1,
                WidthScalar   = FontWidthScalar.w1,
                Font          = ThermalFonts.C,
                AutoNewline   = true,
            };

            // Document template
            // Capture #{}
            // Image....
            // Image....
            // Image...
            // Timestamp
            var document = new StandardDocument()
            {
                // Don't forget to set your codepage!
                CodePage = CodePages.CPSPACE,
            };

            document.Sections.Add(header);
            document.Sections.Add(new Placeholder());  // Placeholder since we know we'll want an image here
            document.Sections.Add(timestamp);
            document.Sections.Add(printStatus);

            int count = 1;

            while (true)
            {
                // Select one printer or the other. Phoenix does not currently
                // support dynamic images over ESC/POS. Images will only
                // be transmitted through the print queue but no examples have
                // been prepared for this.
                //using (var printer = new PhoenixPrinter(phoenixPort))
                using (var printer = new ReliancePrinter(reliancePort))
                    using (var image = Webcam.GrabPicture())
                    {
                        var now = DateTime.Now;
                        Console.WriteLine("Image #{0} taken at {1}", count, now);


                        // Resize image if we want. This will follow ESC/POS justification
                        //logo.Resize(640, 480);
                        image.ApplyDithering(Algorithms.JarvisJudiceNinke, 128);

                        // Print the header document, update with new capture number
                        header.Content = string.Format("Capture #{0} (ЫВФАЫВМОЫВАП)", count);

                        // Printer the timestamp document
                        timestamp.Content = string.Format("{0}: {1}", count++, now);

                        // Get the latest printer status. Note that reliance and phoenix have
                        // slightly different args to this get status command
                        printStatus.Content = printer.GetStatus(StatusTypes.FullStatus).ToJSON(true);

                        // Re-assign this image to the middle part of the document
                        printer.SetImage(image, document, 1);

                        // Send the whole document + image
                        printer.PrintDocument(document);
                        printer.FormFeed();

                        // Wait for next capture period
                        Thread.Sleep(captureRate * 1000);
                    }
            }
        }