Exemplo n.º 1
0
        /// <inheritdoc />
        /// <summary>
        /// This command is processed in real time. The reply to this command is sent
        /// whenever it is received and does not wait for previous ESC/POS commands to be executed first.
        /// If there is no response or an invalid response, IsValidReport will be set to false
        /// </summary>
        /// <remarks>Phoenix does not support Error or Movement status request type</remarks>
        /// <param name="type">StatusRequest type</param>
        /// <returns>Instance of PhoenixStatus</returns>
        public override StatusReport GetStatus(StatusTypes type)
        {
            ReturnCode ret;

            // Translate generic status to phoenix status
            PhoenixStatusRequests r;

            switch (type)
            {
            case StatusTypes.PrinterStatus:
                r = PhoenixStatusRequests.Status;
                break;

            case StatusTypes.OfflineStatus:
                r = PhoenixStatusRequests.OffLineStatus;
                break;

            case StatusTypes.ErrorStatus:
                return(StatusReport.Invalid());;
                break;

            case StatusTypes.PaperStatus:
                r = PhoenixStatusRequests.PaperRollStatus;
                break;

            case StatusTypes.MovementStatus:
                // Not supported on Phoenix
                return(StatusReport.Invalid());;

            case StatusTypes.FullStatus:
                r = PhoenixStatusRequests.FullStatus;
                break;

            default:
                // Unknown status type
                return(StatusReport.Invalid());
            }

            var rts = new StatusReport();

            if (r == PhoenixStatusRequests.FullStatus)
            {
                ret = internalGetStatus(PhoenixStatusRequests.Status, rts);
                ret = ret != ReturnCode.Success ? ret : internalGetStatus(PhoenixStatusRequests.PaperRollStatus, rts);
                ret = ret != ReturnCode.Success ? ret : internalGetStatus(PhoenixStatusRequests.OffLineStatus, rts);

                // Not supported PP-82
                //ret = ret != ReturnCode.Success ? ret : internalGetStatus(PhoenixStatusRequests.ErrorStatus, rts);
            }
            else
            {
                ret = internalGetStatus(r, rts);
            }

            // Return null status object on error
            return(ret == ReturnCode.Success ? rts : StatusReport.Invalid());
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        /// <summary>
        /// This command is processed in real time. The reply to this command is sent
        /// whenever it is received and does not wait for previous ESC/POS commands to be executed first.
        /// If there is no response or an invalid response, If there is a read timeout or comm failure, the
        /// result will have the IsValidReport set to false.
        /// </summary>
        /// <param name="type">StatusRequest type</param>
        /// <returns>Instance of RelianceStatus</returns>
        public override StatusReport GetStatus(StatusTypes type)
        {
            // Translate generic status to phoenix status
            RelianceStatusRequests r;

            switch (type)
            {
            case StatusTypes.PrinterStatus:
                r = RelianceStatusRequests.Status;
                break;

            case StatusTypes.OfflineStatus:
                r = RelianceStatusRequests.OffLineStatus;
                break;

            case StatusTypes.ErrorStatus:
                r = RelianceStatusRequests.ErrorStatus;
                break;

            case StatusTypes.PaperStatus:
                r = RelianceStatusRequests.PaperRollStatus;
                break;

            case StatusTypes.MovementStatus:
                r = RelianceStatusRequests.PrintStatus;
                break;

            case StatusTypes.FullStatus:
                r = RelianceStatusRequests.FullStatus;
                break;

            default:
                // Unknown status type
                return(StatusReport.Invalid());
            }

            // Send the real time status command, r is the argument
            var command = new byte[] { 0x10, 0x04, (byte)r };
            var respLen = (r == RelianceStatusRequests.FullStatus) ? 6 : 1;

            var data = new byte[0];

            try
            {
                Connection.Open();

                var written = Connection.Write(command);

                System.Threading.Thread.Sleep(250);

                // Collect the response
                data = Connection.Read(respLen);
            }
            catch
            { /* Do nothing */ }
            finally
            {
                Connection.Close();
            }

            // Invalid response
            if (data.Length != respLen)
            {
                return(StatusReport.Invalid());
            }

            var rts = new StatusReport();

            switch (r)
            {
            case RelianceStatusRequests.Status:
                // bit 3: 0- online, 1- offline
                rts.IsOnline = (data[0] & 0x08) == 0;
                break;

            case RelianceStatusRequests.OffLineStatus:
                // bit 2: 0- no error, 1- error
                rts.IsCoverClosed = (data[0] & 0x04) == 0;

                // bit 3: 0- no error, 1- error
                rts.IsNormalFeed = (data[0] & 0x08) == 0;

                // bit 5: 0- no error, 1- error
                rts.IsPaperPresent = (data[0] & 0x20) == 0;

                // bit 6: 0- no error, 1- error
                rts.HasError = (data[0] & 0x40) == 0x40;

                break;

            case RelianceStatusRequests.ErrorStatus:
                // bit 3: 0- okay, 1- Not okay
                rts.IsCutterOkay = (data[0] & 8) == 0;

                // bit 5: 0- No fatal (non-recoverable) error, 1- Fatal error
                rts.HasFatalError = (data[0] & 0x20) == 0x20;

                // bit 6: 0- No recoverable error, 1- Recoverable error
                rts.HasRecoverableError = (data[0] & 0x40) == 0x40;
                break;

            case RelianceStatusRequests.PaperRollStatus:
                // bit 2,3: 0- okay, 12- Not okay
                rts.IsPaperLevelOkay = (data[0] & 0x0C) == 0;

                // bit 5,6: 0- okay, 96- Not okay
                rts.IsPaperPresent = (data[0] & 0x60) == 0;
                break;

            case RelianceStatusRequests.PrintStatus:
                // bit 2: 0- motor off, 1: motor on
                rts.IsPaperMotorOff = (data[0] & 4) == 0;
                // bit 5: 0- paper present, 1: motor stopped because out of paper

                rts.IsPaperPresent = (data[0] & 4) == 0;
                break;

            case RelianceStatusRequests.FullStatus:

                rts.IsPaperPresent          = (data[2] & 0x01) == 0;
                rts.IsPaperLevelOkay        = (data[2] & 0x04) == 0;
                rts.IsTicketPresentAtOutput = (data[2] & 0x20) == 0x20;

                // Custom specs duplicates these so if EITHER
                // are set to open, report open. 0: closed, 1: open
                var covera = (data[3] & 0x01) == 0;
                var coverb = (data[3] & 0x02) == 0;

                rts.IsCoverClosed = covera && coverb;

                rts.IsPaperMotorOff      = (data[3] & 0x08) == 0;
                rts.IsDiagButtonReleased = (data[3] & 0x20) == 0;

                rts.IsHeadTemperatureOkay    = (data[4] & 0x01) == 0;
                rts.IsCommsOkay              = (data[4] & 02) == 0;
                rts.IsPowerSupplyVoltageOkay = (data[4] & 0x08) == 0;
                rts.IsPaperPathClear         = (data[4] & 0x40) == 0;

                rts.IsCutterOkay = (data[5] & 0x01) == 0;
                break;

            default:
                rts.IsInvalidReport = true;
                break;
            }

            return(rts);
        }