public Main() { //CheckForIllegalCrossThreadCalls = false; main = this; InitializeComponent(); //显示版本号 this.Text += " " + Application.ProductVersion.ToString(); lblLine.Text += Pqm.line; lblLine.Visible = NTRSjudge.Layout.lineSwitch; //新建文件夹(log、pqm、sum) Document.CreateDocument(); //载入统计信息 try { TxtTotal.Text = Sum.ReadTotal(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n请检查下面统计文件格式或删除文件清零\r\n" + Document.pathList[2] + "total_yield.txt" , "载入统计文件", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(0); } //创建注册表文件 try { Registry.LocalMachine.CreateSubKey(@"software\NTRS"); } catch (Exception ex) { MessageBox.Show(ex.Message); Environment.Exit(0); } //验证(串口) if (!Regedit.verifyPort()) { checkPort: DialogResult dr = MessageBox.Show("串口验证失败,\n按确定键重新设置串口属性或关闭程序。", "错误", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (dr == DialogResult.No) { Environment.Exit(0); } Port port = new Port(); port.ShowDialog(); if (!Regedit.verifyPort()) { goto checkPort; } } //验证(运动轨迹) if (!Regedit.verifyTrajectory()) { checkTrajectory: DialogResult dr = MessageBox.Show("运动轨迹验证失败,\n按确定键重新设置运动轨迹或关闭程序。", "错误", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (dr == DialogResult.No) { Environment.Exit(0); } Trajectory trajectory = new Trajectory(); trajectory.ShowDialog(); if (!Regedit.verifyTrajectory()) { goto checkTrajectory; } } #region 布局 TlpLayout.RowCount = NTRSjudge.Layout.row; TlpLayout.ColumnCount = NTRSjudge.Layout.col; for (int i = 0; i < NTRSjudge.Layout.row; i++) { TlpLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); } for (int i = 0; i < NTRSjudge.Layout.col; i++) { TlpLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); } /* * for (int i = 0; i < NTRSjudge.Layout.row; i++) * { * for (int j = 0; j < NTRSjudge.Layout.col; j++) * { * Label label = new Label(); * label.Dock = DockStyle.Fill; * label.BackColor = Color.Red; * label.Text = "\r\n\r\n\r\n(" + (i + 1).ToString() + "," + (j + 1).ToString() + ")"; * tableLayoutPanel1.Controls.Add(label, j, i); * //下面这句要是在行和列不够的情况下,会建到100行1000列 * //tableLayoutPanel1.Controls.Add(label1, 100, 1000); * } * } */ #endregion //定时执行 SetTaskAtFixedTime(); }
void Action(string SN) { Application.DoEvents(); //填满之后,清空 object sender = new object { }; if (sequence == NTRSjudge.Layout.sum) { BtnClear_Click(sender, new EventArgs()); } //if (mode == Mode.旧机器 && !SN.Contains("ERROR")) // SN = SN.Substring(0, 17); if (!SN.Contains("ERROR")) { SN = SN.Substring(0, 17); } Judge.judge(SN); //Judge.judge("ERROR"); TxtSN.Text = string.Empty; #region 生产模式(不同方式串口发送信息) //接收(光子云拍照):一整盘由","隔开的SN //ERROR,GH945678901LKRQ01,......GH945678901LKRQ64, //发送:一整盘ok发"ok,",存在非"PASS"发送"ng," //"ok," "ng," //MessageBox.Show("away API,mode="+mode.ToString()); if (mode == Mode.光子云)//光子云 { if (AllInfo.SNlist.Count == NTRSjudge.Layout.sum) { string sendStr = "ok,"; foreach (var var in AllInfo.SNlist) { if (var.result != "PASS") { sendStr = "ng,"; break; } } SptReceiveOrSend.Write(sendStr); MessageShow(ChkTest_ShowMessage.Checked, "mode=" + mode + ",串口1发出" + sendStr.Length + "字节Byte:\r\n" + sendStr); } } //接收(扫描器):一个接一个的SN //ERROR GH945678901LKRQ01 //发送:一整盘ok发"0",存在非"PASS"发送坐标 //"0" "X0 = 2,Y0 = 3,X1 = 4,Y1 = 5," //(第2行第3列,第4行第5列材料NG,需要捡出) else if (mode == Mode.大研)//大研 { if (AllInfo.SNlist.Count == NTRSjudge.Layout.sum) { //string sendStr =type + snInfo.firstTime.ToString("yyyyMMddHHmmss"); string sendStr = Pqm.type + Pqm.line.Remove(0, 1) + Pqm.process.Substring(0, 1) + AllInfo.SNlist[AllInfo.SNlist.Count - 1].firstTime.ToString("yyMMddHHmmss").Remove(0, 1); for (int i = 1; i <= AllInfo.SNlist.Count; i++) { if (AllInfo.SNlist[i - 1].result != "PASS") { //如果"01.02.05."去掉"."的话,要是串口数据丢失一个,后面全部都会识别错误 //不去掉"."的话,只会识别丢失的位置 if (i < 10) { sendStr += "0" + i.ToString(); } else { sendStr += i.ToString(); } } } SptReceiveOrSend.Write(sendStr + "\r\n"); MessageShow(ChkTest_ShowMessage.Checked, "mode=" + mode + ",串口1发出" + (sendStr.Length + 1).ToString() + "字节Byte:\r\n" + sendStr + "\r\n(回车)"); } } //每次接收分析后发一个信号给串口 //接收(扫描器):一个接一个的SN+"," //GH945678901LKRQ01, //发送:根据结果"MISS"、"PASS"、"FAIL"、"SKIP"分别发送他们的头一个字母 //"M" "P" "F" "S" else if (mode == Mode.单片机)//单片机 { switch (AllInfo.SNlist[AllInfo.SNlist.Count - 1].result) { case "MISS": SptSend.Write("M"); MessageShow(ChkTest_ShowMessage.Checked, "mode=" + mode + ",串口2发出1字节Byte:\r\nM"); break; case "PASS": SptSend.Write("P"); MessageShow(ChkTest_ShowMessage.Checked, "mode=" + mode + ",串口2发出1字节Byte:\r\nP"); break; case "FAIL": SptSend.Write("F"); MessageShow(ChkTest_ShowMessage.Checked, "mode=" + mode + ",串口2发出1字节Byte:\r\nF"); break; case "HOLD": SptSend.Write("F"); MessageShow(ChkTest_ShowMessage.Checked, "mode=" + mode + ",串口2发出1字节Byte:\r\nF"); break; case "SKIP": SptSend.Write("S"); MessageShow(ChkTest_ShowMessage.Checked, "mode=" + mode + ",串口2发出1字节Byte:\r\nS"); break; default: SptSend.Write("F"); MessageShow(ChkTest_ShowMessage.Checked, "mode=" + mode + ",串口2发出1字节Byte:\r\nF"); break; } } //发送错误坐标或ok //接收(光子云拍照):一整盘由","隔开的SN //ERROR,GH945678901LKRQ01,......GH945678901LKRQ64, //发送:一整盘ok发"ok",存在非"PASS"发送坐标加".",最后结尾都加回车 //"ok\r\n" "1,1.1,2\r\n" else if (mode == Mode.ONS)//供应商 { if (AllInfo.SNlist.Count == NTRSjudge.Layout.sum) { string sendStr = ""; for (int i = 0; i < AllInfo.SNlist.Count; i++) { if (AllInfo.SNlist[i].result != "PASS") { //固定布局(竖排或横排) //int x = i / APP_Config.row; //int y = i % APP_Config.row; //sendStr += (x + 1).ToString() + "," + (y + 1).ToString() + "."; sendStr += Regedit.Trajectory[i] + "."; } } if (sendStr == "") { sendStr = "ok"; } //SptSend.WriteLine(sendStr);// SptSend.Write(sendStr + "\r\n"); MessageShow(ChkTest_ShowMessage.Checked, "mode=" + mode + ",串口2发出" + (sendStr.Length + 1).ToString() + "字节Byte:\r\n" + sendStr + "\r\n(回车)"); } } #endregion //方块布局显示 int[] location = Array.ConvertAll(Regedit.Trajectory[sequence].Split(','), int.Parse); try { TlpLayout.Controls.Add(NTRSjudge.Layout.paint(AllInfo.SNlist[AllInfo.SNlist.Count - 1]), location[0] - 1, location[1] - 1); } catch (Exception ex) { MessageBox.Show(ex.Message); } //数据显示 SNlab.Text = AllInfo.SNlist[AllInfo.SNlist.Count - 1].SN; TxtDetail.Text = AllInfo.SNlist[AllInfo.SNlist.Count - 1].detail; LblJudge.Text = AllInfo.SNlist[AllInfo.SNlist.Count - 1].result; //写log Log.WriteLog(SNlab.Text, TxtDetail.Text, LblJudge.Text); //非"MISS"("PASS"、"FAIL"、"SKIP"),写sum和csv if (LblJudge.Text != "MISS") { switch (LblJudge.Text) { case "PASS": Sum.passQty++; break; case "FAIL": Sum.failQty++; break; case "SKIP": Sum.skipQty++; break; } Sum.WriteTotal(); TxtTotal.Text = Sum.ReadTotal(); Pqm.WriteCSV(AllInfo.SNlist[AllInfo.SNlist.Count - 1]); } sequence++; }