Пример #1
0
 private void ExceptionMesgSend3(string ErrCode, string SealerID, string EventMesg, string ExMesg)
 {
     networkmain.Client_SendAlarmMessage(ErrCode, EventMesg, "SET");
     LogEr.Info(ErrCode + ";" + EventMesg + "; SET");
     MyEventQ.AddQ("535;Sealer3Error;SealerID;" + SealerID + ";SealerErrorCode;" + ErrCode + ";ErrorMessage;" + EventMesg);
     EvtLog.Info("535;Sealer3Error;SealerID;" + SealerID + ";SealerErrorCode;" + ErrCode + ";ErrorMessage;" + EventMesg);
 }
Пример #2
0
        public void RunStation05Sealer1(object msgobj)
        {
            MainNetworkClass networkmain = (MainNetworkClass)msgobj;

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

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


                            #region    //Sealer1

                            byte[] tmparray2 = new byte[10];
                            //DM5080
                            Array.Copy(PLCQueryRx6, 171, tmparray2, 0, 10);
                            //convert array to string
                            Station5ForSealer1Scanboxid = System.Text.Encoding.Default.GetString(tmparray2);
                            if (Station5ForSealer1Scanboxid != "\0\0\0\0\0\0\0\0\0\0")
                            {
                                ScanboxidSt5S1 = Station5ForSealer1Scanboxid;
                                Sealer1Log.Info("Finishing Label for Station 5 Sealer1 " + Station5ForSealer1Scanboxid);
                                networkmain.stn5log = Station5ForSealer1Scanboxid + " slr.1 recieved";
                                #region Desiccant Timmer
                                Thread.Sleep(10);
                                if ((PLCQueryRx6[PLCQueryRx_DM5111 + 12] == 0X07) && (PLCWriteCommand6[PLCWriteCommand_DM5405]) == 0x00)//D5117
                                {
                                    try {
                                        #region HIC YES Or No Check

                                        //if(Station5ForSealer1HICYESNO=="NO")
                                        //{
                                        //(PLCWriteCommand6[PLCWriteCommand_DM5405]) = 0x07;
                                        //}


                                        //else
                                        //{

                                        Sealer1Log.Info("Finishing Label for Station 5 Sealer1 PLC Send HIC/Desiccant stop Signal " + Station5ForSealer1Scanboxid);
                                        networkmain.stn5log = Station5ForSealer1Scanboxid + " slr.1 HIC/Desct stop";
                                        if (Sealerflag1 == false)
                                        {
                                            try
                                            {
                                                Sealerflag1 = true;
                                                TimeSpan span = DateTime.Now.Subtract(DesiccantTimingMap[Station5ForSealer1Scanboxid]);
                                                double   secs = span.TotalSeconds;
                                                Sealer1Log.Info("PC delete HIC/Desiccant Finishing Label for Station 5 Sealer1 " + Station5ForSealer1Scanboxid);
                                                networkmain.stn5log = Station5ForSealer1Scanboxid + " slr.1 PC delete HIC/Desiccant";
                                                // if (secs > 175) //NEED TO OPEN WHEN REAL TIME PRODUCTION
                                                if (secs > 300)
                                                {
                                                    //Desiccant Expired. Reject the Part.
                                                    //D5412=445
                                                    Statusst5 = "Fail";
                                                    MyEventQ.AddQ("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer1Scanboxid);
                                                    EvtLog.Info("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer1Scanboxid);
                                                    byte[] tmp = new byte[2];
                                                    tmp = Encoding.ASCII.GetBytes("RJ");
                                                    Array.Copy(tmp, 0, PLCWriteCommand6, 445, 2);

                                                    try
                                                    {
                                                        while ((!networkmain.UpdateRJLabelst5S1(Station5ForSealer1Scanboxid, "RJ", "500") && !bTerminate))
                                                        {
                                                            Thread.Sleep(100);
                                                        }
                                                        Sealer1Log.Info(" HIC/Desiccant Timeout Finishing Label (RJ) for Station 5 Sealer1  " + Station5ForSealer1Scanboxid);
                                                        networkmain.stn5log     = Station5ForSealer1Scanboxid + " slr.1 HIC/Desiccant Timeout";
                                                        networkmain.OperatorLog = "Stn.5 Slr.1 HIC/Desiccant Timeout " + Station5ForSealer1Scanboxid;
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Sealer1Log.Error("station 5 Sealer1 HIC/Desiccant (RJ) Fail" + ex);
                                                        networkmain.stn5log     = "slr.1 HIC/Desiccant fail";
                                                        networkmain.OperatorLog = "Stn.5 Slr.1HIC/Desiccant fail " + Station5ForSealer1Scanboxid;
                                                        byte[] tmp1 = new byte[2];
                                                        tmp1 = Encoding.ASCII.GetBytes("RJ");
                                                        Array.Copy(tmp1, 0, PLCWriteCommand6, 445, 2);

                                                        MyEventQ.AddQ("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer1Scanboxid);
                                                        EvtLog.Info("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer1Scanboxid);
                                                    }
                                                }
                                                else
                                                {
                                                    if (CheckeRJStatusForSealer1(Station5ForSealer1Scanboxid) == true)
                                                    {
                                                        Sealer1Log.Info(" HIC/Desiccant Pass Finishing Label for Station 5 Sealer1  " + Station5ForSealer1Scanboxid);
                                                        networkmain.stn5log = Station5ForSealer1Scanboxid + " slr.1 HIC/Desiccant Pass";
                                                        Statusst5           = "Pass";
                                                    }
                                                    else
                                                    {
                                                        while ((!networkmain.UpdateRJLabelst5S1(Station5ForSealer1Scanboxid, "RJ", RJResultst5S1) && !bTerminate))
                                                        {
                                                            Thread.Sleep(100);
                                                        }


                                                        byte[] tmp1 = new byte[2];
                                                        tmp1 = Encoding.ASCII.GetBytes("RJ");
                                                        Array.Copy(tmp1, 0, PLCWriteCommand6, 445, 2);
                                                        Statusst5 = "Fail";
                                                        Sealer1Log.Info(" Finishing Label for Station 5 Sealer1 (RJ) because of other station " + Station5ForSealer1Scanboxid + " RJ Code," + RJResultst5S1);
                                                    }
                                                }

                                                DesiccantTimingMap.Remove(Station5ForSealer1Scanboxid);
                                                (PLCWriteCommand6[PLCWriteCommand_DM5405]) = 0x07;
                                            }
                                            catch (Exception ex)
                                            {
                                                Sealer1Log.Error(ex.ToString());

                                                while ((!networkmain.UpdateRJLabelst5S1(Station5ForSealer1Scanboxid, "RJ", "505") && !bTerminate))
                                                {
                                                    Thread.Sleep(100);
                                                }
                                                //D5412=445
                                                byte[] tmp = new byte[2];
                                                tmp = Encoding.ASCII.GetBytes("RJ");
                                                Array.Copy(tmp, 0, PLCWriteCommand6, 445, 2);
                                                Statusst5 = "Fail";
                                                Sealer1Log.Info(" HIC/Desiccant Fail Finishing Label (RJ) for Sealer1 because of station 3 but send signal to PLC " + Station5ForSealer1Scanboxid + " RJ Code," + "505");
                                                networkmain.stn5log     = Station5ForSealer1Scanboxid + " slr.1 HIC/Desiccant Fail Label because of station 3";
                                                networkmain.OperatorLog = "Stn.5 Slr.1 HIC/Desiccant Failed because of station 3" + Station5ForSealer1Scanboxid;
                                                (PLCWriteCommand6[PLCWriteCommand_DM5405]) = 0x07;
                                            }
                                        }
                                        //  } //change

                                        #endregion
                                    }

                                    catch (Exception ex)
                                    {
                                        Sealer1Log.Error(ex.ToString());
                                        Statusst5 = "Fail";
                                    }
                                }



                                //  //TEST NEED TO DELET START
                                //if(PLCQueryRx6[PLCQueryRx_DM5111 + 12]==0X07)

                                //{ (PLCWriteCommand6[PLCWriteCommand_DM5405]) = 0x07;
                                //}
                                ////TEST NEED TO DELET END

                                #endregion
                                if (PLCWriteCommand6[PLCWriteCommand_DM5310] == 0x00)
                                {
                                    PLCWriteCommand6[PLCWriteCommand_DM5310] = 0x04; //busy Sealer1
                                    evnt_FindFinishingLabelForSealer1.Set();
                                    Sealer1Log.Info("Finishing Label for Station 5 Sealer1 receipt send already " + Station5ForSealer1Scanboxid);
                                    networkmain.stn5log     = Station5ForSealer1Scanboxid + " slr.1 receipt send already";
                                    networkmain.OperatorLog = "Stn.5 slr.1 " + Station5ForSealer1Scanboxid + " receipt send already";
                                }
                            }
                            else
                            {
                                PLCWriteCommand6[PLCWriteCommand_DM5310]  = 0x00;
                                PLCWriteCommand6[PLCWriteCommand_DM5412]  = 0x00;
                                PLCWriteCommand6[PLCWriteCommand_DM5412b] = 0x00;
                                Station5ForSealer1Scanboxid = "\0\0\0\0\0\0\0\0\0\0";
                                Sealerflag1    = false;
                                pNumber1       = 0;
                                ScanboxidSt5S1 = "";
                                Statusst5      = "";
                            }

                            if (PLCQueryRx6[PLCQueryRx_DM5111 + 12] == 0X00)
                            {
                                (PLCWriteCommand6[PLCWriteCommand_DM5405]) = 0x00;
                            }

                            #endregion


                            #endregion
                            #region Sealercomms
                            if (evnt_FindFinishingLabelForSealer1.WaitOne(0))
                            {
                                try
                                {
                                    if (VS1VacuumSealer != null)
                                    {
                                        //if (!VS1VacuumSealer.IsOpen)
                                        //{
                                        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();
                                    }
                                    // VS1VacuumSealer.SelectAndConfirmProgram(int.Parse(SEALER_RECIPE), InnovacVacuumSealer.SealerBar.Right);
                                    if (networkmain.FindSealerReceipeForSealer1(Station5ForSealer1Scanboxid) == true)
                                    {
                                        short sealerReceipe = networkmain.SealerReceipt1;
                                        Sealer1Log.Info("Sealer1 send receipt " + sealerReceipe + "'" + Station5ForSealer1Scanboxid);
                                        networkmain.stn5log = Station5ForSealer1Scanboxid + " slr.1 send receipt " + sealerReceipe;
                                        VS1VacuumSealer.SelectAndConfirmProgram(sealerReceipe, InnovacVacuumSealer.SealerBar.Right);
                                        //bool type want
                                        PLCWriteCommand6[PLCWriteCommand_DM5310] = 0x08;
                                        //  evnt_FindFinishingLabelForSealer1.Reset();


                                        //// Wait until the sealing is completed/ Error returned/ Timeout happened.
                                        InnovacVacuumSealer.SealingCompleteMessage sealingCompleteMessage;
                                        try {
                                            VS1VacuumSealer.WaitSealingCompleted(out sealingCompleteMessage, 120000);
                                            // Sealing Completed successfully
                                            Sealer1Log.Info(sealingCompleteMessage.ToString());
                                            PLCWriteCommand6[PLCWriteCommand_DM5310] = 0x09;


                                            #region

                                            try
                                            {
                                                //FL 1

                                                pNumber1 = sealingCompleteMessage.ProgramNumber; //3


                                                if (pNumber1 > 0)

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

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


                                                    abc           = Sealer1IDshow.Trim();
                                                    Sealer1IDshow = abc;
                                                    if (Sfunction == "VT")
                                                    {
                                                        Sfunction = "VT";
                                                    }
                                                    if (Sfunction == "VS")
                                                    {
                                                        Sfunction = "VS";
                                                    }
                                                    if (Sfunction == "VT,VS")
                                                    {
                                                        Sfunction = "VTVS";
                                                    }



                                                    networkmain.Client_SendEventMessageForSealer1("503", Station5ForSealer1Scanboxid, Sealer1IDshow, sealingCompleteMessage.ProgramNumber, sealingCompleteMessage.VacuumPV, sealingCompleteMessage.VacuumSP, sealingCompleteMessage.SealerCurrentPV, sealingCompleteMessage.SealerCurrentSP, sealingCompleteMessage.SealingTime, Sfunction);



                                                    Sealer1Log.Info("Sealer1 send SealerInfo to Middleware " + Station5ForSealer1Scanboxid + "," + Sealer1IDshow + "," + sealingCompleteMessage.ProgramNumber + "," + sealingCompleteMessage.VacuumPV + "," + sealingCompleteMessage.VacuumSP + "," + sealingCompleteMessage.SealerCurrentPV + "," + sealingCompleteMessage.SealerCurrentSP + "," + sealingCompleteMessage.SealingTime + "," + Sfunction);
                                                }
                                            }

                                            catch
                                            {}

                                            #endregion
                                        } catch (TimeoutException ex) {
                                            // Timeout Happened
                                            Sealer1Log.Error(ex.ToString());
                                            abc = Sealer1IDshow.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] = 0xFF;
                                            }
                                            else
                                            {
                                                PLCWriteCommand6[PLCWriteCommand_DM5310] = 0x09;
                                            }
                                            if (!Sealer1ErrAtv)
                                            {
                                                Sealer1ErrorCode = "E" + (5600 + ex.ErrorCode).ToString();
                                                Sealer1EventMesg = ex.ErrorMessage;
                                                Sealer1ErrAtv    = true;
                                                ExceptionMesgSend1((5600 + ex.ErrorCode).ToString(), Sealer1IDshow.Trim(), ex.ErrorMessage, ex.ToString());
                                                Sealer1ErrResetTimer.Interval = TimeSpan.FromSeconds(10);
                                                Sealer1ErrResetTimer.Tick    += Sealer1ErrResetTimer_Tick;
                                                Sealer1ErrResetTimer.Start(); //Start the bloody timer
                                            }
                                            else
                                            {
                                                //Reset the timer
                                                Sealer1ErrResetTimer.Stop();
                                                Sealer1ErrResetTimer.Start();
                                            }
                                        }
                                    }
                                    //finishing label not match
                                    // Set Status for PLC to Complete 0x08
                                    else
                                    {
                                        Sealer1Log.Info("Sealer1 Finishing Label don't have in System" + ", " + Station5ForSealer1Scanboxid);
                                        networkmain.stn5log     = Station5ForSealer1Scanboxid + " slr.1 Finishing Label not in system";
                                        networkmain.OperatorLog = "Stn.5 dont have " + Station5ForSealer1Scanboxid + " in system";
                                        PLCWriteCommand6[PLCWriteCommand_DM5310] = 0x0F;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Sealer1Log.Error(ex.ToString());
                                    // Set status for PLC to Error 0x0F
                                    PLCWriteCommand6[PLCWriteCommand_DM5310] = 0x0F;
                                    Sealer1Log.Info("Sealer1 Finishing Label don't have in System" + "," + Station5ForSealer1Scanboxid);
                                    networkmain.stn5log = Station5ForSealer1Scanboxid + " slr.1 Finishing Label not in system";
                                    evnt_FindFinishingLabelForSealer1.Reset();
                                }
                                evnt_FindFinishingLabelForSealer1.Reset();
                            }

                            #endregion
                        }
                    }
                    //  break;
                }
                catch (Exception ex)
                {
                    log.Error(ex.ToString());
                }
            }
        }
Пример #3
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());
                }
            }
        }
Пример #4
0
        public void RunPLC01Scan(object msgobj)
        {
            MainNetworkClass networkmain = (MainNetworkClass)msgobj;

            byte[] tmpRx     = new byte[411];
            byte[] tmpRx1    = new byte[611];
            byte[] tmpRx2    = new byte[811];
            bool   plc1Break = false;

            PLCTelnet = new TelnetClient();
            //check for TCP network connection for PLC
            while (!bTerminate)
            {
                Thread.Sleep(100);
                try
                {
                    if (PLCTelnet.connected == false)
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.Load(@"Config.xml");
                        XmlNode node = doc.SelectSingleNode(@"/CONFIG/PLCCONTROLLER1/ADD");
                        System.Net.IPAddress address = System.Net.IPAddress.Parse(node.InnerText);
                        node = doc.SelectSingleNode(@"/CONFIG/PLCCONTROLLER1/PORT");
                        PLCNetworkAddress = "Trying to connect to " + address.ToString() + " Port : " + node.InnerText;
                        if (PLCTelnet.ConnectToHost(address, int.Parse(node.InnerText)) == false)
                        {
                            PLCNetworkAddress = "Connected to PLCServer1 "
                                                + address.ToString()
                                                + " Port : "
                                                + node.InnerText
                                                + " Fail"; //not connected
                            Thread.Sleep(100);             // try to connect to server
                            if (!plc1Break)
                            {
                                MyEventQ.AddQ("5;PLCCommunicationBreak;PLC Number;1");//Push message to stack
                                EvtLog.Info("5;PLCCommunicationBreak;PLC Number;1");
                                plc1Break = true;
                            }
                            continue;
                        }
                        else
                        {
                            PLCNetworkAddress = "Connected to PLCServer1 " + address.ToString() + " Port : " + node.InnerText;//connected
                        }
                        plc1Break = false;
                    }
                    //PLC Read Write Cycle
                    if (PLCTelnet.connected)
                    {
                        //get read data from PLC
                        PLCTelnet.SendDataToHost(PLCQueryCmd);//query data from plc D000 to D199
                        string tmpstr100;
                        tmpstr100 = PLCTelnet.GetDataFromHost(ref tmpRx, tmpRx.Length);
                        if (tmpstr100.StartsWith("d00000ffff") && tmpstr100.Length == 822)
                        {
                            Array.Copy(tmpRx, PLCQueryRx, PLCQueryRx.Length);
                        }
                        else
                        {
                            tmpstr100 = "No Data";
                        }

                        int timeoutcounter = 0;
                        while ((tmpstr100 == "No Data") && PLCTelnet.connected)
                        {
                            Thread.Sleep(waitdelay);
                            //tmpstr100 = PLCTelnet.GetDataFromHost(ref PLCQueryRx, PLCQueryRx.Length);
                            tmpstr100 = PLCTelnet.GetDataFromHost(ref tmpRx, tmpRx.Length);
                            //tmpstr100 = PLCTelnet.GetDataFromHost(ref PLCQueryRx, PLCQueryRx.Length);
                            if (tmpstr100.StartsWith("d00000ffff") && (tmpstr100.Length == 822))
                            {
                                Array.Copy(tmpRx, PLCQueryRx, PLCQueryRx.Length);
                            }
                            else
                            {
                                tmpstr100 = "No Data";
                            }
                            //log.Info(tmpstr100);
                            timeoutcounter++;
                            if (timeoutcounter == 10)
                            {
                                //assume connection broken
                                PLCTelnet.Close();
                                break;
                            }
                        }

                        //Update 14/12/2015 May Pon
                        #region READ  PLC1 Memory 6100 to 6499



                        timeoutcounter = 0;
                        if (PLCTelnet.connected == false)
                        {
                            continue;
                        }
                        PLCTelnet.SendDataToHost(PLCQueryCmdPara);//query data from plc dm700 to dm999
                        //tmpstr100 = PLCTelnet.GetDataFromHost(ref PLCQueryRx7, PLCQueryRx7.Length);
                        tmpstr100 = PLCTelnet.GetDataFromHost(ref tmpRx2, tmpRx2.Length);
                        //tmpstr100 = PLCTelnet.GetDataFromHost(ref PLCQueryRx, PLCQueryRx.Length);
                        if (tmpstr100.StartsWith("d00000ffff") && (tmpstr100.Length == 1622))
                        {
                            Array.Copy(tmpRx2, PLCQueryRxPara, PLCQueryRxPara.Length);
                        }
                        else
                        {
                            tmpstr100 = "No Data";
                        }

                        while ((tmpstr100 == "No Data") && PLCTelnet.connected)
                        {
                            Thread.Sleep(waitdelay);
                            tmpstr100 = PLCTelnet.GetDataFromHost(ref tmpRx2, tmpRx2.Length);
                            //tmpstr100 = PLCTelnet.GetDataFromHost(ref PLCQueryRx, PLCQueryRx.Length);
                            if ((tmpstr100.StartsWith("d00000ffff") && (tmpstr100.Length == 1622)))
                            {
                                Array.Copy(tmpRx2, PLCQueryRxPara, PLCQueryRxPara.Length);
                            }
                            else
                            {
                                tmpstr100 = "No Data";
                            }

                            timeoutcounter++;
                            if (timeoutcounter == 10)
                            {
                                //assume connection broken
                                PLCTelnet.Close();
                                break;
                            }
                        }



                        #endregion


                        //Update 25/7/2015
                        #region   READ  PLC1 Memory 700 to 999

                        //timeoutcounter = 0;
                        //if (PLCTelnet.connected == false) continue;
                        //PLCTelnet.SendDataToHost(PLCQueryCmd7);//query data from plc dm700 to dm999
                        ////tmpstr100 = PLCTelnet.GetDataFromHost(ref PLCQueryRx7, PLCQueryRx7.Length);
                        //tmpstr100 = PLCTelnet.GetDataFromHost(ref tmpRx1, tmpRx1.Length);
                        ////tmpstr100 = PLCTelnet.GetDataFromHost(ref PLCQueryRx, PLCQueryRx.Length);
                        //if (tmpstr100.StartsWith("d00000ffff") && (tmpstr100.Length == 1222))
                        //{
                        //    Array.Copy(tmpRx1, PLCQueryRx7, PLCQueryRx7.Length);
                        //}
                        //else
                        //    tmpstr100 = "No Data";
                        //log.Info(tmpstr100);
                        //while ((tmpstr100 == "No Data") && PLCTelnet.connected)
                        //{
                        //    Thread.Sleep(waitdelay);
                        //    tmpstr100 = PLCTelnet.GetDataFromHost(ref tmpRx1, tmpRx1.Length);
                        //    //tmpstr100 = PLCTelnet.GetDataFromHost(ref PLCQueryRx, PLCQueryRx.Length);
                        //    if ((tmpstr100.StartsWith("d00000ffff") && (tmpstr100.Length == 1222)))
                        //    {
                        //        Array.Copy(tmpRx1, PLCQueryRx7, PLCQueryRx7.Length);
                        //    }
                        //    else
                        //        tmpstr100 = "No Data";
                        //    log.Info(tmpstr100);
                        //    timeoutcounter++;
                        //    if (timeoutcounter == 10)
                        //    {
                        //        //assume connection broken
                        //        PLCTelnet.Close();
                        //        break;
                        //    }
                        //}
                        #endregion


                        timeoutcounter = 0;
                        if (PLCTelnet.connected == false)
                        {
                            continue;
                        }
                        PLCTelnet.SendDataToHost(PLCWriteCommand);
                        tmpstr100 = PLCTelnet.GetDataFromHost(ref PLCWriteCommandRX, PLCWriteCommandRX.Length);//write to dm 200 to dm 599
                        //  log.Info("PLC 1 Write " + tmpstr100);
                        while ((tmpstr100 == "No Data") && PLCTelnet.connected)
                        {
                            Thread.Sleep(waitdelay);
                            tmpstr100 = PLCTelnet.GetDataFromHost(ref PLCWriteCommandRX, PLCWriteCommandRX.Length);
                            //  log.Info("PLC 1 Write " + tmpstr100);
                            timeoutcounter++;
                            if (timeoutcounter == 10)
                            {
                                //assume connection broken
                                PLCTelnet.Close();
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Info("PLC01Polling Thread Error " + ex.ToString());
                }
            }//while ! terminated loop
        }
        public void RunMiddlewareScan(object msgobj)
        {
            MainNetworkClass networkmain = (MainNetworkClass)msgobj;
            int counter = 0;

            while (!bTerminate)
            {
                Thread.Sleep(10);
                try
                {
                    counter++;
                    connected = networkmain.connected;
                    //if not connected to middleware do a reconnection
                    if (networkmain.connected == false)
                    {
                        System.Net.IPHostEntry oEntry  = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
                        System.Net.IPAddress   address = oEntry.AddressList[0];
                        XmlDocument            doc     = new XmlDocument();
                        doc.Load(@"Config.xml");
                        XmlNode node = doc.SelectSingleNode(@"/CONFIG/MIDDLEWARE/ADD");
                        address        = System.Net.IPAddress.Parse(node.InnerText);
                        node           = doc.SelectSingleNode(@"/CONFIG/MIDDLEWARE/PORT");
                        NetworkAddress = "Trying to connect to " + address.ToString() + " Port : " + node.InnerText;
                        IPAddress ipAddress = address;//Dns.Resolve("localhost").AddressList[2];

                        if (networkmain.ConnectToHost(ipAddress) == false)
                        {
                            NetworkAddress = "Connected to MICServer " + address.ToString() + " Port : " + node.InnerText + " Fail" + "  V9.5.13.38Z_DB";
                            Thread.Sleep(100);// try to connect to server
                            UserName1 = "";
                            UserName2 = "";
                            StationStarStopLog.Info("Middleware Connection break " + ipAddress);
                            networkmain.linePack.Info("Middleware Connection break " + ipAddress);
                            MyEventQ.AddQ("1;MiddlewareCommunicationBreak"); //Push message to stack

                            // EvtLog.Info("1;MiddlewareCommunicationBreak");

                            continue;
                        }
                        NetworkAddress = "Connected to MICServer " + address.ToString() + " Port : " + node.InnerText + "  V9.5.13.38Z_DB";
                        MyEventQ.AddQ("4;InnogrityServerApplicationStarted");

                        BackgroundWorker bw = new BackgroundWorker();
                        bw.DoWork += new DoWorkEventHandler(delegate(object o, DoWorkEventArgs args)
                        {
                            ClearAllJam();
                        });
                        bw.RunWorkerAsync();

                        // EvtLog.Info("4;InnogrityServerApplicationStarted");
                    }
                    if (networkmain.connected)// if connected, do check
                    {
                        if (counter > 100)
                        {
                            networkmain.CheckHost();//have to use proper xml to test check or else server may crash
                            counter = 0;
                        }
                        try
                        {
                            networkmain.GetDataFromHost();
                        }
                        catch (Exception ex) { }
                    }
                    #region Station2
                    //Station 2 check if there is any outgoing messages
                    //Finishing label
                    if (evt_FinishLabelRequest.WaitOne(0))
                    {
                        string Boxnumber = "myboxnumberbarcode";               //sample box number/ finishing label request
                                                                               //save finishing label...to label tracking, label tracking to be updated..later when server reply
                                                                               //send finishing label request
                        if (networkmain.Client_SendScanBox(Scanboxid) == true) //previously wait for reply .. now reply is waited seperately
                                                                               //update label tracking data
                        {
                            #region OEEStep2
                            //OEE MODULE - GET ID and Bind ID number With FL
                            int OEEid = 0;
                            try
                            {
                                OEEid = rq.ReqLastID();
                                rq.UpdFLbyID(Scanboxid, OEEid);
                            }
                            catch (Exception ex)
                            {
                                IGTOEELog.Info("OEEStep2" + ex.ToString());
                            }

                            #endregion
                            SendFL = Scanboxid;
                            Boolean bHotlot = false;
                            string  sHotlot = "";
                            if (PLCQueryRx[11 + 109 * 2] == 0x08) //DM1019  --Hotlot
                            {
                                bHotlot             = true;
                                sHotlot             = "1";
                                networkmain.stn2log = "HotLot :" + Scanboxid;
                                networkmain.linePack.Info("HotLot :" + Scanboxid);
                            }
                            else
                            {
                                sHotlot = "0";
                            }
                            //while ((!networkmain.updatefltrackinginfomation(Scanboxid, OEEid.ToString(), sHotlot) && !bTerminate))
                            //{
                            //    Thread.Sleep(100);
                            //}
                            while ((!networkmain.updatefltrackinginfomationb(Scanboxid, OEEid.ToString(), bHotlot) && !bTerminate))
                            {
                                Thread.Sleep(100);
                            }
                            evt_FinishLabelRequest.Reset();//reset PLC request event
                            StationStarStopLog.Info("Running Start " + Scanboxid);
                            networkmain.linePack.Info("Already Sending Boxid to Middleware  " + Scanboxid);

                            PLCWriteCommand[21] = 0x08;// send request complete DM200
                        }
                        else
                        {
                            //will not write into tracking list.
                            //There is a send fail!
                            evt_FinishLabelRequest.Reset();//reset PLC request event
                            //networkmain.linePack.Info("Reject FL at buffer because of same FL coming two times  " + Scanboxid);
                            networkmain.OperatorLog = "Same FL comging two times " + Scanboxid;
                            networkmain.Client_SendEventMessage("84", "ST2 BUFFER FL DUPLICATE REJECT", "BOX_ID", Scanboxid);
                            AllRJEvent.Info("84" + ";" + "ST2 BUFFER FL DUPPLICATE REJECT" + ";" + "BOX_ID" + ";" + Scanboxid);
                            rq.INS_Func(DateTime.Now);
                            int BufferDup = rq.ReqLastID();
                            rq.UpdST4RJ(BufferDup.ToString(), 4, "294");
                            PLCWriteCommand[21] = 0x0F;// send request complete DM200
                        }
                    }
                    #endregion


                    #region MiddlewareToIGT   LoginCheckQC

                    if (networkmain.MiddlewareToIGTEvt_LoginCheckQC1.WaitOne(0))
                    {
                        try
                        {
                            if (networkmain.CheckServerConnectionWithMiddlwareForQC1(UserName1) == false)
                            {
                                StationStarStopLog.Info("Connection String not Match With Middleware,OP1 Logout " + UserName1);

                                networkmain.linePack.Info("Connection String not Match With Middleware,OP1 Logout " + UserName1);

                                networkmain.Client_SendQCStationLogout("1", networkmain.QC1LoginConnectionCheck1);
                                UserName1 = "";
                                networkmain.QC1LogOutSendReady = true;
                                PLCWriteCommand6[PLCWriteCmdOP01LoginLogout] = 0x00;
                            }

                            networkmain.MiddlewareToIGTEvt_LoginCheckQC1.Reset();
                        }
                        catch
                        {
                        }
                    }



                    if (networkmain.MiddlewareToIGTEvt_LoginCheckQC2.WaitOne(0))
                    {
                        try{
                            if (networkmain.CheckServerConnectionWithMiddlwareForQC2(UserName2) == false)
                            {
                                StationStarStopLog.Info("Connection String not Match With Middleware,OP2 Logout " + UserName2);
                                networkmain.linePack.Info("Connection String not Match With Middleware,OP2 Logout " + UserName2);
                                networkmain.Client_SendQCStationLogout("2", networkmain.QC2LoginConnectionCheck);
                                networkmain.QC2LogOutSendReady = true;
                                UserName2 = "";
                                PLCWriteCommand6[PLCWriteCmdOP02LoginLogout] = 0x00;
                            }

                            networkmain.MiddlewareToIGTEvt_LoginCheckQC2.Reset();
                        }
                        catch
                        {
                        }
                    }

                    #endregion
                    //Station 06 Login/Logout server exchange
                    #region Station06OPLoginLogout
                    //check if there is any incoming messages for login

                    if (networkmain.MiddlewareToIGTEvt_Login.WaitOne(0))
                    {
                        //process incoming messages
                        //Display on Station #
                        //Get username and StationID
                        //XmlNodeList list = networkmain.QCLogin.SelectNodes("MESSAGE/BODY/STATION_ID");
                        XmlNode list      = networkmain.QCLogin.SelectSingleNode("MESSAGE/BODY/STATION_ID");
                        string  StationID = list.InnerText;
                        //string StationID = list.Item(0).ToString();
                        XmlNode list1    = networkmain.QCLogin.SelectSingleNode("MESSAGE/BODY/USER_NAME");
                        String  UserName = list1.InnerText;
                        if (StationID == "1")
                        {
                            UserName1  = UserName;
                            StationID1 = StationID;

                            //reset PLC request event
                            PLCWriteCommand6[PLCWriteCmdOP01LoginLogout] = 0x08;// send request complete DM5200
                            networkmain.MiddlewareToIGTEvt_Login.Reset();
                        }
                        else if (StationID == "2")
                        {
                            UserName2           = UserName;
                            StationID2          = StationID;
                            networkmain.QC2Data = UserName;
                            //reset PLC request event
                            PLCWriteCommand6[PLCWriteCmdOP02LoginLogout] = 0x08;// send request complete DM5201
                            networkmain.MiddlewareToIGTEvt_Login.Reset();
                        }
                    }
                    switch (Operator01LoginState)
                    {
                    case WaitForOperatorLogin:
                        if ((PLCQueryRx6[PLCQueryRx_DM5100] == 0x08) &&
                            (PLCWriteCommand6[PLCWriteCommand_DM5200] == 0x08))    //request finishing label
                        {
                            //log6.Info("Operator 1 Login request "+StationID1+","+UserName1);
                            networkmain.linePack.Info("Operator 1 Login request " + StationID1 + "," + UserName1);
                            networkmain.Client_SendQCStationLogin(StationID1, UserName1);
                            networkmain.QC1LogOutSendReady = false;
                            networkmain.QC1Data            = UserName1;
                            Operator01LoginState           = WaitForOperatorLogout;
                        }


                        if ((PLCQueryRx6[PLCQueryRx_DM5100] == 0x0F) &&
                            (PLCWriteCommand6[PLCWriteCommand_DM5200] == 0x08))    //timeout
                        {
                            networkmain.QC1Data = UserName1;
                            // log6.Info("Operator 1 login 3 mins timeout "+StationID1+","+UserName1);
                            networkmain.linePack.Info("Operator 1 login 3 mins timeout " + StationID1 + "," + UserName1);
                            networkmain.Client_SendQCStationLogout(StationID1, UserName1);
                            networkmain.QC1LogOutSendReady = false;
                            networkmain.QC1Data            = "";
                            UserName1 = "";
                            POcount1  = 0;
                            PLCWriteCommand6[PLCWriteCommand_DM5200] = 0x00;
                            Operator01LoginState = WaitForOperatorLogin;
                        }
                        break;

                    case WaitForOperatorLogout:
                        if ((PLCQueryRx6[PLCQueryRx_DM5100] == 0xF) && (PLCWriteCommand6[PLCWriteCommand_DM5200] == 0x08))
                        {
                            // send middleware operator1 logout
                            PLCWriteCommand6[PLCWriteCommand_DM5200] = 0x00;
                            networkmain.Client_SendQCStationLogout(StationID1, UserName1);

                            networkmain.QC1LogOutSendReady = true;
                            POcount1 = 0;

                            // log6.Info("Operator 1 Logout request "+StationID1+","+UserName1);
                            networkmain.linePack.Info("Operator 1 Logout request " + StationID1 + "," + UserName1);

                            networkmain.QC1Data  = "";
                            UserName1            = "";
                            Operator01LoginState = WaitForOperatorLogin;
                        }
                        break;
                    }
                    switch (Operator02LoginState)
                    {
                    case WaitForOperatorLogin:
                        if ((PLCQueryRx6[PLCQueryRx_DM5100 + 2] == 0x08) &&
                            (PLCWriteCommand6[PLCWriteCommand_DM5200 + 2] == 0x08))    //request finishing label
                        {
                            // log6_1.Info("Operator 2 Login request "+StationID2+","+UserName2);
                            networkmain.linePack.Info("Operator 2 Login request " + StationID2 + "," + UserName2);
                            networkmain.Client_SendQCStationLogin(StationID2, UserName2);
                            networkmain.QC2LogOutSendReady = false;
                            networkmain.QC2Data            = UserName2;
                            Operator02LoginState           = WaitForOperatorLogout;
                        }

                        if ((PLCQueryRx6[PLCQueryRx_DM5100 + 2] == 0x0F) &&
                            (PLCWriteCommand6[PLCWriteCommand_DM5200 + 2] == 0x08))  //timeout
                        {
                            networkmain.QC2Data = UserName2;
                            // log6_1.Info("Operator 2 login 3 mins timeout "+StationID2+","+UserName2);
                            networkmain.linePack.Info("Operator 2 login 3 mins timeout " + StationID2 + "," + UserName2);

                            networkmain.Client_SendQCStationLogout(StationID2, UserName2);
                            networkmain.QC2LogOutSendReady = false;
                            networkmain.QC2Data            = "";
                            UserName2 = "";
                            POcount2  = 0;
                            PLCWriteCommand6[PLCWriteCommand_DM5200 + 2] = 0x00;
                            Operator02LoginState = WaitForOperatorLogin;
                        }

                        break;

                    case WaitForOperatorLogout:
                        if ((PLCQueryRx6[PLCQueryRx_DM5100 + 2] == 0xF) && (PLCWriteCommand6[PLCWriteCommand_DM5200 + 2] == 0x08))
                        {
                            // send middleware operator1 logout
                            PLCWriteCommand6[PLCWriteCommand_DM5200 + 2] = 0x00;
                            networkmain.Client_SendQCStationLogout(StationID2, UserName2);
                            networkmain.QC2LogOutSendReady = true;
                            POcount2 = 0;
                            // log6_1.Info("Operator 2 Logout request "+StationID2+","+UserName2);

                            networkmain.linePack.Info("Operator 2 Logout request " + StationID2 + "," + UserName2);
                            UserName2           = "";
                            networkmain.QC2Data = "";

                            // UserName2="";
                            Operator02LoginState = WaitForOperatorLogin;
                        }
                        break;
                    }
                    #endregion
                    if (evt_FG01_FG02Move.WaitOne(0))
                    {
                        networkmain.Client_sendFG01_FG02_MOVE1(st8FINISH, "FG01_FG02_MOVE");
                        networkmain.Client_sendFG01_FG02_MOVE(st8FINISH, "FG01_FG02_MOVE");

                        evt_FG01_FG02Move.Reset();
                        evt_FG01_FG02Move_Rx.Set();
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.ToString());
                }
            }//
        }
Пример #6
0
        public void RunStation06Operator01Scan(object msgobj)
        {
            MainNetworkClass networkmain = (MainNetworkClass)msgobj;

            Operator01State = 0;
            int    retrycounter = 0;
            string barcode;
            bool   ETI1Down = false;

            byte[] tmparray = new byte[10];
            while (!bTerminate)
            {
                Thread.Sleep(100);
                int   tmp0          = ((6220 - 6000) * 2) + 11;                                //EVENT ID Calculation
                Int16 QC1ETIMonitor = (Int16)(BitConverter.ToInt16(PLCQueryRxParaPlc2, tmp0)); //DM6220

                if (QC1ETIMonitor == 6056 && ETI1Down == false)
                {
                    MyEventQ.AddQ("656;QC1 ETI BUTTON TRIGGER;QcstationNumber;1;OperatorName;" + UserName1);
                    ETI1Down = true;
                }
                else if (QC1ETIMonitor == 0)
                {
                    ETI1Down = false;
                }
                try
                {
                    // JustLogIn(0); //0 is for operator 1, 2 is for operator 2.
                    if ((PLCQueryRx6[PLCQueryRx_DM5100 + 62] == 0x01))
                    {
                        SafetyStatus = AreaStatus.Block;
                    }
                    else if ((PLCQueryRx6[PLCQueryRx_DM5100 + 98] == 99))
                    {
                        SafetyStatus = AreaStatus.EarlyTake;
                        if (!EarlierPickupFlag)
                        {
                            networkmain.Client_SendEventMessage("654", "Station6QC1EarlyPickupDetected", "LotNumber", Station6ForOP1Scanboxid);
                            AllRJEvent.Info("654, Station6QC1EarlyPickupDetected,LotNumber," + Station6ForOP1Scanboxid);
                            EarlierPickupFlag = true;
                        }
                    }
                    else if ((PLCQueryRx6[PLCQueryRx_DM5100 + 98] == 0x01))
                    {
                        SafetyStatus = AreaStatus.MemNoClear;
                    }
                    else
                    {
                        SafetyStatus = AreaStatus.Null;
                    }
                    switch (Operator01State)
                    {
                    case WAITFORFINISHINGLABEL:    //wait for finishing label to be in ie. transition from "/0/0/0/0 .." to a
                        CheckStringClearFor6_OP1(OperatorA_PCtoPLCFinishingLabelOFFSET, Station6ForOP1Scanboxid);

                        //break;
                        if ((PLCQueryRx6[PLCQueryRx_DM5100] != 0x08) || (PLCWriteCommand6[PLCWriteCommand_DM5200] != 0x08))
                        {
                            break;
                        }
                        Array.Copy(PLCQueryRx6, 111, tmparray, 0, 10);
                        //convert array to string
                        Station6ForOP1Scanboxid = System.Text.Encoding.Default.GetString(tmparray);
                        Station6ForOP1Scanboxid.Trim();
                        RJButton = "";
                        //relfect finishing label data status to station 6 OP 1
                        if (Station6ForOP1Scanboxid != "\0\0\0\0\0\0\0\0\0\0")
                        {
                            // log6.Info("Operator 1 getting label from station 5 : " + Station6ForOP1Scanboxid);
                            networkmain.linePack.Info("Operator 1 getting label from station 5 : " + Station6ForOP1Scanboxid);
                            //switch state
                            if (CheckStringUpdateFor6_OP1(OperatorA_PCtoPLCFinishingLabelOFFSET, Station6ForOP1Scanboxid))
                            {
                                Operator01State = DISPLAYVALIDLABELINFO;
                            }
                            else
                            {
                                byte[] tmpbyte = new byte[2];
                                tmpbyte = Encoding.ASCII.GetBytes("ER");
                                Array.Copy(tmpbyte, 0, PLCWriteCommand6, 95, 2);    //copy ER to PLC DM5237
                                Operator01State = INVALIDLABELHANDLE;
                            }
                        }
                        break;

                    case DISPLAYVALIDLABELINFO:                   //display valid label informations.,... this state may not be necessary...
                        ScannerStatus = BarcodeStatus.NotScanned; //reset scan information
                        //may not be necessary
                        //evnt_FindFinishingLabelForOperator.Set();//display finishing label information on user screen
                        st6finish1 = Station6ForOP1Scanboxid;    //display purposes only
                        networkmain.FindFinishingLabelForOperator(Station6ForOP1Scanboxid);
                        st1POcount++;
                        POcount1++;
                        //display finishing label on user screen
                        PLCWriteCommand6[PLCWriteCommand_DM5204] = 0x02; //state 0x02 ready to scan
                        retrycounter    = 0;                             //reset retry counter
                        Operator01State = VALIDLABELRUNSCANNER;
                        break;

                    case VALIDLABELRUNSCANNER:    //finishing label is valid, turn on scanner
                        try
                        {
                            Array.Copy(PLCQueryRx6, 111, tmparray, 0, 10);
                            //convert array to string
                            Station6ForOP1Scanboxid = System.Text.Encoding.Default.GetString(tmparray);
                            Station6ForOP1Scanboxid.Trim();

                            if ((Station6ForOP1Scanboxid == "\0\0\0\0\0\0\0\0\0\0") && (PLCQueryRx6[PLCQueryRx_DM5100 + 4] == 0x0))
                            {
                                Operator01State = ERHANDLER_STEP02;
                            }

                            Station06OOperator01ScannerConnect(networkmain);
                            Array.Copy(PLCQueryRx6, 111, tmparray, 0, 10);
                            //convert array to string
                            Station6ForOP1Scanboxid = System.Text.Encoding.Default.GetString(tmparray);
                            Station6ForOP1Scanboxid.Trim();
                            PLCWriteCommand6[PLCWriteCommand_DM5204] = 0x02;
                            if (retrycounter > X)    //exceed retry
                            {
                                Operator01State = SCANNUMBEREXCEEDHANDLE;
                            }
                            //log6.Info("Operator 1 Scanner FL read " + Station6ForOP1Scanboxid);
                            networkmain.linePack.Info("Operator 1 Scanner FL read " + Station6ForOP1Scanboxid);
                            networkmain.stn6log = Station6ForOP1Scanboxid + " OP1 Scanner read";
                            int cnt = 0;
                            barcode = null;
                            while ((cnt < 100) && (barcode == null))
                            {
                                try
                                {
                                    OP1CognexScanner.ReadTimeout = 100;
                                    barcode = OP1CognexScanner.ReadLine();
                                }
                                catch (Exception) { }
                                cnt++;
                            }
                            if (cnt > 100)
                            {
                                throw new TimeoutException();
                            }
                            //check if barcode equal to incoming finihsing label
                            //ADD NEW
                            if (evnt_RejForOperator1.WaitOne(0))
                            {
                                // set ER to PLC
                                // PLC return 0xF PC return 0xF ==> PLC go to 0x0, PC goto 0x0
                                // wait for Station6ForOP1Scanboxid == "\0\0\0\0\0\0\0\0\0\0"
                                // or reset by change state
                                //reject event recieved
                                Operator01State = ERHANDLER_STEP01;
                                byte[] tmpbyte = new byte[2];
                                tmpbyte = Encoding.ASCII.GetBytes("ER");
                                Array.Copy(tmpbyte, 0, PLCWriteCommand6, 95, 2);    //copy ER to PLC DM5237
                                // log6.Info("Station 6 Operator 1 Technician Reject " + Station6ForOP1Scanboxid);

                                networkmain.linePack.Info("Station 6 Operator 1 Technician Reject " + Station6ForOP1Scanboxid);
                                //need to send ack to middleware
                                networkmain.stn6log = Station6ForOP1Scanboxid + " OP1 Technician Reject";

                                // networkmain.Client_sendFG01_FG02_MOVE(Station6ForOP1Scanboxid, "FG01_FG02_MOVE");


                                evnt_RejForOperator1.Reset();
                            }



                            if (barcode != null)
                            {
                                if (barcode.Contains(Station6ForOP1Scanboxid))    //eliminate additional character issues
                                {
                                    //if equal,operator reject or shutting down program, exit and update PLC
                                    PLCWriteCommand6[PLCWriteCommand_DM5204] = 0x08;
                                    ScannerStatus = BarcodeStatus.Equal;
                                    // log6.Info("Operator 1 Scanner FL contain " + Station6ForOP1Scanboxid);
                                    Operator01State = 99;
                                }
                                else
                                {
                                    //if not equal, number of retry is X number? if X number prompt display <--= dont exit..
                                    //go to read barcode again if not equal.
                                    if (PLCWriteCommand6[PLCWriteCommand_DM5204] != 0x08)
                                    {
                                        networkmain.linePack.Info("Operator 1 Scan Retry");
                                        PLCWriteCommand6[PLCWriteCommand_DM5204] = 0x0F;    //why is this removed??!
                                    }
                                    retrycounter++;
                                    ScannerStatus = BarcodeStatus.NotEqual;
                                    barcode       = null;
                                    Status        = "not equal try again";
                                    //  break;
                                    continue;
                                }
                            }
                        }
                        catch (TimeoutException)
                        {
                            if (PLCWriteCommand6[PLCWriteCommand_DM5204] != 0x08)
                            {
                                networkmain.linePack.Info("Operator 1 Scan Timeout");
                                PLCWriteCommand6[PLCWriteCommand_DM5204] = 0x0F;
                            }

                            //not scan
                            // log6.Info("Operator 1 Scanner Timeout set 0 PLCWriteCommand_DM5204 ==0 ---9");
                            networkmain.stn6log     = "OP 1 Timeout";
                            networkmain.OperatorLog = "Stn.6 OP 1 Timeout";
                            Status        = "Timeout";
                            ScannerStatus = BarcodeStatus.Timeout;
                            barcode       = null;
                            evnt_RejForOperator1.Reset();          //
                            evnt_ScannerRetryForOperator1.Reset(); //
                            Operator01State = SCANNERTIMEOUTHANDLE;
                        }
                        catch (Exception ex)
                        {
                            if (PLCWriteCommand6[PLCWriteCommand_DM5204] != 0x08)
                            {
                                networkmain.linePack.Info("Operator 1 Scanner exception " + ex.ToString());
                                PLCWriteCommand6[PLCWriteCommand_DM5204] = 0x0F;
                            }

                            //log6.Info("Operator 1 Scanner exception " + ex.ToString());

                            networkmain.stn6log     = "OP1 exception";
                            networkmain.OperatorLog = "Stn.6 OP1 Scanning Exception Error";
                            //not scan
                            barcode       = null;
                            ScannerStatus = BarcodeStatus.ExceptionError;
                            Status        = "Exception";
                            evnt_RejForOperator1.Reset();          //
                            evnt_ScannerRetryForOperator1.Reset(); //
                            Operator01State = SCANNERTIMEOUTHANDLE;
                        }
                        break;

                    case SCANNERTIMEOUTHANDLE:    //scan time out
                        // await technician reset or plurge from PLC by setting Er or reject on product
                        ScannerStatus = BarcodeStatus.Timeout;

                        Array.Copy(PLCQueryRx6, 111, tmparray, 0, 10);
                        //convert array to string
                        Station6ForOP1Scanboxid = System.Text.Encoding.Default.GetString(tmparray);
                        Station6ForOP1Scanboxid.Trim();

                        if ((Station6ForOP1Scanboxid == "\0\0\0\0\0\0\0\0\0\0") && (PLCQueryRx6[PLCQueryRx_DM5100 + 4] == 0x0))
                        {
                            Operator01State = ERHANDLER_STEP02;
                        }
                        if (evnt_ScannerRetryForOperator1.WaitOne(0))
                        {
                            //change state to VALIDLABELRUNSCANNER, reset counter
                            Operator01State = VALIDLABELRUNSCANNER;
                            retrycounter    = 0;
                            evnt_ScannerRetryForOperator1.Reset();
                        }
                        if (evnt_RejForOperator1.WaitOne(0))
                        {
                            // set ER to PLC
                            // PLC return 0xF PC return 0xF ==> PLC go to 0x0, PC goto 0x0
                            // wait for Station6ForOP1Scanboxid == "\0\0\0\0\0\0\0\0\0\0"
                            // or reset by change state
                            //reject event recieved
                            Operator01State = ERHANDLER_STEP01;
                            byte[] tmpbyte = new byte[2];
                            tmpbyte = Encoding.ASCII.GetBytes("ER");
                            Array.Copy(tmpbyte, 0, PLCWriteCommand6, 95, 2);    //copy ER to PLC DM5237
                            // log6.Info("Station 6 Operator 1 Technician Reject " + Station6ForOP1Scanboxid);

                            networkmain.linePack.Info("Station 6 Operator 1 Technician Reject " + Station6ForOP1Scanboxid);
                            networkmain.stn6log = Station6ForOP1Scanboxid + " OP1 Technician Reject";
                            //need to send ack to middleware
                            ScannerStatus = BarcodeStatus.Rejected;
                            evnt_RejForOperator1.Reset();
                        }
                        break;

                    case ERHANDLER_STEP01:

                        Array.Copy(PLCQueryRx6, 111, tmparray, 0, 10);
                        //convert array to string
                        Station6ForOP1Scanboxid = System.Text.Encoding.Default.GetString(tmparray);
                        Station6ForOP1Scanboxid.Trim();

                        if ((Station6ForOP1Scanboxid == "\0\0\0\0\0\0\0\0\0\0") && (PLCQueryRx6[PLCQueryRx_DM5100 + 4] == 0x0))
                        {
                            Operator01State = ERHANDLER_STEP02;
                        }
                        if (PLCQueryRx6[PLCQueryRx_DM5100 + 4] == 0xF)
                        {
                            //
                            //scxan not matching 0xf...plc wait for instruction...
                            //5237... na.. er etc etc... if rx er.... clear fl
                            //chk 5202 for 0
                            //send messsage to micron server (TBD)
                            try{
                                string RJCODE = "603";

                                XmlDocument doc = new XmlDocument();
                                doc.Load(@"ConfigEvent.xml");
                                XmlNode node   = doc.SelectSingleNode(@"/EVENT/R" + RJCODE);
                                string  RJName = node.InnerText;

                                try                                                                     //OEE OPERATOR 1 MANUA REJECT
                                {
                                    XmlNode fltrackingroot = networkmain.FLTrackingdoc.DocumentElement; //this house the list of summarized xml details
                                    XmlNode selectednode   = fltrackingroot.SelectSingleNode("descendant::LABEL[ID='" + Station6ForOP1Scanboxid + "']");
                                    if (selectednode != null)
                                    {
                                        string OEEidOP1 = selectednode.SelectSingleNode("OEEid").InnerText;
                                        rq.UpdST6RJ(OEEidOP1, 6, RJCODE);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    IGTOEELog.Info(ex.ToString());
                                }
                                networkmain.Client_SendEventMessage("57", RJName, "BOX_ID", Station6ForOP1Scanboxid);
                                //  log6.Info("QC1 Operator RJ Event Send to Middleware " +"603,"+RJName+","+Station6ForOP1Scanboxid);

                                networkmain.linePack.Info("QC1 Operator RJ Event Send to Middleware " + "603," + RJName + "," + Station6ForOP1Scanboxid);
                                MyEventQ.AddQ("21;Station6SealedMBBRejectedAtStation6;LotNumber;" + Station6ForOP1Scanboxid + ";QcstationNumber;1;OpearatorName;"
                                              + UserName1);

                                AllRJEvent.Info("QC1 Operator RJ Event Send to Middleware " + "603," + RJName + "," + Station6ForOP1Scanboxid);
                            }
                            catch (Exception ex) {
                                networkmain.linePack.Info(ex);
                            }

                            evnt_RejectFinishingLabelForStation6_OP1.Set();

                            st1Rejectcount++;
                            PLCWriteCommand6[PLCWriteCommand_DM5200 + 4] = 0xF;
                            Operator01State = ERHANDLER_STEP02;
                        }
                        break;

                    case ERHANDLER_STEP02:
                        Array.Copy(PLCQueryRx6, 111, tmparray, 0, 10);
                        //convert array to string
                        Station6ForOP1Scanboxid = System.Text.Encoding.Default.GetString(tmparray);
                        Station6ForOP1Scanboxid.Trim();
                        // log6.Info("Operator 1 getting label from station 5 : " + Station6ForOP1Scanboxid);
                        networkmain.linePack.Info("Operator 1 getting label from station 5 : " + Station6ForOP1Scanboxid);

                        //relfect finishing label data status to station 6 OP 1
                        if ((Station6ForOP1Scanboxid == "\0\0\0\0\0\0\0\0\0\0") && (PLCQueryRx6[PLCQueryRx_DM5100 + 4] == 0x0))
                        {
                            //
                            //networkmain.stn6log = Station6ForOP1Scanboxid + " OP1 recieving";
                            //ScannerStatus = BarcodeStatus.Arriving;
                            PLCWriteCommand6[PLCWriteCommand_DM5204]     = 0X0;
                            PLCWriteCommand6[PLCWriteCommand_DM5200 + 4] = 0x0;    //DM202 reject status
                            PLCWriteCommand6[PLCWriteCommand_DM5204 + 4] = 0x0;    //DM206 tracking label status
                            Station6ForOP1Scanboxid        = "\0\0\0\0\0\0\0\0\0\0";
                            Station6ForOP1TrackingLabel    = "\0\0\0\0\0\0\0\0";
                            networkmain.operator1BoxNumber = "";
                            SealerNumberQC1 = "";
                            st6finish1      = "";
                            station6track1  = "";
                            Status          = "";
                            CheckStringClearFor6_OP1(OperatorA_PCtoPLCFinishingLabelOFFSET, _Station6ForOP1Scanboxid);
                            Operator01State = WAITFORFINISHINGLABEL;
                        }
                        break;

                    case ERHANDLER_STEP03:
                        break;

                    case SCANNUMBEREXCEEDHANDLE:    //scan exceed 3 x
                        // await technician reset or plurge from PLC by setting Er or reject on product
                        ScannerStatus = BarcodeStatus.AttemptOut;
                        Array.Copy(PLCQueryRx6, 111, tmparray, 0, 10);
                        //convert array to string
                        Station6ForOP1Scanboxid = System.Text.Encoding.Default.GetString(tmparray);
                        Station6ForOP1Scanboxid.Trim();

                        if ((Station6ForOP1Scanboxid == "\0\0\0\0\0\0\0\0\0\0") && (PLCQueryRx6[PLCQueryRx_DM5100 + 4] == 0x0))
                        {
                            Operator01State = ERHANDLER_STEP02;
                        }

                        if (evnt_ScannerRetryForOperator1.WaitOne(0))
                        {
                            //change state to VALIDLABELRUNSCANNER, reset counter
                            Operator01State = VALIDLABELRUNSCANNER;
                            retrycounter    = 0;
                            evnt_ScannerRetryForOperator1.Reset();
                        }
                        if (evnt_RejForOperator1.WaitOne(0))
                        {
                            // set ER to PLC
                            // PLC return 0xF PC return 0xF ==> PLC go to 0x0, PC goto 0x0
                            // wait for Station6ForOP1Scanboxid == "\0\0\0\0\0\0\0\0\0\0"
                            // or reset by change state
                            //reject event recieved
                            Operator01State = ERHANDLER_STEP01;
                            byte[] tmpbyte = new byte[2];
                            tmpbyte = Encoding.ASCII.GetBytes("ER");
                            Array.Copy(tmpbyte, 0, PLCWriteCommand6, 95, 2);    //copy ER to PLC DM5237
                            //need to send ack to middleware
                            evnt_RejForOperator1.Reset();
                        }
                        break;

                    case SCANMATCHWAITTRACKINGLABEL:    //scan matched, waiting for tracking label or wait for reject
                        if (PLCQueryRx6[PLCQueryRx_DM5100 + 4] == 0xF)
                        {
                            Operator01State = ERHANDLER_STEP01;
                            break;
                        }
                        if (PLCQueryRx6[PLCQueryRx_DM5100 + 4] == 0x9)
                        {
                            Operator01State = SPECLABELPROCESS;
                            break;
                        }
                        Array.Copy(PLCQueryRx6, 111, tmparray, 0, 10);
                        //convert array to string
                        Station6ForOP1Scanboxid = System.Text.Encoding.Default.GetString(tmparray);
                        Station6ForOP1Scanboxid.Trim();

                        if ((Station6ForOP1Scanboxid == "\0\0\0\0\0\0\0\0\0\0") && (PLCQueryRx6[PLCQueryRx_DM5100 + 4] == 0x0))
                        {
                            Operator01State = ERHANDLER_STEP02;
                        }
                        byte[] tmparray1 = new byte[8];
                        //DM5020 TrackingLabel Update
                        Array.Copy(PLCQueryRx6, 51, tmparray1, 0, 8);
                        //convert array to string
                        Station6ForOP1TrackingLabel = System.Text.Encoding.Default.GetString(tmparray1);
                        #region NewCode28042016
                        if ((PLCQueryRx6[PLCQueryRx_DM5100 + 12] == 0x08 && Station6ForOP1TrackingLabel != "\0\0\0\0\0\0\0\0" && PLCWriteCommand6[PLCWriteCommand_DM5204 + 4] != 99))     //added by GY 28/4/2016
                        {
                            byte[] str1 = barcodechangeposition(tmparray1);
                            string st   = System.Text.Encoding.Default.GetString(str1);
                            station6track1 = st.Trim();
                            if (networkmain.CheckTrackingLabel(Station6ForOP1TrackingLabel))
                            {
                                MyEventQ.AddQ("645;Station6QC1TLValidationOK;LotNumber;" + Station6ForOP1Scanboxid + ";LicensePlateBarcode;" + station6track1 +
                                              ";QcstationNumber;1;OperatorName;" + UserName1);
                                networkmain.stn6log = station6track1 + " OP1 TL Validate OK";
                                PLCWriteCommand6[PLCWriteCommand_DM5204 + 4] = 99;
                                ScannerStatus = BarcodeStatus.Null;
                            }
                            else
                            {
                                MyEventQ.AddQ("646;Station6QC1TLValidationNG;LotNumber;" + Station6ForOP1Scanboxid + ";LicensePlateBarcode;" + station6track1 +
                                              ";QcstationNumber;1;OperatorName;" + UserName1);
                                networkmain.stn6log = station6track1 + " OP1 TL Validate NG";
                                PLCWriteCommand6[PLCWriteCommand_DM5204 + 4] = 0x0F;
                                ScannerStatus = BarcodeStatus.Duplicated;
                                continue;
                            }
                        }
                        else if (PLCQueryRx6[PLCQueryRx_DM5100 + 12] == 0x00)
                        {
                            PLCWriteCommand6[PLCWriteCommand_DM5204 + 4] = 0;
                        }

                        if ((PLCQueryRx6[PLCQueryRx_DM5100 + 12] == 99 && Station6ForOP1TrackingLabel != "\0\0\0\0\0\0\0\0"))     //added by GY 28/4/2016
                        {
                            int cnt = 0;
                            if (networkmain.CheckTrackingLabel(Station6ForOP1TrackingLabel))
                            {
                                while (!networkmain.UpdateTrackingLabel(Station6ForOP1Scanboxid,
                                                                        Station6ForOP1TrackingLabel) &&
                                       !bTerminate)                             //assume PLC data moved before server reply
                                {
                                    if (cnt > 10)
                                    {
                                        break;
                                    }
                                    Thread.Sleep(10);
                                    cnt++;
                                    //need to handle invalid tracking label
                                }
                                if (cnt > 10)
                                {
                                    break;
                                }
                                MyEventQ.AddQ("647;Station6QC1TLBindOK;LotNumber;" + Station6ForOP1Scanboxid + ";LicensePlateBarcode;" + station6track1 +
                                              ";QcstationNumber;1;OperatorName;" + UserName1);
                                PLCWriteCommand6[PLCWriteCommand_DM5204 + 4] = 0x08;    // association completed
                                                                                        //--> how to go back 0x0?? if finishing label is /0/0 i can assume all data cleared
                                networkmain.stn6log = station6track1 + "+" + Station6ForOP1Scanboxid + " OP1 Bind OK";
                                ScannerStatus       = BarcodeStatus.Null;
                                Operator01State     = WAITTRACKINGLABELCLEAR;//create a state to wait for tracking label to clear
                            }
                            else
                            {
                                MyEventQ.AddQ("648;Station6QC1TLBindNG;LotNumber;" + Station6ForOP1Scanboxid + ";LicensePlateBarcode;" + station6track1 +
                                              ";QcstationNumber;1;OperatorName;" + UserName1);
                                networkmain.stn6log = station6track1 + "+" + Station6ForOP1Scanboxid + " OP1 Bind NG";
                                PLCWriteCommand6[PLCWriteCommand_DM5204 + 4] = 0x0F;
                            }
                        }
                        #endregion
                        #region ObseleteCode
                        //if ((Station6ForOP1TrackingLabel != "\0\0\0\0\0\0\0\0"))//check for valid tracking label
                        //{

                        //    byte[] str1 = barcodechangeposition(tmparray1);
                        //    string st = System.Text.Encoding.Default.GetString(str1);
                        //    station6track1 = st.Trim();
                        //    //  log6.Info("Operator 1 set tracking label " + station6track1);
                        //    networkmain.linePack.Info("Operator 1 set tracking label " + station6track1);

                        //    networkmain.stn6log = station6track1 + " OP1 Set Tracking Lbl";

                        //    if (networkmain.CheckTrackingLabel(Station6ForOP1TrackingLabel) == true)

                        //    {
                        //        int cnt = 0;
                        //        while (!networkmain.UpdateTrackingLabel(Station6ForOP1Scanboxid,
                        //                                            Station6ForOP1TrackingLabel) &&
                        //                                            !bTerminate)//assume PLC data moved before server reply
                        //        {
                        //            if (cnt > 10) break;
                        //            Thread.Sleep(10);
                        //            cnt++;
                        //            //need to handle invalid tracking label
                        //        }
                        //        if (cnt > 10) break;


                        //        //log6.Info("Operator 1 match " + "," + Station6ForOP1Scanboxid + "," + station6track1);
                        //        networkmain.linePack.Info("Operator 1 match " + "," + Station6ForOP1Scanboxid + "," + station6track1);
                        //        MyEventQ.AddQ("24;Station6SealedMBBAcceptedAtStation6;LotNumber;" + Station6ForOP1Scanboxid + ";LicensePlateBarcode;" + station6track1 +
                        //            ";QcstationNumber;1;OperatorName;" + UserName1);
                        //        PLCWriteCommand6[PLCWriteCommand_DM5204 + 4] = 0x08;// association completed
                        //                                                            //--> how to go back 0x0?? if finishing label is /0/0 i can assume all data cleared
                        //        ScannerStatus = BarcodeStatus.Null;
                        //        Operator01State = WAITTRACKINGLABELCLEAR;//create a state to wait for tracking label to clear


                        //    }
                        //    else

                        //    {
                        //        // log6.Info("Operator 1 Same tracking label  inside the System " + station6track1);
                        //        networkmain.linePack.Info("Operator 1 Same tracking label  inside the System " + station6track1);
                        //        PLCWriteCommand6[PLCWriteCommand_DM5204 + 4] = 0x0F;
                        //        ScannerStatus = BarcodeStatus.Duplicated;
                        //        continue;


                        //    }

                        //}
                        //else
                        //{
                        //    PLCWriteCommand6[PLCWriteCommand_DM5204 + 4] = 0x00;
                        //    // Station6ForOP1TrackingLabel = "\0\0\0\0\0\0\0\0\0\0";
                        //    //  log6.Info("Operator 1 waiting tracking label " + Station6ForOP1Scanboxid);
                        //    networkmain.linePack.Info("Operator 1 waiting tracking label From PLC2 " + Station6ForOP1Scanboxid);

                        //    // need to check for operator reject signal from PLC
                        //}
                        #endregion
                        break;     //update here

                    case WAITTRACKINGLABELCLEAR:
                        //wait for tracking label and finishing label to clear zero??
                        byte[] tmparray2 = new byte[8];
                        //DM5020 TrackingLabel Update
                        Array.Copy(PLCQueryRx6, 51, tmparray2, 0, 8);
                        //convert array to string
                        Station6ForOP1TrackingLabel = System.Text.Encoding.Default.GetString(tmparray2);
                        Array.Copy(PLCQueryRx6, 111, tmparray, 0, 10);
                        //convert array to string
                        Station6ForOP1Scanboxid = System.Text.Encoding.Default.GetString(tmparray);
                        Station6ForOP1Scanboxid.Trim();

                        //relfect finishing label data status to station 6 OP 1
                        if ((Station6ForOP1Scanboxid == "\0\0\0\0\0\0\0\0\0\0") &&
                            (Station6ForOP1TrackingLabel == "\0\0\0\0\0\0\0\0"))
                        {
                            //log6.Info("Operator 1 getting label from station 5 : " + Station6ForOP1Scanboxid);
                            networkmain.linePack.Info("Operator 1 getting label from station 5 : " + Station6ForOP1Scanboxid);
                            networkmain.stn6log = Station6ForOP1Scanboxid + " OP1 recieving frm stn.5";
                            //both id goes zero
                            PLCWriteCommand6[PLCWriteCommand_DM5204]     = 0X0;
                            PLCWriteCommand6[PLCWriteCommand_DM5200 + 4] = 0x0;    //DM202 reject status
                            PLCWriteCommand6[PLCWriteCommand_DM5204 + 4] = 0x0;    //DM206 tracking label status
                            networkmain.operator1BoxNumber = "";
                            Station6ForOP1Scanboxid        = "\0\0\0\0\0\0\0\0\0\0";
                            Station6ForOP1TrackingLabel    = "\0\0\0\0\0\0\0\0";
                            SealerNumberQC1 = "";
                            st6finish1      = "";
                            station6track1  = "";
                            Status          = "";
                            CheckStringClearFor6_OP1(OperatorA_PCtoPLCFinishingLabelOFFSET, _Station6ForOP1Scanboxid);
                            EarlierPickupFlag = false;
                            Operator01State   = WAITFORFINISHINGLABEL;
                        }
                        break;

                    case TRACKINGLABELAVAILABLE:    //tracking label available
                        break;

                    case REJECTRXAFTERSCANMATCHED:    //reject recieved from PLC @ state AFTERSCANMATCHED
                        break;

                    case INVALIDLABELHANDLE:    //recieved an invalid finishing label @ state checkforvalidfinishinglabel
                        //wait for label to be 00
                        Operator01State = ERHANDLER_STEP01;
                        break;

                    case 99:    //recieved an invalid finishing label @ state checkforvalidfinishinglabel
                        //wait for label to be 00
                        if (PLCQueryRx6[PLCQueryRx_DM5100 + 12] == 0x01)
                        {
                            networkmain.linePack.Info("Operator 1 Scanner FL contain " + Station6ForOP1Scanboxid);
                            // networkmain.stn6log = Station6ForOP1Scanboxid + " Scanner FL contain by OP1";
                            Status = "equal";

                            Operator01State = SCANMATCHWAITTRACKINGLABEL;
                        }
                        break;

                    case SPECLABELPROCESS:

                        //byte[] tmpbytesp = new byte[2];
                        //tmpbytesp = Encoding.ASCII.GetBytes("SP");
                        //Array.Copy(tmpbytesp, 0, PLCWriteCommand6, 95, 2);//copy SP to PLC DM5237
                        // log6.Info("Station 6 Operator 1 SPECKTEK " + Station6ForOP1Scanboxid);
                        try                                                                     //OEE OPERATOR 1 MANUA REJECT
                        {
                            XmlNode fltrackingroot = networkmain.FLTrackingdoc.DocumentElement; //this house the list of summarized xml details
                            XmlNode selectednode   = fltrackingroot.SelectSingleNode("descendant::LABEL[ID='" + Station6ForOP1Scanboxid + "']");
                            if (selectednode != null)
                            {
                                string OEEidOP1 = selectednode.SelectSingleNode("OEEid").InnerText;
                                rq.UpdST6RJ(OEEidOP1, 1, "0");
                            }
                        }
                        catch (Exception ex)
                        {
                            IGTOEELog.Info(ex.ToString());
                        }
                        networkmain.linePack.Info("Station 6 Operator 2 SPECKTEK " + Station6ForOP1Scanboxid);
                        MyEventQ.AddQ("22;Station6SealedSpectekAcceptedAtStation6;LotNumber;" + Station6ForOP1Scanboxid + ";QcstationNumber;1;OpearatorName"
                                      + UserName1);
                        PLCWriteCommand6[PLCWriteCommand_DM5200 + 4] = 0x09;
                        networkmain.stn6log = Station6ForOP1Scanboxid + " OP1 SPECK";
                        //networkmain.Client_sendFG01_FG02_MOVE1(Station6ForOP1Scanboxid, "FG01_FG02_MOVE");
                        networkmain.Client_sendFG01_FG02_MOVE(Station6ForOP1Scanboxid, "FG01_FG02_MOVE QC1 Spectex");

                        networkmain.Client_sendFG01_FG02_MOVE6(Station6ForOP1Scanboxid);     //need to open in real time
                        //NEED TO SEND ACK TO MIDDLEWARE
                        Operator01State = ERHANDLER_STEP02;

                        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());
                }
            }
        }
        public void RunPLC02Scan(object msgobj)
        {
            MainNetworkClass networkmain = (MainNetworkClass)msgobj;

            PLCTelnet2 = new TelnetClient();
            byte[] tmpRx6    = new byte[411];
            byte[] tmpRxPlc2 = new byte[1011];
            bool   plc2Break = false;

            while (!bTerminate)
            {
                Thread.Sleep(100);
                try
                {
                    if (PLCTelnet2.connected == false)
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.Load(@"Config.xml");
                        XmlNode node = doc.SelectSingleNode(@"/CONFIG/PLCCONTROLLER2/ADD");
                        System.Net.IPAddress address = System.Net.IPAddress.Parse(node.InnerText);
                        node = doc.SelectSingleNode(@"/CONFIG/PLCCONTROLLER2/PORT");
                        PLC2NetworkAddress = "Trying to connect to " + address.ToString() + " Port : " + node.InnerText;
                        if (PLCTelnet2.ConnectToHost(address, int.Parse(node.InnerText)) == false)
                        {
                            PLC2NetworkAddress = "Connected to PLCServer2 "
                                                 + address.ToString()
                                                 + " Port : "
                                                 + node.InnerText + " Fail"; //not connected
                            Thread.Sleep(100);                               // try to connect to server
                            if (!plc2Break)
                            {
                                MyEventQ.AddQ("5;PLCCommunicationBreak;PLC Number;2");//Push message to stack
                                EvtLog.Info("5;PLCCommunicationBreak;PLC Number;2");
                                plc2Break = true;
                            }
                            continue;
                        }
                        else
                        {
                            PLC2NetworkAddress = "Connected to PLCServer2 " + address.ToString() + " Port : " + node.InnerText;//connected
                        }
                        plc2Break = false;
                    }
                    if (PLCTelnet2.connected)
                    {
                        string tmpstr;
                        int    timeoutcounter = 0;
                        PLCTelnet2.SendDataToHost(PLCQueryCmd6);//PLC02 Read Cycle
                        Thread.Sleep(waitdelay);
                        tmpstr = PLCTelnet2.GetDataFromHost(ref tmpRx6, PLCQueryRx6.Length);
                        //tmpstr100 = PLCTelnet.GetDataFromHost(ref PLCQueryRx, PLCQueryRx.Length);
                        if (tmpstr != "No Data")
                        {
                            if ((tmpstr.StartsWith("d00000ffff")) && (tmpstr.Length == 822))
                            {
                                Array.Copy(tmpRx6, PLCQueryRx6, PLCQueryRx6.Length);
                            }
                            else
                            {
                                PLCTelnet2.Close();
                            }
                        }
                        //  log.Info(tmpstr);
                        while ((tmpstr == "No Data") && PLCTelnet.connected)
                        {
                            Thread.Sleep(waitdelay);
                            tmpstr = PLCTelnet2.GetDataFromHost(ref tmpRx6, PLCQueryRx6.Length);
                            if (tmpstr != "No Data")
                            {
                                if ((tmpstr.StartsWith("d00000ffff")) && (tmpstr.Length == 822))
                                {
                                    Array.Copy(tmpRx6, PLCQueryRx6, PLCQueryRx6.Length);
                                }
                                else
                                {
                                    PLCTelnet2.Close();
                                    break;
                                }
                            }
                            //No Data loop again
                            //  log.Info(tmpstr);
                            timeoutcounter++;
                            if (timeoutcounter == 10)
                            {
                                //assume connection broken
                                PLCTelnet2.Close();
                                break;
                            }
                        }


                        #region READ  PLC2 Memory 6100 to 6499



                        timeoutcounter = 0;
                        if (PLCTelnet2.connected == false)
                        {
                            continue;
                        }
                        PLCTelnet2.SendDataToHost(PLCQueryCmdParaPlc2);//query data from plc dm700 to dm999
                        //tmpstr100 = PLCTelnet.GetDataFromHost(ref PLCQueryRx7, PLCQueryRx7.Length);
                        tmpstr = PLCTelnet2.GetDataFromHost(ref tmpRxPlc2, tmpRxPlc2.Length);
                        //tmpstr100 = PLCTelnet.GetDataFromHost(ref PLCQueryRx, PLCQueryRx.Length);
                        if (tmpstr.StartsWith("d00000ffff") && (tmpstr.Length == 2022))
                        {
                            Array.Copy(tmpRxPlc2, PLCQueryRxParaPlc2, PLCQueryRxParaPlc2.Length);
                        }
                        else
                        {
                            tmpstr = "No Data";
                        }

                        while ((tmpstr == "No Data") && PLCTelnet2.connected)
                        {
                            Thread.Sleep(waitdelay);
                            tmpstr = PLCTelnet2.GetDataFromHost(ref tmpRxPlc2, tmpRxPlc2.Length);
                            //tmpstr = PLCTelnet.GetDataFromHost(ref PLCQueryRx, PLCQueryRx.Length);
                            if ((tmpstr.StartsWith("d00000ffff") && (tmpstr.Length == 2022)))
                            {
                                Array.Copy(tmpRxPlc2, PLCQueryRxParaPlc2, PLCQueryRxParaPlc2.Length);
                            }
                            else
                            {
                                tmpstr = "No Data";
                            }

                            timeoutcounter++;
                            if (timeoutcounter == 10)
                            {
                                //assume connection broken
                                PLCTelnet2.Close();
                                break;
                            }
                        }



                        #endregion



                        timeoutcounter = 0;
                        PLCTelnet2.SendDataToHost(PLCWriteCommand6);//PLC02 Write cycle
                        Thread.Sleep(waitdelay);
                        tmpstr = PLCTelnet2.GetDataFromHost(ref PLCWriteCommandRX6, PLCWriteCommandRX6.Length);
                        //   log.Info("PLC 2 Write " + tmpstr);
                        while ((tmpstr == "No Data") && PLCTelnet.connected)
                        {
                            Thread.Sleep(waitdelay);
                            tmpstr = PLCTelnet2.GetDataFromHost(ref PLCWriteCommandRX6, PLCWriteCommandRX6.Length);
                            //    log.Info("PLC 2 Write " + tmpstr);
                            timeoutcounter++;
                            if (timeoutcounter == 10)
                            {
                                //assume connection broken
                                PLCTelnet2.Close();
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.ToString());
                }
            }
        }
Пример #9
0
        public void RunStation02Scan(object msgobj)
        {
            MainNetworkClass networkmain = (MainNetworkClass)msgobj;

            while (!bTerminate)
            {
                Thread.Sleep(100);
                try
                {
                    if ((PLCQueryRx == null) || (PLCWriteCommand == null))
                    {
                        Thread.Sleep(100);
                        continue;
                    }
                    #region PLC_RequestFinishingLabelFromMiddleWare
                    //Process PLC Data
                    //Check Station 2 Finishing Label Status
                    //      plc TRIGGER @ DM0100     server send is in ready state @ DM200
                    if ((PLCQueryRx[PLCQueryRx_DM100] == 0x08) && (PLCWriteCommand[PLCWriteCommand_DM200] == 0))//request finishing label
                    {
                        //PLC request FL from IGT
                        //set busy flag
                        PLCWriteCommand[PLCWriteCommand_DM200] = 0x04; //busy
                        //get barcode scan string from DM010
                        //test code tmp//
                        byte[] bcarray = new byte[10];
                        Array.Copy(PLCQueryRx, 31, bcarray, 0, 10);
                        Scanboxid = System.Text.Encoding.Default.GetString(bcarray);
                        if (Scanboxid != "\0\0\0\0\0\0\0\0\0\0")
                        {
                            evt_FinishLabelRequest.Set();
                        }
                        else
                        {
                            PLCWriteCommand[PLCWriteCommand_DM200] = 0x00;
                        }
                    }
                    //trigger is cleared    Send Complete       Send Error
                    if ((PLCQueryRx[PLCQueryRx_DM100] == 0x0) && ((PLCWriteCommand[PLCWriteCommand_DM200] == 0x08) ||
                                                                  (PLCWriteCommand[PLCWriteCommand_DM200] == 0xF)))
                    {
                        PLCWriteCommand[PLCWriteCommand_DM200] = 0;//Server Send Ready
                    }
                    #endregion
                    #region Update_RA_RB_RC_Label
                    //      PLC Move FL to A, B, C Zone.
                    byte[] tmparray = new byte[10];
                    //DM0050
                    Array.Copy(PLCQueryRx, 111, tmparray, 0, 10);
                    //convert array to string
                    ST02Rotatary_A_Str = System.Text.Encoding.Default.GetString(tmparray);

                    if (ST02Rotatary_A_Str != "\0\0\0\0\0\0\0\0\0\0")
                    {
                        ReceiveFL = ST02Rotatary_A_Str;
                    }


                    if (ST02Rotatary_A_Str == "\0\0\0\0\0\0\0\0\0\0")
                    {
                        ReceiveFL    = "";
                        PrintStatus  = "";
                        VisionStatus = "";
                    }

                    if (ST02Rotatary_B_Str == "\0\0\0\0\0\0\0\0\0\0")
                    {
                        ReceiveFL1    = "";
                        PrintStatus1  = "";
                        VisionStatus1 = "";
                    }

                    if (ST02Rotatary_B_Str != "\0\0\0\0\0\0\0\0\0\0")
                    {
                        ReceiveFL1 = ST02Rotatary_B_Str;
                    }



                    if (ST02Rotatary_C_Str == "\0\0\0\0\0\0\0\0\0\0")
                    {
                        ReceiveFL2    = "";
                        PrintStatus2  = "";
                        VisionStatus2 = "";
                    }



                    if (ST02Rotatary_C_Str != "\0\0\0\0\0\0\0\0\0\0")
                    {
                        ReceiveFL2 = ST02Rotatary_C_Str;
                    }


                    //DM0060
                    Array.Copy(PLCQueryRx, 131, tmparray, 0, 10);
                    //convert array to string
                    ST02Rotatary_B_Str = System.Text.Encoding.Default.GetString(tmparray);
                    //DM0070
                    Array.Copy(PLCQueryRx, 151, tmparray, 0, 10);
                    //convert array to string
                    ST02Rotatary_C_Str = System.Text.Encoding.Default.GetString(tmparray);
                    //table
                    #endregion
                    #region PLCStatusUpdateOnRARBRC
                    //update RA RB RC status (later.. on station 4, 5, 6, 7??)
                    CheckStringClear(RA_PCtoPLCFinishingLabelOFFSET, ST02Rotatary_A_Str);
                    CheckStringClear(RB_PCtoPLCFinishingLabelOFFSET, ST02Rotatary_B_Str);
                    CheckStringClear(RC_PCtoPLCFinishingLabelOFFSET, ST02Rotatary_C_Str);
                    CheckStringUpdate(RA_PCtoPLCFinishingLabelOFFSET, ST02Rotatary_A_Str);
                    CheckStringUpdate(RB_PCtoPLCFinishingLabelOFFSET, ST02Rotatary_B_Str);
                    CheckStringUpdate(RC_PCtoPLCFinishingLabelOFFSET, ST02Rotatary_C_Str);
                    //Int64 rst;
                    #endregion
                    #region UpdateRJ
                    //Rotary A
                    byte[] tmparrayERA = new byte[2];
                    Array.Copy(PLCQueryRx, 121, tmparrayERA, 0, 2); //DM55=121
                    //convert Byte array to int
                    Int32 erA = (Int32)(BitConverter.ToInt16(tmparrayERA, 0));
                    if (erA > 0)
                    {
                        byte[] tmpbyte = new byte[2];
                        tmpbyte = Encoding.ASCII.GetBytes("RJ");
                        Array.Copy(tmpbyte, 0, PLCWriteCommand, 95, 2); //D237
                        string rj = "RJ";
                        try
                        {
                            while ((!networkmain.UpdateRJLabel(ST02Rotatary_A_Str, rj, erA.ToString()) && !bTerminate))
                            {
                                Thread.Sleep(100);
                            }
                            // St2Log.Info("Update RJ for Rotary A " + ST02Rotatary_A_Str +","+erA);
                            networkmain.linePack.Info("Update RJ for Rotary A " + ST02Rotatary_A_Str + "," + erA);
                        }
                        catch (Exception ex)
                        {
                            // St2Log.Error("station 2 RA error" + ex);
                            networkmain.linePack.Error("station 2 RA error" + ex);
                            byte[] tmpbyte1 = new byte[2];
                            tmpbyte1 = Encoding.ASCII.GetBytes("RJ");
                            Array.Copy(tmpbyte1, 0, PLCWriteCommand, 95, 2); //D237
                            //update fail..
                            // reply to PLC update fail
                            // may need this other time
                        }
                    }


                    //Rotary B

                    byte[] tmparrayERB = new byte[2];
                    Array.Copy(PLCQueryRx, 141, tmparrayERB, 0, 2); //DM65=141
                    //convert Byte array to int
                    Int32 erB = (Int32)(BitConverter.ToInt16(tmparrayERB, 0));
                    if (erB > 0)
                    {
                        byte[] tmpbyte = new byte[2];
                        tmpbyte = Encoding.ASCII.GetBytes("RJ");
                        Array.Copy(tmpbyte, 0, PLCWriteCommand, 157, 2); //D268
                        string rj = "RJ";
                        try
                        {
                            while ((!networkmain.UpdateRJLabel(ST02Rotatary_B_Str, rj, erB.ToString()) && !bTerminate))
                            {
                                Thread.Sleep(100);
                            }
                            //   St2Log.Info("Update RJ for Rotary B " + ST02Rotatary_B_Str+","+erB);
                            networkmain.linePack.Info("Update RJ for Rotary B " + ST02Rotatary_B_Str + "," + erB);
                        }
                        catch (Exception ex)
                        {
                            // St2Log.Error("station 2 RB error" + ex);

                            networkmain.linePack.Error("station 2 RB error" + ex);
                            byte[] tmpbyte1 = new byte[2];
                            tmpbyte1 = Encoding.ASCII.GetBytes("RJ");
                            Array.Copy(tmpbyte1, 0, PLCWriteCommand, 157, 2); //D268
                            //update fail..
                            // reply to PLC update fail
                            // may need this other time
                        }
                    }


                    //RC
                    byte[] tmparrayERC = new byte[2];
                    Array.Copy(PLCQueryRx, 161, tmparrayERC, 0, 2); //DM75=161
                    //convert Byte array to int
                    Int32 erC = (Int32)(BitConverter.ToInt16(tmparrayERC, 0));
                    if (erC > 0)
                    {
                        byte[] tmpbyte = new byte[2];
                        tmpbyte = Encoding.ASCII.GetBytes("RJ");
                        Array.Copy(tmpbyte, 0, PLCWriteCommand, 217, 2); //D298
                        string rj = "RJ";
                        try
                        {
                            while ((!networkmain.UpdateRJLabel(ST02Rotatary_C_Str, rj, erC.ToString()) && !bTerminate))
                            {
                                Thread.Sleep(100);
                            }
                            // St2Log.Info("Update RJ for Rotary C " + ST02Rotatary_C_Str+","+erC);

                            networkmain.linePack.Info("Update RJ for Rotary C " + ST02Rotatary_C_Str + "," + erC);
                        }
                        catch (Exception ex)
                        {
                            // St2Log.Error("station 2 RC error" + ex);

                            networkmain.linePack.Error("station 2 RC error" + ex);
                            byte[] tmpbyte1 = new byte[2];
                            tmpbyte1 = Encoding.ASCII.GetBytes("RJ");
                            Array.Copy(tmpbyte1, 0, PLCWriteCommand, 217, 2); //D298
                            //update fail..
                            // reply to PLC update fail
                            // may need this other time
                        }
                    }
                    #endregion
                    #region Station2_PLC_RequestPrint
                    //check finishing label data ready at respective station or rotary
                    //check DM101,102,103
                    if ((PLCQueryRx[PLCQueryRx_DM100 + 2] == 0x0) && //send reset signal to the IGT server DM101,102,103 have to be set to 0;
                        (PLCQueryRx[PLCQueryRx_DM100 + 4] == 0x0) && //assume at any one time, only one rotary is doing the request
                        (PLCQueryRx[PLCQueryRx_DM100 + 6] == 0x0))   //optimization code needed for PLC to print and inspect at the same time
                    {
                        PLCWriteCommand[PLCWriteCommand_DM200 + 2] = 0x00;
                    }
                    ////////////////////////////////////////
                    // Station 2 Testpront Function ////////
                    ////////////////////////////////////////
                    if ((PLCQueryRx[PLCQueryRx_DM100 + 2] == 0x99) //request print for rotary A        /*DM101*///state 1
                        &&
                        (!evt_Station02PrintReq.WaitOne(0))
                        &&
                        (PLCWriteCommand[PLCWriteCommand_DM200 + 2] == 0x00)/*DM201*/
                        )
                    {
                        PLCWriteCommand[PLCWriteCommand_DM200 + 2] = 0x4; //set busy signal

                        ZebraTestPrint zbt     = new ZebraTestPrint();
                        bool           Printok = zbt.ChecknLoadZPLForTestPrint(2);
                        if (Printok)
                        {
                            MyEventQ.AddQ("82;PrinterTestPrint;PrinterNumber;2"); //Push message to stack
                            EvtLog.Info("82;PrinterTestPrint;PrinterNumber;2");
                        }
                        else
                        {
                            MyEventQ.AddQ("11;PrinterCommunicationBreak;Stationnumber;2"); //Push message to stack
                        }
                        PLCWriteCommand[PLCWriteCommand_DM200 + 2] = 0x99;                 //set ok signal
                        zbt = null;
                    }
                    ////////////////////////////////////////
                    //request Orientation Chk on RA/B/C ////
                    ////////////////////////////////////////
                    if ((PLCQueryRx[PLCQueryRx_DM100 + 2] == 0x3) /*DM101*/  //state 1
                        &&
                        (PLCWriteCommand[PLCWriteCommand_DM200 + 2] == 0x00) /*DM201*/
                        )
                    {
                        PLCWriteCommand[PLCWriteCommand_DM200 + 2] = 0x4; //set busy signal
                        evt_Station02InspectionReq.Set();
                    }
                    if ((PLCQueryRx[PLCQueryRx_DM100 + 2] == 0x1) //request print for rotary A        /*DM101*///state 1
                        &&
                        (!evt_Station02PrintReq.WaitOne(0))
                        &&
                        (PLCWriteCommand[PLCWriteCommand_DM200 + 2] == 0x00)/*DM201*/
                        )
                    {
                        if (ST02Rotatary_A_Str.Trim().Length == 0)
                        {
                            log.Error("ST2 RotaryA FL label is empty when requesting print");
                        }
                        else if (ST02Rotatary_A_Str == "\0\0\0\0\0\0\0\0\0\0")
                        {
                            log.Error("ST2 RotaryA FL label is \0\0\0\0\0\0\0\0\0\0 when requesting print");
                        }
                        else
                        {
                            PLCWriteCommand[PLCWriteCommand_DM200 + 2] = 0x4; //set busy signal
                            ST02Rotatary_Str = ST02Rotatary_A_Str;

                            //show in table FL
                            //fire printer thread
                            //Printer01Thread = new Thread(new ParameterizedThreadStart(Printer01Th));
                            //Printer01Thread.Start(networkmain);
                            evt_Station02PrintReq.Set();
                            log.Info("ST2 RotaryA Start request printing:" + ST02Rotatary_Str);
                        }
                    }
                    if ((PLCQueryRx[PLCQueryRx_DM100 + 4] == 0x1) //request print for rotary B        /*DM102*///state 1
                        &&
                        (!evt_Station02PrintReq.WaitOne(0))
                        &&
                        (PLCWriteCommand[PLCWriteCommand_DM200 + 2] == 0x00)) /*DM201*/
                    {
                        if (ST02Rotatary_B_Str.Trim().Length == 0)
                        {
                            log.Error("ST2 RotaryB FL label is empty when requesting print");
                        }
                        else if (ST02Rotatary_B_Str == "\0\0\0\0\0\0\0\0\0\0")
                        {
                            log.Error("ST2 RotaryB FL label is \0\0\0\0\0\0\0\0\0\0 when requesting print");
                        }
                        else
                        {
                            PLCWriteCommand[PLCWriteCommand_DM200 + 2] = 0x4; //set busy signal
                            ST02Rotatary_Str = ST02Rotatary_B_Str;

                            //fire printer thread
                            //Printer01Thread = new Thread(new ParameterizedThreadStart(Printer01Th));
                            //Printer01Thread.Start(networkmain);
                            evt_Station02PrintReq.Set();
                            log.Info("ST2 RotaryB Start request printing:" + ST02Rotatary_Str);
                        }
                    }
                    if ((PLCQueryRx[PLCQueryRx_DM100 + 6] == 0x1) //request print for rotary C        /*DM103*///state 1
                        &&
                        (!evt_Station02PrintReq.WaitOne(0))
                        &&
                        (PLCWriteCommand[PLCWriteCommand_DM200 + 2] == 0x00)) /*DM201*/
                    {
                        if (ST02Rotatary_C_Str.Trim().Length == 0)
                        {
                            log.Error("ST2 RotaryC FL label is empty when requesting print");
                        }
                        else if (ST02Rotatary_C_Str == "\0\0\0\0\0\0\0\0\0\0")
                        {
                            log.Error("ST2 RotaryC FL label is \0\0\0\0\0\0\0\0\0\0 when requesting print");
                        }
                        else
                        {
                            PLCWriteCommand[PLCWriteCommand_DM200 + 2] = 0x4; //set busy signal
                            ST02Rotatary_Str = ST02Rotatary_C_Str;
                            PrintStatus2     = "Received";
                            //fire printer thread
                            //Printer01Thread = new Thread(new ParameterizedThreadStart(Printer01Th));
                            //Printer01Thread.Start(networkmain);
                            evt_Station02PrintReq.Set();
                            log.Info("ST2 RotaryC Start request printing:" + ST02Rotatary_Str);
                        }
                    }
                    #endregion
                    #region Station2_PLC_RequestLabelInspection
                    if ((PLCQueryRx[PLCQueryRx_DM157 + 26] == 0x0) && //send reset signal to the IGT server DM101,102,103 have to be set to 0;
                        (PLCQueryRx[PLCQueryRx_DM157 + 30] == 0x0) && //assume at any one time, only one rotary is doing the request
                        (PLCQueryRx[PLCQueryRx_DM157 + 34] == 0x0))   //optimization code needed for PLC to print and inspect at the same time
                    {
                        PLCWriteCommand[PLCWriteCommand_DM380 + 2] = 0x00;
                    }
                    #region RotaryARequest
                    if ((PLCQueryRx[PLCQueryRx_DM100 + 2] == 0x1)//vision inspection ready/*DM101*///state 2
                        &&
                        (PLCWriteCommand[PLCWriteCommand_DM200 + 2] == 0x05)
                        &&
                        (!evt_Station02PrintReq.WaitOne(0))//assumming data had been send to vision also
                        )
                    {
                        PLCWriteCommand[PLCWriteCommand_DM200 + 2] = 0x06;//print send complete
                        PrintStatus = "Received";
                    }
                    if ((PLCQueryRx[PLCQueryRx_DM157 + 26] == 0x2)           //vision inspection trigger /*DM170*///state 2
                        &&
                        (PLCWriteCommand[PLCWriteCommand_DM380 + 2] == 0x00) //vision ready signal
                        )
                    {
                        //  PLCWriteCommand[PLCWriteCommand_DM380 + 2] = 0x08;
                        //St02Vision01Thread = new Thread(new ParameterizedThreadStart(ST02Vision01Th));
                        //St02Vision01Thread.Start(networkmain);
                        VisionRotaryCheck = "1";
                        evt_Station02InspectionReq.Set();
                    }
                    #endregion
                    #region RotaryBRequest
                    if ((PLCQueryRx[PLCQueryRx_DM100 + 4] == 0x1)//vision inspection ready/*DM101*///state 2
                        &&
                        (PLCWriteCommand[PLCWriteCommand_DM200 + 2] == 0x05)
                        &&
                        (!evt_Station02PrintReq.WaitOne(0))//assumming data had been send to vision also
                        )
                    {
                        PLCWriteCommand[PLCWriteCommand_DM200 + 2] = 0x06;//print send complete
                        PrintStatus1 = "Received";
                    }
                    if ((PLCQueryRx[PLCQueryRx_DM157 + 30] == 0x2)           //vision inspection trigger /*DM172*///state 2
                        &&
                        (PLCWriteCommand[PLCWriteCommand_DM380 + 2] == 0x00) //vision ready signal
                        )
                    {
                        // PLCWriteCommand[PLCWriteCommand_DM380 + 2] = 0x08;
                        //St02Vision01Thread = new Thread(new ParameterizedThreadStart(ST02Vision01Th));
                        //St02Vision01Thread.Start(networkmain);
                        VisionRotaryCheck = "2";
                        evt_Station02InspectionReq.Set();
                    }
                    #endregion
                    #region RotaryCRequest
                    if ((PLCQueryRx[PLCQueryRx_DM100 + 6] == 0x1)//vision inspection ready/*DM101*///state 2
                        &&
                        (PLCWriteCommand[PLCWriteCommand_DM200 + 2] == 0x05)
                        &&
                        (!evt_Station02PrintReq.WaitOne(0))//assumming data had been send to vision also
                        )
                    {
                        PLCWriteCommand[PLCWriteCommand_DM200 + 2] = 0x06;//print send complete
                        PrintStatus2 = "Received";
                    }
                    if ((PLCQueryRx[PLCQueryRx_DM157 + 34] == 0x2)           //Rotary A vision inspection trigger /*DM174*///state 2
                        &&
                        (PLCWriteCommand[PLCWriteCommand_DM380 + 2] == 0x00) //vision ready signal
                        )
                    {
                        //  PLCWriteCommand[PLCWriteCommand_DM380 + 2] = 0x08;
                        //St02Vision01Thread = new Thread(new ParameterizedThreadStart(ST02Vision01Th));
                        //St02Vision01Thread.Start(networkmain);
                        VisionRotaryCheck = "3";
                        evt_Station02InspectionReq.Set();
                    }
                    #endregion
                    #endregion

                    #region Output Transpoter

                    try
                    {
                        //Tracking Label
                        byte[] temp83 = new byte[10];
                        Array.Copy(PLCQueryRx, 241, temp83, 0, 10);       // DM 115~119 PLC1
                        OutputTranspoterFL = System.Text.Encoding.Default.GetString(temp83);
                        if (OutputTranspoterFL != "\0\0\0\0\0\0\0\0\0\0")
                        {
                            #region RJ status update
                            //need lock
                            //DM154
                            byte[] tmparrayER7 = new byte[2];
                            Array.Copy(PLCQueryRx, 319, tmparrayER7, 0, 2);
                            //convert Byte array to int
                            Int32 er7 = (Int32)(BitConverter.ToInt16(tmparrayER7, 0));
                            if (er7 > 0)
                            {
                                string rj = "RJ";
                                try
                                {
                                    while ((!networkmain.UpdateRJLabel(OutputTranspoterFL, rj, er7.ToString()) && !bTerminate))
                                    {
                                        Thread.Sleep(100);
                                    }
                                }
                                catch
                                {
                                }
                            }
                            #endregion

                            PLCWriteCommand[309] = 0x0F;      //D344
                        }
                        else
                        {
                            OutputTranspoterFL   = "\0\0\0\0\0\0\0\0\0\0";
                            PLCWriteCommand[309] = 0x00;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log1.Info(ex.ToString());
                    }



                    #endregion


                    #region Printer Clear Data

                    #region RA

                    if ((PLCQueryRx[PLCQueryRx_DM150] == 0x01)
                        &&
                        (PLCWriteCommand[PLCWriteCommand_DM340] == 0x00)
                        &&
                        (!evt_Station02PrintClearReqRA.WaitOne(0))
                        )
                    {
                        PLCWriteCommand[PLCWriteCommand_DM340] = 0x4; //set busy signal

                        // St2Log.Info("Station 2 Printing clear  Start");
                        networkmain.linePack.Info("Station 2 Printing clear  Start");
                        ST02Rotatary_Str = ST02Rotatary_A_Str;
                        evt_Station02PrintClearReqRA.Set();
                    }

                    if ((PLCQueryRx[PLCQueryRx_DM150] == 0x1)//vision inspection ready
                        &&
                        (PLCWriteCommand[PLCWriteCommand_DM340] == 0x05)
                        &&
                        (!evt_Station02PrintClearReqRA.WaitOne(0)) //assumming data had been send to vision also
                        )
                    {
                        PLCWriteCommand[PLCWriteCommand_DM340] = 0x06;//print send complete
                        //PrintStatus = "print send complete";
                    }


                    if (PLCQueryRx[PLCQueryRx_DM150] == 0x00)
                    {
                        PLCWriteCommand[PLCWriteCommand_DM340] = 0x00;
                    }


                    #endregion



                    #endregion


                    #region Station 2 Error code

                    byte[] tmparrayER2_ = new byte[2];
                    Array.Copy(PLCQueryRx, 371, tmparrayER2_, 0, 2);  //180=371,181=373,182=375,183=377,184=379,185=381,186=383,187=385
                    //convert Byte array to int
                    Int32 erst2 = (Int32)(BitConverter.ToInt16(tmparrayER2_, 0));
                    ErrCode2 = erst2.ToString();

                    byte[] tmparrayER2_1 = new byte[2];
                    Array.Copy(PLCQueryRx, 373, tmparrayER2_1, 0, 2);  //181=373,182=375,183=377,184=379,185=381,186=383,187=385
                    //convert Byte array to int
                    Int32 erst2_1 = (Int32)(BitConverter.ToInt16(tmparrayER2_1, 0));
                    ErrCode2_1 = erst2_1.ToString();

                    byte[] tmparrayER2_2 = new byte[2];
                    Array.Copy(PLCQueryRx, 375, tmparrayER2_2, 0, 2);  //182=375,183=377,184=379,185=381,186=383,187=385
                    //convert Byte array to int
                    Int32 erst2_2 = (Int32)(BitConverter.ToInt16(tmparrayER2_2, 0));
                    ErrCode2_2 = erst2_2.ToString();

                    byte[] tmparrayER2_3 = new byte[2];
                    Array.Copy(PLCQueryRx, 377, tmparrayER2_3, 0, 2);  //183=377,184=379,185=381,186=383,187=385
                    //convert Byte array to int
                    Int32 erst2_3 = (Int32)(BitConverter.ToInt16(tmparrayER2_3, 0));
                    ErrCode2_3 = erst2_3.ToString();

                    byte[] tmparrayER2_4 = new byte[2];
                    Array.Copy(PLCQueryRx, 379, tmparrayER2_4, 0, 2);  //184=379,185=381,186=383,187=385
                    //convert Byte array to int
                    Int32 erst2_4 = (Int32)(BitConverter.ToInt16(tmparrayER2_4, 0));
                    ErrCode2_4 = erst2_4.ToString();

                    byte[] tmparrayER2_5 = new byte[2];
                    Array.Copy(PLCQueryRx, 381, tmparrayER2_5, 0, 2);  //185=381,186=383,187=385
                    //convert Byte array to int
                    Int32 erst2_5 = (Int32)(BitConverter.ToInt16(tmparrayER2_5, 0));
                    ErrCode2_5 = erst2_5.ToString();

                    byte[] tmparrayER2_6 = new byte[2];
                    Array.Copy(PLCQueryRx, 383, tmparrayER2_6, 0, 2);  //186=383,187=385
                    //convert Byte array to int
                    Int32 erst2_6 = (Int32)(BitConverter.ToInt16(tmparrayER2_6, 0));
                    ErrCode2_6 = erst2_6.ToString();

                    byte[] tmparrayER2_7 = new byte[2];
                    Array.Copy(PLCQueryRx, 385, tmparrayER2_7, 0, 2);  //187=385
                    //convert Byte array to int
                    Int32 erst2_7 = (Int32)(BitConverter.ToInt16(tmparrayER2_7, 0));
                    ErrCode2_7 = erst2_7.ToString();



                    #region NewErrorCode
                    if (erst2 > 0 || erst2_1 > 0 || erst2_2 > 0 || erst2_3 > 0 || erst2_4 > 0 || erst2_5 > 0 || erst2_6 > 0 || erst2_7 > 0)
                    {
                        //GYL: erst2~erst2_7 is represent DM180=DM2031,DM181=2033,182=DM2038,183=DM2043,184=2036,185=2037,186=DM2039,187=2046
                        //   LogEr.Info("Station 2 Error Code"+ErrCode2+ErrCode2_1+ErrCode2_2+ErrCode2_3+ErrCode2_4+ErrCode2_5+ErrCode2_6+ErrCode2_7);

                        Errmessage2 = "Stn.2 Err " +
                                      (erst2 > 0 ? ErrCode2 + ": " + Stn2ErrToMsg(erst2) : "") +
                                      (erst2_1 > 0 && erst2_1 != erst2 ? ", " + ErrCode2_1 + ": " + Stn2ErrToMsg(erst2_1) : "") +
                                      (erst2_2 > 0 && erst2_2 != erst2 ? ", " + ErrCode2_2 + ": " + Stn2ErrToMsg(erst2_2) : "") +
                                      (erst2_3 > 0 && erst2_3 != erst2 ? ", " + ErrCode2_3 + ": " + Stn2ErrToMsg(erst2_3) : "") +
                                      (erst2_4 > 0 && erst2_4 != erst2 ? ", " + ErrCode2_4 + ": " + Stn2ErrToMsg(erst2_4) : "") +
                                      (erst2_5 > 0 && erst2_5 != erst2 ? ", " + ErrCode2_5 + ": " + Stn2ErrToMsg(erst2_5) : "") +
                                      (erst2_6 > 0 && erst2_6 != erst2 ? ", " + ErrCode2_6 + ": " + Stn2ErrToMsg(erst2_6) : "") +
                                      (erst2_7 > 0 && erst2_7 != erst2 ? ", " + ErrCode2_7 + ": " + Stn2ErrToMsg(erst2_7) : "");

                        //  LogEr.Info(Errmessage2);
                        //GYL:Add Pause STN2 Function,and ST2 JAM trigger
                        if (!ST2JamFlag)
                        {
                            bool St2JamTrig = ST2PauseFunction(2, erst2 + ";" + erst2_1 + ";" + erst2_2 + ";" + erst2_3 + ";" + erst2_4 + ";" + erst2_5 + ";" + erst2_6 + ";" + erst2_7);
                            if (St2JamTrig)
                            {
                                ST2JamFlag = true;

                                //string[] FLbatch = rq.UpdJamstatus(2, 222); //Update Jam FL

                                //if (FLbatch != null)
                                //{
                                //    networkmain.Client_SendEventMsg("265", "Station2FLJAMRecovery", FLbatch);//Update Jam recovery FL to middleware

                                //}
                            }
                        }
                    }
                    else
                    {
                        Errmessage2 = String.Empty;
                        ST2JamFlag  = false;
                    }
                    #endregion
                    #region OldAlarm
                    //if (erst2 > 0 || erst2_1 > 0 || erst2_2 > 0 || erst2_3 > 0 || erst2_4 > 0 || erst2_5 > 0 || erst2_6 > 0 || erst2_7 > 0)
                    //{

                    //    //   LogEr.Info("Station 2 Error Code"+ErrCode2+ErrCode2_1+ErrCode2_2+ErrCode2_3+ErrCode2_4+ErrCode2_5+ErrCode2_6+ErrCode2_7);

                    //    Errmessage2 = "Stn.2 Err " +
                    //               (erst2 > 0 ? ErrCode2 + ": " + Stn2ErrToMsg(erst2) : "") +
                    //               (erst2_1 > 0 && erst2_1 != erst2 ? ", " + ErrCode2_1 + ": " + Stn2ErrToMsg(erst2_1) : "") +
                    //               (erst2_2 > 0 && erst2_2 != erst2 ? ", " + ErrCode2_2 + ": " + Stn2ErrToMsg(erst2_2) : "") +
                    //               (erst2_3 > 0 && erst2_3 != erst2 ? ", " + ErrCode2_3 + ": " + Stn2ErrToMsg(erst2_3) : "") +
                    //               (erst2_4 > 0 && erst2_4 != erst2 ? ", " + ErrCode2_4 + ": " + Stn2ErrToMsg(erst2_4) : "") +
                    //               (erst2_5 > 0 && erst2_5 != erst2 ? ", " + ErrCode2_5 + ": " + Stn2ErrToMsg(erst2_5) : "") +
                    //               (erst2_6 > 0 && erst2_6 != erst2 ? ", " + ErrCode2_6 + ": " + Stn2ErrToMsg(erst2_6) : "") +
                    //               (erst2_7 > 0 && erst2_7 != erst2 ? ", " + ErrCode2_7 + ": " + Stn2ErrToMsg(erst2_7) : "");

                    //    //  LogEr.Info(Errmessage2);



                    //}
                    //else
                    //{
                    //    Errmessage2 = String.Empty;
                    //}
                    #endregion
                    UpdateErrorMsg((int)Station.StationNumber.Station02, Errmessage2, ST2JamFlag);



                    if (erst2 > 0 && networkmain.controlst2 == 0)
                    {
                        Errst2 = erst2.ToString();
                        networkmain.controlst2 = 1;
                        messagest2             = Stn2ErrToMsg(erst2);
                        networkmain.Client_SendAlarmMessage2(erst2.ToString(), messagest2, "SET");
                    }

                    if (erst2 == 0 && networkmain.controlst2 == 1)
                    {
                        networkmain.Client_SendAlarmMessage2(Errst2, messagest2, "CLEAR");
                        messagest2             = "";
                        Errst2                 = "";
                        networkmain.controlst2 = 0;
                    }


                    if (erst2_1 > 0 && erst2_1 != erst2 && networkmain.controlst2_1 == 0)
                    {
                        Errst2_1 = erst2_1.ToString();
                        networkmain.controlst2_1 = 1;
                        messagest2_1             = Stn2ErrToMsg(erst2_1);
                        networkmain.Client_SendAlarmMessage2(erst2_1.ToString(), messagest2_1, "SET");
                    }

                    if (erst2_1 == 0 && networkmain.controlst2_1 == 1)
                    {
                        networkmain.Client_SendAlarmMessage2(Errst2_1, messagest2_1, "CLEAR");
                        messagest2_1             = "";
                        Errst2_1                 = "";
                        networkmain.controlst2_1 = 0;
                    }



                    if (erst2_2 > 0 && erst2_2 != erst2 && erst2_2 != erst2_1 && networkmain.controlst2_2 == 0)
                    {
                        Errst2_2 = erst2_2.ToString();
                        networkmain.controlst2_2 = 1;
                        messagest2_2             = Stn2ErrToMsg(erst2_2);
                        networkmain.Client_SendAlarmMessage2(erst2_2.ToString(), messagest2_2, "SET");
                    }

                    if (erst2_2 == 0 && networkmain.controlst2_2 == 1)
                    {
                        networkmain.Client_SendAlarmMessage2(Errst2_2, messagest2_2, "CLEAR");
                        messagest2_2             = "";
                        Errst2_2                 = "";
                        networkmain.controlst2_2 = 0;
                    }



                    if (erst2_3 > 0 && erst2_3 != erst2 && erst2_3 != erst2_2 && erst2_3 != erst2_1 && networkmain.controlst2_3 == 0)
                    {
                        Errst2_3 = erst2_3.ToString();
                        networkmain.controlst2_3 = 1;
                        messagest2_3             = Stn2ErrToMsg(erst2_3);
                        networkmain.Client_SendAlarmMessage2(erst2_3.ToString(), messagest2_3, "SET");
                    }

                    if (erst2_3 == 0 && networkmain.controlst2_3 == 1)
                    {
                        networkmain.Client_SendAlarmMessage2(Errst2_3, messagest2_3, "CLEAR");
                        messagest2_3             = "";
                        Errst2_3                 = "";
                        networkmain.controlst2_3 = 0;
                    }



                    if (erst2_4 > 0 && erst2_4 != erst2 && erst2_4 != erst2_3 && erst2_4 != erst2_2 && erst2_4 != erst2_1 && networkmain.controlst2_4 == 0)
                    {
                        Errst2_4 = erst2_4.ToString();
                        networkmain.controlst2_4 = 1;
                        messagest2_4             = Stn2ErrToMsg(erst2_4);
                        networkmain.Client_SendAlarmMessage2(erst2_4.ToString(), messagest2_4, "SET");
                    }

                    if (erst2_4 == 0 && networkmain.controlst2_4 == 1)
                    {
                        networkmain.Client_SendAlarmMessage2(Errst2_4, messagest2_4, "CLEAR");
                        messagest2_4             = "";
                        Errst2_4                 = "";
                        networkmain.controlst2_4 = 0;
                    }

                    if (erst2_5 > 0 && erst2_5 != erst2 && erst2_5 != erst2_4 && erst2_5 != erst2_3 && erst2_5 != erst2_2 && erst2_5 != erst2_1 && networkmain.controlst2_5 == 0)
                    {
                        Errst2_5 = erst2_5.ToString();
                        networkmain.controlst2_5 = 1;
                        messagest2_5             = Stn2ErrToMsg(erst2_5);
                        networkmain.Client_SendAlarmMessage2(erst2_5.ToString(), messagest2_5, "SET");
                    }

                    if (erst2_5 == 0 && networkmain.controlst2_5 == 1)
                    {
                        networkmain.Client_SendAlarmMessage2(Errst2_5, messagest2_5, "CLEAR");
                        messagest2_5             = "";
                        Errst2_5                 = "";
                        networkmain.controlst2_5 = 0;
                    }


                    if (erst2_6 > 0 && erst2_6 != erst2 && erst2_6 != erst2_5 && erst2_6 != erst2_4 && erst2_6 != erst2_3 && erst2_6 != erst2_2 && erst2_6 != erst2_1 && networkmain.controlst2_6 == 0)
                    {
                        Errst2_6 = erst2_6.ToString();
                        networkmain.controlst2_6 = 1;
                        messagest2_6             = Stn2ErrToMsg(erst2_6);
                        networkmain.Client_SendAlarmMessage2(erst2_6.ToString(), messagest2_6, "SET");
                    }

                    if (erst2_6 == 0 && networkmain.controlst2_6 == 1)
                    {
                        networkmain.Client_SendAlarmMessage2(Errst2_6, messagest2_6, "CLEAR");
                        messagest2_6             = "";
                        Errst2_6                 = "";
                        networkmain.controlst2_6 = 0;
                    }


                    if (erst2_7 > 0 && erst2_7 != erst2 && erst2_7 != erst2_6 && erst2_7 != erst2_5 && erst2_7 != erst2_4 && erst2_7 != erst2_3 && erst2_7 != erst2_2 && erst2_7 != erst2_1 && networkmain.controlst2_7 == 0)
                    {
                        Errst2_7 = erst2_7.ToString();
                        networkmain.controlst2_7 = 1;
                        messagest2_7             = Stn2ErrToMsg(erst2_7);
                        networkmain.Client_SendAlarmMessage2(erst2_7.ToString(), messagest2_7, "SET");
                    }

                    if (erst2_7 == 0 && networkmain.controlst2_7 == 1)
                    {
                        networkmain.Client_SendAlarmMessage2(Errst2_7, messagest2_7, "CLEAR");
                        messagest2_7             = "";
                        Errst2_7                 = "";
                        networkmain.controlst2_7 = 0;
                    }
                    if (PLCQueryRx[PLCQueryRx_DM100 + 16] == 0x4)          //d108
                    {
                        PLCWriteCommand[PLCWriteCommand_DM200 + 60] = 0x0; //D230, Station2 Pause trigger
                    }


                    #endregion


                    #region Checke printer Connection at ST2


                    Ping PingPrinter2 = new Ping();

                    try
                    {
                        if ((PLCQueryRx[PLCQueryRx_DM134] == 0x01)
                            &&
                            (PLCWriteCommand[PLCWriteCommand_DM427] == 0x00)
                            )
                        {
                            PingReply PR2 = PingPrinter2.Send("192.168.3.224");
                            if (PR2.Status == IPStatus.Success)
                            {
                                PLCWriteCommand[PLCWriteCommand_DM427] = 0x09;
                            }
                            else if (PR2.Status == IPStatus.DestinationHostUnreachable)
                            {
                                PLCWriteCommand[PLCWriteCommand_DM427] = 0xFF;
                            }
                        }


                        if (PLCQueryRx[PLCQueryRx_DM134] == 0x00)
                        {
                            PLCWriteCommand[PLCWriteCommand_DM427] = 0x00;
                        }
                    }
                    catch
                    {
                    }



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