示例#1
0
        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++;
        }