Ejemplo n.º 1
0
 public void ThStreamFirstLineEmptyRunning()//第一条流线-自动
 {
     while (true)
     {
         try
         {
             Main.frmMain.ListBoxDisplay("流线1--运行开始-----------------------");
             Main.frmMain.ListBoxDisplay("流线1--等待流线1入料感应感应有产品");
             Main.frmMain.PauseCheck();//暂停
             //do//等待流线1入料感应感应到
             //{
             //    Thread.Sleep(10);
             //    Application.DoEvents();
             //    Main.frmMain.PauseCheck();//暂停
             //} while (GClsMontion.ReadCardExtendInputBit(0, 10) != 1);
             Thread.Sleep(100);
             for (int i = 0; i < 12; i++)                                                               //加载流线1产品选择使能
             {
                 Main.frmMain.dgvData.Rows[27].Cells[i + 1].Value = CAMiClsVariable.isProductSelect[i]; //流线1产品使能放置在27行
             }
             //CAMiClsVariable.CCD1productSelectNO = 0;
             //for (int i = 0; i < 12; i++)
             //{
             //    CAMiClsVariable.CCD1productSelectNO += Convert.ToInt32(Main.frmMain.dgvData.Rows[27].Cells[i + 1].Value);
             //}
             //Main.frmMain.ListBoxDisplay(string.Format("流线1--流线1产品需检测的个数为{0}", CAMiClsVariable.CCD1productSelectNO));
             CAMiClsMethod.StreamCCDDataClear(1);           //清空数据存放区
             Main.frmMain.PauseCheck();                     //暂停
             Main.frmMain.ListBoxDisplay("流线1--流线1启动");
             GClsMontion.WriteCardExtendOutputBit(0, 6, 1); //流线1启动
             Main.frmMain.ListBoxDisplay("流线1--等待流线1到位感应1感应");
             //do//等待流线有料感应2
             //{
             //    Thread.Sleep(10);
             //    Application.DoEvents();
             //    Main.frmMain.PauseCheck();//暂停
             //} while (GClsMontion.ReadCardExtendInputBit(0, 11) != 1);
             Main.frmMain.PauseCheck();//暂停
             Main.frmMain.ListBoxDisplay("流线1--等待流线1到位感应2感应");
             //do//等待到位2感应
             //{
             //    Thread.Sleep(10);
             //    Application.DoEvents();
             //    Main.frmMain.PauseCheck();//暂停
             //} while (GClsMontion.ReadCardExtendInputBit(0, 12) != 1);
             Thread.Sleep(200);                             //先延时再停止,根据需求更改
             Main.frmMain.PauseCheck();                     //暂停
             Main.frmMain.ListBoxDisplay("流线1--停止流线1");
             GClsMontion.WriteCardExtendOutputBit(0, 6, 0); //流线1停止
             Main.frmMain.PauseCheck();                     //暂停
             CAMiClsMethod.StreamTrayLocate(1);             //流线1产品定位
             Main.frmMain.PauseCheck();                     //暂停
             Main.frmMain.ListBoxDisplay("流线1--清空CCD1缓存数据");
             //CAMiClsVariable.cClient.ClientReceive(1, 0);
             Main.frmMain.ListBoxDisplay("流线1--定位结束,开始拍照");
             //开始拍照
             #region CCD1拍照
             for (int i = 0; i < 12; i++)
             {
                 if (Main.frmMain.dgvData.Rows[27].Cells[i + 1].Value.ToString() == "1") //穴位使能打开
                 {
                     Main.frmMain.PauseCheck();                                          //暂停
                     Main.frmMain.ListBoxDisplay("流线1--运行到CCD1-第" + (i + 1).ToString() + "个拍照位置");
                     GClsMontion.AbsoluteMove(0, CAMiClsVariable.CCD1PosXValue[i], CAMiClsVariable.speedCCD1X, CAMiClsVariable.TaccCCD1X);
                     GClsMontion.AbsoluteMove(1, CAMiClsVariable.CCD1PosYValue[i], CAMiClsVariable.speedCCD1Y, CAMiClsVariable.TaccCCD1Y);
                     GClsMontion.WaitMotorStop(0);
                     GClsMontion.WaitMotorStop(1);
                     Main.frmMain.PauseCheck();                    //暂停
                     Thread.Sleep(10);
                     Main.frmMain.ListBoxDisplay("流线1--CCD1拍照触发"); //拍照触发
                     Main.frmMain.PauseCheck();                    //暂停
                     //CAMiClsVariable.cClient.ClientSend(1, (CAMiClsVariable.strTrig1 + ",0," + (i + 1).ToString()));
                     Main.frmMain.PauseCheck();                    //暂停
                     Thread.Sleep(10);
                     //CAMiClsVariable.strCCD1Recv = CAMiClsMethod.ReceiveData(i, 1);
                     //if (CAMiClsVariable.strCCD1Recv.Substring(0, 2) != "T1")
                     //{
                     //    MessageBox.Show("CCD1 拍照T1反馈异常");
                     //}
                     Main.frmMain.ListBoxDisplay("流线1--等待CCD1-第" + (i + 1).ToString() + "个反馈结果");
                 }
                 Main.frmMain.PauseCheck(); //暂停
             }
             Main.frmMain.PauseCheck();     //暂停
             Main.frmMain.ListBoxDisplay("CCD1X轴/CCD1Y轴运动到初始位置");
             GClsMontion.AbsoluteMove(0, CAMiClsVariable.CCD1InitialPosX, CAMiClsVariable.speedCCD1X, CAMiClsVariable.TaccCCD1X);
             GClsMontion.AbsoluteMove(1, CAMiClsVariable.CCD1InitialPosY, CAMiClsVariable.speedCCD1Y, CAMiClsVariable.TaccCCD1Y);
             Main.frmMain.ListBoxDisplay("流线1--获取CCD1数据");
             //while (CAMiClsVariable.strRecvCCD1Data2Array[CAMiClsVariable.CCD1productSelectNO - 1] == "0")
             //{
             //    CAMiClsVariable.recvCCD1DataNO = 0;
             //    CAMiClsVariable.strCCD1Recv = CAMiClsMethod.ReceiveData(0, 1);
             //}
             for (int i = 0; i < 12; i++)
             {
                 Main.frmMain.ListBoxDisplay("流线1--等待CCD1-第" + (i + 1).ToString() + "个反馈结果");
                 if (Convert.ToInt32(Main.frmMain.dgvData.Rows[27].Cells[i + 1].Value) == 1)//穴位使能打开
                 {
                     CAMiClsVariable.recvCCD1DataNO = 0;
                     for (int m = 0; m < i + 1; m++)
                     {
                         CAMiClsVariable.recvCCD1DataNO += Convert.ToInt32(Main.frmMain.dgvData.Rows[27].Cells[m + 1].Value);
                     }
                     //CAMiClsVariable.recvCCD1DataArray = CAMiClsVariable.strRecvCCD1Data2Array[CAMiClsVariable.recvCCD1DataNO - 1].Split(',');
                     //Main.frmMain.dictFirstLine.Clear();//清空数据
                     //for (int j = 0; j < CAMiClsVariable.recvCCD1DataArray.Length; j++)
                     //{
                     //    Main.frmMain.dictFirstLine.Add("第" + i.ToString() + "次拍照的第" + j.ToString() + "次结果", CAMiClsVariable.recvCCD1DataArray[j]);
                     //    Main.frmMain.dgvData.Rows[i + 1].Cells[j + 1].Value = CAMiClsVariable.recvCCD1DataArray[j];
                     //    Main.frmMain.ListBoxDisplay(string.Format("流线1--相机接收到第" + (i + 1).ToString() + "组数据的第" + (j + 1).ToString() + "个数据  {0}", CAMiClsVariable.recvCCD1DataArray[j]));
                     //}
                 }
             }
             #endregion
             Main.frmMain.PauseCheck();          //暂停
             CAMiClsMethod.StreamTrayRelease(1); //流线1产品放行
             Main.frmMain.ListBoxDisplay("流线1--等待流线2允许进料");
             do
             {
                 Thread.Sleep(10);
                 Application.DoEvents();
                 Main.frmMain.PauseCheck();//暂停
             } while (!CAMiClsVariable.isStreamLine2Ready);
             Thread.Sleep(1000);
             Main.frmMain.PauseCheck();    //暂停
             for (int i = 15; i < 27; i++) //清空数据用来放置流线1的数据
             {
                 for (int j = 1; j < 23; j++)
                 {
                     Main.frmMain.dgvData.Rows[i].Cells[j].Value = "";
                 }
             }
             CAMiClsVariable.isStreamLine1Done  = true;
             CAMiClsVariable.isStreamLine2Ready = false;
             Main.frmMain.ListBoxDisplay("流线1--转移数据至表格第15-26行");
             //for (int k = 0; k < 12; k++)
             //{
             //    for (int m = 0; m < CAMiClsVariable.recvCCD1DataArray.Length; m++)
             //    {
             //        Main.frmMain.dgvData.Rows[k + 15].Cells[m + 1].Value = Main.frmMain.dgvData.Rows[k + 1].Cells[m + 1].Value.ToString() != "" ? Main.frmMain.dgvData.Rows[k + 1].Cells[m + 1].Value : 1;
             //    }
             //}
             Main.frmMain.PauseCheck();                     //暂停
             Main.frmMain.ListBoxDisplay("流线1--启动流线1");
             GClsMontion.WriteCardExtendOutputBit(0, 8, 0); //流线1高速
             GClsMontion.WriteCardExtendOutputBit(0, 6, 1); //流线1启动
             Main.frmMain.PauseCheck();                     //暂停
             Main.frmMain.ListBoxDisplay("流线1--等待流线1产品流出");
             Thread.Sleep(3000);
             do//等待流线1到位感应无
             {
                 Thread.Sleep(10);
                 Application.DoEvents();
                 Main.frmMain.PauseCheck();//暂停
             } while (GClsMontion.ReadCardExtendInputBit(0, 11) == 1 || GClsMontion.ReadCardExtendInputBit(0, 12) == 1 ||
                      !CAMiClsVariable.isProductLocateInStreamLine2);
             Main.frmMain.PauseCheck();                            //暂停
             Main.frmMain.ListBoxDisplay("流线1--停止流线1");
             GClsMontion.WriteCardExtendOutputBit(0, 6, 0);        //流线1停止
             CAMiClsVariable.isProductLocateInStreamLine2 = false; //将流线2产品到位信号清掉
             Main.frmMain.ListBoxDisplay("流线1--流线1阻挡气缸伸出");
             CAMiClsCylinder.StreamLine1StopExtend();              //阻挡气缸伸出
             Main.frmMain.PauseCheck();                            //暂停
             Main.frmMain.ListBoxDisplay("等待CCD1X轴/CCD1Y轴运动到初始位置");
             GClsMontion.WaitMotorStop(0);
             GClsMontion.WaitMotorStop(1);
         }
         catch (Exception ex)
         {
             myEmptyMethod.LogRecord(ex.ToString());
         }
     }
 }