private bool ST2PauseFunction(int StationNumber, string errcode) { string[] errcodeArray = errcode.Split(';'); try { bool RetResult = false; XmlDocument doc = new XmlDocument(); doc.Load(@"ConfigJAMErrorList.xml"); foreach (string item in errcodeArray) { System.Data.DataRow[] drs = dbUtils.GetAllDataSet().ErrCode.Select("StNo=" + StationNumber + " and ErrCode=" + item); if (drs != null && (drs.Length > 0)) { dbUtils.ErrHistory_Insert(StationNumber, item); //qf } XmlNode node = doc.SelectSingleNode(@"/ERROR/Station" + StationNumber + "/E" + item.ToString()); if (node == null) { RetResult = RetResult || false; } else { EvtLog.Info("Pause: " + item.ToString() + "/STNo:" + StationNumber); PLCWriteCommand[PLCWriteCommand_DM200 + 60] = 0x4; //D230, Station2 Pause trigger RetResult = RetResult || true; } } ; return(RetResult); } catch (Exception) { throw; } }
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); }
private bool ST1CriticalError(int StationNumber, string errcode) { string[] errcodeArray = errcode.Split(';'); try { bool RetResult = false; XmlDocument doc = new XmlDocument(); doc.Load(@"ConfigJAMErrorList.xml"); foreach (string item in errcodeArray) { XmlNode node = doc.SelectSingleNode(@"/ERROR/Station" + "1" + "/E" + item.ToString()); if (node == null) { RetResult = RetResult || false; } else { EvtLog.Info("ST1 CriticalErr: " + item.ToString() + "/STNo:" + StationNumber); // PLCWriteCommand[PLCWriteCommand_DM200 + 60] = 0x4; //D230, Station2 Pause trigger RetResult = RetResult || true; } } ; return(RetResult); } catch (Exception) { throw; } }
public void AutoDeQ() { ATDeqOn = true; while (MyEventQ.Qcount()) { string value; value = MyEventQ.Rmov(); if (value != "") { value = SReplace2(value, new string[] { "\0" }, ""); value = value.Trim(); // networkmain.Client_SendEventMsg(value); EvtLog.Info("Send OUT: " + value); char[] delimiterChars = { ';', '\t' }; String[] details = value.Split(delimiterChars); if (details[0].StartsWith("EV")) { //event int stn = Int32.Parse(details[0].Substring(2, 1)); String code = details[0].Substring(2); EvtLog.Debug("DB Insert to EventhEventHistoyistroy " + stn + " ," + code); dbUtils.EventHistory_Insert(stn, code, "E"); } else if (details[0].StartsWith("RJ")) { //reject int stn = 10; String code = details[0].Substring(2); EvtLog.Debug("DB Insert to EventHistoy " + stn + " ," + code); dbUtils.EventHistory_Insert(stn, code, "R"); } } else { EvtLog.Info("Send OUT: Null "); } } ATDeqOn = false; }
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()); } } }
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 RunStation05Sealer3(object msgobj) { MainNetworkClass networkmain = (MainNetworkClass)msgobj; while (!bTerminate) { Thread.Sleep(100); try { bool Sealerflag3 = false; if (PLCTelnet2 != null) { if (PLCTelnet2.connected) { #region sealer program For Station5 #region //Sealer3 byte[] tmparray4 = new byte[10]; //DM5090 Array.Copy(PLCQueryRx6, 191, tmparray4, 0, 10); //convert array to string Station5ForSealer3Scanboxid = System.Text.Encoding.Default.GetString(tmparray4); if (Station5ForSealer3Scanboxid != "\0\0\0\0\0\0\0\0\0\0") { ScanboxidSt5S3 = Station5ForSealer3Scanboxid; Sealer3Log.Info("Finishing Label for Station 5 Sealer3 " + Station5ForSealer3Scanboxid); networkmain.stn5log = Station5ForSealer3Scanboxid + " slr.3 Label recieved"; #region Desiccant Timmer Thread.Sleep(10); if ((PLCQueryRx6[PLCQueryRx_DM5111 + 16] == 0X07) && (PLCWriteCommand6[PLCWriteCommand_DM5405 + 4]) == 0x00) //D5119 { Sealer3Log.Info("Finishing Label for Station 5 Sealer3 PLC Send HIC/Desiccant stop Signal " + Station5ForSealer3Scanboxid); networkmain.stn5log = Station5ForSealer3Scanboxid + " Slr.3 stop Signal"; if (Sealerflag3 == false) { try { Sealerflag3 = true; TimeSpan span = DateTime.Now.Subtract(DesiccantTimingMap[Station5ForSealer3Scanboxid]); double secs = span.TotalSeconds; Sealer3Log.Info("PC delete HIC/Desiccant Finishing Label for Station 5 Sealer3 " + Station5ForSealer3Scanboxid); networkmain.stn5log = Station5ForSealer3Scanboxid + " Slr.3 PC delete HIC/Desiccant label"; // if (secs > 175) //NEED TO OPEN WHEN REAL TIME PRODUCTION if (secs > 300) { //Desiccant Expired. Reject the Part. //D5414=449 MyEventQ.AddQ("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer3Scanboxid); EvtLog.Info("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer3Scanboxid); Statusst52 = "Fail"; byte[] tmp7 = new byte[2]; tmp7 = Encoding.ASCII.GetBytes("RJ"); Array.Copy(tmp7, 0, PLCWriteCommand6, 449, 2); try { while ((!networkmain.UpdateRJLabelst5S3(Station5ForSealer3Scanboxid, "RJ", "502") && !bTerminate)) { Thread.Sleep(100); } Sealer3Log.Info(" HIC/Desiccant Timeout Finishing Label (RJ) for Station 5 Sealer3 " + Station5ForSealer3Scanboxid); networkmain.stn5log = Station5ForSealer3Scanboxid + " slr.3 HIC/Desiccant Timeout"; networkmain.OperatorLog = "Stn.5 Slr.3 HIC/Desiccant Timeout " + Station5ForSealer3Scanboxid; } catch (Exception ex) { Sealer3Log.Error("station 5 Sealer3 HIC/Desiccant Fail" + ex); networkmain.stn5log = "HIC/Desiccant Fail Slr.3"; networkmain.OperatorLog = "Stn.5 Slr.3 HIC/Desiccant Fail"; byte[] tmp71 = new byte[2]; tmp71 = Encoding.ASCII.GetBytes("RJ"); Array.Copy(tmp71, 0, PLCWriteCommand6, 449, 2); Statusst52 = "Fail"; MyEventQ.AddQ("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer3Scanboxid); EvtLog.Info("9;Desiccant/HICTimeout;LotNumber;" + Station5ForSealer3Scanboxid); } } else { if (CheckeRJStatusForSealer3(Station5ForSealer3Scanboxid) == true) { Sealer3Log.Info("HIC/Desiccant Pass Finishing Label for Station 5 Sealer3 " + Station5ForSealer3Scanboxid); networkmain.stn5log = Station5ForSealer3Scanboxid + " slr.3 HIC/Desiccant Pass"; Statusst52 = "Pass"; } else { while ((!networkmain.UpdateRJLabelst5S3(Station5ForSealer3Scanboxid, "RJ", RJResultst5S3) && !bTerminate)) { Thread.Sleep(100); } byte[] tmp7 = new byte[2]; tmp7 = Encoding.ASCII.GetBytes("RJ"); Array.Copy(tmp7, 0, PLCWriteCommand6, 449, 2); Sealer3Log.Info(" Finishing Label for Station 5 Sealer3 (RJ) because of other station " + Station5ForSealer3Scanboxid + " RJ Code," + RJResultst5S3); Statusst52 = "Fail"; } } DesiccantTimingMap.Remove(Station5ForSealer3Scanboxid); (PLCWriteCommand6[PLCWriteCommand_DM5405 + 4]) = 0x07; } catch (Exception ex) { Sealer3Log.Error(ex.ToString()); while ((!networkmain.UpdateRJLabel(Station5ForSealer3Scanboxid, "RJ", "507") && !bTerminate)) { Thread.Sleep(100); } //D5414=449 byte[] tmpS = new byte[2]; tmpS = Encoding.ASCII.GetBytes("RJ"); Array.Copy(tmpS, 0, PLCWriteCommand6, 449, 2); Sealer3Log.Info(" HIC/Desiccant Fail (RJ)Finishing Label for Sealer3 but send signal to PLC " + Station5ForSealer3Scanboxid + " RJ Code,507"); networkmain.stn5log = Station5ForSealer3Scanboxid + " slr.3 HIC/Desiccant fail but sent signal to PLC because of st3"; networkmain.OperatorLog = "Stn.5 slr.3 " + Station5ForSealer3Scanboxid + "HIC/Desiccant fail because of st3"; (PLCWriteCommand6[PLCWriteCommand_DM5405 + 4]) = 0x07; Statusst52 = "Fail"; } } } #endregion if (PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] == 0x00) { PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x04; //busy Sealer3 evnt_FindFinishingLabelForSealer3.Set(); Sealer3Log.Info("Finishing Label for Station 5 Sealer3 receipt send already " + Station5ForSealer3Scanboxid); networkmain.stn5log = Station5ForSealer3Scanboxid + " slr.3 receipt sent already"; } } else { PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x00; PLCWriteCommand6[PLCWriteCommand_DM5414] = 0x00; PLCWriteCommand6[PLCWriteCommand_DM5414b] = 0x00; Station5ForSealer3Scanboxid = "\0\0\0\0\0\0\0\0\0\0"; Sealerflag3 = false; pNumber3 = 0; ScanboxidSt5S3 = ""; Statusst52 = ""; } if (PLCQueryRx6[PLCQueryRx_DM5111 + 16] == 0X00) //D5119 { (PLCWriteCommand6[PLCWriteCommand_DM5405 + 4]) = 0x00; } #endregion #endregion #region Sealercomms if (evnt_FindFinishingLabelForSealer3.WaitOne(0)) { try { if (VS3VacuumSealer != null) { //if (!VS3VacuumSealer.IsOpen) //{ try { VS3VacuumSealer.Close(); } catch (Exception) { } VS3VacuumSealer = null; //} } if (VS3VacuumSealer == null) { XmlDocument doc = new XmlDocument(); doc.Load(@"Config.xml"); XmlNode Sealernode = doc.SelectSingleNode(@"/CONFIG/SEALER3/PORT"); String comport = Sealernode.InnerText; //TODO: ConfigFIle VS3VacuumSealer = new InnovacVacuumSealer(comport); VS3VacuumSealer.Open(); } //For test Only // VS3VacuumSealer.SelectAndConfirmProgram(240, InnovacVacuumSealer.SealerBar.Right); //PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x08; if (networkmain.FindSealerReceipeForSealer3(Station5ForSealer3Scanboxid) == true) { short sealerReceipe = networkmain.SealerReceipt3; Sealer3Log.Info("Sealer3 send receipt" + sealerReceipe); VS3VacuumSealer.SelectAndConfirmProgram(sealerReceipe, InnovacVacuumSealer.SealerBar.Right); //bool type want PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x08; // Set Status for PLC to Complete 0x08 //// Wait until the sealing is completed/ Error returned/ Timeout happened. InnovacVacuumSealer.SealingCompleteMessage sealingCompleteMessage3; try { VS3VacuumSealer.WaitSealingCompleted(out sealingCompleteMessage3, 120000); // Sealing Completed successfully Sealer3Log.Info(sealingCompleteMessage3.ToString()); PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x09; #region try { //FL 1 pNumber3 = sealingCompleteMessage3.ProgramNumber; //3 if (pNumber3 > 0) { // InnovacVacuumSealer.SealerBar SBar=sealingCompleteMessage.SelectedSealerBar; // InnovacVacuumSealer.MessageCode Com =sealingCompleteMessage.Command; short vacuumPV = sealingCompleteMessage3.VacuumPV; //ActualVacuumReading 4 short VacuumSP = sealingCompleteMessage3.VacuumSP; //RecipeVacuumReading 5 short SCurrentPV = sealingCompleteMessage3.SealerCurrentPV; //ActualCurrentReading 6 short SCurrentSP = sealingCompleteMessage3.SealerCurrentSP; //RecipeCurrentReading 7 float sealingTime = sealingCompleteMessage3.SealingTime; //8 string Sfunction = sealingCompleteMessage3.UsedFunction.ToString(); //9 string abc = Sealer3IDshow.Trim(); Sealer3IDshow = abc; if (Sfunction == "VT") { Sfunction = "VT"; } if (Sfunction == "VS") { Sfunction = "VS"; } if (Sfunction == "VT,VS") { Sfunction = "VTVS"; } networkmain.Client_SendEventMessageForSealer3("503", Station5ForSealer3Scanboxid, Sealer3IDshow, sealingCompleteMessage3.ProgramNumber, sealingCompleteMessage3.VacuumPV, sealingCompleteMessage3.VacuumSP, sealingCompleteMessage3.SealerCurrentPV, sealingCompleteMessage3.SealerCurrentSP, sealingCompleteMessage3.SealingTime, Sfunction); Sealer3Log.Info("Sealer3 send SealerInfo to Middleware " + Station5ForSealer3Scanboxid + "," + Sealer3IDshow + "," + sealingCompleteMessage3.ProgramNumber + "," + sealingCompleteMessage3.VacuumPV + "," + sealingCompleteMessage3.VacuumSP + "," + sealingCompleteMessage3.SealerCurrentPV + "," + sealingCompleteMessage3.SealerCurrentSP + "," + sealingCompleteMessage3.SealingTime + "," + Sfunction); } } catch {} #endregion } catch (TimeoutException ex) { // Timeout Happened Sealer3Log.Error(ex.ToString()); string abc = Sealer3IDshow.Trim(); MyEventQ.AddQ("8;SealerCommunicationBreak;SealerID;" + abc); EvtLog.Info("8;SealerCommunicationBreak;SealerID;" + abc); } catch (InnovacVacuumSealer.SealingErrorException ex) { // Sealer return Error if (ex.ErrorCode == 2 || ex.ErrorCode == 3 || ex.ErrorCode == 7) { PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0xFF; } else { PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x09; } if (!Sealer3ErrAtv) { Sealer3ErrorCode = "E" + (5660 + ex.ErrorCode).ToString(); Sealer3EventMesg = ex.ErrorMessage; Sealer3ErrAtv = true; ExceptionMesgSend3((5660 + ex.ErrorCode).ToString(), Sealer3IDshow.Trim(), ex.ErrorMessage, ex.ToString()); Sealer3ErrResetTimer.Interval = TimeSpan.FromSeconds(10); Sealer3ErrResetTimer.Tick += Sealer3ErrResetTimer_Tick; Sealer3ErrResetTimer.Start(); //Start the bloody timer } else { //Reset the timer Sealer3ErrResetTimer.Stop(); Sealer3ErrResetTimer.Start(); } } } //finishing label not match else { Sealer3Log.Info("Sealer3 Finishing Label don't have in System" + "," + Station5ForSealer3Scanboxid); PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x0F; } } catch (Exception ex) { Sealer3Log.Error(ex.ToString()); // Set status for PLC to Error 0x0F PLCWriteCommand6[PLCWriteCommand_DM5310 + 4] = 0x0F; Sealer3Log.Info("Sealer3 Finishing Label don't have in System" + "," + Station5ForSealer3Scanboxid); } evnt_FindFinishingLabelForSealer3.Reset(); } #endregion } } // break; } catch (Exception ex) { log.Error(ex.ToString()); } } }
public void RunStation05Sealers(object msgobj) { MainNetworkClass networkmain = (MainNetworkClass)msgobj; while (!bTerminate) { Thread.Sleep(100); try { bool Sealerflag1 = false; bool Sealerflag2 = false; bool Sealerflag3 = false; if (PLCTelnet2 != null) { if (PLCTelnet2.connected) { #region Sealer ID //Sealer1 byte[] temps1 = new byte[12]; Array.Copy(PLCQueryRx6, 91, temps1, 0, 12); // DM 5040 PLC2 Sealer1ID = System.Text.Encoding.Default.GetString(temps1); if (Sealer1ID != "\0\0\0\0\0\0\0\0\0\0\0\0" && Sealer1ID != " ") { Sealer1IDshow = Sealer1ID; } else { Sealer1IDshow = "Sealer1IDisNULL"; } byte[] temps2 = new byte[12]; Array.Copy(PLCQueryRx6, 141, temps2, 0, 12); // DM 5065 PLC2 Sealer2ID = System.Text.Encoding.Default.GetString(temps2); if (Sealer2ID != "\0\0\0\0\0\0\0\0\0\0\0\0" && Sealer2ID != " ") { Sealer2IDshow = Sealer2ID; } else { Sealer2IDshow = "Sealer2IDisNULL"; } byte[] temps3 = new byte[12]; Array.Copy(PLCQueryRx6, 153, temps3, 0, 12); // DM 5071 PLC2 Sealer3ID = System.Text.Encoding.Default.GetString(temps3); if (Sealer3ID != "\0\0\0\0\0\0\0\0\0\0\0\0" && Sealer3ID != " ") { Sealer3IDshow = Sealer3ID; } else { Sealer3IDshow = "Sealer3IDisNULL"; } #endregion #region sealer program For Station5 //edit ............................. byte[] temp2 = new byte[10]; Array.Copy(PLCQueryRx6, 201, temp2, 0, 10); // DM 5095 PLC2 =201 offset Station5ForTransferScanboxidFromPLC2 = System.Text.Encoding.Default.GetString(temp2); if (Station5ForTransferScanboxidFromPLC2 != "\0\0\0\0\0\0\0\0\0\0") { ST5NewFLRev = true; CheckStringUpdateFor5(PLCFinishingLabelOFFSET, Station5ForTransferScanboxidFromPLC2); } else { ST5NewFLRev = false; Station5ForTransferScanboxidFromPLC2 = "\0\0\0\0\0\0\0\0\0\0"; CheckStringClearFor5(PLCFinishingLabelOFFSET, Station5ForTransferScanboxidFromPLC2); // DM5271 } // Compare PLC fl and thread fl // Set Status to Busy #endregion #region Sealer checking in Station 5 Initialization time /* * if (evnt_CheckingConnectionForSealer1.WaitOne(50)) * { * try * { * if (VS1VacuumSealer != null) * { * * try * { * VS1VacuumSealer.Close(); * } * catch (Exception) { } * VS1VacuumSealer = null; * * } * if (VS1VacuumSealer == null) * { * XmlDocument doc = new XmlDocument(); * doc.Load(@"Config.xml"); * XmlNode Sealernode = doc.SelectSingleNode(@"/CONFIG/SEALER1/PORT"); * String comport = Sealernode.InnerText; * //TODO: ConfigFIle * VS1VacuumSealer = new InnovacVacuumSealer(comport); * VS1VacuumSealer.Open(); * // short testreceipe = 240; * //VS1VacuumSealer.SelectAndConfirmProgram(testreceipe, InnovacVacuumSealer.SealerBar.Right); * Sealer1Log.Info("Sealer1 connected at initialization time"); * networkmain.stn5log ="slr.1 connected at initialization"; * networkmain.OperatorLog = "Sealer1 connected at initialization time"; * InnovacVacuumSealer.SystemStatus sysMessage; * VS1VacuumSealer.GetSystemStatus(out sysMessage); * if (sysMessage != InnovacVacuumSealer.SystemStatus.Undefined && sysMessage != InnovacVacuumSealer.SystemStatus.Error && Sealer1IDshow != "Sealer1IDisNULL") * { * PLCWriteCommand6[PLCWriteCommand_DM5362] = 0x06; * } * else * { * PLCWriteCommand6[PLCWriteCommand_DM5362] = 0xFF; * } * } * * * } * catch (Exception ex) * { * Sealer1Log.Error(ex.ToString()); * * PLCWriteCommand6[PLCWriteCommand_DM5362] = 0xFF; * Sealer1Log.Info("Sealer1 Can't connected at initialization time"); * networkmain.stn5log = "slr.1 Can't connected at initialization"; * networkmain.OperatorLog = "Sealer1 Can't connected at initialization time"; * string abc = Sealer1IDshow.Trim(); * MyEventQ.AddQ("8;SealerCommunicationBreak;SealerID;" + abc); * EvtLog.Info("8;SealerCommunicationBreak;SealerID;" + abc); * * evnt_CheckingConnectionForSealer1.Reset(); * } * evnt_CheckingConnectionForSealer1.Reset(); * } * */ if (evnt_CheckingConnectionForSealer2.WaitOne(50)) { try { if (VS2VacuumSealer != null) { try { VS2VacuumSealer.Close(); } catch (Exception) { } VS2VacuumSealer = null; } if (VS2VacuumSealer == null) { XmlDocument doc = new XmlDocument(); doc.Load(@"Config.xml"); XmlNode Sealernode = doc.SelectSingleNode(@"/CONFIG/SEALER2/PORT"); String comport = Sealernode.InnerText; //TODO: ConfigFIle VS2VacuumSealer = new InnovacVacuumSealer(comport); VS2VacuumSealer.Open(); //short testreceipe = 240; // VS2VacuumSealer.SelectAndConfirmProgram(testreceipe, InnovacVacuumSealer.SealerBar.Right); Sealer2Log.Info("Sealer2 connected at initialization time"); networkmain.stn5log = "slr.2 connected at initialization"; networkmain.OperatorLog = "Sealer2 connected at initialization time"; InnovacVacuumSealer.SystemStatus sysMessage; VS2VacuumSealer.GetSystemStatus(out sysMessage); if (sysMessage != InnovacVacuumSealer.SystemStatus.Undefined && sysMessage != InnovacVacuumSealer.SystemStatus.Error && Sealer2IDshow != "Sealer2IDisNULL") { PLCWriteCommand6[PLCWriteCommand_DM5363] = 0x06; } else { PLCWriteCommand6[PLCWriteCommand_DM5363] = 0xFF; } } } catch (Exception ex) { Sealer2Log.Error(ex.ToString()); PLCWriteCommand6[PLCWriteCommand_DM5363] = 0xFF; Sealer2Log.Info("Sealer2 Can't connected at initialization time"); networkmain.stn5log = "slr.2 Can't connected at initialization"; networkmain.OperatorLog = "Sealer2 Can't connected at initialization time"; string abc = Sealer2IDshow.Trim(); MyEventQ.AddQ("8;SealerCommunicationBreak;SealerID;" + abc); EvtLog.Info("8;SealerCommunicationBreak;SealerID;" + abc); evnt_CheckingConnectionForSealer2.Reset(); } evnt_CheckingConnectionForSealer2.Reset(); } if (evnt_CheckingConnectionForSealer3.WaitOne(50)) { try { if (VS3VacuumSealer != null) { try { VS3VacuumSealer.Close(); } catch (Exception) { } VS3VacuumSealer = null; } if (VS3VacuumSealer == null) { XmlDocument doc = new XmlDocument(); doc.Load(@"Config.xml"); XmlNode Sealernode = doc.SelectSingleNode(@"/CONFIG/SEALER3/PORT"); String comport = Sealernode.InnerText; //TODO: ConfigFIle VS3VacuumSealer = new InnovacVacuumSealer(comport); VS3VacuumSealer.Open(); //short testreceipe = 240; //VS3VacuumSealer.SelectAndConfirmProgram(testreceipe, InnovacVacuumSealer.SealerBar.Right); Sealer3Log.Info("Sealer3 connected at initialization time"); networkmain.stn5log = "slr.3 connected at initialization"; networkmain.OperatorLog = "Sealer3 connected at initialization time"; InnovacVacuumSealer.SystemStatus sysMessage; VS3VacuumSealer.GetSystemStatus(out sysMessage); if (sysMessage != InnovacVacuumSealer.SystemStatus.Undefined && sysMessage != InnovacVacuumSealer.SystemStatus.Error && Sealer3IDshow != "Sealer3IDisNULL") { PLCWriteCommand6[PLCWriteCommand_DM5426] = 0x06; } else { PLCWriteCommand6[PLCWriteCommand_DM5426] = 0xFF; } } } catch (Exception ex) { Sealer3Log.Error(ex.ToString()); PLCWriteCommand6[PLCWriteCommand_DM5426] = 0xFF; Sealer3Log.Info("Sealer3 Can't connected at initialization time"); networkmain.stn5log = "slr.3 Can't connected at initialization"; networkmain.OperatorLog = "Sealer3 Can't connected at initialization time"; string abc = Sealer3IDshow.Trim(); MyEventQ.AddQ("8;SealerCommunicationBreak;SealerID;" + abc); EvtLog.Info("8;SealerCommunicationBreak;SealerID;" + abc); evnt_CheckingConnectionForSealer3.Reset(); } evnt_CheckingConnectionForSealer3.Reset(); } #endregion #region Station 5 Error Code byte[] tmparrayERst5 = new byte[2]; Array.Copy(PLCQueryRx6, 401, tmparrayERst5, 0, 2); //5195 //convert Byte array to int Int32 erst5 = (Int32)(BitConverter.ToInt16(tmparrayERst5, 0)); byte[] tmparrayERst5_1 = new byte[2]; Array.Copy(PLCQueryRx6, 403, tmparrayERst5_1, 0, 2); //5196 //convert Byte array to int Int32 erst5_1 = (Int32)(BitConverter.ToInt16(tmparrayERst5_1, 0)); byte[] tmparrayERst5_2 = new byte[2]; Array.Copy(PLCQueryRx6, 359, tmparrayERst5_2, 0, 2); //5174 //convert Byte array to int Int32 erst5_2 = (Int32)(BitConverter.ToInt16(tmparrayERst5_2, 0)); ErrCode5_2 = erst5_2.ToString(); ErrCode5_1 = erst5_1.ToString(); ErrCode5 = erst5.ToString(); #region NewErrorCode if (erst5 > 0 || erst5_1 > 0 || erst5_2 > 0) { // LogEr.Info("Station 5 Error Code"+ErrCode5+ErrCode5_1+ErrCode5_2); Errmessage5 = "Stn.5 Err " + (erst5 > 0 ? ErrCode5 + ": " + Stn5ErrToMsg(erst5) : "") + (erst5_1 > 0 && erst5 != erst5_1 ? ", " + ErrCode5_1 + ": " + Stn5ErrToMsg(erst5_1) : "") + (erst5_2 > 0 && erst5 != erst5_2 ? ", " + ErrCode5_2 + ": " + Stn5ErrToMsg(erst5_2) : ""); if (!ST5JamFlag) { bool St5JamTrig = ST2PauseFunction(5, erst5 + ";" + erst5_1 + ";" + erst5_2); //Check if is a JAM if (St5JamTrig) { ST5JamFlag = true; //string[] FLbatch = rq.UpdJamstatus(5, 555); //Update Jam FL //if (FLbatch != null) //{ // networkmain.Client_SendEventMsg("536", "Station5FLJAMRecovery", FLbatch);//Update Jam recovery FL to middleware //} } } } else { ST5JamFlag = false; Errmessage5 = String.Empty; } #endregion #region OldCode //if (erst5 > 0 || erst5_1 > 0 || erst5_2 > 0) //{ // // LogEr.Info("Station 5 Error Code"+ErrCode5+ErrCode5_1+ErrCode5_2); // Errmessage5 = "Stn.5 Err " + // (erst5 > 0 ? ErrCode5 + ": " + Stn5ErrToMsg(erst5) : "") + // (erst5_1 > 0 && erst5 != erst5_1 ? ", " + ErrCode5_1 + ": " + Stn5ErrToMsg(erst5_1) : "") + // (erst5_2 > 0 && erst5 != erst5_2 ? ", " + ErrCode5_2 + ": " + Stn5ErrToMsg(erst5_2) : ""); // // LogEr.Info(Errmessage5); //} //else //{ // Errmessage5 = String.Empty; //} #endregion UpdateErrorMsg((int)Station.StationNumber.Station05, Errmessage5, ST5JamFlag); if ((erst5 > 0) && networkmain.controlst5 == 0) { Errst5 = erst5.ToString(); networkmain.controlst5 = 1; messagest5 = Stn5ErrToMsg(erst5); networkmain.Client_SendAlarmMessage5(erst5.ToString(), messagest5, "SET"); } if (erst5 == 0 && networkmain.controlst5 == 1) { networkmain.Client_SendAlarmMessage5(Errst5, messagest5, "CLEAR"); networkmain.controlst5 = 0; Errst5 = ""; messagest5 = ""; } if ((erst5_1 > 0) && (erst5_1 != erst5) && networkmain.controlst5_1 == 0) { Errst5_1 = erst5_1.ToString(); networkmain.controlst5_1 = 1; messagest5_1 = Stn5ErrToMsg(erst5_1); networkmain.Client_SendAlarmMessage5(erst5_1.ToString(), messagest5_1, "SET"); } if (erst5_1 == 0 && networkmain.controlst5_1 == 1) { networkmain.Client_SendAlarmMessage5(Errst5_1, messagest5_1, "CLEAR"); networkmain.controlst5_1 = 0; Errst5_1 = ""; messagest5_1 = ""; } if (erst5_2 > 0 && erst5 != erst5_2 && (erst5_1 != erst5_2) && networkmain.controlst5_2 == 0) { Errst5_2 = erst5_2.ToString(); networkmain.controlst5_2 = 1; messagest5_2 = Stn5ErrToMsg(erst5_2); networkmain.Client_SendAlarmMessage5(erst5_2.ToString(), messagest5_2, "SET"); } if (erst5_2 == 0 && networkmain.controlst5_2 == 1) { networkmain.Client_SendAlarmMessage5(Errst5_2, messagest5_2, "CLEAR"); networkmain.controlst5_2 = 0; Errst5_2 = ""; messagest5_2 = ""; } #endregion } } // break; } catch (Exception ex) { log.Error(ex.ToString()); } } }
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()); } } }
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()); } } }