示例#1
0
        // public bool GetResultShow(int numOfSource)
        // {
        //     if (myJobManager == null)
        //     {
        //         return false;
        //     }
        //     ICogRecord tmpRecord;
        //     ICogRecord topRecord = myJobManager.UserResult();
        //     if (null != cogRecordDisplay)
        //     {
        //         tmpRecord = topRecord.SubRecords["ShowLastRunRecordForUserQueue"];
        //         tmpRecord = tmpRecord.SubRecords["LastRun"];
        //         tmpRecord = tmpRecord.SubRecords["CogFixtureTool1.OutputImage"];
        //         if (null != tmpRecord.Content)
        //         {
        //             cogRecordDisplay[numOfSource].Record = tmpRecord;
        //         }
        //         cogRecordDisplay[numOfSource].Fit(true);
        //     }
        //     return true;
        // }
        /// <summary>
        /// Get All Results together
        /// </summary>
        /// <param name="resultin"></param>
        /// <param name="resultout"></param>
        /// <returns></returns>
        public bool GetResult(List <string> resultin, ref List <double> resultout)
        {
            if (null == myJobManager)
            {
                return(false);
            }
            ICogRecord tmpRecord;
            ICogRecord topRecord = myJobManager.UserResult();

            if (null == topRecord)
            {
                return(false);
            }
            if (null == resultin)
            {
                for (int i = 0; i < resultin.Count; i++)
                {
                    if (null == resultin[i])
                    {
                        return(false);
                    }
                    else
                    {
                        ResultRequest[i] = "@\"" + resultin[i] + "\"";
                        tmpRecord        = topRecord.SubRecords[ResultRequest[i]];                            resultout[i] = (double)tmpRecord.Content;
                        ResultRequest[i] = null;
                    }
                }
                return(true);
            }
            return(false);
        }
        public MainWindow_ViewModel()
        {
            //임의의 Record 만들기 (기존 레코드가 있다면 그것을 불러와 사용)
            m_OriginRecord = new CogRecord {
                ContentType = typeof(ICogImage), Content = new CogImage8Grey(100, 100)
            };
            m_OriginRecord.SubRecords.Add(new CogRecord {
                RecordKey = "A Record", ContentType = typeof(CogGraphicLabel), Content = new CogGraphicLabel {
                    Text = "A", X = 10, Y = 10, Color = CogColorConstants.Red
                }
            });
            m_OriginRecord.SubRecords.Add(new CogRecord {
                RecordKey = "B Record", ContentType = typeof(CogGraphicLabel), Content = new CogGraphicLabel {
                    Text = "B", X = 50, Y = 10, Color = CogColorConstants.Orange
                }
            });
            m_OriginRecord.SubRecords.Add(new CogRecord {
                RecordKey = "C Record", ContentType = typeof(CogGraphicLabel), Content = new CogGraphicLabel {
                    Text = "C", X = 10, Y = 50, Color = CogColorConstants.Yellow
                }
            });
            m_OriginRecord.SubRecords.Add(new CogRecord {
                RecordKey = "D Record", ContentType = typeof(CogGraphicLabel), Content = new CogGraphicLabel {
                    Text = "D", X = 50, Y = 50, Color = CogColorConstants.Green
                }
            });

            //호출되는 내용 선언
            HostLoaded          = new RelayCommand <WindowsFormsHost>(OnHostLoaded);
            RecordChecked       = new RelayCommand <string>(OnChecked);
            RecordUnchecked     = new RelayCommand <string>(OnUnchecked);
            ImageLoadBtnClick   = new RelayCommand(OnImageLoad);
            OverlaySaveBtnClick = new RelayCommand(OnOverlaySave);
        }
        private void CogToolGroup_OnRan(object sender, EventArgs e)
        {
            #region Graphics
            // Graphics
            ICogRecord lastRunRecord = null;
            // Only assign graphic if the display has been created
            CognexCamera7 cogCam = CogCamera;
            if (cogCam != null && cogCam.CogDisplayWindows != null && cogCam.CogDisplayWindows.Count > 0)
            {
                foreach (CogDisplay cogDisplay in cogCam.CogDisplayWindows)
                {
                    if (lastRunRecord == null)
                    {
                        lastRunRecord = CogToolGroup.CreateLastRunRecord();
                    }
                    AssignCogRecordToDisplay(cogDisplay as Control, lastRunRecord);
                }
            }


            #endregion

            // Release the wait handle
            _autoResetEventWaitToolRun.Set();
        }
示例#4
0
        private void AssignLastRunRecord(ICogRecord lastRunRecord)
        {
            CognexCamera8 cogCam = CogCamera;

            if (cogCam != null && cogCam.CogDisplayWindows != null && cogCam.CogDisplayWindows.Count > 0)
            {
                //Parallel.ForEach<CogDisplay>(cogCam.CogDisplayWindows, currentDisplay =>
                //{

                //    if (lastRunRecord == null)
                //    {
                //        lastRunRecord = CogToolGroup.CreateLastRunRecord();
                //    }
                //    //currentDisplay.Image = null;
                //    //currentDisplay.Invalidate();
                //    AssignCogRecordToDisplay(currentDisplay as Control, lastRunRecord);

                //});

                foreach (CogDisplay cogDisplay in cogCam.CogDisplayWindows)
                {
                    if (lastRunRecord == null)
                    {
                        lastRunRecord = CogToolGroup.CreateLastRunRecord();
                    }
                    //cogDisplay.Image = null;
                    AssignCogRecordToDisplay(cogDisplay as Control, lastRunRecord);
                }
            }
        }
示例#5
0
        public static void FillUserResultData(Control ctrl, ICogRecord result, string path, bool convertRadiansToDegrees)
        {
            // Extract the data identified by the path (if available) from the given result record.
            // Use a format string for doubles.
            string rtn;
            HorizontalAlignment align = HorizontalAlignment.Left;

            if (result == null)
            {
                rtn = ResourceUtility.GetString("RtResultNotAvailable");
            }
            else
            {
                object obj = null;

                try
                {
                    obj = result.SubRecords[path].Content;
                }
                catch
                {
                }

                // check if data is available
                if (obj != null && obj.GetType().FullName != "System.Object")
                {
                    if (obj.GetType() == typeof(double))
                    {
                        double d = (double)obj;
                        if (convertRadiansToDegrees)
                        {
                            d = CogMisc.RadToDeg(d);
                        }
                        rtn = d.ToString("0.000");
                    }
                    else
                    {
                        rtn = obj.ToString();
                    }

                    if (TypeIsNumeric(obj.GetType()))
                    {
                        align = HorizontalAlignment.Right;
                    }
                }
                else
                {
                    rtn = ResourceUtility.GetString("RtResultNotAvailable");
                }
            }

            ctrl.Text = rtn;
            TextBox box = ctrl as TextBox;

            if (box != null)
            {
                box.TextAlign = align;
            }
        }
        private void AssignCogRecordToDisplay(Control cogDisplay, ICogRecord cogRecord)
        {
            if (cogDisplay.InvokeRequired)
            {
                cogDisplay.BeginInvoke(new _delParamCogDisplayIcogRecord(AssignCogRecordToDisplay), new object[] { cogDisplay, cogRecord });
                return;
            }

            if (cogDisplay is CogRecordsDisplay)
            {
                (cogDisplay as CogRecordsDisplay).Subject = cogRecord;
            }
            else if (cogDisplay is CogDisplay)
            {
                if (cogRecord.SubRecords == null || cogRecord.SubRecords.Count == 0)
                {
                    return;
                }
                // Assign image if it is not there
                if ((cogDisplay as CogDisplay).Image == null && CogCamera != null)
                {
                    // Assign image
                    lock (CogCamera.LockCogDisplay)
                    {
                        (cogDisplay as CogDisplay).Image = cogRecord.SubRecords[0].Content as ICogImage;
                        (cogDisplay as CogDisplay).Fit(true);
                    }
                }
                // Assign graphic if any
                (cogDisplay as CogDisplay).InteractiveGraphics.Clear();
                foreach (ICogRecord record in cogRecord.SubRecords[0].SubRecords)
                {
                    if (record.Content is CogGraphicCollection)
                    {
                        foreach (CogCompositeShape graphic in (record.Content as CogGraphicCollection))
                        {
                            (cogDisplay as CogDisplay).InteractiveGraphics.Add(graphic, this.Name, false);
                        }
                    }
                    if (record.Content is ICogGraphicInteractive)
                    {
                        (cogDisplay as CogDisplay).InteractiveGraphics.Add(record.Content as ICogGraphicInteractive, this.Name, false);
                    }
                }
            }
            else
            {
                // There is no Cognex Display, do nothing
            }
        }
示例#7
0
        public bool GetResult(int numOfVpps, List <string> resultin, ref List <double> resultout)
        {
            if (null == myJobManager)
            {
                return(false);
            }
            if (null == myJobManager[numOfVpps])
            {
                return(false);
            }
            ICogRecord tmpRecord;
            ICogRecord topRecord = myJobManager[numOfVpps].UserResult();

            if (null == topRecord)
            {
                return(false);
            }
            if (null != resultin)
            {
                for (int i = 0; i < resultin.Count; i++)
                {
                    if (null == resultin[i])
                    {
                        return(false);
                    }
                    else
                    {
                        ResultRequest[i] = "@\"" + resultin[i] + "\"";
                        tmpRecord        = topRecord.SubRecords[ResultRequest[i]];
                        resultout[i]     = (double)tmpRecord.Content;
                        ResultRequest[i] = null;
                    }
                }
                return(true);
            }
            if (null != cogRecordDisplay)
            {
                tmpRecord = topRecord.SubRecords["ShowLastRunRecordForUserQueue"];
                tmpRecord = tmpRecord.SubRecords["LastRun"];
                tmpRecord = tmpRecord.SubRecords["CogFixtureTool1.OutputImage"];
                if (null != tmpRecord.Content)
                {
                    cogRecordDisplay.Record = tmpRecord;
                }
                cogRecordDisplay.Fit(true);
            }
            return(false);
        }
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //생성 :
        //추가 :
        //목적 : 툴 내 파인드 라인 그래픽 -> 현재 디스플레이에 표시
        //설명 : 소스코드야 미안하다
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void GetFindLineBottom()
        {
            do
            {
//                 // 디스플레이 초기화
//                 m_objCogDisplayMain.Image = null;
//                 // 이미지 유무 체크해서 메인 디스플레이에 이미지를 가져옴
//                 SetMainImage();
//                 // 디스플레이 클리어
//                 m_objCogDisplayMain.StaticGraphics.Clear();
//                 m_objCogDisplayMain.InteractiveGraphics.Clear();
                // 이미지 유무 체크
                if (null == m_objCogDisplayMain.Image)
                {
                    break;
                }
                // 극성 방향
                CogLineSegment objLineSegment;
                // 캘리퍼 사각형's
                CogGraphicCollection objRegions;
                m_objFindLineToolBottom.CurrentRecordEnable = CogFindLineCurrentRecordConstants.All;
                ICogRecord objCogRecord = m_objFindLineToolBottom.CreateCurrentRecord();
                objLineSegment = ( CogLineSegment )objCogRecord.SubRecords["InputImage"].SubRecords["ExpectedShapeSegment"].Content;
                objRegions     = ( CogGraphicCollection )objCogRecord.SubRecords["InputImage"].SubRecords["CaliperRegions"].Content;
                // 캘리퍼 선
                objLineSegment.Color = CogColorConstants.Green;
                //objLineSegment.Interactive = false;
                //m_objCogDisplayMain.InteractiveGraphics.Add( ( ICogGraphicInteractive )objLineSegment, "", false );
                m_objCogDisplayMain.StaticGraphics.Add(( ICogGraphicInteractive )objLineSegment, "");

                // 캘리퍼 상자
                if (null != objRegions)
                {
                    for (int iLoopCount = 0; iLoopCount < objRegions.Count; iLoopCount++)
                    {
                        objRegions[iLoopCount].Color = CogColorConstants.Green;
                        //m_objCogDisplayMain.InteractiveGraphics.Add( ( ICogGraphicInteractive )objRegions[ iLoopCount ], "", false );
                        m_objCogDisplayMain.StaticGraphics.Add(( ICogGraphicInteractive )objRegions[iLoopCount], "");
                    }
                }
            } while(false);
        }
示例#9
0
        private void mToolBlockProcess_Ran(object sender, EventArgs e)
        {
            // This method executes each time the TB runs
            bool result = (bool)(objectManager.mToolBlockProcess.Outputs["InspectionPassed"].Value);

            if (result)
            {
                objectManager.numPass++;
            }
            else
            {
                objectManager.numFail++;
            }
            // Update the label with pass and fail
            nPass.Text = objectManager.numPass.ToString();
            nFail.Text = objectManager.numFail.ToString();

            CogBlobTool mBlobTool = objectManager.mToolBlockProcess.Tools["CogBlobTool1"] as CogBlobTool;

            //get result
            var blobResult = mBlobTool.Results;
            var all_blob   = blobResult.GetBlobs();

            Console.WriteLine($"number blob detected = {all_blob.Count}");
            for (int i = 0; i < all_blob.Count; i++)
            {
                interfaceManager.SendMessage(Blob_Packet(all_blob[i]));
            }

            //var blobRunParam = mBlobTool.RunParams;

            //Assign picture to display
            ICogRecord temp = mBlobTool.CreateLastRunRecord();

            //temp = temp.SubRecords["BlobImage"];
            temp = temp.SubRecords["InputImage"];
            cogRecordDisplay1.Record = temp;
            cogRecordDisplay1.Fit(true);

            Display(result);
            Console.WriteLine("Ran done!, time processing = {0} ms", objectManager.mToolBlockProcess.RunStatus.TotalTime);
        }
示例#10
0
        private void ZJYContent()
        {
            Class1.CogJobManager.Run();
            while (true)         //更新运行状态
            {
                Thread.Sleep(1); //线程延迟
                //获取实时运行状态,当运行状态为None,没有事件运行
                if (Class1.CogJobManager.JobsRunningState == CogJobsRunningStateConstants.None)
                {
                    Class1.CogToolGroup = cogJobManagerEdit1.Subject.Job("CogJob_ZJY").VisionTool as CogToolGroup;
                    Class1.CogToolBlock = Class1.CogToolGroup.Tools["CogToolBlock1"] as CogToolBlock;
                    ICogRecord cogRecord = Class1.CogToolBlock.CreateLastRunRecord();
                    cogRecordDisplay1.Record = cogRecord.SubRecords[1];
                    cogRecordDisplay1.Fit(true);
                    panel1.Show();

                    Double C = (System.Double)Class1.CogToolBlock.Outputs["Distance1"].Value;
                    MessageBox.Show("距离为:" + C.ToString());
                    return;
                }
            }
        }
示例#11
0
        static public ICogRecord TraverseSubRecords(ICogRecord r, string[] subs)
        {
            // Utility function to walk down to a specific subrecord
            if (r == null)
            {
                return(r);
            }

            foreach (string s in subs)
            {
                if (r.SubRecords.ContainsKey(s))
                {
                    r = r.SubRecords[s];
                }
                else
                {
                    return(null);
                }
            }

            return(r);
        }
示例#12
0
        //触发时的内容
        private void SelectContent()
        {
            Class1.CogJobManager.Run(); //Class1.CogJobManager.RunContinuous();  连续运行作业
            while (true)                //更新运行状态
            {
                Thread.Sleep(1);        //线程延迟
                //获取实时运行状态,当运行状态为CogJobsRunningStateConstants.None,没有事件运行
                if (Class1.CogJobManager.JobsRunningState.ToString().Equals("None"))
                {
                    Class1.CogToolGroup = cogJobManagerEdit1.Subject.Job("CogJobSelect").VisionTool as CogToolGroup;
                    Class1.CogToolBlock = Class1.CogToolGroup.Tools["CogToolBlock1"] as CogToolBlock; //调用CogToolBlock1
                    ICogRecord cogRecord = Class1.CogToolBlock.CreateLastRunRecord();                 //job中的CogToolBlock1创建结果图像
                    cogRecordDisplay1.Record = cogRecord.SubRecords[1];                               //取出序号为n的图像
                    cogRecordDisplay1.Fit(true);                                                      //图像显示控件图像自适应大小
                    panel1.Show();

                    if (Class1.Img == 1)
                    {
                        SaveImg(cogRecordDisplay1);      //调用图片保存至文件的方法
                    }

                    Class1.CogToolBlock = Class1.CogToolGroup.Tools["CogToolBlock2"] as CogToolBlock;
                    string text = Class1.CogToolBlock.Outputs["Output"].Value.ToString();
                    if (Class1.File == 1)
                    {
                        SaveFile(text);  //调用数据写入文件的方法
                    }

                    string file = Class1.CogToolBlock.Outputs["Text"].Value.ToString();
                    if (Class1.Execl == 1)
                    {
                        SaveExcel(file);
                    }
                    return;
                }
            }
        }
示例#13
0
        static public bool AddRecordToDisplay(CogRecordsDisplay disp, ICogRecord r, string[] subs,
                                              bool pickBestImage)
        {
            // Utility function to put a specific subrecord into a display
            ICogRecord addrec = Utility.TraverseSubRecords(r, subs);

            if (addrec != null)
            {
                // if this is the first record in, then always select an image
                if (disp.Subject == null)
                {
                    pickBestImage = true;
                }

                disp.Subject = addrec;

                if (pickBestImage)
                {
                    // select first non-empty image record, to workaround the fact that the input image tool
                    // adds an empty subrecord to the LastRun record when it is disabled (when an image file
                    // tool is used, for example)
                    for (int i = 0; i < addrec.SubRecords.Count; ++i)
                    {
                        ICogImage img = addrec.SubRecords[i].Content as ICogImage;
                        if (img != null && img.Height != 0 && img.Width != 0)
                        {
                            disp.SelectedRecordKey = addrec.RecordKey + "." + addrec.SubRecords[i].RecordKey;
                            break;
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
示例#14
0
        private void CogToolGroup_OnRan(object sender, EventArgs e)
        {
            ICogRecord lastRunRecord = CogToolGroup.CreateLastRunRecord();

            _autoResetEventWaitToolRun.Set();
            Task.Run(() => AssignLastRunRecord(lastRunRecord));


            /*
             #region Graphics
             * // Graphics
             * ICogRecord lastRunRecord = null;
             * // Only assign graphic if the display has been created
             * CognexCamera8 cogCam = CogCamera;
             * if (cogCam != null && cogCam.CogDisplayWindows != null && cogCam.CogDisplayWindows.Count > 0)
             * {
             *  foreach (CogDisplay cogDisplay in cogCam.CogDisplayWindows)
             *  {
             *
             *      if (lastRunRecord == null)
             *      {
             *          lastRunRecord = CogToolGroup.CreateLastRunRecord();
             *      }
             *      cogDisplay.Image = null;
             *      AssignCogRecordToDisplay(cogDisplay as Control, lastRunRecord);
             *  }
             * }
             *
             *
             *
             #endregion
             */

            // Release the wait handle
            //_autoResetEventWaitToolRun.Set();
        }
示例#15
0
        /// <summary>
        /// 获取结果
        /// </summary>
        ///
        /// <param name="result">< 结构体用于储存结果 ></param>
        ///
        /// <returns>< bool判定是否获取成功 ></returns>
        private bool GetResult(ref Result result)
        {
            bool IsResult1 = false;
            bool IsResult2 = false;
            bool IsResult3 = false;
            bool IsDispaly = false;

            if (myJobManager == null)
            {
                return(false);
            }
            ICogRecord tmpRecord;
            ICogRecord topRecord = myJobManager.UserResult();

            if (topRecord == null)
            {
                return(false);
            }
            try
            {
                tmpRecord = topRecord.SubRecords[@"X"];
                if (tmpRecord.Content != null)
                {
                    result.X  = (double)tmpRecord.Content;
                    IsResult1 = true;
                }
            }
            catch
            {
                IsResult1 = false;
            }
            try
            {
                tmpRecord = topRecord.SubRecords[@"Y"];
                if (tmpRecord.Content != null)
                {
                    result.Y  = (double)tmpRecord.Content;
                    IsResult2 = true;
                }
            }
            catch
            {
                IsResult2 = false;
            }
            try
            {
                tmpRecord = topRecord.SubRecords[@"Angle"];
                if (tmpRecord.Content != null)
                {
                    result.Angle = (double)tmpRecord.Content;
                    IsResult3    = true;
                }
            }
            catch
            {
                IsResult3 = false;
            }
            try
            {
                if (null != cogRecordDisplay)
                {
                    tmpRecord = topRecord.SubRecords["ShowLastRunRecordForUserQueue"];
                    tmpRecord = tmpRecord.SubRecords["LastRun"];
                    tmpRecord = tmpRecord.SubRecords["CogFixtureTool1.OutputImage"];
                    if (null != tmpRecord.Content)
                    {
                        cogRecordDisplay.Record = tmpRecord;
                        IsDispaly = true;
                    }
                    cogRecordDisplay.AutoFit = true;
                }
            }
            catch
            {
                IsDispaly = false;
            }
            if (IsResult1 && IsResult2 && IsResult3 && IsDispaly)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#16
0
        private void AssignCogRecordToDisplay(Control cogDisplay, ICogRecord cogRecord)
        {
            if (cogDisplay.Visible != true)
            {
                return;
            }

            if (cogDisplay.InvokeRequired)
            {
                cogDisplay.BeginInvoke(new _delParamCogDisplayIcogRecord(AssignCogRecordToDisplay), new object[] { cogDisplay, cogRecord });
                return;
            }

            if (cogDisplay is CogRecordsDisplay)
            {
                (cogDisplay as CogRecordsDisplay).Subject = cogRecord;
            }

            else if (cogDisplay is CogDisplay)
            {
                CogDisplay cDisplay = cogDisplay as CogDisplay;
                try
                {
                    //cogDisplay.Visible = false;
                    if (cogRecord.SubRecords == null || cogRecord.SubRecords.Count == 0)
                    {
                        return;
                    }


                    if (cogRecord.Content != null && cogRecord.Content is List <ICogRecord> )
                    {
                        List <ICogRecord> recordList = cogRecord.Content as List <ICogRecord>;
                        CogGraphicInteractiveCollection cogGraphicInteractCollection = new CogGraphicInteractiveCollection();
                        foreach (ICogRecord record in recordList)
                        {
                            // Assign image if it is not there
                            if ((cDisplay.Image == null || !(cDisplay.Image is CogImage8Grey)) &&
                                CogCamera != null)
                            {
                                // Assign image
                                lock (CogCamera.LockCogDisplay)
                                {
                                    cDisplay.Image = record.SubRecords[0].Content as ICogImage;
                                    cDisplay.Fit(true);
                                }
                            }

                            cDisplay.InteractiveGraphics.Clear();

                            if (IsDisplayGraphic)
                            {
                                //Assign graphic if any
                                foreach (ICogRecord subRecord in record.SubRecords[0].SubRecords)
                                {
                                    if (subRecord.Content is CogGraphicCollection)
                                    {
                                        CogGraphicCollection contentCollect = subRecord.Content as CogGraphicCollection;
                                        if (contentCollect != null)
                                        {
                                            foreach (CogCompositeShape graphic in contentCollect)
                                            {
                                                //cDisplay.InteractiveGraphics.Add(graphic, this.Name, false);
                                                cogGraphicInteractCollection.Add(graphic);
                                            }
                                        }
                                    }
                                    if (subRecord.Content is ICogGraphicInteractive)
                                    {
                                        //cDisplay.InteractiveGraphics.Add(subRecord.Content as ICogGraphicInteractive, this.Name, false);
                                        cogGraphicInteractCollection.Add(subRecord.Content as ICogGraphicInteractive);
                                    }
                                }


                                if (EnableDisplayTimeLabel)
                                {
                                    CogGraphicLabel cogLabel = new CogGraphicLabel();
                                    cogLabel.SelectedSpaceName = "@";
                                    cogLabel.Color             = CogColorConstants.Green;
                                    cogLabel.SetXYText(TimeLabelLocX, TimeLabelLocY, DateTime.Now.ToString("HH:mm:ss:fff"));
                                    cogGraphicInteractCollection.Add(cogLabel);
                                }

                                cDisplay.InteractiveGraphics.AddList(cogGraphicInteractCollection, this.Name, false);
                                //(cogDisplay as CogDisplay).Invalidate();
                            }
                        }
                    }
                    else
                    {
                        // Assign image if it is not there
                        if ((cDisplay.Image == null || !(cDisplay.Image is CogImage8Grey)) &&
                            CogCamera != null)
                        {
                            // Assign image
                            lock (CogCamera.LockCogDisplay)
                            {
                                //(cogDisplay as CogDisplay).Image = cogRecord.SubRecords[0].Content as ICogImage;
                                cDisplay.Image = cogRecord.SubRecords[cogRecord.SubRecords.Count - 1].Content as ICogImage;
                                cDisplay.Fit(true);
                            }
                        }

                        cDisplay.InteractiveGraphics.Clear();
                        if (IsDisplayGraphic)
                        {
                            // Assign graphic if any
                            CogGraphicInteractiveCollection cogGraphicInteractCollection = new CogGraphicInteractiveCollection();


                            foreach (ICogRecord record in cogRecord.SubRecords[cogRecord.SubRecords.Count - 1].SubRecords)
                            {
                                if (record.Content is CogGraphicCollection)
                                {
                                    CogGraphicCollection contentCollect = record.Content as CogGraphicCollection;

                                    foreach (CogObjectBase objBase in contentCollect)
                                    {
                                        ICogGraphicInteractive graphic = objBase as ICogGraphicInteractive;
                                        if (graphic != null)
                                        {
                                            //cDisplay.InteractiveGraphics.Add(graphic, this.Name, false);
                                            cogGraphicInteractCollection.Add(graphic);
                                        }
                                    }
                                }
                                else if (record.Content is ICogGraphicInteractive)
                                {
                                    //cDisplay.InteractiveGraphics.Add(record.Content as ICogGraphicInteractive, this.Name, false);
                                    cogGraphicInteractCollection.Add(record.Content as ICogGraphicInteractive);
                                }
                            }


                            if (EnableDisplayTimeLabel)
                            {
                                CogGraphicLabel cogLabel = new CogGraphicLabel();
                                cogLabel.SelectedSpaceName = "@";
                                cogLabel.Color             = CogColorConstants.Green;
                                cogLabel.SetXYText(TimeLabelLocX, TimeLabelLocY, DateTime.Now.ToString("HH:mm:ss:fff"));
                                cogGraphicInteractCollection.Add(cogLabel);
                            }

                            cDisplay.InteractiveGraphics.AddList(cogGraphicInteractCollection, this.Name, false);

                            //(cogDisplay as CogDisplay).Invalidate();
                        }
                    }
                }
                finally
                {
                    //cogDisplay.Visible = true;
                    //cogDisplay.Update();
                }

                //CogDisplayResult =new Bitmap((cogDisplay as CogDisplay).CreateContentBitmap(CogDisplayContentBitmapConstants.Image, null, 0));
            }
            else
            {
                // There is no Cognex Display, do nothing
            }
        }
示例#17
0
 public VisionResultAvailableEventArgs(ICogRecord result, SortedList <string, string> dataResult)
 {
     LastRunRecord = result;
     DataResult    = dataResult;
 }
示例#18
0
 public static void Run(Bitmap image, int index, out ArrayList data, out ICogImage outimage, out ICogRecord outrecord)
 {
     outimage = new CogImage8Grey(image);
     block.Inputs["InputImage"].Value = outimage;
     block.Inputs["Index"].Value      = index;
     block.Run();
     outrecord = block.CreateLastRunRecord();
     if (block.RunStatus.Result == CogToolResultConstants.Accept)
     {
         data = (ArrayList)block.Outputs["data"].Value;
     }
     else
     {
         throw new Exception("Vision Run Fail");
     }
 }
示例#19
0
 public static void FillUserResultData(Control ctrl, ICogRecord result, string path)
 {
     FillUserResultData(ctrl, result, path, false);
 }
        private void AssignCogRecordToDisplay(Control cogDisplay, ICogRecord cogRecord)
        {
            if (cogDisplay.InvokeRequired)
            {
                cogDisplay.BeginInvoke(new _delParamCogDisplayIcogRecord(AssignCogRecordToDisplay), new object[] { cogDisplay, cogRecord });
                return;
            }

            if (cogDisplay is CogRecordsDisplay)
            {
                (cogDisplay as CogRecordsDisplay).Subject = cogRecord;
            }

            else if (cogDisplay is CogDisplay)
            {
                try
                {
                    cogDisplay.Visible = false;
                    if (cogRecord.SubRecords == null || cogRecord.SubRecords.Count == 0)
                    {
                        return;
                    }


                    if (cogRecord.Content != null && cogRecord.Content is List <ICogRecord> )
                    {
                        List <ICogRecord> recordList = cogRecord.Content as List <ICogRecord>;
                        foreach (ICogRecord record in recordList)
                        {
                            // Assign image if it is not there
                            if (((cogDisplay as CogDisplay).Image == null || !((cogDisplay as CogDisplay).Image is CogImage8Grey)) &&
                                CogCamera != null)
                            {
                                // Assign image
                                lock (CogCamera.LockCogDisplay)
                                {
                                    (cogDisplay as CogDisplay).Image = record.SubRecords[0].Content as ICogImage;
                                    (cogDisplay as CogDisplay).Fit(true);
                                    (cogDisplay as CogDisplay).InteractiveGraphics.Clear();
                                }
                            }



                            //Assign graphic if any
                            foreach (ICogRecord subRecord in record.SubRecords[0].SubRecords)
                            {
                                if (subRecord.Content is CogGraphicCollection)
                                {
                                    foreach (CogCompositeShape graphic in (subRecord.Content as CogGraphicCollection))
                                    {
                                        (cogDisplay as CogDisplay).InteractiveGraphics.Add(graphic, this.Name, false);
                                    }
                                }
                                if (subRecord.Content is ICogGraphicInteractive)
                                {
                                    (cogDisplay as CogDisplay).InteractiveGraphics.Add(subRecord.Content as ICogGraphicInteractive, this.Name, false);
                                }
                            }
                        }
                    }
                    else
                    {
                        // Assign image if it is not there
                        if (((cogDisplay as CogDisplay).Image == null || !((cogDisplay as CogDisplay).Image is CogImage8Grey)) &&
                            CogCamera != null)
                        {
                            // Assign image
                            lock (CogCamera.LockCogDisplay)
                            {
                                //(cogDisplay as CogDisplay).Image = cogRecord.SubRecords[0].Content as ICogImage;
                                (cogDisplay as CogDisplay).Image = cogRecord.SubRecords[cogRecord.SubRecords.Count - 1].Content as ICogImage;
                                (cogDisplay as CogDisplay).Fit(true);
                            }
                        }
                        // Assign graphic if any
                        (cogDisplay as CogDisplay).InteractiveGraphics.Clear();
                        //foreach (ICogRecord record in cogRecord.SubRecords[0].SubRecords)
                        foreach (ICogRecord record in cogRecord.SubRecords[cogRecord.SubRecords.Count - 1].SubRecords)
                        {
                            if (record.Content is CogGraphicCollection)
                            {
                                foreach (CogCompositeShape graphic in (record.Content as CogGraphicCollection))
                                {
                                    (cogDisplay as CogDisplay).InteractiveGraphics.Add(graphic, this.Name, false);
                                }
                            }
                            if (record.Content is ICogGraphicInteractive)
                            {
                                (cogDisplay as CogDisplay).InteractiveGraphics.Add(record.Content as ICogGraphicInteractive, this.Name, false);
                            }
                        }
                    }
                }
                finally
                {
                    cogDisplay.Visible = true;
                }

                CogDisplayResult = new Bitmap((cogDisplay as CogDisplay).CreateContentBitmap(CogDisplayContentBitmapConstants.Image, null, 0));
            }
            else
            {
                // There is no Cognex Display, do nothing
            }
        }