コード例 #1
0
 /// <summary>
 /// Конструктор для десериализации
 /// </summary>
 /// <param name="info">Класс <see cref="SerializationInfo"/> для информации о сериализации</param>
 /// <param name="context">Источник для сериализации</param>
 protected PrinterStatusFlags(SerializationInfo info, StreamingContext context)
 {
     Printing       = info.GetBoolean("Printing");
     PaperOut       = (PaperOutStatus)info.GetValue("PaperOut", typeof(PaperOutStatus));
     OpenedDocument = info.GetBoolean("OpenedDocument");
     OpenedDrawer   = info.GetBoolean("OpenedDrawer");
 }
コード例 #2
0
        protected override void OnCloseDocument(bool cutPaper)
        {
            if (_currDocType != DocumentType.XReport &&
                _currDocType != DocumentType.ZReport &&
                _currDocType != DocumentType.SectionsReport)
            {
                ExecuteDriverCommand("22");
            }

            // проверяем статус документа
            if (ErrorCode.Succeeded && _paperStatus != PaperOutStatus.Present)
            {
                ExecuteDriverCommand(true, protocol =>
                {
                    protocol.ExecuteCommand("A0");
                    int status = protocol.GetFieldAsInt(3);
                    status   >>= 4;
                    if (status == 8)
                    {
                        // Команда закрытия была отправлена в ЭКЛЗ, но документ не был завершен
                        // Требуется команда завершения печати
                        _paperStatus = PaperOutStatus.OutActive;
                    }
                });
            }
        }
コード例 #3
0
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="printing">Идет печать документа</param>
 /// <param name="paperOut">Нет бумаги</param>
 /// <param name="openedDocument">Открытый документ</param>
 /// <param name="openedDrawer">Открытый денежный ящик</param>
 public PrinterStatusFlags(bool printing, PaperOutStatus paperOut, bool openedDocument,
                           bool openedDrawer)
 {
     Printing       = printing;
     PaperOut       = paperOut;
     OpenedDocument = openedDocument;
     OpenedDrawer   = openedDrawer;
 }
コード例 #4
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));
        }
コード例 #5
0
        private void ExecuteDriverCommand(bool printable, ExecuteCommandDelegate executeCommandDelegate)
        {
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);

            if (!Active)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Inactive);
                return;
            }

            try
            {
                if (_spProtocol == null)
                {
                    _spProtocol = new SPProtocol(Port, PASSWORD);
                }
                executeCommandDelegate(_spProtocol);
                if (printable)
                {
                    _paperStatus = PaperOutStatus.Present;
                }
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout, _spProtocol.GetCommandDump());
            }
            catch (DeviceErrorException E)
            {
                // отлавливаем ошибки принтера
                if (E.ErrorCode == 8 || E.ErrorCode == 9)
                {
                    _paperStatus = PaperOutStatus.OutPassive;
                }
                else if (E.ErrorCode == 1 && _paperStatus != PaperOutStatus.Present)
                {
                }

                ErrorCode = new ServerErrorCode(this, E.ErrorCode, GetSpecificDescription(E.ErrorCode),
                                                _spProtocol.GetCommandDump());
            }
            catch (Exception E)
            {
                ErrorCode = new ServerErrorCode(this, E);
            }
        }
コード例 #6
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                DeviceTester <IPrintableDevice> tester = new DeviceTester <IPrintableDevice>(
                    deviceId,
                    delegate(IPrintableDevice device)
                {
                    // проверка наличия бумаги
                    PaperOutStatus paperStatus = device.PrinterStatus.PaperOut;
                    if (!device.ErrorCode.Succeeded)
                    {
                        MessageBox.Show(this, device.ErrorCode.FullDescription,
                                        Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (paperStatus == PaperOutStatus.OutActive ||
                        paperStatus == PaperOutStatus.OutPassive)
                    {
                        MessageBox.Show(this,
                                        "Отсутствует бумага в печатающем устройстве", Text,
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    // печать
                    device.Print(GetXmlDocument());
                    if (!device.ErrorCode.Succeeded)
                    {
                        MessageBox.Show(this, device.ErrorCode.FullDescription,
                                        Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                });
                tester.Execute();
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: radtek/POSDeviceManager
        static void Main(string[] args)
        {
            Console.WriteLine("POS device manager test utility");
            Console.WriteLine("version 2.0");
            Console.WriteLine();

            try
            {
                if (args.Length == 0)
                {
                    ViewHelp();
                }
                else
                {
                    string host = args.Length > 0 ? args[0] : "localhost";
                    using (DeviceManagerClient dmc = new DeviceManagerClient(host))
                    {
                        dmc.Login();
                        string deviceID = args.Length > 1 ? args[1] : "”стройство1";
                        dmc.Capture(deviceID, WaitConstant.Infinite);
                        try
                        {
                            IPrintableDevice device = (IPrintableDevice)dmc[deviceID];
                            Console.WriteLine(string.Format("Device status: {0}",
                                                            device.Active ? "active" : "inactive"));

                            if (!device.Active)
                            {
                                Console.WriteLine("Trying to re-activate.");
                                device.Active = true;
                                if (!device.Active)
                                {
                                    Console.WriteLine("Re-activate failed.");
                                }
                                else
                                {
                                    Console.WriteLine("Re-activate succeeded.");
                                }
                            }

                            if (device.Active)
                            {
                                PaperOutStatus paperStatus = device.PrinterStatus.PaperOut;
                                if (ProcessErrorCode(device.ErrorCode, false))
                                {
                                    Console.WriteLine(string.Format("Paper: {0}", paperStatus));
                                    if (paperStatus == PaperOutStatus.Present || paperStatus == PaperOutStatus.OutAfterActive)
                                    {
                                        XmlDocument xmlDoc = new XmlDocument();
                                        xmlDoc.Load(args.Length > 2 ? args[2] : "receipt.xml");
                                        device.Print(xmlDoc.OuterXml);
                                        ProcessErrorCode(device.ErrorCode, true);
                                    }
                                    else
                                    {
                                        Console.WriteLine("Printer not ready.");
                                    }
                                }
                            }
                        }
                        finally
                        {
                            dmc.Release(deviceID);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception.");
                Console.WriteLine(e.Message);
                Console.WriteLine("View stack trace (y/n)?:");
                ConsoleKeyInfo info = Console.ReadKey(true);
                Console.WriteLine();
                if (info.Key == ConsoleKey.Y)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }

            Console.WriteLine("Done. Press any key.");
            Console.ReadKey(true);
        }