/// <summary>
        /// Sample : Display user defined character.
        /// </summary>
        public static Communication.PeripheralStatus DoUserDefinedCharacterPattern(bool set, IPort port)
        {
            // Check display status.
            Communication.PeripheralStatus status = GetDiaplayStatus(port);

            if (status != Communication.PeripheralStatus.Connect) // Display is not connected.
            {
                return(status);
            }

            // Create display commands.
            byte[] displayCommands = DisplayFunctions.CreateUserDefinedCharacter(set);

            // Send display commands.
            CommunicationResult result = Communication.SendCommandsDoNotCheckCondition(displayCommands, port);

            if (result.Result != Communication.Result.Success)
            {
                return(Communication.PeripheralStatus.Impossible);
            }
            else
            {
                return(Communication.PeripheralStatus.Connect);
            }
        }
        public static CommunicationResult GetProductSerialNumber(ref string serialNumber, string portName, string portSettings, int timeout)
        {
            CommunicationResult result = new CommunicationResult();

            IPort port = null;

            try
            {
                result.Result = Result.ErrorOpenPort;

                port = Factory.I.GetPort(portName, portSettings, timeout);

                result = GetProductSerialNumber(ref serialNumber, port);
            }
            catch (PortException ex)
            {
                result.Code = ex.ErrorCode;
            }
            finally
            {
                if (port != null)
                {
                    Factory.I.ReleasePort(port);
                }
            }

            return(result);
        }
        /// <summary>
        /// Sample : Display graphic.
        /// </summary>
        public static Communication.PeripheralStatus DoGraphicPattern(DisplayFunctionManager.GraphicPattern pattern, IPort port)
        {
            // Check display status.
            Communication.PeripheralStatus status = GetDiaplayStatus(port);

            if (status != Communication.PeripheralStatus.Connect) // Display is not connected.
            {
                return(status);
            }

            // Create display commands.
            byte[] displayCommands = DisplayFunctions.CreateGraphicPattern(pattern);

            // Send display commands.
            CommunicationResult result = Communication.SendCommandsDoNotCheckCondition(displayCommands, port);

            if (result.Result != Communication.Result.Success)
            {
                return(Communication.PeripheralStatus.Impossible);
            }
            else
            {
                return(Communication.PeripheralStatus.Connect);
            }
        }
        /// <summary>
        /// Sample : Display character set code page type.
        /// </summary>
        public static Communication.PeripheralStatus DoCharacterSetCodePagePattern(DisplayCodePageType codePageType, IPort port)
        {
            // Check display status.
            Communication.PeripheralStatus status = GetDiaplayStatus(port);

            if (status != Communication.PeripheralStatus.Connect) // Display is not connected.
            {
                return(status);
            }

            // Select character set.
            DisplayInternationalType internationalType = SharedInformationManager.SelectedDisplayInternationalType;

            // Create display commands.
            byte[] displayCommands = DisplayFunctions.CreateCharacterSet(internationalType, codePageType);

            // Send display commands.
            CommunicationResult result = Communication.SendCommandsDoNotCheckCondition(displayCommands, port);

            if (result.Result != Communication.Result.Success)
            {
                return(Communication.PeripheralStatus.Impossible);
            }
            else
            {
                return(Communication.PeripheralStatus.Connect);
            }
        }
        public static void SendCommandsWithProgressBarInternal(byte[] commands, string portName, string portSettings, int timeout, bool checkCondition, bool showResult)
        {
            CommunicationResult result = new CommunicationResult();

            ProgressBarWindow progressBarWindow = new ProgressBarWindow("Communicating...", () =>
            {
                if (checkCondition)
                {
                    result = SendCommands(commands, portName, portSettings, timeout);
                }
                else
                {
                    result = SendCommandsDoNotCheckCondition(commands, portName, portSettings, timeout);
                }
            });

            progressBarWindow.ShowDialog();

            if (!showResult &&
                result.Result == Result.Success)
            {
                return;
            }

            ShowCommunicationResultMessage(result);
        }
        /// <summary>
        /// Sample : Getting display status.
        /// </summary>
        public static Communication.PeripheralStatus GetDiaplayStatus(IPort port)
        {
            // Create IPeripheralConnectParser object.
            IPeripheralConnectParser parser = StarIoExt.CreateDisplayConnectParser(DisplayModel.SCD222);

            // Usage of parser sample is "Communication.ParseDoNotCheckCondition(IPeripheralCommandParser parser, IPort port)".
            CommunicationResult result = Communication.ParseDoNotCheckCondition(parser, port);

            // Check peripheral status.
            Communication.PeripheralStatus status = Communication.PeripheralStatus.Invalid;
            if (result.Result == Communication.Result.Success)
            {
                // Check parser property value.
                if (parser.IsConnected) // connect
                {
                    status = Communication.PeripheralStatus.Connect;
                }
                else // disconnect
                {
                    status = Communication.PeripheralStatus.Disconnect;
                }
            }
            else // communication error
            {
                status = Communication.PeripheralStatus.Impossible;
            }

            return(status);
        }
Example #7
0
        private void PrintReceipt()
        {
            lock (lockObject)
            {
                CommunicationResult result = new CommunicationResult();

                ReceiptInformationManager receiptInfo = SharedInformationManager.ReceiptInformationManager;

                ProgressBarWindow progressBarWindow = new ProgressBarWindow("Communicating...", () =>
                {
                    byte[] commands = AllReceiptsSampleManager.CreateLocalizeReceiptWithAllReceiptsCommands(receiptInfo);

                    if (commands == null) // All print settings (Receipt, Information, QR Code) are OFF.
                    {
                        result.Result = Communication.Result.Success;
                        result.Code   = StarResultCode.Succeeded;

                        return;
                    }

                    result = Communication.SendCommands(commands, port);
                });

                progressBarWindow.ShowDialog();

                Communication.ShowCommunicationResultMessage(result);
            }
        }
        public static void PrintLocalizeReceiptWithAllReceipts(ReceiptInformationManager receiptInfo)
        {
            CommunicationResult result = new CommunicationResult();

            ProgressBarWindow progressBarWindow = new ProgressBarWindow("Communicating...", () =>
            {
                // Create print receipt with AllReceipts commands.
                byte[] commands = CreateLocalizeReceiptWithAllReceiptsCommands(receiptInfo);

                if (commands == null) // All print settings (Receipt, Information, QR Code) are OFF.
                {
                    result.Result = Communication.Result.Success;
                    result.Code   = StarResultCode.Succeeded;

                    return;
                }

                // Your printer PortName and PortSettings.
                string portName     = SharedInformationManager.SelectedPortName;
                string portSettings = SharedInformationManager.SelectedPortSettings;

                // Send commands to printer
                result = Communication.SendCommands(commands, portName, portSettings, 30000);
            });

            progressBarWindow.ShowDialog();

            Communication.ShowCommunicationResultMessage(result);
        }
Example #9
0
        public static void SendCommandsWithProgressBarInternal(byte[] commands, IPort port, bool checkCondition, bool showResult)
        {
            CommunicationResult result = CommunicationResult.ErrorUnknown;

            ProgressBarWindow progressBarWindow = new ProgressBarWindow("Communicating...", () =>
            {
                if (checkCondition)
                {
                    result = SendCommands(commands, port);
                }
                else
                {
                    result = SendCommandsDoNotCheckCondition(commands, port);
                }
            });

            progressBarWindow.ShowDialog();

            if (!showResult &&
                result == CommunicationResult.Success)
            {
                return;
            }

            ShowCommunicationResultMessage(result);
        }
Example #10
0
        public static CommunicationResult ParseDoNotCheckConditionWithProgressBar(IPeripheralCommandParser parser, string portName, string portSettings, int timeout)
        {
            CommunicationResult result = CommunicationResult.ErrorUnknown;

            IPort port = null;

            try
            {
                result = CommunicationResult.ErrorOpenPort;

                port = Factory.I.GetPort(portName, portSettings, timeout);

                result = ParseDoNotCheckConditionWithProgressBar(parser, port);
            }
            catch (PortException)
            {
            }
            finally
            {
                if (port != null)
                {
                    Factory.I.ReleasePort(port);
                }
            }

            return(result);
        }
Example #11
0
        public static CommunicationResult GetSerialNumber(ref string serialNumber, string portName, string portSettings, int timeout)
        {
            CommunicationResult result = CommunicationResult.ErrorUnknown;

            IPort port = null;

            try
            {
                result = CommunicationResult.ErrorOpenPort;

                port = Factory.I.GetPort(portName, portSettings, timeout);

                result = GetSerialNumber(ref serialNumber, port);
            }
            catch (PortException)
            {
            }
            finally
            {
                if (port != null)
                {
                    Factory.I.ReleasePort(port);
                }
            }

            return(result);
        }
Example #12
0
        /// <summary>
        /// Sample : Getting printer firmware information.
        /// </summary>
        public static CommunicationResult RequestFirmwareInformation(ref Dictionary <string, string> firmwareInformation, IPort port)
        {
            CommunicationResult result = CommunicationResult.ErrorUnknown;

            try
            {
                result = CommunicationResult.ErrorOpenPort;

                if (port == null)
                {
                    return(CommunicationResult.ErrorOpenPort);
                }

                result = CommunicationResult.ErrorReadPort;

                firmwareInformation = port.GetFirmwareInformation();

                result = CommunicationResult.Success;
            }
            catch (PortException)
            {
            }

            return(result);
        }
Example #13
0
        /// <summary>
        /// Sample : Retrieving printer status.
        /// </summary>
        public static CommunicationResult RetrieveStatus(ref StarPrinterStatus printerStatus, string portName, string portSettings, int timeout)
        {
            CommunicationResult result = CommunicationResult.ErrorUnknown;

            IPort port = null;

            try
            {
                result = CommunicationResult.ErrorOpenPort;

                port = Factory.I.GetPort(portName, portSettings, timeout);

                result = CommunicationResult.ErrorReadPort;

                printerStatus = port.GetParsedStatus();

                result = CommunicationResult.Success;
            }
            catch (PortException)
            {
            }
            finally
            {
                if (port != null)
                {
                    Factory.I.ReleasePort(port);
                }
            }

            return(result);
        }
        public static CommunicationResult ParseDoNotCheckCondition(IPeripheralCommandParser parser, string portName, string portSettings, int timeout)
        {
            CommunicationResult result = new CommunicationResult();

            IPort port = null;

            try
            {
                result.Result = Result.ErrorOpenPort;

                port = Factory.I.GetPort(portName, portSettings, timeout);

                result = ParseDoNotCheckCondition(parser, port);
            }
            catch (PortException ex)
            {
                result.Code = ex.ErrorCode;
            }
            finally
            {
                if (port != null)
                {
                    Factory.I.ReleasePort(port);
                }
            }

            return(result);
        }
        public static CommunicationResult RequestFirmwareInformation(ref Dictionary <string, string> firmwareInformation, string portName, string portSettings, int timeout)
        {
            CommunicationResult result = new CommunicationResult();

            IPort port = null;

            try
            {
                result.Result = Result.ErrorOpenPort;

                port = Factory.I.GetPort(portName, portSettings, timeout);

                result = RequestFirmwareInformation(ref firmwareInformation, port);
            }
            catch (PortException ex)
            {
                result.Code = ex.ErrorCode;
            }
            finally
            {
                if (port != null)
                {
                    Factory.I.ReleasePort(port);
                }
            }

            return(result);
        }
        public static string GetCommunicationResultMessage(CommunicationResult result)
        {
            StringBuilder builder = new StringBuilder();

            switch (result.Result)
            {
            case Result.Success:
                builder.Append("Success!");
                break;

            case Result.ErrorOpenPort:
                builder.Append("Fail to openPort");
                break;

            case Result.ErrorBeginCheckedBlock:
                builder.Append("Printer is offline (BeginCheckedBlock)");
                break;

            case Result.ErrorEndCheckedBlock:
                builder.Append("Printer is offline (EndCheckedBlock)");
                break;

            case Result.ErrorReadPort:
                builder.Append("Read port error (ReadPort)");
                break;

            case Result.ErrorWritePort:
                builder.Append("Write port error (WritePort)");
                break;

            default:
            case Result.ErrorUnknown:
                builder.Append("Unknown error");
                break;
            }

            if (result.Result != Result.Success)
            {
                builder.Append(Environment.NewLine);
                builder.Append(Environment.NewLine);
                builder.Append("Error code: ");
                builder.Append(result.Code.ToString());

                if (result.Code == StarResultCode.ErrorFailed)
                {
                    builder.Append(" (Failed)");
                }
                else if (result.Code == StarResultCode.ErrorInUse)
                {
                    builder.Append(" (In use)");
                }
            }

            return(builder.ToString());
        }
Example #17
0
 private void DidChangeUSBSerialNumberSettings(CommunicationResult result)
 {
     if (result.Result == Communication.Result.Success)
     {
         MessageBox.Show("To apply settings, please turn the device power OFF and ON.", "Complete");
     }
     else
     {
         Communication.ShowCommunicationResultMessage(result);
     }
 }
Example #18
0
        /// <summary>
        /// Sample : Initializing USB serial number.
        /// </summary>
        private void InitializeUSBSerialNumber(bool isEnabled)
        {
            // Your printer PortName and PortSettings.
            string portName     = SharedInformationManager.SelectedPortName;
            string portSettings = SharedInformationManager.SelectedPortSettings;

            // Initializing USB serial number sample is in "Communication.InitializeUSBSerialNumber(bool isEnabled, IPort port)".
            CommunicationResult result = Communication.InitializeUSBSerialNumberWithProgressBar(isEnabled, portName, portSettings, 30000);

            DidChangeUSBSerialNumberSettings(result);
        }
        public static CommunicationResult ParseDoNotCheckConditionWithProgressBar(IPeripheralCommandParser parser, IPort port)
        {
            CommunicationResult result = new CommunicationResult();

            ProgressBarWindow progressBarWindow = new ProgressBarWindow("Communicating...", () =>
            {
                result = ParseDoNotCheckCondition(parser, port);
            });

            progressBarWindow.ShowDialog();

            return(result);
        }
        public static CommunicationResult SetUSBSerialNumberWithProgressBar(byte[] serialNumber, bool isEnabled, IPort port)
        {
            CommunicationResult result = new CommunicationResult();

            ProgressBarWindow progressBarWindow = new ProgressBarWindow("Communicating...", () =>
            {
                result = SetUSBSerialNumber(serialNumber, isEnabled, port);
            });

            progressBarWindow.ShowDialog();

            return(result);
        }
        public static CommunicationResult InitializeUSBSerialNumberWithProgressBar(bool isEnabled, string portName, string portSettings, int timeout)
        {
            CommunicationResult result = new CommunicationResult();

            ProgressBarWindow progressBarWindow = new ProgressBarWindow("Communicating...", () =>
            {
                result = InitializeUSBSerialNumber(isEnabled, portName, portSettings, timeout);
            });

            progressBarWindow.ShowDialog();

            return(result);
        }
Example #22
0
        /// <summary>
        /// Sample : Sending commands to printer without check condition.
        /// </summary>
        public static CommunicationResult SendCommandsDoNotCheckCondition(byte[] commands, string portName, string portSettings, int timeout)
        {
            CommunicationResult result = CommunicationResult.ErrorUnknown;

            IPort port = null;

            try
            {
                result = CommunicationResult.ErrorOpenPort;

                port = Factory.I.GetPort(portName, portSettings, timeout);

                StarPrinterStatus status;

                result = CommunicationResult.ErrorWritePort;

                status = port.GetParsedStatus();

                if (status.RawStatus.Length == 0)
                {
                    throw new PortException("Unable to communicate with printer.");
                }

                uint commandsLength = (uint)commands.Length;

                uint writtenLength = port.WritePort(commands, 0, commandsLength);

                if (writtenLength != commandsLength)
                {
                    throw new PortException("WritePort failed.");
                }

                result = CommunicationResult.ErrorWritePort;

                status = port.GetParsedStatus();

                result = CommunicationResult.Success;
            }
            catch (PortException)
            {
            }
            finally
            {
                if (port != null)
                {
                    Factory.I.ReleasePort(port);
                }
            }

            return(result);
        }
Example #23
0
        /// <summary>
        /// Sample : Getting device status.
        /// </summary>
        private StarPrinterStatus GetDeviceStatus()
        {
            // Your printer PortName and PortSettings.
            string portName     = SharedInformationManager.SelectedPortName;
            string portSettings = SharedInformationManager.SelectedPortSettings;

            StarPrinterStatus   status = null;
            CommunicationResult result = Communication.RetrieveStatus(ref status, portName, portSettings, 30000);

            if (result.Result != Communication.Result.Success)
            {
                return(null);
            }

            return(status);
        }
        private Dictionary <string, string> GetFirmwareInformation()
        {
            // Your printer PortName and PortSettings.
            string portName     = SharedInformationManager.SelectedPortName;
            string portSettings = SharedInformationManager.SelectedPortSettings;

            // Request firmware information.
            Dictionary <string, string> firmwareInformation = null;
            CommunicationResult         result = Communication.RequestFirmwareInformation(ref firmwareInformation, portName, portSettings, 30000);

            if (result.Result != Communication.Result.Success)
            {
                return(null);
            }

            return(firmwareInformation);
        }
Example #25
0
        public static CommunicationResult GetSerialNumberWithProgressBar(ref string serialNumber, IPort port)
        {
            CommunicationResult result = CommunicationResult.ErrorUnknown;

            string temp = "";

            ProgressBarWindow progressBarWindow = new ProgressBarWindow("Communicating...", () =>
            {
                result = GetSerialNumber(ref temp, port);
            });

            progressBarWindow.ShowDialog();

            serialNumber = temp;

            return(result);
        }
        public static CommunicationResult GetProductSerialNumberWithProgressBar(ref string serialNumber, string portName, string portSettings, int timeout)
        {
            CommunicationResult result = new CommunicationResult();

            string temp = "";

            ProgressBarWindow progressBarWindow = new ProgressBarWindow("Communicating...", () =>
            {
                result = GetProductSerialNumber(ref temp, portName, portSettings, timeout);
            });

            progressBarWindow.ShowDialog();

            serialNumber = temp;

            return(result);
        }
Example #27
0
        /// <summary>
        /// Sample : Checking barcode reader status.
        /// </summary>
        private void CheckBarcodeReaderStatus()
        {
            // Create IPeripheralConnectParser object.
            IPeripheralConnectParser parser = StarIoExt.CreateBcrConnectParser(BcrModel.POP1);

            // Usage of parser sample is "Communication.ParseDoNotCheckCondition(IPeripheralCommandParser parser, IPort port)".
            CommunicationResult result = Communication.ParseDoNotCheckCondition(parser, port);

            // Check peripheral status.
            barcodeReaderStatus = Communication.PeripheralStatus.Invalid;
            if (result.Result == Communication.Result.Success)
            {
                // Check parser property value.
                if (parser.IsConnected) // connect
                {
                    barcodeReaderStatus = Communication.PeripheralStatus.Connect;
                }
                else // disconnect
                {
                    barcodeReaderStatus = Communication.PeripheralStatus.Disconnect;
                }
            }
            else // communication error
            {
                barcodeReaderStatus = Communication.PeripheralStatus.Impossible;
            }

            switch (barcodeReaderStatus)
            {
            default:
            case Communication.PeripheralStatus.Impossible:
                OnBarcodeReaderImpossible();
                break;

            case Communication.PeripheralStatus.Connect:
                OnBarcodeReaderConnect();
                break;

            case Communication.PeripheralStatus.Disconnect:
                OnBarcodeReaderDisconnect();
                break;
            }
        }
Example #28
0
        public static void ShowPrinterSerialNumber()
        {
            // Your printer PortName and PortSettings.
            string portName     = SharedInformationManager.SelectedPortName;
            string portSettings = SharedInformationManager.SelectedPortSettings;

            string serialNumber = "";

            // Getting printer serial number sample is in "Communication.GetProductSerialNumber(ref string serialNumber, IPort port)".
            CommunicationResult result = Communication.GetProductSerialNumberWithProgressBar(ref serialNumber, portName, portSettings, 30000);

            if (result.Result == Communication.Result.Success)
            {
                MessageBox.Show(serialNumber, "Product Serial Number");
            }
            else
            {
                Communication.ShowCommunicationResultMessage(result);
            }
        }
Example #29
0
        public static string GetCommunicationResultMessage(CommunicationResult result)
        {
            string message;

            switch (result)
            {
            case CommunicationResult.Success:
                message = "Success!";
                break;

            case CommunicationResult.ErrorOpenPort:
                message = "Fail to openPort";
                break;

            case CommunicationResult.ErrorBeginCheckedBlock:
                message = "Printer is offline (beginCheckedBlock)";
                break;

            case CommunicationResult.ErrorEndCheckedBlock:
                message = "Printer is offline (endCheckedBlock)";
                break;

            case CommunicationResult.ErrorReadPort:
                message = "Read port error (readPort)";
                break;

            case CommunicationResult.ErrorWritePort:
                message = "Write port error (writePort)";
                break;

            default:
            case CommunicationResult.ErrorUnknown
                :
                message = "Unknown error";
                break;
            }

            return(message);
        }
Example #30
0
        /// <summary>
        /// Sample : Sending commands to printer without check condition (already open port).
        /// </summary>
        public static CommunicationResult SendCommandsDoNotCheckCondition(byte[] commands, IPort port)
        {
            CommunicationResult result = CommunicationResult.ErrorUnknown;

            try
            {
                if (port == null)
                {
                    return(CommunicationResult.ErrorOpenPort);
                }

                StarPrinterStatus status;

                result = CommunicationResult.ErrorWritePort;

                status = port.GetParsedStatus();

                uint commandsLength = (uint)commands.Length;

                uint writtenLength = port.WritePort(commands, 0, commandsLength);

                if (writtenLength != commandsLength)
                {
                    throw new PortException("WritePort failed.");
                }

                result = CommunicationResult.ErrorWritePort;

                status = port.GetParsedStatus();

                result = CommunicationResult.Success;
            }
            catch (PortException)
            {
            }

            return(result);
        }