Exemplo n.º 1
0
        /// <summary>
        /// Returns the status of the printer.
        /// </summary>
        /// <returns>An object that contains the status of the printer.</returns>
        public override PrinterStatus GetStatus()
        {
            int  resultCode;
            long statusCode;
            var  printerStatus = new PrinterStatus();

            resultCode = niiPrinter.NiiGetStatus(PrinterName, out statusCode);
            if (resultCode != 0)
            {
                LastException = new NiiStatusException(resultCode);
                throw LastException;
            }

            statusCode = statusCode & 0x1F;
            printerStatus.ReceiptPaperNearEmpty = (statusCode & 0x01) > 0;
            printerStatus.CoverOpen             = (statusCode & 0x02) > 0;
            printerStatus.ReceiptPaperEmpty     = (statusCode & 0x04) > 0;
            printerStatus.OverTemp    = (statusCode & 0x08) > 0;
            printerStatus.CutterError = (statusCode & 0x10) > 0;
            printerStatus.IsOffline   = (statusCode & 0x80) > 0;

            if (LastStatus == null)
            {
                LastStatus = printerStatus;
            }

            return(printerStatus);
        }
Exemplo n.º 2
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                var status           = GetStatus();
                var comparisonResult = compareLogic.Compare(status, LastStatus);

                LastException = null;
                LastStatus    = status;

                if (!comparisonResult.AreEqual)
                {
                    OnPrinterStatusUpdate(EventArgs.Empty);
                }
            }
            catch (NiiStatusException ex)
            {
                var comparisonResult = compareLogic.Compare(ex, LastException);
                LastException = ex;
                if (!comparisonResult.AreEqual)
                {
                    OnPrinterStatusUpdate(EventArgs.Empty);
                }
            }
            finally
            {
                timer.Enabled = true;
            }
        }