protected override PrinterStatusFlags OnQueryPrinterStatus(DevicesBase.Communicators.TcpCommunicator communicator)
        {
            var  poStatus      = PaperOutStatus.Present;
            bool bDrawerOpened = false;
            bool bPrinting     = false;

            ExecuteDriverCommand(delegate()
            {
                WriteDebugLine("OnQueryPrinterStatus");

                // запрос состояния ДЯ
                byte nRsp     = CheckStatusByte(communicator, 1);
                bDrawerOpened = !((nRsp & 0x04) == 0x04);

                // запрос состояния бумаги
                nRsp = CheckStatusByte(communicator, 4);


                if (((nRsp & 0x0C) == 0x0C) || ((nRsp & 0x60) == 0x60))
                {
                    poStatus = PaperOutStatus.OutPassive;
                }
                else
                {
                    poStatus = PaperOutStatus.Present;
                }
            });

            return(new PrinterStatusFlags(bPrinting, poStatus, bOpenedDoc, bDrawerOpened));
        }
        private byte CheckStatusByte(DevicesBase.Communicators.TcpCommunicator communicator, int mode)
        {
            int retriesCount = 0;

            do
            {
                try
                {
                    var buffer = new byte[256];
                    WriteDebugLine("Очистка исходящего буфера устройства");
                    communicator.Read(buffer, 0, 0);
                    WriteDebugLine("Запрос статусного байта");
                    communicator.Write(new byte[] { 0x10, 0x04, (byte)mode }, 0, 3);

                    WriteDebugLine("Чтение статусного байта " + (retriesCount + 1));
                    byte nRsp = (byte)communicator.ReadByte();
                    WriteDebugLine("Статусный байт:", new byte[] { nRsp }, 1);

                    return(nRsp);
                }
                catch (CommunicationException E)
                {
                    WriteDebugLine("CommunicationException" + E.ToString());
                    if (retriesCount++ >= 5)
                    {
                        throw;
                    }
                    System.Threading.Thread.Sleep(1000);
                }
            }while (true);
        }
Example #3
0
        protected override PrinterStatusFlags OnQueryPrinterStatus(DevicesBase.Communicators.TcpCommunicator communicator)
        {
            PaperOutStatus poStatus      = PaperOutStatus.Present;
            bool           bDrawerOpened = false;
            bool           bPrinting     = false;

            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
            return(new PrinterStatusFlags(bPrinting, poStatus, _openedDoc, bDrawerOpened));
        }