public void RunStation05Sealer2(object msgobj)
        {
            MainNetworkClass networkmain = (MainNetworkClass)msgobj;

            while (!bTerminate)
            {
                Thread.Sleep(100);
                try
                {
                    bool Sealerflag2 = false;


                    if (PLCTelnet2 != null)
                    {
                        if (PLCTelnet2.connected)
                        {
                            #region  sealer program For Station5


                            #region  //Sealer2
                            byte[] tmparray3 = new byte[10];
                            //DM5085
                            Array.Copy(PLCQueryRx6, 181, tmparray3, 0, 10);
                            //convert array to string
                            Station5ForSealer2Scanboxid = System.Text.Encoding.Default.GetString(tmparray3);
                            if (Station5ForSealer2Scanboxid != "\0\0\0\0\0\0\0\0\0\0")
                            {
                                ScanboxidSt5S2 = Station5ForSealer2Scanboxid;
                                Sealer2Log.Info("Finishing Label for Station 5 Sealer2 " + Station5ForSealer2Scanboxid);
                                networkmain.stn5log = Station5ForSealer2Scanboxid + " slr. 2 recieved";
                                #region Desiccant Timmer Sealer2
                                Thread.Sleep(10);
                                if ((PLCQueryRx6[PLCQueryRx_DM5111 + 14] == 0X07) && (PLCWriteCommand6[PLCWriteCommand_DM5405 + 2]) == 0x00) //D5117
                                {
                                    Sealer2Log.Info("Finishing Label for Station 5 Sealer2 PLC Send HIC/Desiccant stop Signal " + Station5ForSealer2Scanboxid);
                                    networkmain.stn5log = Station5ForSealer2Scanboxid + " slr.2 PLC Send HIC/Desiccant stop Signal";

                                    if (Sealerflag2 == false)
                                    {
                                        try
                                        {
                                            Sealerflag2 = true;
                                            TimeSpan span = DateTime.Now.Subtract(DesiccantTimingMap[Station5ForSealer2Scanboxid]);
                                            Sealer2Log.Info("PC delete HIC/Desiccant Finishing Label for Station 5 Sealer2 " + Station5ForSealer2Scanboxid);
                                            networkmain.stn5log = Station5ForSealer2Scanboxid + " slr.2 deleted HIC/Desiccant";
                                            double secs = span.TotalSeconds;
                                            // if (secs > 175) //NEED TO OPEN WHEN REAL TIME PRODUCTION
                                            if (secs > 300)
                                            {
                                                //Desiccant Expired. Reject the Part.
                                                Statusst51 = "Fail";
                                                MyEventQ.AddQ("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer2Scanboxid);
                                                EvtLog.Info("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer2Scanboxid);
                                                //D5413=447
                                                byte[] tmp = new byte[2];
                                                tmp = Encoding.ASCII.GetBytes("RJ");
                                                Array.Copy(tmp, 0, PLCWriteCommand6, 447, 2);


                                                try
                                                {
                                                    Sealer2Log.Info(" HIC/Desiccant Timeout Finishing Label(RJ) for Station 5 Sealer2 " + Station5ForSealer2Scanboxid);
                                                    networkmain.stn5log     = Station5ForSealer2Scanboxid + " HIC/Desiccant Timeout slr.2";
                                                    networkmain.OperatorLog = "Stn.5 slr.2 " + Station5ForSealer2Scanboxid + "HIC/Desiccant Timeout";
                                                    while ((!networkmain.UpdateRJLabelst5S2(Station5ForSealer2Scanboxid, "RJ", "501") && !bTerminate))
                                                    {
                                                        Thread.Sleep(100);
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    Sealer2Log.Error("station 5 Sealer2 HIC/Desiccant Fail" + ex);
                                                    networkmain.stn5log     = "Fail HIC/Des slr.2 EX";
                                                    networkmain.OperatorLog = "Stn.5 slr.2 HIC/Des Fail EX";
                                                    byte[] tmp1 = new byte[2];
                                                    tmp1 = Encoding.ASCII.GetBytes("RJ");
                                                    Array.Copy(tmp1, 0, PLCWriteCommand6, 447, 2);
                                                    Sealer2Log.Info("RJ" + Station5ForSealer2Scanboxid);
                                                    Statusst51 = "Fail";
                                                    MyEventQ.AddQ("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer2Scanboxid);
                                                    EvtLog.Info("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer2Scanboxid);
                                                }
                                            }
                                            else
                                            {
                                                if (CheckeRJStatusForSealer2(Station5ForSealer2Scanboxid) == true)
                                                {
                                                    Sealer2Log.Info(" HIC/Desiccant Pass Finishing Label for Station 5 Sealer2 " + Station5ForSealer2Scanboxid);
                                                    networkmain.stn5log = Station5ForSealer2Scanboxid + " slr.2 HIC/Desiccant Pass";
                                                    Statusst51          = "Pass";
                                                }
                                                else
                                                {
                                                    while ((!networkmain.UpdateRJLabelst5S2(Station5ForSealer2Scanboxid, "RJ", RJResultst5S2) && !bTerminate))
                                                    {
                                                        Thread.Sleep(100);
                                                    }



                                                    byte[] tmp = new byte[2];
                                                    tmp = Encoding.ASCII.GetBytes("RJ");
                                                    Array.Copy(tmp, 0, PLCWriteCommand6, 447, 2);
                                                    Sealer2Log.Info(" Finishing Label for Station 5 Sealer2 (RJ) because of other station " + Station5ForSealer2Scanboxid + " RJ Code," + RJResultst5S2);
                                                    Statusst51 = "Fail";
                                                }
                                            }


                                            DesiccantTimingMap.Remove(Station5ForSealer2Scanboxid);
                                            (PLCWriteCommand6[PLCWriteCommand_DM5405 + 2]) = 0x07;
                                        }
                                        catch (Exception ex)
                                        {
                                            Sealer2Log.Error(ex.ToString());
                                            while ((!networkmain.UpdateRJLabelst5S2(Station5ForSealer2Scanboxid, "RJ", "506") && !bTerminate))
                                            {
                                                Thread.Sleep(100);
                                            }
                                            Sealer2Log.Info(" HIC/Desiccant Fail Finishing Label for Sealer2 because of st3 (RJ) but send signal to PLC " + Station5ForSealer2Scanboxid + " RJ Code,506");
                                            networkmain.stn5log     = Station5ForSealer2Scanboxid + " slr.2 fail but sent signal to PLC because of st3";
                                            networkmain.OperatorLog = "Stn.5 slr.2 " + Station5ForSealer2Scanboxid + " fail because of st3";
                                            //D5413=447
                                            byte[] tmp = new byte[2];
                                            tmp = Encoding.ASCII.GetBytes("RJ");
                                            Array.Copy(tmp, 0, PLCWriteCommand6, 447, 2);
                                            (PLCWriteCommand6[PLCWriteCommand_DM5405 + 2]) = 0x07;
                                            Statusst51 = "Fail";
                                        }
                                    }
                                }


                                //  //TEST NEED TO DELETE START
                                //if (PLCQueryRx6[PLCQueryRx_DM5111 + 14] == 0X07)
                                //{ (PLCWriteCommand6[PLCWriteCommand_DM5405 + 2]) = 0x07; }

                                ////TEST NEED TO DELETE START END

                                #endregion

                                if (PLCWriteCommand6[PLCWriteCommand_DM5310 + 2] == 0x00)
                                {
                                    PLCWriteCommand6[PLCWriteCommand_DM5310 + 2] = 0x04; //busy Sealer2
                                    evnt_FindFinishingLabelForSealer2.Set();
                                    Sealer2Log.Info("Finishing Label for Station 5 Sealer2 receipt send already " + Station5ForSealer2Scanboxid);
                                    networkmain.stn5log = Station5ForSealer2Scanboxid + " receipt sent";
                                }
                            }
                            else
                            {
                                PLCWriteCommand6[PLCWriteCommand_DM5310 + 2] = 0x00;
                                PLCWriteCommand6[PLCWriteCommand_DM5413]     = 0x00;
                                PLCWriteCommand6[PLCWriteCommand_DM5413b]    = 0x00;
                                Station5ForSealer2Scanboxid = "\0\0\0\0\0\0\0\0\0\0";
                                Sealerflag2    = false;
                                ScanboxidSt5S2 = "";
                                pNumber2       = 0;
                                Statusst51     = "";
                            }

                            if (PLCQueryRx6[PLCQueryRx_DM5111 + 14] == 0X00) //D5118
                            {
                                (PLCWriteCommand6[PLCWriteCommand_DM5405 + 2]) = 0x00;
                            }

                            #endregion



                            #endregion
                            #region Sealercomms

                            if (evnt_FindFinishingLabelForSealer2.WaitOne(0))
                            {
                                try
                                {
                                    if (VS2VacuumSealer != null)
                                    {
                                        //if (!VS2VacuumSealer.IsOpen)
                                        //{
                                        try
                                        {
                                            VS2VacuumSealer.Close();
                                        }
                                        catch (Exception) { }
                                        VS2VacuumSealer = null;
                                        //}
                                    }
                                    if (VS2VacuumSealer == null)
                                    {
                                        XmlDocument doc = new XmlDocument();
                                        doc.Load(@"Config.xml");
                                        XmlNode Sealernode = doc.SelectSingleNode(@"/CONFIG/SEALER2/PORT");
                                        String  comport    = Sealernode.InnerText;
                                        //TODO: ConfigFIle
                                        VS2VacuumSealer = new InnovacVacuumSealer(comport);
                                        VS2VacuumSealer.Open();
                                    }
                                    //for testing only
                                    //VS2VacuumSealer.SelectAndConfirmProgram(240, InnovacVacuumSealer.SealerBar.Right);
                                    //PLCWriteCommand6[PLCWriteCommand_DM5310 + 2] = 0x08;
                                    #region
                                    if (networkmain.FindSealerReceipeForSealer2(Station5ForSealer2Scanboxid) == true)
                                    {
                                        short sealerReceipe = networkmain.SealerReceipt2;
                                        Sealer2Log.Info("Sealer2 send receipt " + sealerReceipe + "'" + Station5ForSealer2Scanboxid);
                                        VS2VacuumSealer.SelectAndConfirmProgram(sealerReceipe, InnovacVacuumSealer.SealerBar.Right);
                                        //bool type want
                                        PLCWriteCommand6[PLCWriteCommand_DM5310 + 2] = 0x08;
                                        // Set Status for PLC to Complete 0x08



                                        //// Wait until the sealing is completed/ Error returned/ Timeout happened.
                                        InnovacVacuumSealer.SealingCompleteMessage sealingCompleteMessage2;
                                        try {
                                            VS2VacuumSealer.WaitSealingCompleted(out sealingCompleteMessage2, 120000);
                                            // Sealing Completed successfully
                                            Sealer2Log.Info(sealingCompleteMessage2.ToString());
                                            PLCWriteCommand6[PLCWriteCommand_DM5310 + 2] = 0x09;
                                            #region

                                            try
                                            {
                                                //FL 1

                                                pNumber2 = sealingCompleteMessage2.ProgramNumber; //3


                                                if (pNumber2 > 0)

                                                {
                                                    // InnovacVacuumSealer.SealerBar SBar=sealingCompleteMessage.SelectedSealerBar;
                                                    // InnovacVacuumSealer.MessageCode Com   =sealingCompleteMessage.Command;

                                                    short  vacuumPV    = sealingCompleteMessage2.VacuumPV;                //ActualVacuumReading 4
                                                    short  VacuumSP    = sealingCompleteMessage2.VacuumSP;                //RecipeVacuumReading 5
                                                    short  SCurrentPV  = sealingCompleteMessage2.SealerCurrentPV;         //ActualCurrentReading 6
                                                    short  SCurrentSP  = sealingCompleteMessage2.SealerCurrentSP;         //RecipeCurrentReading 7
                                                    float  sealingTime = sealingCompleteMessage2.SealingTime;             //8
                                                    string Sfunction   = sealingCompleteMessage2.UsedFunction.ToString(); //9
                                                    string abc         = Sealer2IDshow.Trim();
                                                    Sealer2IDshow = abc;

                                                    if (Sfunction == "VT")
                                                    {
                                                        Sfunction = "VT";
                                                    }
                                                    if (Sfunction == "VS")
                                                    {
                                                        Sfunction = "VS";
                                                    }
                                                    if (Sfunction == "VT,VS")
                                                    {
                                                        Sfunction = "VTVS";
                                                    }



                                                    networkmain.Client_SendEventMessageForSealer2("503", Station5ForSealer2Scanboxid, Sealer2IDshow, sealingCompleteMessage2.ProgramNumber, sealingCompleteMessage2.VacuumPV, sealingCompleteMessage2.VacuumSP, sealingCompleteMessage2.SealerCurrentPV, sealingCompleteMessage2.SealerCurrentSP, sealingCompleteMessage2.SealingTime, Sfunction);

                                                    Sealer2Log.Info("Sealer2 send SealerInfo to Middleware " + Station5ForSealer2Scanboxid + "," + Sealer2IDshow + "," + sealingCompleteMessage2.ProgramNumber + "," + sealingCompleteMessage2.VacuumPV + "," + sealingCompleteMessage2.VacuumSP + "," + sealingCompleteMessage2.SealerCurrentPV + "," + sealingCompleteMessage2.SealerCurrentSP + "," + sealingCompleteMessage2.SealingTime + "," + Sfunction);
                                                }
                                            }

                                            catch
                                            {}

                                            #endregion
                                        } catch (TimeoutException ex) {
                                            // Timeout Happened
                                            Sealer2Log.Error(ex.ToString());
                                            string abc = Sealer2IDshow.Trim();
                                            MyEventQ.AddQ("8;SealerCommunicationBreak;SealerID;" + abc);
                                            EvtLog.Info("8;SealerCommunicationBreak;SealerID;" + abc);
                                        } catch (InnovacVacuumSealer.SealingErrorException ex) {
                                            // Sealer return Error
                                            if (ex.ErrorCode == 2 || ex.ErrorCode == 3 || ex.ErrorCode == 7)
                                            {
                                                PLCWriteCommand6[PLCWriteCommand_DM5310 + 2] = 0xFF;
                                            }
                                            else
                                            {
                                                PLCWriteCommand6[PLCWriteCommand_DM5310 + 2] = 0x09;
                                            }
                                            if (!Sealer2ErrAtv)
                                            {
                                                Sealer2ErrorCode = "E" + (5630 + ex.ErrorCode).ToString();
                                                Sealer2EventMesg = ex.ErrorMessage;
                                                Sealer2ErrAtv    = true;
                                                ExceptionMesgSend2((5630 + ex.ErrorCode).ToString(), Sealer2IDshow.Trim(), ex.ErrorMessage, ex.ToString());
                                                Sealer2ErrResetTimer.Interval = TimeSpan.FromSeconds(10);
                                                Sealer2ErrResetTimer.Tick    += Sealer2ErrResetTimer_Tick;
                                                Sealer2ErrResetTimer.Start(); //Start the bloody timer
                                            }
                                            else
                                            {
                                                //Reset the timer
                                                Sealer2ErrResetTimer.Stop();
                                                Sealer2ErrResetTimer.Start();
                                            }
                                        }
                                    }
                                    //finishing label not match
                                    else
                                    {
                                        PLCWriteCommand6[PLCWriteCommand_DM5310 + 2] = 0x0F;
                                        Sealer2Log.Info("Sealer2 Finishing Label don't have in System" + "," + Station5ForSealer2Scanboxid);
                                    }



                                    #endregion
                                }
                                catch (Exception ex)
                                {
                                    Sealer2Log.Error(ex.ToString());
                                    // Set status for PLC to Error 0x0F
                                    PLCWriteCommand6[PLCWriteCommand_DM5310 + 2] = 0x0F;
                                    Sealer2Log.Info("Sealer2 Finishing Label don't have in System" + "," + Station5ForSealer2Scanboxid);
                                    networkmain.stn5log = Station5ForSealer2Scanboxid + " slr.2 Finishing Label not in system";
                                }
                                evnt_FindFinishingLabelForSealer2.Reset();
                            }

                            #endregion
                        }
                    }
                    //  break;
                }
                catch (Exception ex)
                {
                    log.Error(ex.ToString());
                }
            }
        }
        public void RunStation05Sealers(object msgobj)
        {
            MainNetworkClass networkmain = (MainNetworkClass)msgobj;

            while (!bTerminate)
            {
                Thread.Sleep(100);
                try
                {
                    bool Sealerflag1 = false;
                    bool Sealerflag2 = false;
                    bool Sealerflag3 = false;

                    if (PLCTelnet2 != null)
                    {
                        if (PLCTelnet2.connected)
                        {
                            #region Sealer ID
                            //Sealer1

                            byte[] temps1 = new byte[12];
                            Array.Copy(PLCQueryRx6, 91, temps1, 0, 12); // DM 5040 PLC2
                            Sealer1ID = System.Text.Encoding.Default.GetString(temps1);

                            if (Sealer1ID != "\0\0\0\0\0\0\0\0\0\0\0\0" && Sealer1ID != "            ")
                            {
                                Sealer1IDshow = Sealer1ID;
                            }
                            else
                            {
                                Sealer1IDshow = "Sealer1IDisNULL";
                            }


                            byte[] temps2 = new byte[12];
                            Array.Copy(PLCQueryRx6, 141, temps2, 0, 12); // DM 5065 PLC2
                            Sealer2ID = System.Text.Encoding.Default.GetString(temps2);

                            if (Sealer2ID != "\0\0\0\0\0\0\0\0\0\0\0\0" && Sealer2ID != "            ")
                            {
                                Sealer2IDshow = Sealer2ID;
                            }
                            else
                            {
                                Sealer2IDshow = "Sealer2IDisNULL";
                            }


                            byte[] temps3 = new byte[12];
                            Array.Copy(PLCQueryRx6, 153, temps3, 0, 12); // DM 5071 PLC2
                            Sealer3ID = System.Text.Encoding.Default.GetString(temps3);

                            if (Sealer3ID != "\0\0\0\0\0\0\0\0\0\0\0\0" && Sealer3ID != "            ")
                            {
                                Sealer3IDshow = Sealer3ID;
                            }
                            else
                            {
                                Sealer3IDshow = "Sealer3IDisNULL";
                            }


                            #endregion



                            #region  sealer program For Station5
                            //edit .............................

                            byte[] temp2 = new byte[10];
                            Array.Copy(PLCQueryRx6, 201, temp2, 0, 10); // DM 5095 PLC2 =201 offset
                            Station5ForTransferScanboxidFromPLC2 = System.Text.Encoding.Default.GetString(temp2);

                            if (Station5ForTransferScanboxidFromPLC2 != "\0\0\0\0\0\0\0\0\0\0")
                            {
                                ST5NewFLRev = true;
                                CheckStringUpdateFor5(PLCFinishingLabelOFFSET, Station5ForTransferScanboxidFromPLC2);
                            }
                            else
                            {
                                ST5NewFLRev = false;
                                Station5ForTransferScanboxidFromPLC2 = "\0\0\0\0\0\0\0\0\0\0";
                                CheckStringClearFor5(PLCFinishingLabelOFFSET, Station5ForTransferScanboxidFromPLC2); // DM5271
                            }
                            // Compare PLC fl and thread fl
                            // Set Status to Busy


                            #endregion



                            #region  Sealer checking in Station 5 Initialization time

                            /*
                             * if (evnt_CheckingConnectionForSealer1.WaitOne(50))
                             * {
                             *  try
                             *  {
                             *      if (VS1VacuumSealer != null)
                             *      {
                             *
                             *          try
                             *          {
                             *              VS1VacuumSealer.Close();
                             *          }
                             *          catch (Exception) { }
                             *          VS1VacuumSealer = null;
                             *
                             *      }
                             *      if (VS1VacuumSealer == null)
                             *      {
                             *          XmlDocument doc = new XmlDocument();
                             *          doc.Load(@"Config.xml");
                             *          XmlNode Sealernode = doc.SelectSingleNode(@"/CONFIG/SEALER1/PORT");
                             *          String comport = Sealernode.InnerText;
                             *          //TODO: ConfigFIle
                             *          VS1VacuumSealer = new InnovacVacuumSealer(comport);
                             *          VS1VacuumSealer.Open();
                             *         // short testreceipe = 240;
                             *          //VS1VacuumSealer.SelectAndConfirmProgram(testreceipe, InnovacVacuumSealer.SealerBar.Right);
                             *         Sealer1Log.Info("Sealer1 connected at initialization time");
                             *         networkmain.stn5log ="slr.1 connected at initialization";
                             *         networkmain.OperatorLog = "Sealer1 connected at initialization time";
                             *         InnovacVacuumSealer.SystemStatus sysMessage;
                             *         VS1VacuumSealer.GetSystemStatus(out sysMessage);
                             *         if (sysMessage != InnovacVacuumSealer.SystemStatus.Undefined && sysMessage != InnovacVacuumSealer.SystemStatus.Error && Sealer1IDshow != "Sealer1IDisNULL")
                             *         {
                             *             PLCWriteCommand6[PLCWriteCommand_DM5362] = 0x06;
                             *         }
                             *         else
                             *         {
                             *             PLCWriteCommand6[PLCWriteCommand_DM5362] = 0xFF;
                             *         }
                             *      }
                             *
                             *
                             *  }
                             *  catch (Exception ex)
                             *  {
                             *      Sealer1Log.Error(ex.ToString());
                             *
                             *      PLCWriteCommand6[PLCWriteCommand_DM5362] = 0xFF;
                             *      Sealer1Log.Info("Sealer1 Can't connected at initialization time");
                             *      networkmain.stn5log = "slr.1 Can't connected at initialization";
                             *      networkmain.OperatorLog = "Sealer1 Can't connected at initialization time";
                             *      string  abc = Sealer1IDshow.Trim();
                             *      MyEventQ.AddQ("8;SealerCommunicationBreak;SealerID;" + abc);
                             *      EvtLog.Info("8;SealerCommunicationBreak;SealerID;" + abc);
                             *
                             *      evnt_CheckingConnectionForSealer1.Reset();
                             *  }
                             *  evnt_CheckingConnectionForSealer1.Reset();
                             * }
                             *
                             */


                            if (evnt_CheckingConnectionForSealer2.WaitOne(50))
                            {
                                try
                                {
                                    if (VS2VacuumSealer != null)
                                    {
                                        try
                                        {
                                            VS2VacuumSealer.Close();
                                        }
                                        catch (Exception) { }
                                        VS2VacuumSealer = null;
                                    }
                                    if (VS2VacuumSealer == null)
                                    {
                                        XmlDocument doc = new XmlDocument();
                                        doc.Load(@"Config.xml");
                                        XmlNode Sealernode = doc.SelectSingleNode(@"/CONFIG/SEALER2/PORT");
                                        String  comport    = Sealernode.InnerText;
                                        //TODO: ConfigFIle
                                        VS2VacuumSealer = new InnovacVacuumSealer(comport);
                                        VS2VacuumSealer.Open();
                                        //short testreceipe = 240;
                                        // VS2VacuumSealer.SelectAndConfirmProgram(testreceipe, InnovacVacuumSealer.SealerBar.Right);
                                        Sealer2Log.Info("Sealer2 connected at initialization time");
                                        networkmain.stn5log     = "slr.2 connected at initialization";
                                        networkmain.OperatorLog = "Sealer2 connected at initialization time";
                                        InnovacVacuumSealer.SystemStatus sysMessage;
                                        VS2VacuumSealer.GetSystemStatus(out sysMessage);
                                        if (sysMessage != InnovacVacuumSealer.SystemStatus.Undefined && sysMessage != InnovacVacuumSealer.SystemStatus.Error && Sealer2IDshow != "Sealer2IDisNULL")
                                        {
                                            PLCWriteCommand6[PLCWriteCommand_DM5363] = 0x06;
                                        }
                                        else
                                        {
                                            PLCWriteCommand6[PLCWriteCommand_DM5363] = 0xFF;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Sealer2Log.Error(ex.ToString());

                                    PLCWriteCommand6[PLCWriteCommand_DM5363] = 0xFF;
                                    Sealer2Log.Info("Sealer2 Can't connected at initialization time");
                                    networkmain.stn5log     = "slr.2 Can't connected at initialization";
                                    networkmain.OperatorLog = "Sealer2 Can't connected at initialization time";

                                    string abc = Sealer2IDshow.Trim();
                                    MyEventQ.AddQ("8;SealerCommunicationBreak;SealerID;" + abc);
                                    EvtLog.Info("8;SealerCommunicationBreak;SealerID;" + abc);
                                    evnt_CheckingConnectionForSealer2.Reset();
                                }
                                evnt_CheckingConnectionForSealer2.Reset();
                            }



                            if (evnt_CheckingConnectionForSealer3.WaitOne(50))
                            {
                                try
                                {
                                    if (VS3VacuumSealer != null)
                                    {
                                        try
                                        {
                                            VS3VacuumSealer.Close();
                                        }
                                        catch (Exception) { }
                                        VS3VacuumSealer = null;
                                    }
                                    if (VS3VacuumSealer == null)
                                    {
                                        XmlDocument doc = new XmlDocument();
                                        doc.Load(@"Config.xml");
                                        XmlNode Sealernode = doc.SelectSingleNode(@"/CONFIG/SEALER3/PORT");
                                        String  comport    = Sealernode.InnerText;
                                        //TODO: ConfigFIle
                                        VS3VacuumSealer = new InnovacVacuumSealer(comport);
                                        VS3VacuumSealer.Open();
                                        //short testreceipe = 240;
                                        //VS3VacuumSealer.SelectAndConfirmProgram(testreceipe, InnovacVacuumSealer.SealerBar.Right);
                                        Sealer3Log.Info("Sealer3 connected at initialization time");
                                        networkmain.stn5log     = "slr.3 connected at initialization";
                                        networkmain.OperatorLog = "Sealer3 connected at initialization time";
                                        InnovacVacuumSealer.SystemStatus sysMessage;
                                        VS3VacuumSealer.GetSystemStatus(out sysMessage);
                                        if (sysMessage != InnovacVacuumSealer.SystemStatus.Undefined && sysMessage != InnovacVacuumSealer.SystemStatus.Error && Sealer3IDshow != "Sealer3IDisNULL")
                                        {
                                            PLCWriteCommand6[PLCWriteCommand_DM5426] = 0x06;
                                        }
                                        else
                                        {
                                            PLCWriteCommand6[PLCWriteCommand_DM5426] = 0xFF;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Sealer3Log.Error(ex.ToString());

                                    PLCWriteCommand6[PLCWriteCommand_DM5426] = 0xFF;
                                    Sealer3Log.Info("Sealer3 Can't connected at initialization time");
                                    networkmain.stn5log     = "slr.3 Can't connected at initialization";
                                    networkmain.OperatorLog = "Sealer3 Can't connected at initialization time";

                                    string abc = Sealer3IDshow.Trim();
                                    MyEventQ.AddQ("8;SealerCommunicationBreak;SealerID;" + abc);
                                    EvtLog.Info("8;SealerCommunicationBreak;SealerID;" + abc);

                                    evnt_CheckingConnectionForSealer3.Reset();
                                }
                                evnt_CheckingConnectionForSealer3.Reset();
                            }

                            #endregion


                            #region Station 5 Error Code


                            byte[] tmparrayERst5 = new byte[2];
                            Array.Copy(PLCQueryRx6, 401, tmparrayERst5, 0, 2); //5195
                            //convert Byte array to int
                            Int32 erst5 = (Int32)(BitConverter.ToInt16(tmparrayERst5, 0));

                            byte[] tmparrayERst5_1 = new byte[2];
                            Array.Copy(PLCQueryRx6, 403, tmparrayERst5_1, 0, 2); //5196
                            //convert Byte array to int
                            Int32 erst5_1 = (Int32)(BitConverter.ToInt16(tmparrayERst5_1, 0));

                            byte[] tmparrayERst5_2 = new byte[2];
                            Array.Copy(PLCQueryRx6, 359, tmparrayERst5_2, 0, 2); //5174
                            //convert Byte array to int
                            Int32 erst5_2 = (Int32)(BitConverter.ToInt16(tmparrayERst5_2, 0));

                            ErrCode5_2 = erst5_2.ToString();
                            ErrCode5_1 = erst5_1.ToString();
                            ErrCode5   = erst5.ToString();



                            #region NewErrorCode
                            if (erst5 > 0 || erst5_1 > 0 || erst5_2 > 0)
                            {
                                // LogEr.Info("Station 5 Error Code"+ErrCode5+ErrCode5_1+ErrCode5_2);
                                Errmessage5 = "Stn.5 Err " +
                                              (erst5 > 0 ? ErrCode5 + ": " + Stn5ErrToMsg(erst5) : "") +
                                              (erst5_1 > 0 && erst5 != erst5_1 ? ", " + ErrCode5_1 + ": " + Stn5ErrToMsg(erst5_1) : "") +
                                              (erst5_2 > 0 && erst5 != erst5_2 ? ", " + ErrCode5_2 + ": " + Stn5ErrToMsg(erst5_2) : "");

                                if (!ST5JamFlag)
                                {
                                    bool St5JamTrig = ST2PauseFunction(5, erst5 + ";" + erst5_1 + ";" + erst5_2); //Check if is a JAM
                                    if (St5JamTrig)
                                    {
                                        ST5JamFlag = true;
                                        //string[] FLbatch = rq.UpdJamstatus(5, 555); //Update Jam FL
                                        //if (FLbatch != null)
                                        //{
                                        //    networkmain.Client_SendEventMsg("536", "Station5FLJAMRecovery", FLbatch);//Update Jam recovery FL to middleware
                                        //}
                                    }
                                }
                            }
                            else
                            {
                                ST5JamFlag  = false;
                                Errmessage5 = String.Empty;
                            }
                            #endregion
                            #region OldCode
                            //if (erst5 > 0 || erst5_1 > 0 || erst5_2 > 0)
                            //{

                            //    // LogEr.Info("Station 5 Error Code"+ErrCode5+ErrCode5_1+ErrCode5_2);
                            //    Errmessage5 = "Stn.5 Err " +
                            //        (erst5 > 0 ? ErrCode5 + ": " + Stn5ErrToMsg(erst5) : "") +
                            //        (erst5_1 > 0 && erst5 != erst5_1 ? ", " + ErrCode5_1 + ": " + Stn5ErrToMsg(erst5_1) : "") +
                            //        (erst5_2 > 0 && erst5 != erst5_2 ? ", " + ErrCode5_2 + ": " + Stn5ErrToMsg(erst5_2) : "");


                            //    //     LogEr.Info(Errmessage5);



                            //}
                            //else
                            //{
                            //    Errmessage5 = String.Empty;
                            //}
                            #endregion
                            UpdateErrorMsg((int)Station.StationNumber.Station05, Errmessage5, ST5JamFlag);

                            if ((erst5 > 0) && networkmain.controlst5 == 0)
                            {
                                Errst5 = erst5.ToString();
                                networkmain.controlst5 = 1;
                                messagest5             = Stn5ErrToMsg(erst5);
                                networkmain.Client_SendAlarmMessage5(erst5.ToString(), messagest5, "SET");
                            }
                            if (erst5 == 0 && networkmain.controlst5 == 1)
                            {
                                networkmain.Client_SendAlarmMessage5(Errst5, messagest5, "CLEAR");
                                networkmain.controlst5 = 0;
                                Errst5     = "";
                                messagest5 = "";
                            }



                            if ((erst5_1 > 0) && (erst5_1 != erst5) && networkmain.controlst5_1 == 0)
                            {
                                Errst5_1 = erst5_1.ToString();
                                networkmain.controlst5_1 = 1;
                                messagest5_1             = Stn5ErrToMsg(erst5_1);
                                networkmain.Client_SendAlarmMessage5(erst5_1.ToString(), messagest5_1, "SET");
                            }
                            if (erst5_1 == 0 && networkmain.controlst5_1 == 1)
                            {
                                networkmain.Client_SendAlarmMessage5(Errst5_1, messagest5_1, "CLEAR");
                                networkmain.controlst5_1 = 0;
                                Errst5_1     = "";
                                messagest5_1 = "";
                            }

                            if (erst5_2 > 0 && erst5 != erst5_2 && (erst5_1 != erst5_2) && networkmain.controlst5_2 == 0)
                            {
                                Errst5_2 = erst5_2.ToString();
                                networkmain.controlst5_2 = 1;
                                messagest5_2             = Stn5ErrToMsg(erst5_2);
                                networkmain.Client_SendAlarmMessage5(erst5_2.ToString(), messagest5_2, "SET");
                            }
                            if (erst5_2 == 0 && networkmain.controlst5_2 == 1)
                            {
                                networkmain.Client_SendAlarmMessage5(Errst5_2, messagest5_2, "CLEAR");
                                networkmain.controlst5_2 = 0;
                                Errst5_2     = "";
                                messagest5_2 = "";
                            }

                            #endregion
                        }
                    }
                    //  break;
                }
                catch (Exception ex)
                {
                    log.Error(ex.ToString());
                }
            }
        }