Пример #1
0
 void WaitingPCIE(object LockWatingThread)
 {
     while (true)
     {
         pCH368 = CH368.CH367mOpenDevice(CH368Index, TRUE, TRUE, 0x00);
         if (pCH368 != (IntPtr)(-1))
         {
             this.Invoke((EventHandler)(delegate
             {
                 InitPCIE();
             }));
             return;
         }
         Thread.Sleep(1000);
         lock (LockWatingThread)
         {
             wp.SetProcessBarPerformStep();
             if (wp.HasBeenCancelled())
             {
                 this.Invoke((EventHandler)(delegate
                 {
                     this.Close();
                 }));
                 return;
             }
         }
     }
 }
 void WaitingStart(object LockWatingThread)
 {
     while (true)
     {
         TcpModbusPacket tp = form1.ReadPLC();
         if (tp != null)
         {
             ushort D100 = BytesOP.MakeByte(tp.Data[1], tp.Data[2]);
             if (BytesOP.GetBit(D100, 0))//系统已经启动
             {
                 form1.SetMotor(motorRev, motorTorque);
                 this.Invoke((EventHandler)(delegate
                 {
                     chart1.Series[0].Points.Clear();
                     waitTimer.Enabled = true;
                 }));
                 return;
             }
         }
         Thread.Sleep(1000);
         lock (LockWatingThread)
         {
             wpStart.SetProcessBarPerformStep();
             if (wpStart.HasBeenCancelled())
             {
                 return;
             }
         }
     }
 }
Пример #3
0
 void WaitingStart(object LockWatingThread)
 {
     while (true)
     {
         TcpModbusPacket tp = ReadPLC();
         if (tp != null)
         {
             ushort D100 = BytesOP.MakeByte(tp.Data[1], tp.Data[2]);
             if (BytesOP.GetBit(D100, 0))     //系统已经启动
             {
                 if (BytesOP.GetBit(D100, 1)) //判断正反转
                 {
                     bForeward = true;
                     this.Invoke((EventHandler)(delegate
                     {
                         listView1.Items[6].SubItems[1].Text = "正转";
                     }));
                 }
                 else
                 {
                     bForeward = false;
                     this.Invoke((EventHandler)(delegate
                     {
                         listView1.Items[6].SubItems[1].Text = "反转";
                     }));
                 }
                 SetMotor(openRev, NiuJuPID.sp);
                 motorRev    = openRev;
                 motorTorque = NiuJuPID.sp;
                 this.Invoke((EventHandler)(delegate
                 {
                     listView1.Items[6].SubItems[1].Text = openRev.ToString("F3");
                     listView2.Items[6].SubItems[1].Text = NiuJuPID.sp.ToString();
                     listView1.Items[1].SubItems[1].Text = "";
                     listView2.Items[1].SubItems[1].Text = "";
                     chart1.Series[0].Points.Clear();
                     chart1.Series[1].Points.Clear();
                     chart2.Series[0].Points.Clear();
                     chart2.Series[1].Points.Clear();
                     openTimes = 0;
                     openTimer.Enabled = true;
                 }));
                 return;
             }
         }
         Thread.Sleep(1000);
         lock (LockWatingThread)
         {
             wpStart.SetProcessBarPerformStep();
             if (wpStart.HasBeenCancelled())
             {
                 return;
             }
         }
     }
 }
 void WaitingExposureVerify(object LockWatingThread)
 {
     while (true)
     {
         double miu;
         double delta;
         double miuCC;
         this.Invoke((EventHandler)(delegate
         {
             exposureVerifyChart.Series["miu"].Points.Clear();
             exposureVerifyChart.Series["delta"].Points.Clear();
             exposureVerifyChart.Series["miuCC"].Points.Clear();
             for (int step = 0; step < SystemParam.n; step++)
             {
                 WFGlobal.WaitMS(1);
                 int ex = SystemParam.NTmin + step * SystemParam.NTexp;
                 tcpCCS.LightSet(SystemParam.lambda_Oe, SystemParam.Oe);
                 exposureVerifyListView.Items[4].SubItems[1].Text = step.ToString();
                 if (!UDPProc.CollectImage(this, ex, 2))
                 {
                     exposureVerifyWaitingProc.ExitWatting();
                     return;
                 }
                 UDPProc.ccdImageList[0].save(SystemParam.TempPicPath + "Ev" + step.ToString() + "_0.bin");
                 UDPProc.ccdImageList[1].save(SystemParam.TempPicPath + "Ev" + step.ToString() + "_1.bin");
                 ccdImage.Calc_miu_delta(UDPProc.ccdImageList[0], UDPProc.ccdImageList[1], out miu, out delta, out miuCC);
                 exposureVerifyChart.Series["miu"].Points.AddXY(step, miu);
                 exposureVerifyChart.Series["delta"].Points.AddXY(step, delta);
                 exposureVerifyChart.Series["miuCC"].Points.AddXY(step, miuCC);
                 if (exposureVerifyWaitingProc.HasBeenCancelled())
                 {
                     return;
                 }
                 exposureVerifyWaitingProc.SetProcessBarPerformStep();
             }
         }));
         if (exposureVerifyWaitingProc.HasBeenCancelled())
         {
             return;
         }
         if (MessageBox.Show("测试完毕,是否修改要修改参数", "测试完成", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             FormParam f = new FormParam();
             f.ShowDialog();
         }
         else
         {
             return;
         }
     }
 }
        static void WaitingImageList(object LockWatingThread)
        {
            int        retry    = 5;
            IPEndPoint dIP      = new IPEndPoint(DeviceIP, DeviceDataPort);
            UdpClient  udpcSend = new UdpClient();
            UdpClient  udpcRecv = new UdpClient(PCDataPort);

            udpcRecv.Client.ReceiveTimeout = 2000;
            ushort ImageCount;
            ushort ImageIndex = 0;
            ushort RowCount;
            ushort rowIndex;

            lock (LockWatingThread)
            {
                while (retry != 0)
                {
                    try
                    {
                        while (true)
                        {
                            if (wp != null)
                            {
                                if (wp.HasBeenCancelled())
                                {
                                    return;
                                }
                            }
                            byte[] rxList = udpcRecv.Receive(ref dIP);
                            if (rxList[0] != 0x81)
                            {
                                continue;
                            }
                            ImageCount = BytesOP.MakeShort(rxList[1], rxList[2]);
                            ImageIndex = BytesOP.MakeShort(rxList[3], rxList[4]);
                            RowCount   = BytesOP.MakeShort(rxList[5], rxList[6]);
                            rowIndex   = BytesOP.MakeShort(rxList[7], rxList[8]);
                            //确认收到了某行
                            ccdImageList[ImageIndex].rxConfirm[rowIndex, rxList[9]] = true;
                            int dataAddr = rowIndex * SystemParam.CCD_N * 2 + 1440 * rxList[9];
                            Array.Copy(rxList, 10, ccdImageList[ImageIndex].byteList, dataAddr, 1440);
                            if (rowIndex == RowCount && rxList[9] == 11)//最后一帧
                            {
                                byte[] tx = new byte[34];
                                tx[0] = 0x05;
                                tx[1] = 0x01;//图像接收正确,无需重传
                                for (int i = 0; i < SystemParam.CCD_M; i++)
                                {
                                    for (int j = 0; j < 12; j++)
                                    {
                                        if (ccdImageList[ImageIndex].rxConfirm[i, j] == false)
                                        {
                                            tx[1] = 0x00;
                                            break;
                                        }
                                    }
                                    if (tx[1] == 0x00)
                                    {
                                        break;
                                    }
                                }
                                tx[2] = BytesOP.GetLowByte(ImageIndex);
                                tx[3] = BytesOP.GetHighByte(ImageIndex);
                                udpcSend.Send(tx, tx.Length, dIP);
                                if (tx[1] == 0x01)
                                {
                                    if (wp != null)
                                    {
                                        wp.SetProcessBarPerformStep();
                                    }
                                    ccdImageRxConfirm[ImageIndex]       = true;
                                    ccdImageList[ImageIndex].ImageCount = ImageCount;
                                    ccdImageList[ImageIndex].ImageIndex = ImageIndex;
                                    ccdImageList[ImageIndex].RowCount   = RowCount;
                                    if ((ImageIndex + 1) == ImageCount)
                                    {
                                        return;
                                    }
                                }
                                else
                                {
                                    retry--;
                                    break;
                                }
                            }
                        }
                    }
                    catch //(Exception ex)
                    {
                        //WFNetLib.WFGlobal.WaitMS(1);
                        //MessageBox.Show("读取数据失败");
                        //Application.DoEvents();
                        retry--;
                        continue;
                    }
                }
            }
            MessageBox.Show("采集图像失败:" + (ImageIndex + 1).ToString());
            return;
        }
        void WaitingExposureTest(object LockWatingThread)
        {
            Imin = 0;
            Imax = 100;
            while (true)
            {
                double[] miu   = new double[10];
                double[] delta = new double[10];
                double[] miuCC = new double[10];
                exposureWaitingProc.SetProcessBar(0);
                this.Invoke((EventHandler)(delegate
                {
                    WFGlobal.WaitMS(1);
                    exposureChart.Series["miu"].Points.Clear();
                    exposureChart.Series["delta"].Points.Clear();
                    double gap = (Imax - Imin) / 9;
                    for (int step = 0; step < 10; step++)
                    {
                        double oe_per = Imin + gap * step;
                        tcpCCS.LightSet(SystemParam.lambda_Oe, oe_per);
                        exposureListView.Items[2].SubItems[1].Text = (Imin.ToString("F2") + "-" + Imax.ToString("F2"));
                        exposureListView.Items[3].SubItems[1].Text = oe_per.ToString("F2");
                        if (!UDPProc.CollectImage(this, NT, 2))
                        {
                            exposureWaitingProc.ExitWatting();
                            return;
                        }
                        UDPProc.ccdImageList[0].save(SystemParam.TempPicPath + "E" + step.ToString() + "_0.bin");
                        UDPProc.ccdImageList[1].save(SystemParam.TempPicPath + "E" + step.ToString() + "_1.bin");
                        ccdImage.Calc_miu_delta(UDPProc.ccdImageList[0], UDPProc.ccdImageList[1], out miu[step], out delta[step], out miuCC[step]);
                        exposureChart.Series["miu"].Points.AddXY(oe_per, miu[step]);
                        exposureChart.Series["delta"].Points.AddXY(oe_per, delta[step]);
                        if (exposureWaitingProc.HasBeenCancelled())
                        {
                            return;
                        }
                        exposureWaitingProc.SetProcessBarPerformStep();
                    }
                }));
                if (exposureWaitingProc.HasBeenCancelled())
                {
                    return;
                }
                // 方差全部相等(且接近0),则在之前照度第一个区间分10个照度等级
                double close0 = 0.01;
                if (delta[0] < close0 && delta[1] < close0)
                {
                    Imax = (Imax - Imin) / 9;
                }
                //如果方差单调升则修改NT=10*NT_min
                else if (delta[0] < delta[1])//单调增
                {
                    bool bMonotonicity = true;
                    for (int i = 0; i < 9; i++)
                    {
                        if (delta[i + 1] < delta[i])//增减转折
                        {
                            Imin          = (Imax - Imin) * (i + 1);
                            bMonotonicity = false;
                            break;
                        }
                    }
                    if (bMonotonicity)
                    {
                        NT = NT * 10;
//                         while(true)
//                         {
//                             string strNTmin = InputBox.ShowInputBox("请重新设定最小曝光周期数", SystemParam.NTmin.ToString());
//                             if (!int.TryParse(strNTmin, out SystemParam.NTmin))
//                             {
//                                 MessageBox.Show("所设定的最小曝光周期数有误!!!");
//                             }
//                             break;
//                         }
                    }
                }
                else//第一个就是减,那应该都是减函数
                {
                    SystemParam.Oe = tcpCCS.Per2LX(Imin / (SystemParam.n - 5));
                    iniFileOP.Write("Light Param", "Oe", SystemParam.Oe.ToString());
                    SystemParam.Osat = tcpCCS.Per2LX(Imin);
                    iniFileOP.Write("CCD Param", "Osat", SystemParam.Osat.ToString(), strCCDINIPath);
                    SystemParam.miu_sat = miu[0];
                    iniFileOP.Write("CCD Param", "miu_sat", SystemParam.miu_sat.ToString(), strCCDINIPath);
                    SystemParam.NTexp = SystemParam.NTmin * (SystemParam.n - 5) / SystemParam.n;
                    iniFileOP.Write("Collect Param", "NTexp", SystemParam.NTexp.ToString());
                    this.Invoke((EventHandler)(delegate
                    {
                        exposureListView.Items[4].SubItems[1].Text = SystemParam.Oe.ToString("F2");
                        exposureListView.Items[5].SubItems[1].Text = miu[0].ToString("F2");
                        exposureListView.Items[6].SubItems[1].Text = SystemParam.NTexp.ToString("F2");
                    }));
                    MessageBox.Show("曝光步距测试完毕");
                    return;
                }
            }
        }