コード例 #1
0
        public void create()
        {
            int starusID = Convert.ToInt32(StatusID);

            using (ContextModel db = new ContextModel())
            {
                if (starusID == 0)
                {
                    PrinterStatus printerStatus = new PrinterStatus
                    {
                        PrinterName = StatusName
                    };
                    db.PrinterStatus.Add(printerStatus);
                }
                else
                {
                    var mpToUpdate = db.PrinterStatus.SingleOrDefault(pm => pm.PrinterStatusID == starusID);
                    if (mpToUpdate != null)
                    {
                        mpToUpdate.PrinterName = StatusName;
                    }
                }
                db.SaveChanges();

                load();
            }
        }
コード例 #2
0
        private void statusUpdateThread()
        {
            try {
                ZebraPrinterConnection connection = getConnection();
                ZebraPrinter           printer    = ZebraPrinterFactory.GetInstance(connection);
                String statusMessages;

                while (getConnection() != null && connection.IsConnected())
                {
                    PrinterStatus         printerStatus = printer.GetCurrentStatus();
                    PrinterStatusMessages messages      = new PrinterStatusMessages(printerStatus);
                    String[] messagesArray = messages.GetStatusMessage();

                    statusMessages  = "Ready to Print: " + Convert.ToString(printerStatus.IsReadyToPrint);
                    statusMessages += "\r\nLabels in Batch: " + Convert.ToString(printerStatus.LabelsRemainingInBatch);
                    statusMessages += "\r\nLabels in Buffer: " + Convert.ToString(printerStatus.NumberOfFormatsInReceiveBuffer) + "\r\n\r\n";

                    foreach (String message in messagesArray)
                    {
                        statusMessages += message + "\r\n";
                    }
                    Invoke(new statusEventHandler(updateStatusMessage), statusMessages);
                    Thread.Sleep(4000);
                }
            } catch (ZebraException) {
                disconnected();
                updateGuiFromWorkerThread("COMM Error! Disconnected", Color.Red);
            }
        }
コード例 #3
0
        private async void CheckPrinterStatusButton_Clicked(object sender, EventArgs eventArgs)
        {
            SetInputEnabled(false);
            PrinterStatusLabel.Text = "Checking printer status...";

            Connection connection = null;

            try {
                await Task.Factory.StartNew(() => {
                    connection = CreateConnection();
                    connection.Open();

                    ZebraPrinter printer             = ZebraPrinterFactory.GetInstance(connection);
                    ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.CreateLinkOsPrinter(printer);

                    PrinterStatus printerStatus = linkOsPrinter?.GetCurrentStatus() ?? printer.GetCurrentStatus();

                    Device.BeginInvokeOnMainThread(() => {
                        PrinterStatusLabel.Text = BuildPrinterStatusString(printerStatus);
                    });
                });
            } catch (Exception e) {
                PrinterStatusLabel.Text = $"Error: {e.Message}";
                await DisplayAlert("Error", e.Message, "OK");
            } finally {
                try {
                    connection?.Close();
                } catch (ConnectionException) { }

                SetInputEnabled(true);
            }
        }
コード例 #4
0
        /* Returns true if the printer is ready to print, else false
         * Called before printing
         */
        private static string CheckPrinterStatus(Connection conn)
        {
            ZebraPrinter printer = ZebraPrinterFactory.GetLinkOsPrinter(conn);

            if (printer == null)
            {
                printer = ZebraPrinterFactory.GetInstance(PrinterLanguage.ZPL, conn);
            }

            PrinterStatus printerStatus = printer.GetCurrentStatus();

            if (printerStatus.isReadyToPrint)
            {
                return("true");
            }
            else if (printerStatus.isPaused)
            {
                return("Error: Printer is paused");
            }
            else if (printerStatus.isHeadOpen)
            {
                return("Error: Printer head is open");
            }
            else if (printerStatus.isPaperOut)
            {
                return("Error: Paper is out");
            }
            return("Error");
        }
コード例 #5
0
        public void DeveExibirTampaFechada(byte valor)
        {
            PrinterStatus test = new PrinterStatus();

            test.SetIndicadorDesligamento(valor);
            Assert.False(test.TampaAberta);
        }
コード例 #6
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);
        }
コード例 #7
0
        /// <summary>
        /// Handles the <see cref="Timer.Elapsed"/> event.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">The data of the event.</param>
        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)
                {
                    OnPrinterStatusChanged(new PrinterStatusChangedEventArgs(lastStatus));
                }
            }
            catch (Exception ex)
            {
                var comparisonResult = compareLogic.Compare(ex, lastException);
                lastException = ex;

                if (!comparisonResult.AreEqual)
                {
                    OnPrinterStatusChanged(new PrinterStatusChangedEventArgs(lastException));
                }
            }
            finally
            {
                timer.Enabled = true;
            }
        }
コード例 #8
0
ファイル: DpclDevice.cs プロジェクト: StasAlb/CardRoute
        public override bool StartCard()
        {
            frontBitmap = null;
            backBitmap  = null;
            PrinterStatus ps = GetPrinterStatus();

            if (ps != PrinterStatus.Ready)
            {
                throw new Exception($"Printer {printerName} not ready");
            }
            JobId = GetNewJobID();
            LogClass.WriteToLog($"CardId = {cardId}, Printer = {printerName}, Start Job {JobId}, Hopper {HopperID}");
            var startJob2In = new StartJob2Input
            {
                client        = ClientId,
                jobId         = JobId,
                settingsGroup = string.Empty,
                exceptionJob  = false
            };

            dpcl2Client.StartJob3(startJob2In);

            Pick((HopperID > 0) ? (uint)HopperID : (uint)1);
            //WaitForActionCompletion();
            return(JobId > 0);
        }
コード例 #9
0
        /// <summary>
        /// Returns the status of the printer.
        /// </summary>
        /// <returns>An object that contains the status of the printer.</returns>
        public override PrinterStatus GetStatus()
        {
            IPort port          = null;
            var   printerStatus = new PrinterStatus();

            try
            {
                port = Factory.I.GetPort(PrinterName, string.Empty, Timeout);
                var status = port.GetParsedStatus();

                if (status == null)
                {
                    throw new PrinterException("The printer status is null.");
                }

                printerStatus.ReceiptPaperNearEmpty = status.ReceiptPaperNearEmptyInner || status.ReceiptPaperNearEmptyOuter;
                printerStatus.CoverOpen             = status.CoverOpen;
                printerStatus.ReceiptPaperEmpty     = status.ReceiptPaperEmpty;
                printerStatus.OverTemp    = status.OverTemp;
                printerStatus.CutterError = status.CutterError;
                printerStatus.IsOffline   = status.Offline;

                return(printerStatus);
            }
            finally
            {
                if (port != null)
                {
                    Factory.I.ReleasePort(port);
                }
            }
        }
コード例 #10
0
        private void SetErrCode(PrinterStatus errStatus)
        {
            errCode = Printer_ErrorCodes.Success;

            if (errStatus == PrinterStatus.CutterError)
            {
                errCode = Printer_ErrorCodes.CutterError;
            }
            else if (errStatus == PrinterStatus.HeadingOverTemperatureError)
            {
                errCode = Printer_ErrorCodes.UnknownError;
            }
            else if (errStatus == PrinterStatus.NotchError)
            {
                errCode = Printer_ErrorCodes.UnknownError;
            }
            else if (errStatus == PrinterStatus.PaperEnd)
            {
                errCode = Printer_ErrorCodes.UnknownError;
            }
            else if (errStatus == PrinterStatus.PowerSupplyVoltageError)
            {
                errCode = Printer_ErrorCodes.UnknownError;
            }
            else if (errStatus == PrinterStatus.WrongCommand)
            {
                errCode = Printer_ErrorCodes.UnknownError;
            }
            else if (errStatus == PrinterStatus.Unknown)
            {
                errCode = Printer_ErrorCodes.UnknownError;
            }
            log.Debug("Debug SetErrCode -> SetErrCode() : " + errCode.ToString());
        }
コード例 #11
0
        public void DeveExibirEmNaoErro(byte valor)
        {
            PrinterStatus test = new PrinterStatus();

            test.SetIndicadorErro(valor);
            Assert.False(test.EmErro);
        }
コード例 #12
0
ファイル: Printer.cs プロジェクト: Yarikh-Development/demo3
        /// <summary>
        /// 获取打印机状态
        /// </summary>
        /// <param name="PrinterDevice"></param>
        /// <returns></returns>

        /*public static PrinterStatus GetPrinterStatus(string PrinterDevice)
         * {
         *      PrinterStatus ret = 0;
         *      string path = @"win32_printer.DeviceId='" + PrinterDevice + "'";
         *      ManagementObject printer = new ManagementObject(path);
         *      printer.Get();
         *      ret = (PrinterStatus)Convert.ToInt32(printer.Properties["PrinterStatus"].Value);
         *      return ret;
         * }*/

        //获取网络打印机在线状态
        private static void GetPrinterStatus(string printerName)
        {
            try
            {
                ret  = 0;
                rets = 0;
                string result = LinkPrinter(printerName, TcpConnection.DEFAULT_ZPL_TCP_PORT);
                if (IsPrinterOnline())
                {
                    ret = (PrinterStatus)1;
                    if (IsReadyToPrint())
                    {
                        rets = (PrinterReadyStatus)1;
                    }
                    else
                    {
                        rets = (PrinterReadyStatus)2;
                    }
                }
                else
                {
                    ret = (PrinterStatus)0;
                }
            }
            finally
            {
                ClosePrinter();
            }
        }
コード例 #13
0
        public void DeveExibirSemPapel(byte valor)
        {
            PrinterStatus test = new PrinterStatus();

            test.SetSensorPapel(valor);
            Assert.True(test.SemPapel);
        }
コード例 #14
0
ファイル: PrintController.cs プロジェクト: JBPKII/PRUSA3D
        private void OnStop()
        {
            Status = PrinterStatus.Stoped;

            double gapInMilimetres = 50.0 /*mm*/;

            try
            {
                Interpreter.RequireCommand -= PrinterInterpreter_RequireCommand;
            }
            catch (Exception)
            { }

            Interpreter.SendTemperature();

            // Presenta el trazado
            StrokeSLT trzPresent = new StrokeSLT();

            trzPresent.Destino   = new VertexSLT(lastPoint.X, lastPoint.Y, lastPoint.Z + gapInMilimetres /*mm*/);
            trzPresent.E         = 0.0;
            trzPresent.Mode      = Modes.ModeTraslation;
            trzPresent.Pendiente = true;
            Interpreter.SendStroke(trzPresent);

            trzPresent.Destino   = new VertexSLT(0.0, 0.0, lastPoint.Z + gapInMilimetres /*mm*/);
            trzPresent.E         = 0.0;
            trzPresent.Mode      = Modes.ModeTraslation;
            trzPresent.Pendiente = true;
            Interpreter.SendStroke(trzPresent);
        }
コード例 #15
0
        public void DeveExibirComPapelPeloSensorPoucoPapel(byte valor)
        {
            PrinterStatus test = new PrinterStatus();

            test.SetSensorPapel(valor);
            Assert.False(test.PoucoPapel);
        }
コード例 #16
0
ファイル: StatusHub.cs プロジェクト: kickhad/overseer
 public static void PushStatusUpdate(PrinterStatus statusUpdate)
 {
     GlobalHost.ConnectionManager.GetHubContext <StatusHub>()
     .Clients
     .Group(MonitoringGroupName)
     .StatusUpdate(statusUpdate);
 }
コード例 #17
0
        //private PrinterStatus _lastStatus;
        public PrinterStatus GetPrinterStatus()
        {
            PrinterStatus status = PrinterStatus.Ok;
            var           queue  = _printQueue.GetPrintJobInfoCollection();
            var           count  = queue.Count();

            //MessageBox.Show($"Count={count}   NumberOfJobs={_printQueue.NumberOfJobs}   QueueStatus= { _printQueue.QueueStatus}");//DEBUG
            if (count > 0)
            {
                status = PrinterStatus.QueueContainsElements;
            }
            else
            if (_printQueue.IsInError)
            {
                status = PrinterStatus.IsInError;
            }
            else
            if (_printQueue.IsOutOfPaper)
            {
                status = PrinterStatus.IsOutOfPaper;
            }
            else
            if (_printQueue.IsPaperJammed)
            {
                status = PrinterStatus.IsOutOfPaper;
            }
            else
            if (_printQueue.HasPaperProblem)
            {
                status = PrinterStatus.HasPaperProblem;
            }

            return(status);
        }
コード例 #18
0
        public void DeveExibirGavetaAberta(byte valor)
        {
            PrinterStatus test = new PrinterStatus();

            test.SetEstadoImpressora(valor);
            Assert.True(test.SinalGaveta);
        }
コード例 #19
0
        public bool GetStatus(ref PrinterStatus status)
        {
            errCode = Printer_ErrorCodes.Success;
            errDesc = String.Empty;
            String        error         = String.Empty;
            PrinterStatus printerStatus = PrinterStatus.NoError;
            bool          result        = false;

            try
            {
                result = qrPrinter.GetStatus(ref printerStatus, ref error);
                if (printerStatus != PrinterStatus.NoError)
                {
                    result = false;
                    SetErrCode(printerStatus);
                    log.Error("Exception Message : " + error);
                    errDesc = "Exception Message : " + error;
                }
            }
            catch (Exception ex)
            {
                result  = false;
                errCode = Printer_ErrorCodes.UnknownError;
                errDesc = "Exception Message : " + ex.Message;
                log.Error("Error QRPrinter -> Init() : " + errDesc);
            }
            status = printerStatus;
            return(result);
        }
コード例 #20
0
        public async Task <bool> CetakZebraAsync(PrintTicket printData, string printerName)
        {
            var        parser    = new FileIniDataParser();
            IniData    iniData   = parser.ReadFile("Configuration.ini");
            string     serverUrl = iniData["server"]["url"];
            string     serverApi = iniData["server"]["api"];
            Connection conn      = null;

            try
            {
                conn = new DriverPrinterConnection(printerName);
                conn.Open();
                ZebraPrinter  zebraPrinter = ZebraPrinterFactory.GetInstance(conn);
                PrinterStatus printStatus  = zebraPrinter.GetCurrentStatus();
                if (printStatus.isReadyToPrint)
                {
                    foreach (TicketData data in printData.tickets)
                    {
                        byte[] buffer1 = ASCIIEncoding.ASCII.GetBytes(data.ticket);
                        conn.SendAndWaitForResponse(buffer1, 1000, 1000, null);
                        await UpdateStatus(data.id, serverApi, serverUrl, "printed");
                    }
                    conn.Close();
                    return(true);
                }
                else
                {
                    MessageBox.Show("Printer is not ready!");
                    foreach (TicketData data in printData.tickets)
                    {
                        await UpdateStatus(data.id, serverApi, serverUrl, "draft");
                    }
                    return(false);
                }
            }
            catch (ConnectionException e)
            {
                MessageBox.Show(e.Message);
                foreach (TicketData data in printData.tickets)
                {
                    await UpdateStatus(data.id, serverApi, serverUrl, "draft");
                }
                return(false);
            }
            finally
            {
                try
                {
                    if (conn != null)
                    {
                        conn.Close();
                    }
                }
                catch (ConnectionException e)
                {
                    MessageBox.Show(e.Message);
                }
            }
        }
コード例 #21
0
        public void UpdatePrinterStatus()
        {
            if (!Active)
            {
                return;
            }
            if (IPAddress == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(Webhook))
            {
                return;
            }

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    //Check printer status
                    var duetStatusRequest = GetStatus(client);

                    //Check printer state. if it has changed then we'll send a message to discord.
                    var duetStatus = PrinterStatusMethods.GetCurrentStatus(duetStatusRequest.Status);

                    //The status has changed
                    if (duetStatus != PrinterStatus)
                    {
                        SendMessage($"Status has changed from {PrinterStatus.GetString()} to {duetStatus.GetString()}");
                        PrinterStatus = duetStatus;

                        if (PrinterStatus == PrinterStatus.Printing)
                        {
                            GetFileInfo(client);
                            LastReportedPercent = 0;
                            SendMessage($"Printing {CurrentFileName}");
                        }
                    }

                    //Check printer Percentage.
                    if (PrinterStatus == PrinterStatus.Printing)
                    {
                        var increment = (int)duetStatusRequest.FractionPrinted / 10; //We'll start with 10% increments and eventually make this configurable
                        if (increment > LastReportedPercent)
                        {
                            SendMessage($"Print is currently at {increment * 10}%");
                            LastReportedPercent = increment;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                PrinterStatus = PrinterStatus.Unknown; //May be disconnected or missed messages
                                                       //There was an error communicating with the printer.
            }
        }
コード例 #22
0
ファイル: PrintController.cs プロジェクト: JBPKII/PRUSA3D
        public void Print(bool isTest = false)
        {
            if (Status != PrinterStatus.Printing)
            {
                Status = PrinterStatus.Printing;

                Interpreter.IsTest          = isTest;
                Interpreter.RequireCommand += PrinterInterpreter_RequireCommand;

                Interpreter.SendTemperature(225.0);

                /*if (_TImprimir == null || !_TImprimir.IsAlive)
                 * {
                 *  _TImprimir = new Thread(new ThreadStart(_Draw));
                 *  _TImprimir.Start();
                 * }
                 * else
                 * {
                 *  //avisa de que ya está en ejecución
                 *  System.Windows.Forms.MessageBox.Show("Proceso de impresión ejecutándose.");
                 * }*/

                StrokeSLT _Trazo = null;

                //Printing = true;

                /*_TGenerarLayer = new Thread(new ThreadStart(_GeneraLayer));
                 * _TGenerarLayer.Start();
                 * _GenerandoLayer = true;*/

                Model.GenerateLayer();

                /*while(_GenerandoLayer )
                 * {
                 *  System.Threading.Thread.Sleep(500);
                 * }*/

                Model.ChangeLayer();

                /*_TGenerarLayer = new Thread(new ThreadStart(_GeneraLayer));
                 * _TGenerarLayer.Start();*/

                Model.GenerateLayer();


                //if (ZCalculo <= Solido.Top)

                //IsTrazando = true;

                _Trazo = Model.FirstStroke();

                //Para calcular la distancia del trazado
                lastPoint = new Punto(_Trazo.Destino.X, _Trazo.Destino.Y, _Trazo.Destino.Z);

                //Envía el trazo
                Interpreter.SendStroke(_Trazo);
            }
        }
コード例 #23
0
ファイル: PrintController.cs プロジェクト: JBPKII/PRUSA3D
 public void Resume()
 {
     if (Status == PrinterStatus.Pause)
     {
         Status = PrinterStatus.Printing;
         Interpreter.RequireCommand += PrinterInterpreter_RequireCommand;
         PrinterInterpreter_RequireCommand();
     }
 }
コード例 #24
0
        public static PrinterStatus GetPrinterStat(string PrinterDevice)
        {
            PrinterStatus    ret     = 0;
            string           path    = @"win32_printer.DeviceId='" + PrinterDevice + "'";
            ManagementObject printer = new ManagementObject(path);

            ret = (PrinterStatus)Convert.ToInt32(printer.Properties["PrinterStatus"].Value);
            return(ret);
        }
コード例 #25
0
        public void printThread(SKBitmap toPrint)
        {
            try
            {
                var context = global::Android.App.Application.Context;

                Printer printer = new Printer();

                string[] models = new string[6];
                models[0] = PrinterInfo.Model.PtP950nw.ToString();
                models[1] = PrinterInfo.Model.PtP950nw.ToString().Replace("_", "-");
                models[2] = "PtP950nw";
                models[3] = "PTP950NW";
                models[4] = "PT-P950NW";
                models[5] = "Pt-P950nw";

                NetPrinter[] printers = new NetPrinter[0];// printer.GetNetPrinters(models);

                PrinterInfo printInfo = new PrinterInfo();
                printInfo.PrinterModel = PrinterInfo.Model.PtP950nw;
                printInfo.Port         = PrinterInfo.PortEnum.Net;

                if (printers.Length == 0)
                {
                    printInfo.IpAddress = "192.168.43.126";
                }
                else
                {
                    printInfo.IpAddress = printers[0].IpAddress;
                }

                printInfo.PaperSize     = PrinterInfo.PaperSizeEnum.Custom;
                printInfo.PaperPosition = PrinterInfo.AlignEnum.Center;
                printInfo.Orientation   = PrinterInfo.OrientationEnum.Landscape;

                printInfo.LabelNameIndex = LabelInfo.PT.W36.Ordinal();
                printInfo.IsAutoCut      = true;
                printInfo.IsCutAtEnd     = true;
                printInfo.IsHalfCut      = true;

                printer.SetPrinterInfo(printInfo);

                printer.StartCommunication();

                using (Bitmap bmp = toPrint.ToBitmap())
                {
                    PrinterStatus status = printer.PrintImage(bmp);

                    bmp.Recycle();
                }

                printer.EndCommunication();
            }
            catch (Exception ex)
            {
            }
        }
コード例 #26
0
 private static void WritePrinterStatus(PrinterStatus printerStatus)
 {
     Console.WriteLine("Offline: {0}", printerStatus.IsOffline);
     Console.WriteLine("Receipt paper near empty: {0}", printerStatus.ReceiptPaperNearEmpty);
     Console.WriteLine("Receipt paper empty: {0}", printerStatus.ReceiptPaperEmpty);
     Console.WriteLine("Cover open: {0}", printerStatus.CoverOpen);
     Console.WriteLine("Over temp: {0}", printerStatus.OverTemp);
     Console.WriteLine("Cutter error: {0}", printerStatus.CutterError);
 }
コード例 #27
0
        public String[] ReadMagCard(int timeout)
        {
            bool error = true;

            try
            {
                ThePrinterConn.Open();
                printer = ZebraPrinterFactory.GetInstance(ThePrinterConn);
                mcr     = printer.GetMagCardReader();

                PrinterStatus printerStatus = printer.GetCurrentStatus();
                bool          ready         = printerStatus.IsReadyToPrint;
                if (ready == false)
                {
                    return(null);
                }

                //MagCardReader mcr = printer.GetMagCardReader();
                if (mcr != null)
                {
                    //read
                    String[] tracks = mcr.Read(timeout);

                    if (tracks[0] != "" || tracks[1] != "" || tracks[2] != "")
                    {
                        ready = printerStatus.IsReadyToPrint;
                        if (ready)
                        {
                            String header = "! 0 200 200 0 1";
                            ThePrinterConn.Write(Encoding.UTF8.GetBytes(header + "\r\nBEEP 1\r\nPRINT\r\n"));
                        }
                    }

                    //SystemSounds.Beep.Play();
                    return(tracks);
                }

                //thePrinterConn.Close();

                error = false;
            }
            catch (Exception e)
            {
                Logger.Logger.Log(e);
                error = true;
            }
            if (error)
            {
                return(null);
            }
            else
            {
                return(new String[3] {
                    "", "", ""
                });
            }
        }
コード例 #28
0
        private async void GetPrinterStatusButton_Clicked(object sender, EventArgs eventArgs)
        {
            AvailableChannelsLabel.Text = "";
            PrinterStatusLabel.Text     = "Retrieving printer status...";
            SetInputEnabled(false);

            StatusConnection statusConnection = null;
            Connection       rawConnection    = null;

            try {
                statusConnection = CreateStatusConnection();

                if (statusConnection == null)
                {
                    return;
                }

                if (GetSelectedConnectionType() == ConnectionType.Bluetooth)
                {
                    try {
                        // Over Bluetooth, the printer only broadcasts the status connection if a valid raw connection is open
                        rawConnection = DependencyService.Get <IConnectionManager>().GetBluetoothConnection(AddressEntry.Text);
                    } catch (NotImplementedException) {
                        throw new NotImplementedException("Bluetooth connection not supported on this platform");
                    }

                    await Task.Factory.StartNew(() => {
                        rawConnection.Open();
                    });

                    await Task.Delay(3000); // Give the printer some time to start the status connection
                }

                await Task.Factory.StartNew(() => {
                    statusConnection.Open();

                    ZebraPrinter printer        = ZebraPrinterFactory.GetLinkOsPrinter(statusConnection);
                    PrinterStatus printerStatus = printer.GetCurrentStatus();

                    Device.BeginInvokeOnMainThread(() => {
                        UpdateResult(printerStatus);
                    });
                });
            } catch (Exception e) {
                PrinterStatusLabel.Text = $"Error: {e.Message}";
                await DisplayAlert("Error", e.Message, "OK");
            } finally {
                try {
                    statusConnection?.Close();
                    rawConnection?.Close();
                } catch (ConnectionException) { }

                SetInputEnabled(true);
            }
        }
コード例 #29
0
        public bool Init(string logo, Bitmap image, ref PrinterStatus status, ref string err)
        {
            bool Result = true;

            status = PrinterStatus.Unknown;
            err    = "";

            if (printerPort == string.Empty)
            {
                string[] portNames = SerialPort.GetPortNames();

                Result = (portNames.Length > 0);

                int pp = 0;

                do
                {
                    printerPort = portNames[pp];

                    Result = CommOpen(printerPort, ref err);
                    if (Result)
                    {
                        Result = GetStatus(ref status, ref err);
                    }

                    if (!Result)
                    {
                        CommClose(ref err);
                    }

                    pp++;
                }while ((pp < portNames.Length) && (!Result));
            }
            else
            {
                Result = CommOpen(printerPort, ref err);
                if (Result)
                {
                    Result = GetStatus(ref status, ref err);
                }
            }

            if ((Result) && (logo != ""))
            {
                Result = LogoExist(logo, ref err);
                if (!Result)
                {
                    Result = SaveImage(1, logo, image, ref err);
                }
            }

            GetStatus(ref status, ref err);

            return(Result);
        }
コード例 #30
0
ファイル: PrinterHelper.cs プロジェクト: zanderzhg/STO.Print
        /// <summary>
        /// 打印机属性转换
        /// </summary>
        /// <param name="printerDevice">打印机名(DeviceID)</param>
        /// <param name="iCount">当前任务数</param>
        /// <returns>打印机状态名字</returns>
        public static PrinterStatus GetPrinterState(string printerDevice, ref int iCount)
        {
            PrinterStatus    ret     = 0;
            string           path    = @"win32_printer.DeviceId='" + printerDevice + "'";
            ManagementObject printer = new ManagementObject(path);

            printer.Get();
            ret    = (PrinterStatus)Convert.ToInt32(printer.Properties["PrinterStatus"].Value);
            iCount = Convert.ToInt32(printer.Properties["JobCountSinceLastReset"].Value);
            return(ret);
        }
コード例 #31
0
ファイル: PrinterWrapper.cs プロジェクト: kukareka/printbox
 public void UpdateStatus()
 {
     this._statusText = GetStatusMessage();
     this._printerStatus = ParseStatus(_statusText);
 }
コード例 #32
0
ファイル: EmulatorSession.cs プロジェクト: ewcasas/DVTK
        /// <summary>
        /// <see cref="IPrinter.ApplyStatus"/>
        /// </summary>
        public void ApplyStatus(PrinterStatus printerStatus, System.String statusInfo, bool sendStatusEvent)
        {
            if (statusInfo == null) throw new System.ArgumentNullException("statusInfo");
            switch (printerStatus)
            {
                case PrinterStatus.NORMAL: this.m_adaptee.MPrinter.Status = "NORMAL"; break;
                case PrinterStatus.WARNING: this.m_adaptee.MPrinter.Status = "WARNING"; break;
                case PrinterStatus.FAILURE: this.m_adaptee.MPrinter.Status = "FAILURE"; break;
                default: System.Diagnostics.Trace.Assert(false); break;
            }
            this.m_adaptee.MPrinter.StatusInfo = statusInfo;

            if(sendStatusEvent)
            {
                this.m_adaptee.SendStatusEvent();
            }
        }
コード例 #33
0
ファイル: EmulatorSession.cs プロジェクト: ewcasas/DVTK
 /// <summary>
 /// Apply a new printer status and corresponding status info.
 /// </summary>
 /// <param name="printerStatus">Printer device status.</param>
 /// <param name="statusInfo">Additional information about Printer Status.</param>
 /// <param name="sendStatusEvent">Indicates the status event should be sent to SUT</param>
 public void ApplyStatus(PrinterStatus printerStatus, System.String statusInfo, bool sendStatusEvent)
 {
     ((DvtkSession.EmulatorSession)Implementation).Printer.ApplyStatus(Convert(printerStatus), statusInfo, true);
 }