Example #1
0
        public void RunStation05Sealer3(object msgobj)
        {
            MainNetworkClass networkmain = (MainNetworkClass)msgobj;

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

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



                            #region //Sealer3
                            byte[] tmparray4 = new byte[10];
                            //DM5090
                            Array.Copy(PLCQueryRx6, 191, tmparray4, 0, 10);
                            //convert array to string
                            Station5ForSealer3Scanboxid = System.Text.Encoding.Default.GetString(tmparray4);
                            if (Station5ForSealer3Scanboxid != "\0\0\0\0\0\0\0\0\0\0")
                            {
                                ScanboxidSt5S3 = Station5ForSealer3Scanboxid;
                                Sealer3Log.Info("Finishing Label for Station 5 Sealer3 " + Station5ForSealer3Scanboxid);
                                networkmain.stn5log = Station5ForSealer3Scanboxid + " slr.3 Label recieved";
                                #region Desiccant Timmer
                                Thread.Sleep(10);
                                if ((PLCQueryRx6[PLCQueryRx_DM5111 + 16] == 0X07) && (PLCWriteCommand6[PLCWriteCommand_DM5405 + 4]) == 0x00) //D5119
                                {
                                    Sealer3Log.Info("Finishing Label for Station 5 Sealer3 PLC Send HIC/Desiccant stop Signal " + Station5ForSealer3Scanboxid);
                                    networkmain.stn5log = Station5ForSealer3Scanboxid + " Slr.3 stop Signal";
                                    if (Sealerflag3 == false)
                                    {
                                        try
                                        {
                                            Sealerflag3 = true;
                                            TimeSpan span = DateTime.Now.Subtract(DesiccantTimingMap[Station5ForSealer3Scanboxid]);
                                            double   secs = span.TotalSeconds;
                                            Sealer3Log.Info("PC delete HIC/Desiccant Finishing Label for Station 5 Sealer3 " + Station5ForSealer3Scanboxid);
                                            networkmain.stn5log = Station5ForSealer3Scanboxid + " Slr.3 PC delete HIC/Desiccant label";
                                            // if (secs > 175) //NEED TO OPEN WHEN REAL TIME PRODUCTION
                                            if (secs > 300)
                                            {
                                                //Desiccant Expired. Reject the Part.
                                                //D5414=449
                                                MyEventQ.AddQ("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer3Scanboxid);
                                                EvtLog.Info("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer3Scanboxid);
                                                Statusst52 = "Fail";
                                                byte[] tmp7 = new byte[2];
                                                tmp7 = Encoding.ASCII.GetBytes("RJ");
                                                Array.Copy(tmp7, 0, PLCWriteCommand6, 449, 2);
                                                try
                                                {
                                                    while ((!networkmain.UpdateRJLabelst5S3(Station5ForSealer3Scanboxid, "RJ", "502") && !bTerminate))
                                                    {
                                                        Thread.Sleep(100);
                                                    }
                                                    Sealer3Log.Info(" HIC/Desiccant Timeout Finishing Label (RJ) for Station 5 Sealer3  " + Station5ForSealer3Scanboxid);
                                                    networkmain.stn5log     = Station5ForSealer3Scanboxid + " slr.3 HIC/Desiccant Timeout";
                                                    networkmain.OperatorLog = "Stn.5 Slr.3 HIC/Desiccant Timeout " + Station5ForSealer3Scanboxid;
                                                }
                                                catch (Exception ex)
                                                {
                                                    Sealer3Log.Error("station 5 Sealer3 HIC/Desiccant Fail" + ex);
                                                    networkmain.stn5log     = "HIC/Desiccant Fail Slr.3";
                                                    networkmain.OperatorLog = "Stn.5 Slr.3 HIC/Desiccant Fail";
                                                    byte[] tmp71 = new byte[2];
                                                    tmp71 = Encoding.ASCII.GetBytes("RJ");
                                                    Array.Copy(tmp71, 0, PLCWriteCommand6, 449, 2);
                                                    Statusst52 = "Fail";

                                                    MyEventQ.AddQ("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer3Scanboxid);
                                                    EvtLog.Info("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer3Scanboxid);
                                                }
                                            }
                                            else
                                            {
                                                if (CheckeRJStatusForSealer3(Station5ForSealer3Scanboxid) == true)
                                                {
                                                    Sealer3Log.Info("HIC/Desiccant Pass Finishing Label for Station 5 Sealer3 " + Station5ForSealer3Scanboxid);
                                                    networkmain.stn5log = Station5ForSealer3Scanboxid + " slr.3 HIC/Desiccant Pass";
                                                    Statusst52          = "Pass";
                                                }
                                                else
                                                {
                                                    while ((!networkmain.UpdateRJLabelst5S3(Station5ForSealer3Scanboxid, "RJ", RJResultst5S3) && !bTerminate))
                                                    {
                                                        Thread.Sleep(100);
                                                    }



                                                    byte[] tmp7 = new byte[2];
                                                    tmp7 = Encoding.ASCII.GetBytes("RJ");
                                                    Array.Copy(tmp7, 0, PLCWriteCommand6, 449, 2);
                                                    Sealer3Log.Info(" Finishing Label for Station 5 Sealer3 (RJ) because of other station " + Station5ForSealer3Scanboxid + " RJ Code," + RJResultst5S3);
                                                    Statusst52 = "Fail";
                                                }
                                            }
                                            DesiccantTimingMap.Remove(Station5ForSealer3Scanboxid);
                                            (PLCWriteCommand6[PLCWriteCommand_DM5405 + 4]) = 0x07;
                                        }
                                        catch (Exception ex)
                                        {
                                            Sealer3Log.Error(ex.ToString());
                                            while ((!networkmain.UpdateRJLabel(Station5ForSealer3Scanboxid, "RJ", "507") && !bTerminate))
                                            {
                                                Thread.Sleep(100);
                                            }
                                            //D5414=449
                                            byte[] tmpS = new byte[2];
                                            tmpS = Encoding.ASCII.GetBytes("RJ");
                                            Array.Copy(tmpS, 0, PLCWriteCommand6, 449, 2);
                                            Sealer3Log.Info(" HIC/Desiccant Fail (RJ)Finishing Label for Sealer3 but send signal to PLC " + Station5ForSealer3Scanboxid + " RJ Code,507");
                                            networkmain.stn5log     = Station5ForSealer3Scanboxid + " slr.3 HIC/Desiccant fail but sent signal to PLC because of st3";
                                            networkmain.OperatorLog = "Stn.5 slr.3 " + Station5ForSealer3Scanboxid + "HIC/Desiccant fail because of st3";
                                            (PLCWriteCommand6[PLCWriteCommand_DM5405 + 4]) = 0x07;
                                            Statusst52 = "Fail";
                                        }
                                    }
                                }
                                #endregion
                                if (PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] == 0x00)
                                {
                                    PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x04; //busy Sealer3
                                    evnt_FindFinishingLabelForSealer3.Set();
                                    Sealer3Log.Info("Finishing Label for Station 5 Sealer3 receipt send already " + Station5ForSealer3Scanboxid);
                                    networkmain.stn5log = Station5ForSealer3Scanboxid + " slr.3 receipt sent already";
                                }
                            }
                            else
                            {
                                PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x00;
                                PLCWriteCommand6[PLCWriteCommand_DM5414]     = 0x00;
                                PLCWriteCommand6[PLCWriteCommand_DM5414b]    = 0x00;
                                Station5ForSealer3Scanboxid = "\0\0\0\0\0\0\0\0\0\0";
                                Sealerflag3    = false;
                                pNumber3       = 0;
                                ScanboxidSt5S3 = "";
                                Statusst52     = "";
                            }
                            if (PLCQueryRx6[PLCQueryRx_DM5111 + 16] == 0X00) //D5119
                            {
                                (PLCWriteCommand6[PLCWriteCommand_DM5405 + 4]) = 0x00;
                            }
                            #endregion

                            #endregion
                            #region Sealercomms

                            if (evnt_FindFinishingLabelForSealer3.WaitOne(0))
                            {
                                try
                                {
                                    if (VS3VacuumSealer != null)
                                    {
                                        //if (!VS3VacuumSealer.IsOpen)
                                        //{
                                        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();
                                    }
                                    //For test Only
                                    // VS3VacuumSealer.SelectAndConfirmProgram(240, InnovacVacuumSealer.SealerBar.Right);
                                    //PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x08;
                                    if (networkmain.FindSealerReceipeForSealer3(Station5ForSealer3Scanboxid) == true)
                                    {
                                        short sealerReceipe = networkmain.SealerReceipt3;
                                        Sealer3Log.Info("Sealer3 send receipt" + sealerReceipe);
                                        VS3VacuumSealer.SelectAndConfirmProgram(sealerReceipe, InnovacVacuumSealer.SealerBar.Right);
                                        //bool type want
                                        PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x08;
                                        // Set Status for PLC to Complete 0x08

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

                                            try
                                            {
                                                //FL 1

                                                pNumber3 = sealingCompleteMessage3.ProgramNumber; //3


                                                if (pNumber3 > 0)

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

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

                                                    string abc = Sealer3IDshow.Trim();
                                                    Sealer3IDshow = abc;

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


                                                    networkmain.Client_SendEventMessageForSealer3("503", Station5ForSealer3Scanboxid, Sealer3IDshow, sealingCompleteMessage3.ProgramNumber, sealingCompleteMessage3.VacuumPV, sealingCompleteMessage3.VacuumSP, sealingCompleteMessage3.SealerCurrentPV, sealingCompleteMessage3.SealerCurrentSP, sealingCompleteMessage3.SealingTime, Sfunction);

                                                    Sealer3Log.Info("Sealer3 send SealerInfo to Middleware " + Station5ForSealer3Scanboxid + "," + Sealer3IDshow + "," + sealingCompleteMessage3.ProgramNumber + "," + sealingCompleteMessage3.VacuumPV + "," + sealingCompleteMessage3.VacuumSP + "," + sealingCompleteMessage3.SealerCurrentPV + "," + sealingCompleteMessage3.SealerCurrentSP + "," + sealingCompleteMessage3.SealingTime + "," + Sfunction);
                                                }
                                            }

                                            catch
                                            {}

                                            #endregion
                                        } catch (TimeoutException ex) {
                                            // Timeout Happened
                                            Sealer3Log.Error(ex.ToString());
                                            string abc = Sealer3IDshow.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 + 4] = 0xFF;
                                            }
                                            else
                                            {
                                                PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x09;
                                            }
                                            if (!Sealer3ErrAtv)
                                            {
                                                Sealer3ErrorCode = "E" + (5660 + ex.ErrorCode).ToString();
                                                Sealer3EventMesg = ex.ErrorMessage;
                                                Sealer3ErrAtv    = true;
                                                ExceptionMesgSend3((5660 + ex.ErrorCode).ToString(), Sealer3IDshow.Trim(), ex.ErrorMessage, ex.ToString());
                                                Sealer3ErrResetTimer.Interval = TimeSpan.FromSeconds(10);
                                                Sealer3ErrResetTimer.Tick    += Sealer3ErrResetTimer_Tick;
                                                Sealer3ErrResetTimer.Start(); //Start the bloody timer
                                            }
                                            else
                                            {
                                                //Reset the timer
                                                Sealer3ErrResetTimer.Stop();
                                                Sealer3ErrResetTimer.Start();
                                            }
                                        }
                                    }
                                    //finishing label not match
                                    else
                                    {
                                        Sealer3Log.Info("Sealer3 Finishing Label don't have in System" + "," + Station5ForSealer3Scanboxid);
                                        PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x0F;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Sealer3Log.Error(ex.ToString());
                                    // Set status for PLC to Error 0x0F
                                    PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x0F;
                                    Sealer3Log.Info("Sealer3 Finishing Label don't have in System" + "," + Station5ForSealer3Scanboxid);
                                }
                                evnt_FindFinishingLabelForSealer3.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());
                }
            }
        }