Пример #1
0
 private void WriteToStream(string stringWriteTo)
 {
     try
     {
         GlobalNetSockets.WriteToStream(inkJetNetworkStream, stringWriteTo);
     }
     catch (Exception exception)
     { throw exception; }
 }
Пример #2
0
        private bool WaitForPrintingAcknowledge(ref string stringReadFrom)
        {
            try
            {
                bool returnValue = false;
                this.inkJetNetworkStream.ReadTimeout = 300; //Default = -1;


                stringReadFrom = GlobalNetSockets.ReadFromStream(inkJetTcpClient, inkJetNetworkStream);

                if (stringReadFrom == GlobalVariables.charPrintingACK.ToString()) //OK State
                {
                    returnValue = true;                                           // GlobalVariables.DominoProductCounter[(int)this.DominoPrinterNameID]++;
                }
                else//  !=  : Need to check some other condition
                {
                    int countPrintingACK = GlobalStaticFunction.CountStringOccurrences(stringReadFrom, GlobalVariables.charPrintingACK.ToString());

                    if (countPrintingACK == 1)      //OK: but in case of receive only one PrintingACK, following by something: Ignore. Later: Maybe ADD SOME CODE to SHOW on screen what stringReadFrom is
                    {
                        this.MainStatus = "NMVN: Some extra thing received: " + stringReadFrom;
                        returnValue     = true; // GlobalVariables.DominoProductCounter[(int)this.DominoPrinterNameID]++;
                    }
                    else if (countPrintingACK > 1)
                    {
                        this.MainStatus = "NMVN: Receive more than one printing acknowledge, a message may printed more than one times";
                        returnValue     = true; // GlobalVariables.DominoProductCounter[(int)this.DominoPrinterNameID] = GlobalVariables.DominoProductCounter[(int)this.DominoPrinterNameID] + countPrintingACK;
                    }
                    else // countPrintingACK < 1    :   Fail
                    {
                        this.MainStatus = "NMVN: Random received: " + stringReadFrom;
                        returnValue     = false;
                    }
                }

                this.inkJetNetworkStream.ReadTimeout = -1; //Default = -1
                return(returnValue);
            }

            catch (Exception exception)
            {
                //Ignore when timeout
                if (exception.Message != "Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.")
                {
                    this.MainStatus = exception.Message;
                }

                this.inkJetNetworkStream.ReadTimeout = -1; //Default = -1
                return(false);
            }
        }
Пример #3
0
        private bool ReadFromStream(ref string stringReadFrom, bool waitForACK, string commandCode, long commandLength)
        {
            try
            {
                stringReadFrom = GlobalNetSockets.ReadFromStream(inkJetTcpClient, inkJetNetworkStream);

                if (waitForACK)
                {
                    if (stringReadFrom.ElementAt(0) == GlobalVariables.charACK)
                    {
                        return(true);
                    }
                    else
                    {
                        if (stringReadFrom.ElementAt(0) == GlobalVariables.charNACK && stringReadFrom.Length >= 4)
                        {
                            lastNACKCode = stringReadFrom.Substring(1, 3);                                                                                        //[0]: NACK + [1][2][3]: 3 Digit --- Error Code
                        }
                        return(false);
                    }
                }
                else if (commandLength == 0 || stringReadFrom.Length >= commandLength)
                {   //stringReadFrom(0): ESC;----stringReadFrom(1): COMMAND;----stringReadFrom(2->N): PARAMETER;----stringReadFrom(stringReadFrom.Length): EOT
                    if (stringReadFrom.ElementAt(0) == GlobalVariables.charESC && stringReadFrom.ElementAt(1) == commandCode.ElementAt(0) && stringReadFrom.ElementAt(stringReadFrom.Length - 1) == GlobalVariables.charEOT)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }

            catch (Exception exception)
            {
                this.MainStatus = exception.Message; // ToString();
                return(false);
            }
        }
Пример #4
0
        private bool WaitForBarcode(ref string stringReadFrom)
        {
            try
            {
                this.barcodeNetworkStream.ReadTimeout = 120; //Default = -1;

                stringReadFrom = GlobalNetSockets.ReadFromStream(barcodeTcpClient, barcodeNetworkStream).Trim();

                this.barcodeNetworkStream.ReadTimeout = -1; //Default = -1
                return(stringReadFrom != "");
            }

            catch (Exception exception)
            {
                this.barcodeNetworkStream.ReadTimeout = -1; //Default = -1

                //Ignore when timeout
                if (exception.Message == "Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.")
                {
                    stringReadFrom = "";
                    return(false);
                }
                else
                {
                    throw exception;
                }



                ////this.LedGreenOn = this.barcodeTcpClient.Connected;//this.LedAmberOn = readyToPrint;
                ////this.LedRedOn = !this.barcodeTcpClient.Connected;
                ////this.NotifyPropertyChanged("LedStatus");


                ////this.MainStatus = this.LedGreenOn ? (this.onPrinting ? "Scanning ...." : "Ready to scan") : exception.Message;
            }
        }