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;
        }
示例#2
0
 private void Proc(object LockWatingThread)
 {
     Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
     try
     {
         app.Visible = false;
         Workbook wBook = app.Workbooks.Add(true);
         wp.SetCursorStyle(Cursors.Default);
         ExcelWorkbookCallbackProc(wBook, -1);//用于回调函数执行列标题定义操作
         int percent = 0;
         if (Count == -1)
         {
             Count = 0;
             while (true)
             {
                 percent++;
                 if (percent == 10000)
                 {
                     percent = 0;
                 }
                 wp.SetProcessBar(percent / 100);
                 lock (LockWatingThread)
                 {
                     if (!ExcelWorkbookCallbackProc(wBook, Count++))
                     {
                         break;
                     }
                     wp.SetProcessBar(100);
                     if (Count > 65530)
                     {
                         MessageBox.Show("条目过多,只导出前65530条");
                         break;
                     }
                 }
                 if (wp.HasBeenCancelled())
                 {
                     app.DisplayAlerts = false;
                     app.Quit();
                     return;
                 }
             }
         }
         else
         {
             for (int i = 0; i < Count; i++)
             {
                 percent++;
                 wp.SetProcessBar(percent * 100 / Count);
                 lock (LockWatingThread)
                 {
                     if (!ExcelWorkbookCallbackProc(wBook, i))
                     {
                         break;
                     }
                 }
                 if (wp.HasBeenCancelled())
                 {
                     app.DisplayAlerts = false;
                     app.Quit();
                     return;
                 }
             }
         }
         ExcelWorkbookCallbackProc(wBook, int.MaxValue); //全部导出完成,用于回调函数执行整体界面设定
         app.Visible     = true;
         app.WindowState = XlWindowState.xlMaximized;
     }
     catch (System.Exception ex)
     {
         MessageBox.Show("导出Excel出错!错误原因" + ex.Message);
         app.DisplayAlerts = false;
         app.Quit();
         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;
                }
            }
        }