public static void Output(MSG_TYPE msgType, string name, string str) { if (s_myInstance == null) { s_myInstance = new SystemRecord(); } s_myInstance.logout(msgType, name, str); }
public static void Output(MSG_TYPE msgType, string name, string format, params object[] args) { if (s_myInstance == null) { s_myInstance = new SystemRecord(); } s_myInstance.logout(msgType, name, string.Format(format, args)); }
public MainWindow() { InitializeComponent(); string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Major.ToString(); //AssemblyVersion을 가져온다. version += "." + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString(); version += "." + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build.ToString(); Title = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " " + version; m_flowDoc = richTextBox.Document; m_flowDoc.LineHeight = 2; richTextBox.VerticalScrollBarVisibility = ScrollBarVisibility.Visible; m_observerLog = new EventBroker.EventObserver(OnReceiveLog); EventBroker.AddObserver(EventBroker.EventID.etLog, m_observerLog); SystemLog.Output(SystemLog.MSG_TYPE.War, Title, "Started "); SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "Record- Reset", DateTime.Now.ToString("dd-MM-yyyy")); machineOperations = new List <MachineOperation>(); machineOperationsOld = new List <MachineOperation>(); //timer.Interval = TimeSpan.FromMilliseconds(100); //timer.Tick += timer_Tick; //timer.IsEnabled = true; }
private DataMQC GetDataMQCRealtime(string IP, string line, DataMQC dataOld) { DataMQC dataMQC = null; try { Plc.Instance.Connect(IP, SettingClass.PLCTimeOut); if (Plc.Instance.ConnectionState == ConnectionStates.Online) {// doc barcode truoc var ListTag = Plc.Instance.ReadTags(tags); if (ListTag.Count == 4) { MachineOperation ma1 = new MachineOperation(); ma1.Line = line; ma1.IP = IP; ma1.Output = (ListTag[0].ItemValue.ToString() != null) ? double.Parse(ListTag[0].ItemValue.ToString()) : 0; ma1.NG = (ListTag[1].ItemValue.ToString() != null) ? double.Parse(ListTag[1].ItemValue.ToString()) : 0; ma1.Rework = (ListTag[2].ItemValue.ToString() != null) ? double.Parse(ListTag[2].ItemValue.ToString()) : 0; ma1.ONOFF = (ListTag[3].ItemValue.ToString() != null) ? ListTag[3].ItemValue.ToString() : ""; ma1.Status = Plc.Instance.ConnectionState.ToString(); if (dataOld != null) { #region Running if (dataOld.STARTSTOP == "False" && ma1.ONOFF == "False") { dataMQC = new DataMQC(); ma1.Lot = dataOld.PLC_Barcode; dataMQC.PLC_Barcode = dataOld.PLC_Barcode; dataMQC.Good_Products_Total = ma1.Output; dataMQC.NG_Products_Total = ma1.NG; dataMQC.RW_Products_Total = ma1.Rework; dataMQC.STARTSTOP = ma1.ONOFF; if (dataOld.PLC_Barcode != null && (dataOld.PLC_Barcode.Contains("0010;B01;B01") || dataOld.PLC_Barcode.Contains("0010;B01;B02"))) { dataMQC.NG_Products_NG_ = new int[38]; int CountNG = 0; int CountRW = 0; if (dataMQC.NG_Products_Total > dataOld.NG_Products_Total) { var ListNG = Plc.Instance.ReadTags(tagsError); foreach (var item in ListNG) { dataMQC.NG_Products_NG_[CountNG] = int.Parse(item.ItemValue.ToString()); CountNG++; } } else { dataMQC.NG_Products_NG_ = dataOld.NG_Products_NG_; } dataMQC.RW_Products_NG_ = new int[38]; if (dataMQC.RW_Products_Total > dataOld.RW_Products_Total) { var ListRW = Plc.Instance.ReadTags(tagsRework); foreach (var item in ListRW) { dataMQC.RW_Products_NG_[CountRW] = int.Parse(item.ItemValue.ToString()); CountRW++; } } else { dataMQC.RW_Products_NG_ = dataOld.RW_Products_NG_; } } else { var barcode = Plc.Instance.ReadTagsToString(tagsbarcode); dataMQC.PLC_Barcode = barcode; ma1.Lot = barcode; SystemLog.Output(SystemLog.MSG_TYPE.War, "Barcode is wrong format: IPMachine :", IP); } if (dataMQC.Good_Products_Total == 0 && dataMQC.NG_Products_Total == 0 && dataMQC.RW_Products_Total == 0) { var barcode = Plc.Instance.ReadTagsToString(tagsbarcode); dataMQC.PLC_Barcode = barcode; ma1.Lot = barcode; } machineOperations.Add(ma1); } #endregion #region chuyen giao giua chay va reset else if (dataOld.STARTSTOP == "False" && ma1.ONOFF == "True") { var barcode = Plc.Instance.ReadTagsToString(tagsbarcode); ma1.Lot = barcode; if (dataOld.PLC_Barcode != null && (dataOld.PLC_Barcode.Contains("0010;B01;B01") || dataOld.PLC_Barcode.Contains("0010;B01;B02"))) { dataMQC = new DataMQC(); ma1.Lot = barcode; dataMQC.PLC_Barcode = barcode; dataMQC.Good_Products_Total = ma1.Output; dataMQC.NG_Products_Total = ma1.NG; dataMQC.RW_Products_Total = ma1.Rework; dataMQC.STARTSTOP = ma1.ONOFF; dataMQC.NG_Products_NG_ = new int[38]; int CountNG = 0; int CountRW = 0; if (dataMQC.NG_Products_Total > dataOld.NG_Products_Total) { var ListNG = Plc.Instance.ReadTags(tagsError); foreach (var item in ListNG) { dataMQC.NG_Products_NG_[CountNG] = int.Parse(item.ItemValue.ToString()); CountNG++; } } else { dataMQC.NG_Products_NG_ = dataOld.NG_Products_NG_; } dataMQC.RW_Products_NG_ = new int[38]; if (dataMQC.RW_Products_Total > dataOld.RW_Products_Total) { var ListRW = Plc.Instance.ReadTags(tagsRework); foreach (var item in ListRW) { dataMQC.RW_Products_NG_[CountRW] = int.Parse(item.ItemValue.ToString()); CountRW++; } } else { dataMQC.RW_Products_NG_ = dataOld.RW_Products_NG_; } Uploaddata uploaddata = new Uploaddata(); uploaddata.InsertToMQC_Realtime(dataOld.PLC_Barcode, line, "", "0", "Reset", 0); if (SettingClass.usingOfftlineServer) { UploadLocalPLCDB uploadLocalPLCDB = new UploadLocalPLCDB(); uploadLocalPLCDB.InsertToMQC_Realtime(dataOld.PLC_Barcode, line, "", "0", "Reset", 0, SettingClass); } } else { dataMQC = dataOld; SystemLog.Output(SystemLog.MSG_TYPE.War, "Barcode is wrong format: IPMachine :", IP); } try { if (dataOld != null) { Uploaddata uploaddata = new Uploaddata(); string model = uploaddata.GetModelFromLot(dataOld.PLC_Barcode); SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "Line: " + line + " QR code: " + dataOld.PLC_Barcode + " Model: " + model, " Reset "); SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "Line: " + line + " QR code: " + dataOld.PLC_Barcode + " Model: " + model, " OP " + dataOld.Good_Products_Total); SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "Line: " + line + " QR code: " + dataOld.PLC_Barcode + " Model: " + model, " NG " + dataOld.NG_Products_Total); SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "Line: " + line + " QR code: " + dataOld.PLC_Barcode + " Model: " + model, " RW " + dataOld.RW_Products_Total); } } catch (Exception ex) { SystemLog.Output(SystemLog.MSG_TYPE.Err, "Write record reset not succesfull" + " Line: " + line + " QR code: " + dataOld.PLC_Barcode, ex.Message); } machineOperations.Add(ma1); } #endregion else if (dataOld.STARTSTOP == "True" && ma1.ONOFF == "True") { var barcode = Plc.Instance.ReadTagsToString(tagsbarcode); ma1.Lot = barcode; machineOperations.Add(ma1); dataMQC = new DataMQC(); dataMQC.STARTSTOP = ma1.ONOFF; dataMQC.PLC_Barcode = barcode; } else if (dataOld.STARTSTOP == "True" && ma1.ONOFF == "False") { var barcode = Plc.Instance.ReadTagsToString(tagsbarcode); ma1.Lot = barcode; machineOperations.Add(ma1); dataMQC = new DataMQC(); dataMQC.STARTSTOP = ma1.ONOFF; dataMQC.PLC_Barcode = barcode; } else { if (dataOld.STARTSTOP == null) { SystemLog.Output(SystemLog.MSG_TYPE.Err, "dataOld.STARTSTOP == null", ma1.Lot); } else if (ma1.ONOFF == null) { SystemLog.Output(SystemLog.MSG_TYPE.Err, "ma1.ONOFF == null", ma1.Lot); } var barcode = Plc.Instance.ReadTagsToString(tagsbarcode); ma1.Lot = barcode; machineOperations.Add(ma1); if (barcode != null && (barcode.Contains("0010;B01;B01") || barcode.Contains("0010;B01;B02"))) { dataMQC = new DataMQC(); ma1.Lot = barcode; dataMQC.PLC_Barcode = barcode; dataMQC.Good_Products_Total = ma1.Output; dataMQC.NG_Products_Total = ma1.NG; dataMQC.RW_Products_Total = ma1.Rework; dataMQC.STARTSTOP = ma1.ONOFF; dataMQC.NG_Products_NG_ = new int[38]; int CountNG = 0; int CountRW = 0; if (dataMQC.NG_Products_Total > dataOld.NG_Products_Total) { var ListNG = Plc.Instance.ReadTags(tagsError); foreach (var item in ListNG) { dataMQC.NG_Products_NG_[CountNG] = int.Parse(item.ItemValue.ToString()); CountNG++; } } else { dataMQC.NG_Products_NG_ = dataOld.NG_Products_NG_; } dataMQC.RW_Products_NG_ = new int[38]; if (dataMQC.RW_Products_Total > dataOld.RW_Products_Total) { var ListRW = Plc.Instance.ReadTags(tagsRework); foreach (var item in ListRW) { dataMQC.RW_Products_NG_[CountRW] = int.Parse(item.ItemValue.ToString()); CountRW++; } } else { dataMQC.RW_Products_NG_ = dataOld.RW_Products_NG_; } } else { dataMQC = dataOld; SystemLog.Output(SystemLog.MSG_TYPE.War, "Barcode is wrong format: IPMachine :", IP); } } } else { dataMQC = new DataMQC(); var barcode = Plc.Instance.ReadTagsToString(tagsbarcode); ma1.Lot = barcode; dataMQC.STARTSTOP = ma1.ONOFF; dataMQC.PLC_Barcode = barcode; dataMQC.Good_Products_Total = ma1.Output; dataMQC.NG_Products_Total = ma1.NG; dataMQC.RW_Products_Total = ma1.Rework; dataMQC.STARTSTOP = ma1.ONOFF; machineOperations.Add(ma1); SystemLog.Output(SystemLog.MSG_TYPE.War, "Data old = null: IPMachine :", IP); } } else { MachineOperation ma1 = new MachineOperation(); ma1.Line = line; ma1.IP = IP; ma1.Status = Plc.Instance.ConnectionState.ToString(); machineOperations.Add(ma1); dataMQC = dataOld; SystemLog.Output(SystemLog.MSG_TYPE.War, "Readtag fail: IPMachine ", IP); } } else { MachineOperation ma1 = new MachineOperation(); ma1.Line = line; ma1.IP = IP; ma1.Status = Plc.Instance.ConnectionState.ToString(); machineOperations.Add(ma1); dataMQC = dataOld; SystemLog.Output(SystemLog.MSG_TYPE.War, "Machine is offline", IP); } } catch (Exception ex) { SystemLog.Output(SystemLog.MSG_TYPE.Err, "DataMQC GetDataMQCRealtime line " + line, ex.Message); } return(dataMQC); }
void bg_DoWork(object sender, DoWorkEventArgs e) { // does a job like writing to serial communication, webservices etc var worker = sender as BackgroundWorker; stopwatch = new Stopwatch(); try { stopwatch.Start(); // if (ListMachines != null) { machineOperations = new List <MachineOperation>(); //MachineItem machine = new MachineItem(); //machine.IP = "172.16.1.145"; //machine.Line = "L03"; LoadAdress();//load list PLC machine foreach (var machine in ListMachines) { try { // machine.IP = MQCVariable mQCOld = new MQCVariable(); if (DicMQCVariableIP.ContainsKey(machine.IP)) { mQCOld = DicMQCVariableIP[machine.IP]; } MQCVariable mQCPLC = GetMQCVariableRealtime(machine.IP, mQCOld); MQCVariable mQCChanged = new MQCVariable(); if (mQCPLC.Connection == 0) { bool isChanged = false; List <string> listChanged = new List <string>(); // if (mQCPLC.DicSPLCtatus[VariablePLC.FlagKT] == true) { mQCChanged = GetMQCVariableDisCrepancy(mQCPLC, mQCOld, ref isChanged, ref listChanged); if (DicMQCVariableIP.ContainsKey(machine.IP)) { DicMQCVariableIP[machine.IP] = mQCPLC; } else { DicMQCVariableIP.Add(machine.IP, mQCPLC); } if (listChanged.Contains("Reset")) { //MachineOperation operation = new MachineOperation(); //operation.IP = machine.IP; //operation.Line = machine.Line; //operation.Lot = qRMQC_MES.PO; //operation.Inspector = qRIDMES.FullName; //operation.product = qRMQC_MES.Product; //operation.Output = mQCPLC.ListMQCQty[0]; //operation.NG = mQCPLC.ListMQCQty[1]; //operation.Rework = mQCPLC.ListMQCQty[2]; //operation.Status = "Reset"; SQLUpload.SQLQRUpdate sQLQRUpdate = new SQLQRUpdate(); sQLQRUpdate.UpdateOrInsertQRRecordTable(mQCOld, machine.Line); SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "QR MES Reset", mQCOld.QRMES); SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "QR Inspector", mQCOld.QRID); SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "Ouput Quantity", mQCOld.ListMQCQty[0].ToString()); SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "NG Quantity", mQCOld.ListMQCQty[1].ToString()); SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "RW Quantity", mQCOld.ListMQCQty[2].ToString()); return; } UploadPLCtoDatabase(mQCChanged, listChanged, machine.Line); QRMQC_MES qRMQC_MES = QRSpilittoClass.QRstring2MQCFormat(mQCPLC.QRMES); QRIDMES qRIDMES = QRSpilittoClass.QRstring2IDFormat(mQCPLC.QRID); MachineOperation operation = new MachineOperation(); operation.IP = machine.IP; operation.Line = machine.Line; operation.Lot = qRMQC_MES.PO; operation.Inspector = qRIDMES.FullName; operation.product = qRMQC_MES.Product; if (mQCPLC.ListMQCQty.Count == 3) { operation.Output = mQCPLC.ListMQCQty[0]; operation.NG = mQCPLC.ListMQCQty[1]; operation.Rework = mQCPLC.ListMQCQty[2]; operation.Status = "Updating"; } else if (mQCPLC.ListMQCQty.Count == 0) { operation.Output = 0; operation.NG = 0; operation.Rework = 0; operation.Status = "Waiting"; } //if (listChanged.Contains("Reset")) //{ // operation.Status = "Reset"; // //SQLUpload.SQLQRUpdate sQLQRUpdate = new SQLQRUpdate(); // //sQLQRUpdate.UpdateOrInsertQRRecordTable(mQCPLC, machine.Line); // SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "QR MES Reset", mQCPLC.QRMES); // SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "QR Inspector", mQCPLC.QRID); // SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "Ouput Quantity", mQCPLC.ListMQCQty[0].ToString()); // SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "NG Quantity", mQCPLC.ListMQCQty[1].ToString()); // SystemRecord.Output(SystemRecord.MSG_TYPE.Nor, "RW Quantity", mQCPLC.ListMQCQty[2].ToString()); //} //else //{ // operation.Status = "Updating"; //} machineOperations.Add(operation); } } else { MachineOperation operation = new MachineOperation(); operation.IP = machine.IP; operation.Line = machine.Line; Sharp7.S7Client client = new Sharp7.S7Client(); operation.Status = client.ErrorText(mQCPLC.Connection); machineOperations.Add(operation); } } catch (Exception ex) { SystemLog.Output(SystemLog.MSG_TYPE.Err, "PLC IP : " + machine.IP, ex.Message); } } } stopwatch.Stop(); } catch (Exception ex) { SystemLog.Output(SystemLog.MSG_TYPE.Err, "Read PLC fail", ex.Message); } System.Threading.Thread.Sleep(100); }