Exemple #1
0
        /// <summary>
        /// 线程读取DB块
        /// </summary>
        private void ThreadReadServer()
        {
            aa : while (isThreadRun)                       //线程的运行状态
            {
                flag = s7Postion.Read(0).CastTo <int>(-1); //获取标志位
                listRobot.Clear();
                list.Clear();
                if (flag == 1 && isThreadRun)//允许采集热点信息
                {
                    stopwatch.Reset();
                    stopwatch.Start();
                    SendFlag = flag;
                    try
                    {
                        axis_3_x = s7Postion.Read(1).CastTo <double>(-1);             //axis 3 x 轴三点中心点X坐标
                        axis_3_y = s7Postion.Read(2).CastTo <double>(-1);             //axis 3  y 轴三点中心点Y坐标
                                                                                      //获取相机所在的位置
                        AngleTheta    = s7Postion.Read(3).CastTo <double>(-1) / 1000; // 角度 theta θ
                        AngleAlpha    = s7Postion.Read(4).CastTo <double>(-1) / 1000; //角度2 alpha α
                        shishibanjing = s7Postion.Read(5).CastTo <double>(-1);        //实时半径
                        UpdataLabel(lblrealreidan, "实时半径:" + shishibanjing);
                    }
                    catch (Exception ex)
                    {
                        FormMain.GetOPCTaskInfo("读取PLC错误:" + ex.Message);
                        goto bb;
                    }
                    calculator.PotDiamerter = shishibanjing;
                    for (int i = 0; i < comboBoxOnlineDevice.Items.Count; i++)//获取到在线相机
                    {
                        if (comboBoxOnlineDevice.Items[i].ToString().Contains("conn"))
                        {
                            FormDisplay frmDisplay = _DataControl.GetBindedDisplayForm(_LstEnumInfo[i].intCamIp);
                            if (frmDisplay == null)
                            {
                                //FormMain.GetOPCTaskInfo("未获取到该热像仪画面: IP:" + _LstEnumInfo[i].intCamIp);
                                continue;
                            }
                            else
                            {
                                try
                                {
                                    calculator.GetCameraPosition(AngleTheta, AngleAlpha, axis_3_x, axis_3_y, _LstEnumInfo[i].intCamIp); //计算当前相机所在的位置
                                                                                                                                        //if(i == 0)
                                                                                                                                        //{

                                    //    //相机与柱心距离=515.5
                                    //  // UpdataLabel( lbl1x,"相机1X"+ axis_3_x + "-" + 515.5 + "*Math.Cos((" + AngleTheta + "+" + AngleAlpha + ")*(" + (Math.PI / 180) + "))=" + (axis_3_x - 515.5 * Math.Cos((AngleTheta + AngleAlpha) * (Math.PI / 180))));
                                    //   // UpdataLabel(lbl1y, "相机1Y"+ axis_3_y + "-" + 515.5 + "*Math.Sin((" + AngleTheta + "+" + AngleAlpha + ")*(" + (Math.PI / 180) + "))=" + (axis_3_y - 515.5 * Math.Sin((AngleTheta + AngleAlpha) * (Math.PI / 180))));
                                    //   // FormMain.GetOPCTaskInfo(lbl1x.Text);
                                    //  //  FormMain.GetOPCTaskInfo(lbl1y.Text);
                                    //   // LogManager.WriteLog(LogFile.Trace,"相机1坐标X"+ lbl1x.Text);
                                    //    //LogManager.WriteLog(LogFile.Trace, "相机2坐标Y"+lbl1y.Text);
                                    //}
                                    //else if( i==1)
                                    //{
                                    //  // UpdataLabel(lbl2x,"相机2x"+ axis_3_x + "+" + 515.5 + "*Math.Cos((" + AngleTheta + "+" + AngleAlpha + ")*(" + (Math.PI / 180) + "))=" + (axis_3_x + 515.5 * Math.Cos((AngleTheta + AngleAlpha) * (Math.PI / 180))));
                                    //  //  UpdataLabel(lbl2y,"相机2y"+ axis_3_y + "+" + 515.5 + "*Math.Sin((" + AngleTheta + "+" + AngleAlpha + ")*(" + (Math.PI / 180) + "))=" + (axis_3_y + 515.5 * Math.Sin((AngleTheta + AngleAlpha) * (Math.PI / 180))));
                                    //   // FormMain.GetOPCTaskInfo(lbl2x.Text);
                                    //   // FormMain.GetOPCTaskInfo(lbl2y.Text);
                                    //   // LogManager.WriteLog(LogFile.Trace,"相机2坐标X"+ lbl2x.Text);
                                    //   // LogManager.WriteLog(LogFile.Trace, "相机2坐标Y"+ lbl2y.Text);
                                    //}
                                    list.Add(frmDisplay.NewGetInfo()); //获取温度信息
                                                                       //FormMain.GetOPCTaskInfo("窗体:" + frmDisplay.Name + ",IP:" + _LstEnumInfo[i].intCamIp);
                                }
                                catch (Exception ex)
                                {
                                    FormMain.GetOPCTaskInfo(ex.Message);
                                    LogManager.WriteLog(LogFile.Error, GetSaveStringFromException("获取相机坐标时出错", ex));
                                    goto bb;
                                }
                            }
                        }
                        else
                        {
                            //FormMain.GetOPCTaskInfo("此相机不处于连接状态:" + comboBoxOnlineDevice.Items[i].ToString());
                        }
                    }

                    for (int i = 0; i < list.Count; i++)
                    {
                        if (list[i].Count == 0)
                        {
                            continue;
                        }
                        outlist.Clear();
                        //1.移除在一个区间内的温度点(现在取出来的都是相机里面的坐标)
                        outlist = calculator.RecursiveDeduplication(list[i], Globals.ComparisonInterval, new List <ImgPosition>(), Globals.AngleInterval);
                        //2.将相机温度坐标转换成实际坐标
                        try
                        {
                            List <RobotPositionSort> realTmper = calculator.GetRobotPositionByImagePoint(outlist, (AngleTheta + AngleAlpha), axis_3_x, axis_3_y, _LstEnumInfo[i].intCamIp, out string OutStr);//将一个相机的热点进行实际值的换算

                            FormMain.GetOPCTaskInfo(OutStr);
                            // UpdataLabel(lbldetail, "计算明细:" + OutStr);
                            foreach (var item in realTmper)
                            {
                                listRobot.Add(item);//将实际坐标放到一个集合里面
                            }
                        }
                        catch (Exception ex)
                        {
                            LogManager.WriteLog(LogFile.Error, GetSaveStringFromException("计算热点发生致命错误:", ex));
                            FormMain.GetOPCTaskInfo("计算热点发生致命错误,停止采集,错误信息:" + GetSaveStringFromException("计算热点发生致命错误:", ex));
                            goto bb;
                        }
                    }
                    listRobot.Sort(new RobotPositionSort());//温度从高到低排序
                    if (listRobot.Count == 0)
                    {
                        FormMain.GetOPCTaskInfo("未采集到热点,重新采集");
                        goto aa;
                    }
                    FormMain.GetOPCTaskInfo("采集到热点个数:" + listRobot.Count);
                    try
                    {
                        //移除实际坐标相近的点
                        listRobot = calculator.RecursiveDeduplicationReal(listRobot, Globals.ComparisonIntervalReal, new List <RobotPositionSort>(), Globals.AngleIntervalReal);

                        listRobot = calculator.Filtering(listRobot, 1);//滤波
                    }
                    catch (Exception ex)
                    {
                        LogManager.WriteLog(LogFile.Error, GetSaveStringFromException("滤波或者移除相近坐标时发生致命错误,停止采集,错误信息:", ex));
                        FormMain.GetOPCTaskInfo("滤波或者移除相近坐标时发生致命错误,停止采集,错误信息:" + GetSaveStringFromException("滤波或者移除相近坐标时发生致命错误:", ex));
                        goto bb;
                    }

                    object[] values = calculator.ReplaceIndex(listRobot.Take(20).ToList()); //重新排序
                    s7Task.Write(values);                                                   //写入任务
                    FormMain.GetOPCTaskInfo("写入任务!热点个数:" + values[0]);
                    stopwatch.Stop();
                    UpdataLabel(lblOutTime, "整体耗时:" + stopwatch.Elapsed.TotalMilliseconds + "毫秒");
                    Thread.Sleep(timeSleep);//未取到数据时 根据间隔再取
                }
                else
                {
                    if (SendFlag.GetHashCode() != flag.GetHashCode())
                    {
                        FormMain.GetOPCTaskInfo("读取到标志位为" + flag + ",0.5秒后重复读取,直到标志位变化!");
                        SendFlag = flag;
                    }
                    Thread.Sleep(timeSleep);//根据间隔再取 标志位数据
                }
            }
            Thread.Sleep(500);
            goto aa;

            bb :  FormMain.GetOPCTaskInfo("因为错误,停止采集热点信息!");
        }