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);
        }
Beispiel #2
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);
                    }
            }
        }