//void PLCScanBCallback(string bar) //{ // GlobalVar.AddMessage(bar); // if (bar != "Error") // { // plc.PLCWrite(STATE, "M262", "FF00"); // } // else // { // plc.PLCWrite(STATE, "M264", "FF00"); // } // SaveCSVfileBarcode(bar); //} //private void SaveCSVfileBarcode(string bar) //{ // string filepath = "D:\\生产记录\\条码" + GlobalVar.GetBanci() + ".csv"; // if (!Directory.Exists("D:\\生产记录")) // { // Directory.CreateDirectory("D:\\生产记录"); // } // try // { // if (!File.Exists(filepath)) // { // string[] heads = { "Date", "Barcode"}; // Csvfile.AddNewLine(filepath, heads); // } // string[] conte = { System.DateTime.Now.ToString(), bar }; // Csvfile.AddNewLine(filepath, conte); // } // catch (Exception ex) // { // GlobalVar.AddMessage(ex.Message); // } //} private void SaveCSVfileAlarm(string alrstr) { string filepath = "D:\\报警记录\\报警记录" + GlobalVar.GetBanci() + ".csv"; if (!Directory.Exists("D:\\报警记录")) { Directory.CreateDirectory("D:\\报警记录"); } try { if (!File.Exists(filepath)) { string[] heads = { "AlarmDate", "MachineID", "UserID", "AlarmMessage" }; Csvfile.AddNewLine(filepath, heads); } string[] conte = { System.DateTime.Now.ToString(), GlobalVar.MachineID, GlobalVar.UserID, alrstr }; Csvfile.AddNewLine(filepath, conte); } catch (Exception ex) { GlobalVar.AddMessage(ex.Message); } }
private void DispatcherTimerAction(Object sender, EventArgs e) { if (!File.Exists(@"D:\Maintain.csv")) { string[] heads = { "时间", "机台号", "触发次数", "扫码次数", "上传次数" }; Csvfile.AddNewLine(@"D:\Maintain.csv", heads); } if (LastCleanRecordFlag != GetBanciDate() + GetBanci()) { LastCleanRecordFlag = GetBanciDate() + GetBanci(); Inifile.INIWriteValue(ParameterIniPath, "Record", "LastCleanRecordFlag", LastCleanRecordFlag); if (!Directory.Exists("D:\\" + LastCleanRecordFlag)) { Directory.CreateDirectory("D:\\" + LastCleanRecordFlag); } string[] count = { DateTime.Now.ToString(), JiTaiHao, TrigerTimes.ToString(), ScanTimes.ToString(), UpdateTimes.ToString() }; Csvfile.AddNewLine(@"D:\Maintain.csv", count); TrigerTimes = 0; ScanTimes = 0; UpdateTimes = 0; Inifile.INIWriteValue(ParameterIniPath, "Times", "TrigerTimes", TrigerTimes.ToString()); Inifile.INIWriteValue(ParameterIniPath, "Times", "ScanTimes", ScanTimes.ToString()); Inifile.INIWriteValue(ParameterIniPath, "Times", "UpdateTimes", UpdateTimes.ToString()); MsgText = AddMessage("记录清空"); } if (recordItemList.Count > 0) { lock (LockObject) { foreach (RecordItem item in recordItemList) { RecordCollection.Add(item); } recordItemList.Clear(); } } }
private void WriteRecordtoExcel(DP6SQLROW dP6SQLROW, bool flag) { string bcstr = GetBanci(); string filename = @"D:\Record\" + bcstr + ".csv"; if (!flag) { filename = @"D:\NotUpdate.csv"; } try { if (!File.Exists(filename)) { string[] heads = { "BLDATE", "BLID", "BLNAME", "BLUID", "BLMID", "Bar" }; Csvfile.AddNewLine(filename, heads); } string[] conte = { dP6SQLROW.BLDATE, dP6SQLROW.BLID, dP6SQLROW.BLNAME, dP6SQLROW.BLUID, dP6SQLROW.BLMID, dP6SQLROW.Bar }; Csvfile.AddNewLine(filename, conte); } catch (Exception ex) { MsgText = AddMessage(ex.Message); } }
public void PlcRun() { bool first = true; bool scanFlag = false; Random rd = new Random(); while (true) { System.Threading.Thread.Sleep(10); if (Xinjie == null) { System.Threading.Thread.Sleep(1000); } else { try { PLCConnect = Xinjie.ReadM(24576); if (PLCConnect) { PlcIn = Xinjie.ReadMultiMCoil(1500); Xinjie.WritMultiMCoil(1800, PlcOut); Xinjie.WriteW(150, rd.Next(0, 999).ToString()); dd8170 = Xinjie.ReadD(16554); dd4208 = Xinjie.ReadD(4208); RotalAngle = (dd8170 - dd4208) / 91776 * 360; //扫码 if (scanFlag != PlcIn[0]) { scanFlag = PlcIn[0]; if (scanFlag) { Abarcode_f = false; Bbarcode_f = false; PlcOut[0] = false; PlcOut[1] = false; PlcOut[2] = false; Xinjie.WritMultiMCoil(1800, PlcOut); ScanA.GetBarCode(ScanActionCallback1); ScanB.GetBarCode(ScanActionCallback2); TrigerTimes++; Inifile.INIWriteValue(ParameterIniPath, "Times", "TrigerTimes", TrigerTimes.ToString()); } else { PlcOut[0] = false; } } if (Abarcode_f && Bbarcode_f) { Abarcode_f = false; Bbarcode_f = false; PlcOut[0] = true; PlcOut[1] = Abarcode_s; PlcOut[2] = Bbarcode_s; if (Abarcode_s && Bbarcode_s) { ScanTimes++; Inifile.INIWriteValue(ParameterIniPath, "Times", "ScanTimes", ScanTimes.ToString()); } RecordItem recordItem = new RecordItem(); recordItem.日期 = GetBanciDate(); recordItem.班次 = GetBanci(); recordItem.机台号 = JiTaiHao; recordItem.产品barcode = Abarcode; recordItem.机台穴号 = Bbarcode; lock (LockObject) { recordItemList.Add(recordItem); } if (Directory.Exists("D:\\" + GetBanciDate() + GetBanci())) { string filename = "D:\\" + GetBanciDate() + GetBanci() + "\\" + GetBanciDate() + GetBanci() + ".csv"; if (File.Exists(filename)) { string[] heads = { "日期", "班次", "机台号", "机台穴号", "产品barcode" }; Csvfile.AddNewLine(filename, heads); } string[] count = { recordItem.日期, recordItem.班次, recordItem.机台号, recordItem.机台穴号, recordItem.产品barcode }; Csvfile.AddNewLine(filename, count); } } } else { if (first) { first = false; } else { MsgText = AddMessage("PLC断线,重新连接..."); } Xinjie.ModbusDisConnect(); System.Threading.Thread.Sleep(1000); Xinjie.ModbusInit(PLCPortCom, 19200, System.IO.Ports.Parity.Even, 8, System.IO.Ports.StopBits.One); Xinjie.ModbusConnect(); } } catch (Exception ex) { MsgText = AddMessage(ex.Message); PLCConnect = false; } } } }
private void SaveCSVfileBarcode(string bar, int index) { string filepath = "F:\\生产记录\\条码" + GlobalVar.GetBanci() + ".csv"; if (!Directory.Exists("F:\\生产记录")) { Directory.CreateDirectory("F:\\生产记录"); } try { if (!File.Exists(filepath)) { string[] heads = { "Date", "Index", "Barcode", "MachineID", "UserID", "ProductName", "MachineName", "FactoryArea", "FactorySeparation", "ZhijuClass", "Barcodeproofing", "scancodetype", "CCD", "NNNN", }; Csvfile.AddNewLine(filepath, heads); } string[] conte = { System.DateTime.Now.ToString(), index.ToString(), bar, GlobalVar.MachineID, GlobalVar.UserID, GlobalVar.ProductName, GlobalVar.MachineName, GlobalVar.FactoryArea, GlobalVar.FactorySeparation, GlobalVar.ZhijuClass, GlobalVar.Barcodeproofing, GlobalVar.scancodetype, GlobalVar.CCD, GlobalVar.NNNN, }; Csvfile.AddNewLine(filepath, conte); MESDataItem tr = new MESDataItem() { Date = System.DateTime.Now.ToString(), Index = index.ToString(), Barcode = bar, MachineID = GlobalVar.MachineID, UserID = GlobalVar.UserID, ProductName = GlobalVar.ProductName, MachineName = GlobalVar.MachineName, FactoryArea = GlobalVar.FactoryArea, FactorySeparation = GlobalVar.FactorySeparation, ZhijuClass = GlobalVar.ZhijuClass, Barcodeproofing = GlobalVar.Barcodeproofing, scancodetype = GlobalVar.scancodetype, CCD = GlobalVar.CCD, NNNN = GlobalVar.NNNN, }; lock (GlobalVar.obj1) { // GlobalVar.AlarmRecord.Add(tr); GlobalVar.MESDataRecordQueue.Enqueue(tr); } string para1 = GlobalVar.MAC + "|" + GlobalVar.CCD + "," + GlobalVar.NNNN + "," + GlobalVar.ProductName + "," + GlobalVar.MachineID + "," + GlobalVar.UserID + "," + GlobalVar.MachineName + "," + GlobalVar.ZhijuClass + "," + GlobalVar.Barcodeproofing + "," + GlobalVar.FactoryArea + "," + GlobalVar.FactorySeparation + "," + GlobalVar.scancodetype + "," + bar; //进程锁住,防止与自动重传操作冲突 lock (GlobalVar.obj2) { DataSet ds = webServiceSZ.ws.getDataFromSer("MAC", "MAC", GlobalVar.MachineID, "MWS01", "MWS_ZX01", para1, System.DateTime.Now.ToShortDateString()); GlobalVar.AddMessage("上传信息;" + para1); GlobalVar.AddMessage(ds.Tables[0].Rows[0].ItemArray[0].ToString()); if (!ds.Tables[0].Rows[0].ItemArray[0].ToString().Contains("OK")) { string configPath = System.Environment.CurrentDirectory + "\\ReUpdateData.config"; if (File.Exists(configPath)) { try { //如果文件存在则先读出来 FileStream fileStream = new FileStream(configPath, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryFormatter mBinFmat = new BinaryFormatter(); UploadData Ud = mBinFmat.Deserialize(fileStream) as UploadData; fileStream.Close(); //追加记录,并覆盖原文件 Ud.ReUpdate.Add(new Tuple <string, DateTime>(para1, DateTime.Now)); fileStream = new FileStream(configPath, FileMode.Create); BinaryFormatter b = new BinaryFormatter(); b.Serialize(fileStream, Ud); fileStream.Close(); GlobalVar.AddMessage(bar + " 上传失败,保存到本地"); } catch (Exception ex) { GlobalVar.AddMessage(ex.Message); } } else { try { //如果文件不存在则直接创建 UploadData Ud = new UploadData(); Ud.ReUpdate.Add(new Tuple <string, DateTime>(para1, DateTime.Now)); FileStream fileStream = new FileStream(configPath, FileMode.Create); BinaryFormatter b = new BinaryFormatter(); b.Serialize(fileStream, Ud); fileStream.Close(); GlobalVar.AddMessage(bar + " 上传失败,保存到本地"); } catch (Exception ex) { GlobalVar.AddMessage(ex.Message); } } } } } catch (Exception ex) { GlobalVar.AddMessage(ex.Message); } }