private void ReloadDeviceInformationWithProgressBar()
        {
            DeviceStatusListBox.ItemsSource        = null;
            FirmwareInformationListBox.ItemsSource = null;

            StarPrinterStatus           status = null;
            Dictionary <string, string> firmwareInformation = null;

            ProgressBarWindow progressBarWindow = new ProgressBarWindow("Communicating...", () =>
            {
                status = GetDeviceStatus();
                if (status == null)
                {
                    return;
                }

                firmwareInformation = GetFirmwareInformation();
            });

            progressBarWindow.ShowDialog();

            if (status == null && firmwareInformation == null) // Communication failure.
            {
                Util.ShowMessage("Error", "Communication error");

                return;
            }

            // Parse printer status.
            ParsePrinterStatus(status, SharedInformationManager.GetDrawerOpenStatus());

            // Parse firmware information.
            ParseFirmwareInformation(firmwareInformation);
        }
        /// <summary>
        /// Sample : Monitoring printer process.
        /// </summary>
        private void MonitoringPrinter()
        {
            while (true)
            {
                lock (lockObject)
                {
                    try
                    {
                        if (port != null)
                        {
                            StarPrinterStatus status = port.GetParsedStatus();

                            // Your printer cash drawer open status.
                            bool cashDrawerOpenActiveHigh = SharedInformationManager.GetDrawerOpenStatus();

                            if (status.CompulsionSwitch == cashDrawerOpenActiveHigh) // Cash drawer open
                            {
                                OnCashDrawerOpen();
                            }
                            else
                            {
                                OnCashDrawerClose();                                 // Cash drawer close
                            }
                        }
                    }
                    catch (Exception) // Printer impossible
                    {
                        OnPrinterImpossible();
                    }

                    Thread.Sleep(1000);
                }
            }
        }
        /// <summary>
        /// Sample : Monitoring printer process.
        /// </summary>
        private void MonitoringPrinter()
        {
            uint tickCount = (uint)Environment.TickCount;

            while (true)
            {
                // Check printer status is changed for update status to Star Cloud Services.
                isChangeStatus = false;

                lock (lockObject)
                {
                    try
                    {
                        if (port != null)
                        {
                            StarPrinterStatus status = port.GetParsedStatus();

                            // if printer status is changed "isChangeStatus" comes true.
                            CheckPrinterStatus(status); // Check printer status.

                            CheckPaperStatus(status);   // Check paper status.

                            CheckCoverStatus(status);   // Check cover status.

                            // Your printer cash drawer open status.
                            bool cashDrawerOpenActiveHigh = SharedInformationManager.GetDrawerOpenStatus();
                            CheckCashDrawerStatus(status, cashDrawerOpenActiveHigh);  // Check cash drawer status.
                        }
                    }
                    catch (Exception) // Printer impossible
                    {
                        OnPrinterImpossible();
                    }
                    finally
                    {
                        // if printer status is not changed for some times, update status.
                        if ((UInt32)Environment.TickCount - tickCount >= 300000)
                        {
                            isChangeStatus = true;
                        }

                        // if printer status is changed, upload printer status to Star Cloud Services.
                        if (isChangeStatus)
                        {
                            OnStatusUpdated();
                        }

                        tickCount = (UInt32)Environment.TickCount;
                    }

                    Thread.Sleep(1000);
                }
            }
        }
Beispiel #4
0
        private void CheckCashDrawer(StarPrinterStatus status)
        {
            // Your printer cash drawer open status.
            bool cashDrawerOpenActiveHigh = SharedInformationManager.GetDrawerOpenStatus();

            if (status.CompulsionSwitch == cashDrawerOpenActiveHigh) // Cash drawer open
            {
                OnCashDrawerOpen();
            }
            else
            {
                OnCashDrawerClose();                                 // Cash drawer close
            }
        }