private void AppLoadedEventCommandExecute() { AddMessage("软件加载完成"); try { Mysql mysql = new Mysql(); if (mysql.Connect()) { string stm = $"SELECT NOW()"; DataSet ds = mysql.Select(stm); AddMessage($"数据库连接成功{ ds.Tables["table0"].Rows[0][0]}"); StatusDataBase = true; } else { AddMessage("数据库未连接"); StatusDataBase = false; } mysql.DisConnect(); } catch (Exception ex) { AddMessage($"数据库连接失败{ex.Message}"); StatusDataBase = false; } tcpServer = new DXH.Net.DXHTCPServer(); tcpServer.LocalIPAddress = Inifile.INIGetStringValue(iniParameterPath, "Server", "IP", "127.0.0.1"); tcpServer.LocalIPPort = int.Parse(Inifile.INIGetStringValue(iniParameterPath, "Server", "PORT", "11001")); tcpServer.SocketListChanged += TcpServer_SocketListChanged; tcpServer.ConnectStateChanged += TcpServer_ConnectStateChanged; tcpServer.Received += TcpServer_Received; tcpServer.StartTCPListen(); Run(); }
public Server(PluginLoadData pluginLoadData) : base(pluginLoadData) { // Connection to DB DB = DataBase.getInstance().mysql; DB.Connect(pluginLoadData.DatabaseManager.GetConnectionString("db")); ClientManager.ClientConnected += ClientConnected; }
public void StartMySql() { Mysql repo = new Mysql(); if (repo.Connect()) { Console.WriteLine("MySQL connection established successfully."); moviesRepo = repo; // RenderMenu(); } else { Console.WriteLine("Connection to DB failed. Program can't work... Sorry.."); } }
async void AlarmAction(int i) { while (true) { await Task.Delay(100); try { if (LampGreenSw.Elapsed.TotalMinutes > 3) { break; } } catch (Exception ex) { AddMessage("AlarmAction" + ex.Message); } } AlarmList[i].End = DateTime.Now; AddMessage(AlarmList[i].Code + AlarmList[i].Content + "解除"); TimeSpan time = AlarmList[i].End - AlarmList[i].Start - LampGreenSw.Elapsed; string result = await Task <string> .Run(() => { try { int _result = -999; Mysql mysql = new Mysql(); if (mysql.Connect()) { string stm = string.Format("INSERT INTO HA_F4_DATA_ALARM (PM, GROUP1,TRACK,MACID,NAME,SSTARTDATE,SSTARTTIME,SSTOPDATE,SSTOPTIME,TIME,CLASS,WORKSTATION) VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')" , _PM, _GROUP1, _TRACK, _MACID, AlarmList[i].Content, AlarmList[i].Start.ToString("yyyyMMdd"), AlarmList[i].Start.ToString("HHmmss"), AlarmList[i].End.ToString("yyyyMMdd"), AlarmList[i].End.ToString("HHmmss"), time.TotalMinutes.ToString("F1"), GetBanci(), _WORKSTATION); _result = mysql.executeQuery(stm); } mysql.DisConnect(); return(_result.ToString()); } catch (Exception ex) { return(ex.Message); } }); AddMessage("插入报警" + result); }
private async void FreeBordBarcodeButtonClick(object sender, RoutedEventArgs e) { string barcode = BordBarcode.Text; if (barcode != "") { BordBarcode.Text = ""; string result = await Task <string> .Run(() => { try { Mysql mysql = new Mysql(); string rst = "-999"; if (mysql.Connect()) { string stm = "SELECT * FROM BODMSG WHERE SCBODBAR = '" + barcode + "' ORDER BY SIDATE DESC LIMIT 0,5"; DataSet ds = mysql.Select(stm); DataTable dt = ds.Tables["table0"]; if (dt.Rows.Count > 0) { stm = "INSERT INTO BODMSG (SCBODBAR, STATUS) VALUES('" + barcode + "','OFF')"; rst = mysql.executeQuery(stm).ToString(); } else { rst = "信息未录入"; } } mysql.DisConnect(); return(barcode + "解绑 " + rst); } catch (Exception ex) { return(ex.Message); } }); AddMessage(result); } else { AddMessage("条码为空"); } }
private void FreeBordBarcodeButtonClick(object sender, RoutedEventArgs e) { if (BordBarcode.Text != "") { try { Mysql mysql = new Mysql(); if (mysql.Connect()) { string stm = "SELECT * FROM BODMSG WHERE SCBODBAR = '" + BordBarcode.Text + "' ORDER BY SIDATE DESC LIMIT 0,5"; DataSet ds = mysql.Select(stm); DataTable dt = ds.Tables["table0"]; if (dt.Rows.Count > 0) { if ((string)dt.Rows[0]["STATUS"] == "OFF") { AddMessage("板 " + BordBarcode.Text + " 已处于解绑状态"); } else { stm = "INSERT INTO BODMSG (SCBODBAR, STATUS) VALUES('" + BordBarcode.Text + "','OFF')"; mysql.executeQuery(stm); AddMessage("板 " + BordBarcode.Text + " 解绑"); BordBarcode.Text = ""; } } else { AddMessage("板 " + BordBarcode.Text + " 信息无记录"); } } mysql.DisConnect(); } catch (Exception ex) { AddMessage(ex.Message); } } }
private void AppLoadedEventCommandExecute() { AddMessage("软件加载完成"); try { Mysql mysql = new Mysql(); if (mysql.Connect()) { string stm = $"SELECT NOW()"; DataSet ds = mysql.Select(stm); AddMessage($"数据库连接成功{ ds.Tables["table0"].Rows[0][0]}"); StatusDataBase = true; } else { AddMessage("数据库未连接"); StatusDataBase = false; } mysql.DisConnect(); } catch (Exception ex) { AddMessage($"数据库连接失败{ex.Message}"); StatusDataBase = false; } #region 初始化相机 if (mycam.OpenCamera(cameraName, cameraInterface)) { AddMessage("相机打开成功"); } else { AddMessage("相机打开失败"); } #endregion tcpNet.StartTCPConnect(); Run(); }
void CheckBarcode(string barcode, int index) { if (barcode != "Error") { try { Mysql mysql = new Mysql(); if (mysql.Connect()) { string stm = "SELECT * FROM BODMSG WHERE SCBODBAR = '" + barcode + "' ORDER BY SIDATE DESC LIMIT 0,5"; DataSet ds = mysql.Select(stm); DataTable dt = ds.Tables["table0"]; if (dt.Rows.Count > 0) { if (dt.Rows[0]["STATUS"] == DBNull.Value) { AddMessage("板 " + barcode + " 状态栏位为空"); switch (index) { case 0: Fx5u.SetM("M2505", true); break; case 1: Fx5u.SetM("M2507", true); break; default: break; } } else { if ((string)dt.Rows[0]["STATUS"] == "OFF") { AddMessage("板 " + barcode + " 是未测板"); switch (index) { case 0: Fx5u.SetM("M2505", true); break; case 1: Fx5u.SetM("M2507", true); break; default: break; } } else { stm = "INSERT INTO BODMSG (SCBODBAR, STATUS) VALUES('" + barcode + "','OFF')"; AddMessage("板 " + barcode + " 解绑"); mysql.executeQuery(stm); stm = "SELECT * FROM BARBIND WHERE SCBODBAR = '" + barcode + "' ORDER BY SIDATE DESC LIMIT 0,96"; ds = mysql.Select(stm); dt = ds.Tables["table0"]; if (dt.Rows.Count == 96) { //string datetimestr = (string)dt.Rows[0]["SIDATE"]; short[] result = new short[96]; bool checkrst = true; for (int i = 0; i < 96; i++) { DataRow[] drs = dt.Select(string.Format("PCSSER = '{0}'", (BordIndex[i]).ToString())); if (drs.Length == 1) { try { result[i] = short.Parse((string)drs[0]["RESULT"]); } catch (Exception ex) { AddMessage(ex.Message); checkrst = false; break; } } else { AddMessage("板 " + barcode + " 序号 " + (BordIndex[i]).ToString() + "索引数 " + drs.Length.ToString()); checkrst = false; break; } } if (checkrst) { string str; switch (index) { case 0: Fx5u.WriteMultD("D1000", result); str = "A_BordInfo;"; for (int i = 0; i < 96; i++) { str += result[i].ToString() + ";"; } str = str.Substring(0, str.Length - 1); AddMessage(str); Fx5u.SetM("M2504", true); break; case 1: Fx5u.WriteMultD("D1100", result); str = "B_BordInfo;"; for (int i = 0; i < 96; i++) { str += result[i].ToString() + ";"; } str = str.Substring(0, str.Length - 1); AddMessage(str); Fx5u.SetM("M2506", true); break; default: break; } } else { switch (index) { case 0: Fx5u.SetM("M2505", true); break; case 1: Fx5u.SetM("M2507", true); break; default: break; } } } else { AddMessage("板 " + barcode + " 产品信息条目 " + dt.Rows.Count.ToString() + " < 96"); switch (index) { case 0: Fx5u.SetM("M2505", true); break; case 1: Fx5u.SetM("M2507", true); break; default: break; } } } } } else { AddMessage("板 " + barcode + " 信息未录入"); switch (index) { case 0: Fx5u.SetM("M2505", true); break; case 1: Fx5u.SetM("M2507", true); break; default: break; } } } else { AddMessage("Mysql数据库查询失败"); switch (index) { case 0: Fx5u.SetM("M2505", true); break; case 1: Fx5u.SetM("M2507", true); break; default: break; } } mysql.DisConnect(); } catch (Exception ex) { AddMessage(ex.Message); } } else { switch (index) { case 0: Fx5u.SetM("M2505", true); break; case 1: Fx5u.SetM("M2507", true); break; default: break; } } }
void ScanBGetBarcodeCallback(string barcode) { if (barcode != "Error") { Mysql mysql = new Mysql(); if (mysql.Connect()) { string stm = "SELECT * FROM BODMSG WHERE SCBODBAR = '" + barcode + "' ORDER BY SIDATE DESC LIMIT 0,5"; DataSet ds = mysql.Select(stm); DataTable dt = ds.Tables["table0"]; if (dt.Rows.Count > 0) { if (dt.Rows[0]["STATUS"] == DBNull.Value) { this.Dispatcher.Invoke(new Action(() => { AddMessage("板 " + barcode + " 状态栏位为空"); })); Fx5u_2.SetM("M2605", true);//载具扫码-未测过【B轨道】 } else { if ((string)dt.Rows[0]["STATUS"] == "OFF") { this.Dispatcher.Invoke(new Action(() => { AddMessage("板 " + barcode + " 未测试"); })); Fx5u_2.SetM("M2605", true);//载具扫码-未测过【B轨道】 } else { stm = "SELECT * FROM BARBIND WHERE SCBODBAR = '" + barcode + "' ORDER BY SIDATE DESC LIMIT 0,15"; ds = mysql.Select(stm); dt = ds.Tables["table0"]; if (dt.Rows.Count == 15) { stm = "INSERT INTO BODMSG (SCBODBAR, STATUS) VALUES('" + barcode + "','OFF')"; int rstnum = mysql.executeQuery(stm); if (rstnum > 0) { this.Dispatcher.Invoke(new Action(() => { AddMessage("板 " + barcode + " 解绑"); })); short[] result = new short[15]; bool checkrst = true; for (int i = 0; i < 15; i++) { DataRow[] drs = dt.Select(string.Format("PCSSER = '{0}'", (i + 1).ToString())); if (drs.Length == 1) { try { result[i] = short.Parse((string)drs[0]["RESULT"]); } catch (Exception ex) { this.Dispatcher.Invoke(new Action(() => { AddMessage(ex.Message); })); checkrst = false; break; } } else { this.Dispatcher.Invoke(new Action(() => { AddMessage("板 " + barcode + " 序号 " + (i + 1).ToString() + "索引数 " + drs.Length.ToString()); })); checkrst = false; break; } } if (checkrst) { string str; Fx5u_2.WriteMultD("D1020", result); str = "B_BordInfo;"; for (int i = 0; i < 15; i++) { str += result[i].ToString() + ";"; } str = str.Substring(0, str.Length - 1); this.Dispatcher.Invoke(new Action(() => { AddMessage(str); })); Fx5u_2.SetM("M2604", true);//载具扫码-已测过【B轨道】 } else { Fx5u_2.SetM("M2605", true);//载具扫码-未测过【B轨道】 } } else { this.Dispatcher.Invoke(new Action(() => { AddMessage("解绑失败"); })); Fx5u_2.SetM("M2603", true);//载具扫码NG【B轨道】 } } else { this.Dispatcher.Invoke(new Action(() => { AddMessage("板 " + barcode + " 记录数目不是15"); })); Fx5u_2.SetM("M2605", true);//载具扫码-未测过【B轨道】 } } } } else { this.Dispatcher.Invoke(new Action(() => { AddMessage("板 " + barcode + " 信息未录入"); })); Fx5u_2.SetM("M2605", true); //载具扫码-未测过【A轨道】 } Fx5u_2.SetM("M2602", true); //载具扫码OK【B轨道】 } mysql.DisConnect(); } else { this.Dispatcher.Invoke(new Action(() => { AddMessage("扫码失败"); })); Fx5u_2.SetM("M2603", true);//载具扫码NG【B轨道】 } }
async void BigDataRun() { int _LampColor = LampColor; int count1 = 0; LampGreenSw.Start(); bool first = true; while (true) { await Task.Delay(1000);//每秒刷新 #region 报警 if (M300 != null && Fx5u_2.Connect) { for (int i = 0; i < AlarmList.Count; i++) { if (M300[i] != AlarmList[i].State && AlarmList[i].Content != "Null" && (LampGreenSw.Elapsed.TotalMinutes > 3 || first)) { first = false; LampGreenSw.Reset(); AlarmList[i].State = M300[i]; if (AlarmList[i].State) { CurrentAlarm = AlarmList[i].Content; AlarmList[i].Start = DateTime.Now; AlarmList[i].End = DateTime.Now; AddMessage(AlarmList[i].Code + AlarmList[i].Content + "发生"); AlarmAction(i);//等待报警结束 } } } } #endregion #region 灯号更新 switch (LampColor) { case 1: LampGreenElapse += 1; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampGreenElapse", LampGreenElapse.ToString()); break; case 2: LampGreenFlickerElapse += 1; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampGreenFlickerElapse", LampGreenFlickerElapse.ToString()); break; case 3: LampYellowElapse += 1; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampYellowElapse", LampYellowElapse.ToString()); break; case 4: LampYellowFlickerElapse += 1; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampYellowFlickerElapse", LampYellowFlickerElapse.ToString()); break; case 5: LampRedElapse += 1; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampRedElapse", LampRedElapse.ToString()); break; default: break; } count1++; if (_LampColor != LampColor || count1 > 60) { if (LampColor == 1 && _LampColor != LampColor) { LampGreenSw.Restart(); } _LampColor = LampColor; count1 = 0; string result = await Task <string> .Run(() => { try { int _result = -999; Mysql mysql = new Mysql(); if (mysql.Connect()) { string currentAlarm = LampColor == 4 ? CurrentAlarm : "NA"; string stm = string.Format("UPDATE HA_F4_LIGHT SET LIGHT = '{3}',SDATE = '{4}',STIME = '{5}',ALARM = '{6}',TIME_1 = '{8}',TIME_2 = '{9}',TIME_3 = '{10}',TIME_4 = '{11}',TIME_5 = '{12}' WHERE PM = '{0}' AND LIGHT_ID = '{1}' AND MACID = '{2}' AND CLASS = '{7}'" , _PM, _LIGHT_ID, _MACID, LampColor.ToString(), DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), currentAlarm, GetBanci(), ((double)LampGreenElapse / 60).ToString("F2"), ((double)LampGreenFlickerElapse / 60).ToString("F2"), ((double)LampYellowElapse / 60).ToString("F2") , ((double)LampYellowFlickerElapse / 60).ToString("F2"), ((double)LampRedElapse / 60).ToString("F2")); _result = mysql.executeQuery(stm); } mysql.DisConnect(); return(_result.ToString()); } catch (Exception ex) { return(ex.Message); } }); //AddMessage("更新灯信号" + result); } if (LampColor != 1) { LampGreenSw.Reset(); } if (LampColor == 1 && LampGreenSw.Elapsed == TimeSpan.Zero) { LampGreenSw.Restart(); } #endregion #region 机台指标 #endregion GreenElapse.Text = LampGreenSw.Elapsed.TotalMinutes.ToString("F1") + " min"; } }
async void UpdateUI() { while (true) { await Task.Delay(200); #region 更新界面 if (Fx5u.Connect) { EllipsePLCState.Fill = Brushes.Green; } else { EllipsePLCState.Fill = Brushes.Red; } if (Fx5u_2.Connect) { EllipsePLCState2.Fill = Brushes.Green; } else { EllipsePLCState2.Fill = Brushes.Red; } CycleText.Text = SWms.ToString() + " ms"; #endregion #region 换班 if (LastBanci != GetBanci()) { LastBanci = GetBanci(); Inifile.INIWriteValue(iniParameterPath, "Summary", "LastBanci", LastBanci); LampGreenElapse = 0; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampGreenElapse", LampGreenElapse.ToString()); LampGreenFlickerElapse = 0; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampGreenFlickerElapse", LampGreenFlickerElapse.ToString()); LampYellowElapse = 0; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampYellowElapse", LampYellowElapse.ToString()); LampYellowFlickerElapse = 0; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampYellowFlickerElapse", LampYellowFlickerElapse.ToString()); LampRedElapse = 0; Inifile.INIWriteValue(iniParameterPath, "BigData", "LampRedElapse", LampRedElapse.ToString()); await Task.Run(() => { Mysql mysql = new Mysql(); try { int _result = -999; if (mysql.Connect()) { string stm = string.Format("INSERT INTO HA_F4_LIGHT (PM,LIGHT_ID,MACID,CLASS,LIGHT,SDATE,STIME,ALARM,TIME_1,TIME_2,TIME_3,TIME_4,TIME_5,GROUP1,TRACK,WORKSTATION) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','0','0','0','0','0','{8}','{9}','{10}')" , _PM, _LIGHT_ID, _MACID, GetBanci(), LampColor.ToString(), DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), "NA", _GROUP1, _TRACK, _WORKSTATION); _result = mysql.executeQuery(stm); } this.Dispatcher.Invoke(new Action(() => { AddMessage("插入数据库灯信号" + _result.ToString()); })); } catch (Exception ex) { this.Dispatcher.Invoke(new Action(() => { AddMessage(ex.Message); })); } finally { mysql.DisConnect(); } }); Fx5u_2.SetM("M2606", true); CardLockFlag = true; CardLockTime = DateTime.Now; AddMessage("机台锁定!"); AddMessage(LastBanci + " 换班数据清零"); } #endregion } }
private void TcpServer_Received(object sender, string e) { string restr = e.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)[0]; AddMessage("接收:" + restr); Task.Run(() => { try { if (Directory.Exists(WorkPath)) { DirectoryInfo folder = new DirectoryInfo(WorkPath); int cout = 0; FileInfo[] files = folder.GetFiles(restr); while (!(files.Length > 0 && !IsFileLocked(files[0])) && cout < 10) { files = folder.GetFiles(restr); cout++; System.Threading.Thread.Sleep(200); } if (cout < 10) { string[] vs = files[0].Name.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); if (vs.Length == 3) { HObject img; HOperatorSet.ReadImage(out img, files[0].FullName); CameraIamge = new HImage(img); if (!Directory.Exists(Path.Combine(ImageSavePath, vs[1]))) { Directory.CreateDirectory(Path.Combine(ImageSavePath, vs[1])); } string[] vs1 = vs[2].Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); if (!Directory.Exists(Path.Combine(ImageSavePath, vs[1], vs1[0]))) { Directory.CreateDirectory(Path.Combine(ImageSavePath, vs[1], vs1[0])); } File.Copy(files[0].FullName, Path.Combine(ImageSavePath, vs[1], vs1[0], files[0].Name), true); string str = files[0].FullName; File.Delete(str); Mysql mysql = new Mysql(); if (mysql.Connect()) { string stm = ""; switch (vs[1]) { case "M1": stm = $"INSERT INTO aviproductdata (BoardID,PcsIndex,ResultItem1) VALUES ('{vs[0]}',{vs1[0]},'OK')"; break; case "M2": stm = $"UPDATE aviproductdata SET ResultItem2 = 'OK' WHERE BoardID = '{vs[0]}' AND PcsIndex = {vs1[0]}"; break; case "M3": stm = $"UPDATE aviproductdata SET ResultItem3 = 'OK' WHERE BoardID = '{vs[0]}' AND PcsIndex = {vs1[0]}"; break; case "M4": stm = $"UPDATE aviproductdata SET ResultItem4 = 'OK' WHERE BoardID = '{vs[0]}' AND PcsIndex = {vs1[0]}"; break; default: break; } int result = mysql.executeQuery(stm); if (result < 1) { AddMessage("请注意,数据库插入失败"); } StatusDataBase = true; } else { AddMessage("数据库未连接"); StatusDataBase = false; } mysql.DisConnect(); AddMessage($"{str}文件处理完成"); } else { string str = files[0].FullName; File.Delete(str); AddMessage($"{str}文件名非法,已删除"); } } else { AddMessage($"获取文件{restr}超时"); } } } catch (Exception ex) { AddMessage(ex.Message); } }); }
private async void Run() { Mysql mysql; int result; await Task.Delay(1000); while (true) { try { switch (StationNo) { case 1: #region 1号机内容 if (H3u.ReadM("M2000")) { AddMessage("进料位-等待进板"); H3u.SetM("M2000", false); short[] newBoard = new short[70]; for (int i = 0; i < 70; i++) { Random rd = new Random(); if (rd.Next(100) < 80) { newBoard[i] = 1; } else { newBoard[i] = 0; } } H3u.WriteMultD("D4000", newBoard); await Task.Delay(500); H3u.SetM("M2100", true); AddMessage("进料位-进板完成"); } if (H3u.ReadM("M2011")) { AddMessage("工位1-进板完成"); H3u.SetM("M2011", false); mysql = new Mysql(); if (await Task.Run <bool>(() => { return(mysql.Connect()); })) { var guid = Guid.NewGuid(); CurBoardID = guid.ToString(); string stm = $"UPDATE avilinestate SET M1BoardID = '{guid}'"; result = mysql.executeQuery(stm); if (result > 0) { AddMessage($"板编号 {guid}_{MachineID} 更新成功"); } } else { AddMessage("数据库未连接"); StatusDataBase = false; } mysql.DisConnect(); } if (H3u.ReadM("M2010")) { int d2010 = H3u.ReadW("D2010"); AddMessage($"工位1-{d2010}-开始拍照"); H3u.SetM("M2010", false); if (mycam.GrabImage(0, false)) { AddMessage("拍照成功"); CameraIamge = mycam.CurrentImage; if (await Task.Run <bool>(() => { return(mycam.SaveImage("bmp", Path.Combine(RemotePath, $"{CurBoardID}_{MachineID}_{d2010}.bmp"))); })) { AddMessage("图片保存成功"); tcpNet.TCPSend($"{CurBoardID}_{MachineID}_{d2010}.bmp"); } else { AddMessage("图片保存失败"); } H3u.SetM("M2110", true); } } #endregion break; case 2: #region 2号机内容 if (H3u.ReadM("M2021")) { AddMessage("工位2-进板完成"); H3u.SetM("M2021", false); mysql = new Mysql(); if (await Task.Run <bool>(() => { return(mysql.Connect()); })) { string stm = $"SELECT * FROM avilinestate LIMIT 1"; DataSet ds = mysql.Select(stm); DataTable dt = ds.Tables["table0"]; CurBoardID = (string)dt.Rows[0]["M1BoardID"]; stm = $"UPDATE avilinestate SET M2BoardID = '{CurBoardID}'"; result = mysql.executeQuery(stm); if (result > 0) { AddMessage($"板编号 {CurBoardID}_{MachineID} 更新成功"); } } else { AddMessage("数据库未连接"); StatusDataBase = false; } mysql.DisConnect(); } if (H3u.ReadM("M2020")) { int d2020 = H3u.ReadW("D2020"); AddMessage($"工位2-{d2020}-开始拍照"); H3u.SetM("M2020", false); if (mycam.GrabImage(0, false)) { AddMessage("拍照成功"); CameraIamge = mycam.CurrentImage; if (await Task.Run <bool>(() => { return(mycam.SaveImage("bmp", Path.Combine(RemotePath, $"{CurBoardID}_{MachineID}_{d2020}.bmp"))); })) { AddMessage("图片保存成功"); tcpNet.TCPSend($"{CurBoardID}_{MachineID}_{d2020}.bmp"); } else { AddMessage("图片保存失败"); } H3u.SetM("M2120", true); } } #endregion break; case 3: #region 3号机内容 if (H3u.ReadM("M2031")) { AddMessage("工位3-进板完成"); H3u.SetM("M2031", false); mysql = new Mysql(); if (await Task.Run <bool>(() => { return(mysql.Connect()); })) { string stm = $"SELECT * FROM avilinestate LIMIT 1"; DataSet ds = mysql.Select(stm); DataTable dt = ds.Tables["table0"]; CurBoardID = (string)dt.Rows[0]["M2BoardID"]; stm = $"UPDATE avilinestate SET M3BoardID = '{CurBoardID}'"; result = mysql.executeQuery(stm); if (result > 0) { AddMessage($"板编号 {CurBoardID}_{MachineID} 更新成功"); } } else { AddMessage("数据库未连接"); StatusDataBase = false; } mysql.DisConnect(); } if (H3u.ReadM("M2030")) { int d2030 = H3u.ReadW("D2030"); AddMessage($"工位3-{d2030}-开始拍照"); H3u.SetM("M2030", false); if (mycam.GrabImage(0, false)) { AddMessage("拍照成功"); CameraIamge = mycam.CurrentImage; if (await Task.Run <bool>(() => { return(mycam.SaveImage("bmp", Path.Combine(RemotePath, $"{CurBoardID}_{MachineID}_{d2030}.bmp"))); })) { AddMessage("图片保存成功"); tcpNet.TCPSend($"{CurBoardID}_{MachineID}_{d2030}.bmp"); } else { AddMessage("图片保存失败"); } H3u.SetM("M2130", true); } } #endregion break; case 4: #region 4号机内容 if (H3u.ReadM("M2041")) { AddMessage("工位4-进板完成"); H3u.SetM("M2041", false); mysql = new Mysql(); if (await Task.Run <bool>(() => { return(mysql.Connect()); })) { string stm = $"SELECT * FROM avilinestate LIMIT 1"; DataSet ds = mysql.Select(stm); DataTable dt = ds.Tables["table0"]; CurBoardID = (string)dt.Rows[0]["M3BoardID"]; stm = $"UPDATE avilinestate SET M4BoardID = '{CurBoardID}'"; result = mysql.executeQuery(stm); if (result > 0) { AddMessage($"板编号 {CurBoardID}_{MachineID} 更新成功"); } } else { AddMessage("数据库未连接"); StatusDataBase = false; } mysql.DisConnect(); } if (H3u.ReadM("M2040")) { int d2040 = H3u.ReadW("D2040"); AddMessage($"工位4-{d2040}-开始拍照"); H3u.SetM("M2040", false); if (mycam.GrabImage(0, false)) { AddMessage("拍照成功"); CameraIamge = mycam.CurrentImage; if (await Task.Run <bool>(() => { return(mycam.SaveImage("bmp", Path.Combine(RemotePath, $"{CurBoardID}_{MachineID}_{d2040}.bmp"))); })) { AddMessage("图片保存成功"); tcpNet.TCPSend($"{CurBoardID}_{MachineID}_{d2040}.bmp"); } else { AddMessage("图片保存失败"); } H3u.SetM("M2140", true); } } #endregion break; default: break; } StatusPLC = H3u.ConnectState; } catch (Exception ex) { AddMessage(ex.Message); } await Task.Delay(100); } }
private void OperateButtonCommandExecute(object obj) { switch (obj.ToString()) { case "0": if (EStopIsChecked) { //急停按钮按下 AddMessage("急停按钮按下"); try { Mysql mysql = new Mysql(); if (mysql.Connect()) { string stm = $"UPDATE avilinestate SET M1State = -1"; int result = mysql.executeQuery(stm); if (result < 1) { AddMessage("数据库更新失败"); StatusDataBase = false; } else { StatusDataBase = true; } } else { AddMessage("数据库未连接"); StatusDataBase = false; } mysql.DisConnect(); } catch (Exception ex) { AddMessage($"数据库连接失败{ex.Message}"); StatusDataBase = false; } } else { //急停按钮抬起 AddMessage("急停按钮抬起"); try { Mysql mysql = new Mysql(); if (mysql.Connect()) { string stm = $"UPDATE avilinestate SET M1State = 0,M2State = 0,M3State = 0,M4State = 0"; int result = mysql.executeQuery(stm); if (result < 1) { AddMessage("数据库更新失败"); StatusDataBase = false; } else { StatusDataBase = true; } } else { AddMessage("数据库未连接"); StatusDataBase = false; } mysql.DisConnect(); } catch (Exception ex) { AddMessage($"数据库连接失败{ex.Message}"); StatusDataBase = false; } } break; case "1": //Inifile.INIWriteValue(iniParameterPath, "System", "CameraName", "[0] Integrated Camera"); //Inifile.INIWriteValue(iniParameterPath, "System", "CameraInterface", "DirectShow"); //AddMessage("待添加内容"); if (mycam.GrabImage(0, false)) { AddMessage("拍照成功"); CameraIamge = mycam.CurrentImage; } else { AddMessage("拍照失败"); } break; case "2": break; default: break; } }
private async void UIRun() { int oldMinute = -1; string CurrentAlarm = ""; if (!Directory.Exists("D:\\报警记录")) { Directory.CreateDirectory("D:\\报警记录"); } while (true) { #region 报警记录 await Task.Delay(100); try { //读报警 bool[] M300 = await Task.Run <bool[]>(() => { return(h3u.ReadMultiM("M300", (ushort)AlarmList.Count)); }); if (M300 != null && StatusPLC) { for (int i = 0; i < AlarmList.Count; i++) { if (M300[i] != AlarmList[i].State && AlarmList[i].Content != "Null") { AlarmList[i].State = M300[i]; if (AlarmList[i].State) { AlarmList[i].Start = DateTime.Now; AlarmList[i].End = DateTime.Now; AddMessage(AlarmList[i].Code + AlarmList[i].Content + "发生"); if (CurrentAlarm != AlarmList[i].Content) { var nowAlarm = AlarmReportForm.FirstOrDefault(s => s.Code == AlarmList[i].Code); if (nowAlarm == null) { AlarmReportFormViewModel newAlarm = new AlarmReportFormViewModel() { Code = AlarmList[i].Code, Content = AlarmList[i].Content, Count = 1, TimeSpan = AlarmList[i].End - AlarmList[i].Start }; AlarmReportForm.Add(newAlarm); } else { nowAlarm.Count++; } WriteToJson(AlarmReportForm, System.IO.Path.Combine(System.Environment.CurrentDirectory, "AlarmReportForm.json")); #region 写报警记录 string banci = GetBanci(); if (!File.Exists(Path.Combine("D:\\报警记录", "VPP报警记录" + banci + ".csv"))) { string[] heads = new string[] { "时间", "内容" }; Csvfile.savetocsv(Path.Combine("D:\\报警记录", "VPP报警记录" + banci + ".csv"), heads); } string[] conts = new string[] { AlarmList[i].Start.ToString(), AlarmList[i].Content }; Csvfile.savetocsv(Path.Combine("D:\\报警记录", "VPP报警记录" + banci + ".csv"), conts); #endregion #region string Banci = (DateTime.Now.Hour >= 8 && DateTime.Now.Hour < 20) ? "D" : "N"; SZRFUI.Models.Mysql mysql = new Mysql(); if (mysql.Connect()) { string stm = "insert into TED_WARN_DATA (WORKSTATION,PARTNUM,MACID,LOADID,PETID,TDATE,TTIME,CLASS,WARNID,DETAILID,WARNNUM,FL01,FL02,FL03,FL04,FL05,FL06,FL07,FL08,FL09,FL10,SUPPLIER,WARNVER) value('" + TestStation + "','" + ProgramName + "','" + MachineNumber + "','" + MachineNumber + "','','" + DateTime.Now.ToString("yyyyMMdd") + "','" + DateTime.Now.ToString("HHmmss") + "','" + Banci + "','" + AlarmList[i].Content + "','','1','','','','','','','','','','','" + Supplier + "','" + WARNVER + "')"; mysql.executeQuery(stm); } mysql.DisConnect(); #endregion CurrentAlarm = AlarmList[i].Content; } } else { AlarmList[i].End = DateTime.Now; AddMessage(AlarmList[i].Code + AlarmList[i].Content + "解除"); var nowAlarm = AlarmReportForm.FirstOrDefault(s => s.Code == AlarmList[i].Code); if (nowAlarm != null) { nowAlarm.TimeSpan += AlarmList[i].End - AlarmList[i].Start; WriteToJson(AlarmReportForm, System.IO.Path.Combine(System.Environment.CurrentDirectory, "AlarmReportForm.json")); } } } } } } catch (Exception ex) { AddMessage(ex.Message); } #endregion #region 心跳 await Task.Run(() => { if (DateTime.Now.Minute != oldMinute) { oldMinute = DateTime.Now.Minute; #region 心跳 try { int item = h3u.ReadD("D300"); string Status = ""; switch (item) { case 1: Status = "R"; break; case 2: Status = "H"; break; case 3: Status = "A"; break; default: break; } if (item > 0 && item < 4) { Mysql mysql = new Mysql(); if (mysql.Connect()) { string stm = "insert into TED_HEART_DATA (TestStation,MachineNumber,TestDate,TestTime,AlarmCode,Status,ProgramName,Barcode,SystemDate,SystemTime,SUPPLIER) value('" + TestStation + "','" + MachineNumber + "','" + DateTime.Now.ToString("yyyyMMdd") + "','" + DateTime.Now.ToString("HHmmss") + "','NA','" + Status + "','" + ProgramName + "','NA','" + DateTime.Now.ToString("yyyyMMdd") + "','" + DateTime.Now.ToString("HHmmss") + "','" + Supplier + "')"; mysql.executeQuery(stm); } mysql.DisConnect(); AddMessage("上传心跳:" + Status); } else { AddMessage("读取心跳值异常" + item.ToString()); } } catch (Exception ex) { AddMessage(ex.Message); } #endregion } }); #endregion #region 换班 if (LastBanci != GetBanci()) { try { WriteAlarmtoExcel(Path.Combine("D:\\报警记录", "RF报警统计" + LastBanci + ".xlsx")); AlarmReportForm.Clear(); WriteToJson(AlarmReportForm, System.IO.Path.Combine(System.Environment.CurrentDirectory, "AlarmReportForm.json")); LastBanci = GetBanci(); Inifile.INIWriteValue(iniParameterPath, "Summary", "LastBanci", LastBanci); AddMessage(LastBanci + " 换班数据清零"); } catch (Exception ex) { AddMessage(ex.Message); } } #endregion await Task.Delay(200); } }