Exemplo n.º 1
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="cogToolBlock">ToolBlock实例</param>
        /// <returns>结果</returns>
        private bool Init(CogToolBlock cogToolBlock)
        {
            if (cogToolBlock != null)
            {
                visionProDisplayControl.SetCogToolDisplayTool(cogToolBlock);
                visionProConfigControl.SetCogToolBlockEditSubject(cogToolBlock);

                Outputs.Clear();
                for (int i = 0; i < cogToolBlock.Outputs.Count; i++)
                {
                    Outputs.Add(new ItemBase(cogToolBlock.Outputs[i].Name, cogToolBlock.Outputs[i].Value, cogToolBlock.Outputs[i].ValueType, string.IsNullOrEmpty(cogToolBlock.Outputs[i].Description) ? cogToolBlock.Outputs[i].Name : cogToolBlock.Outputs[i].Description));
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Assign input valiue to vision output variable
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public override void AssignOutput(string key, double value)
        {
            CogToolBlock grabberBuffer = GetGrabberBuffer();

            if (grabberBuffer != null)
            {
                foreach (CogToolBlockTerminal output in grabberBuffer.Outputs)
                {
                    if (key == output.Name)
                    {
                        output.Value = value;
                        return;
                    }
                }
                // Create it
                grabberBuffer.Outputs.Add(new CogToolBlockTerminal(key, value));
            }
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (MyTCPServer == null)
            {
                MyTCPServer                 = new TcpServer();
                this.MyTCPServer.Port       = 2000;
                this.MyTCPServer.DataType   = TcpServer.StreamType.Text;
                this.MyTCPServer.OnConnect += Connection2_OnConnect;
                this.MyTCPServer.OnLeaving += Connection2_OnLeaving;

                MyTCPServer.Open();
            }
            else
            {
            }

            SmartRayImageSource.ImageSource srIs = new ImageSource();

            if (srIs.Configure(Application.StartupPath + "/ScanSmartRay_2/SmartRayImageSource.xml"))
            {
                SmartRayImageSource = srIs;

                SmartRayImageSource.OnImage += ImageSource_OnImage;
            }

            if (srIs != null)
            {
                srIs.OnPackageImage += SrIs_OnPackageImage;
            }
            // this.MainDisplay.ColorMapLoad(Application.StartupPath + "/ColorMap.map");


            NotifierHelper.Notify("App.Init.Sucess", "完成初始化。");

            //}


            {
                visionProAlg      = (CogSerializer.LoadObjectFromFile(Application.StartupPath + "/XXX.vpp") as CogToolBlock);
                visionProAlg.Ran += VisionAlgorithm_OnRan;
            }
            MessageBox.Show("完成初始化");
        }
Exemplo n.º 4
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            m_tb = new CogToolBlock();
            string nameOfVpp = Application.StartupPath + "\\..\\..\\..\\demo.vpp";

            m_tb = (CogToolBlock)CogSerializer.LoadObjectFromFile(nameOfVpp);

            CogImageFile imagefile = new CogImageFile();

            imagefile.Open(Application.StartupPath + "/../../../in/bracket_std.idb", CogImageFileModeConstants.Read);

            //imagefile.IsSynchronized ;//();
            //m_Image =
            CogToolCollection tbTc = m_tb.Tools;

            //tbTc.
            //((CogImageFileTool)tbTc["CogImageFileTool1"]).Name = "";
            ((CogImageFileTool)tbTc["CogImageFileTool1"]).InputImage = (CogImage8Grey)imagefile[0];
        }
        private void buttonF8_Click(object sender, EventArgs e)
        {
            CogToolBlock tbTemp = MyGlobal.tbDown2;

            tbTemp.Run();
            //disp[index].Record = tbTemp.CreateLastRunRecord().SubRecords["CogIPOneImageTool1.OutputImage"];
            if (CogToolResultConstants.Accept == tbTemp.RunStatus.Result)
            {
                double x = Math.Round((double)tbTemp.Outputs["X"].Value, 3);
                double y = Math.Round((double)tbTemp.Outputs["Y"].Value, 3);
                double r = Math.Round((double)tbTemp.Outputs["R"].Value, 3);
                this.dataGridView2.Rows[0].Cells[7].Value = x;
                this.dataGridView2.Rows[1].Cells[7].Value = y;
                this.dataGridView2.Rows[2].Cells[7].Value = r;
            }
            else
            {
                MessageBox.Show("获取点失败");
            }
        }
Exemplo n.º 6
0
        private bool disposedValue = false; // 要检测冗余调用

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: 释放托管状态(托管对象)。
                }

                // TODO: 释放未托管的资源(未托管的对象)并在以下内容中替代终结器。
                // TODO: 将大型字段设置为 null。

                cogToolBlock?.Dispose();
                cogToolBlock = null;

                visionProDisplayControl = null;
                visionProConfigControl  = null;

                disposedValue = true;
            }
        }
Exemplo n.º 7
0
        private void CognexJobEditForm_Load(object sender, EventArgs e)
        {
            // Create the edit control
            //_toolGroupEdit = new CogToolGroupEditV2(); // Use in Vision Pro 6
            _toolGroupEdit      = new CogToolGroupEditV2();
            _toolGroupEdit.Dock = DockStyle.Fill;

            panelToolGroupEdit.Controls.Add(_toolGroupEdit);

            // Assign the tool to the edit control
            _toolGroupEdit.Subject = _cognexJob.CogToolGroup;
            if (_cognexJob.CogToolGroup.Tools == null || _cognexJob.CogToolGroup.Tools.Count == 0)
            {
                _toolGroupEdit.ResetText();

                CogToolBlock grabberBufferToolBlock = new CogToolBlock();
                grabberBufferToolBlock.Name = "Grabber Buffer";
                CogToolBlockTerminal outputTerminal = new CogToolBlockTerminal("OutputBuffer", typeof(ICogImage));
                grabberBufferToolBlock.Outputs.Add(outputTerminal);
                _cognexJob.CogToolGroup.Tools.Add(grabberBufferToolBlock);
            }
        }
Exemplo n.º 8
0
        public Boolean SaveToVPPFile(string FileName)//檔案參數儲存
        {
            string ProcID = System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString();

            try
            {
                //建立目錄資料夾
                string        strFolderPath = @"D:\VPS_File\Product\FindCircleTool\" + @FileName + @"\";
                DirectoryInfo DIFO          = new DirectoryInfo(strFolderPath);
                if (DIFO.Exists != true)
                {
                    DIFO.Create();
                }

                //塞到CogTool裡面
                CogToolBlock ToolBlock1 = new CogToolBlock();

                mFindCircleTool.Name = FileName + "_FindCircleTool_";

                ToolBlock1.Tools.Add(mFindCircleTool);

                FileName = strFolderPath + FileName + "_FCT.vpp";

                //有使用到定位跟隨的時候不能存成最壓縮的檔案
                //CogSerializer.SaveObjectToFile(ToolBlock1, @FileName, typeof(BinaryFormatter), CogSerializationOptionsConstants.Minimum);
                CogSerializer.SaveObjectToFile(ToolBlock1, @FileName);

                SaveLog.Msg_("Data of FindCircleTool Saved : " + FileName);
                ToolBlock1            = null;
                FindCircleTool_Status = true;
                return(true);
            }
            catch (Exception ex)
            {
                SaveLog.Msg_("Save FindCircleTool Data Failed : " + ModularID + ":\r\n" + ProcID + ":\r\n" + ex.ToString());
                FindCircleTool_Status = false;
                return(false);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 初始化相机,需要处理异常
        /// </summary>
        public static string Init()
        {
            string rs = "";

            try
            {
                CogToolBlock ctb = CogSerializer.LoadObjectFromFile(AcqFile) as CogToolBlock;
                Acq1   = ctb.Tools[0] as CogAcqFifoTool;
                Acq2   = ctb.Tools[1] as CogAcqFifoTool;
                Acq3   = ctb.Tools[2] as CogAcqFifoTool;
                IFTool = new CogImageFileTool();
            }
            catch (Exception ex)
            {
                rs += ex.Message + ",";
            }

            if (Acq1.Operator == null)
            {
                rs += "cam1 未连接,";
            }
            if (Acq2.Operator == null)
            {
                rs += "cam2 未连接,";
            }
            if (Acq3.Operator == null)
            {
                rs += "cam3 未连接";
            }
            if (rs == "")
            {
                return("OK");
            }
            else
            {
                return(rs);
            }
        }
Exemplo n.º 10
0
        public CogToolBlock LoadVpp()
        {
            if (File.Exists(VppFileName))
            {
                MyCogToolBlock = CogSerializer.LoadObjectFromFile(VppFileName) as CogToolBlock;
            }
            else
            {
                MyCogToolBlock = new CogToolBlock();
            }

            if (!MyCogToolBlock.Inputs.Contains("InputImage"))
            {
                MyCogToolBlock.Inputs.Add(new CogToolBlockTerminal("InputImage", new CogImage8Grey()));
            }

            if (!MyCogToolBlock.Inputs.Contains("Brand"))
            {
                MyCogToolBlock.Inputs.Add(new CogToolBlockTerminal("Brand", ""));
            }

            if (!MyCogToolBlock.Inputs.Contains("iAcquirePositionIndex"))
            {
                MyCogToolBlock.Inputs.Add(new CogToolBlockTerminal("iAcquirePositionIndex", 0));
            }

            if (!MyCogToolBlock.Inputs.Contains("iViewRow"))
            {
                MyCogToolBlock.Inputs.Add(new CogToolBlockTerminal("iViewRow", 1));
            }

            if (!MyCogToolBlock.Inputs.Contains("iViewColumn"))
            {
                MyCogToolBlock.Inputs.Add(new CogToolBlockTerminal("iViewColumn", 20));
            }

            return(MyCogToolBlock);
        }
Exemplo n.º 11
0
        public static void CloseCognexCamera(CogToolBlock toolblock)
        {
            if (toolblock == null) return;

            int n = toolblock.Tools.Count;
            for (int i = 0; i < n; i++)
            {
                if (toolblock.Tools[i] is CogAcqFifoTool)
                {
                    CogAcqFifoTool fifo = (CogAcqFifoTool)toolblock.Tools[i];
                    if (fifo.Operator != null && fifo.Operator.FrameGrabber != null)
                    {
                        fifo.Operator.FrameGrabber.Disconnect(false);
                    }
                }
                else if (toolblock.Tools[i] is CogToolBlock)
                {
                    CogToolBlock tb = (CogToolBlock)toolblock.Tools[i];
                    CloseCognexCamera(tb);
                }
            }

        }
Exemplo n.º 12
0
        private void AssignToolResult(CogToolBlock cogToolBlock)
        {
            foreach (CogToolBlockTerminal output in cogToolBlock.Outputs)
            {
                if ((output.ValueType == typeof(double) || output.ValueType == typeof(int)) && output.Value != null)
                {
                    AddResult(string.Format("{0}.{1}", cogToolBlock.Name, output.Name), Convert.ToDouble(output.Value));
                }
                else if ((output.ValueType == typeof(string)) && output.Value != null)
                {
                    AddResult(string.Format("{0}.{1}", cogToolBlock.Name, output.Name), output.Value.ToString());
                }

                else if (output.ValueType == typeof(CogBlobResults))
                {
                    AssignToolResult(string.Format("{0}.{1}", cogToolBlock.Name, output.Name), output.Value as CogBlobResults);
                }
                else if (output.ValueType == typeof(CogHistogramResult))
                {
                    AssignToolResult(string.Format("{0}.{1}", cogToolBlock.Name, output.Name), output.Value as CogHistogramResult);
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="filePath">文件路径</param>
        public void Init(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath cannot be null");
            }

            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException($"filePath invalid({filePath})");
            }

            try
            {
                vppFilePath = filePath;

                lock (threadLock)
                {
                    IsInit = false;

                    //释放之前的资源
                    cogToolBlock?.Dispose();
                    cogToolBlock = null;

                    //加载VisionPro工具
                    cogToolBlock = CogSerializer.LoadObjectFromFile(vppFilePath) as CogToolBlock;

                    //加载显示界面
                    IsInit = Init(cogToolBlock);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 14
0
        private CogToolBlock GetGrabberBuffer()
        {
            CogToolBlock grabberBuffer = null;

            foreach (ICogTool cogTool in CogToolGroup.Tools)
            {
                //AssignImageToTool(cogTool, cogImage);
                if (cogTool.Name == "Grabber Buffer" && cogTool is CogToolBlock)
                {
                    grabberBuffer  = cogTool as CogToolBlock;
                    _grabberBuffer = grabberBuffer;
                    break;
                }
            }
            if (grabberBuffer == null)
            {
                grabberBuffer      = new CogToolBlock();
                grabberBuffer.Name = "Grabber Buffer";
                CogToolBlockTerminal outputTerminal = new CogToolBlockTerminal("OutputBuffer", typeof(ICogImage));
                grabberBuffer.Outputs.Add(outputTerminal);
                CogToolGroup.Tools.Insert(0, grabberBuffer);
            }
            return(grabberBuffer);
        }
Exemplo n.º 15
0
 public void SetupToolBlockEditSubject(CogToolBlock tool, int index)
 {
     cogToolBlockEditV2[index].Subject = tool;
 }
Exemplo n.º 16
0
 public static void LoadVPP()
 {
     _block = (CogToolBlock)CogSerializer.LoadObjectFromFile(vppFilePath);
 }
Exemplo n.º 17
0
        /// <summary>
        /// 开启vpp编辑画面
        /// </summary>
        /// <param name="cogCalibCheckerboard">棋盘格矫正工具</param>
        /// <param name="cogCalibNPointToNPoint">坐标系标定工具</param>
        /// <param name="enableCheckerboard">启用棋盘格工具</param>
        /// <param name="enableCalibNPointToNPoint">启用坐标系工具</param>
        /// <param name="cogToolBlock">编辑vpp</param>
        /// <param name="backupToolBlock">备份vpp</param>
        /// <param name="toolBlockId">工具id</param>
        /// <param name="titleText">vpp名称</param>
        public void ShowEdit(CogCalibCheckerboardTool cogCalibCheckerboard, CogCalibNPointToNPointTool cogCalibNPointToNPoint, bool enableCheckerboard, bool enableCalibNPointToNPoint, CogToolBlock cogToolBlock, CogToolBlock backupToolBlock, int toolBlockId, string titleText)
        {
            //mod 20200918 by wangsizhe start
            ////_save = false;
            //if (cogToolBlock == null)
            //{
            //    cogToolBlock = new CogToolBlock();
            //}

            //if (cogCalibCheckerboard == null)
            //{
            //    cogCalibCheckerboard = new CogCalibCheckerboardTool();
            //}

            //if (cogCalibNPointToNPoint == null)
            //{
            //    cogCalibNPointToNPoint = new CogCalibNPointToNPointTool();
            //}

            //_enableCheckerboard = enableCheckerboard;
            //_enableCalibNPointToNPoint = enableCalibNPointToNPoint;
            //_cogCalibCheckerboard = cogCalibCheckerboard;
            //_cogCalibNPointToNPoint = cogCalibNPointToNPoint;
            //Text = titleText;
            //_backupToolBlock = backupToolBlock;
            //_cogToolBlock = cogToolBlock;
            //_toolBlockId = toolBlockId;
            //cogToolBlockEditV21.Subject = _cogToolBlock;
            //Show();
            cogToolBlockEditV21.Invoke(new Action(delegate
            {
                if (cogToolBlock == null)
                {
                    cogToolBlock = new CogToolBlock();
                }

                if (cogCalibCheckerboard == null)
                {
                    cogCalibCheckerboard = new CogCalibCheckerboardTool();
                }

                if (cogCalibNPointToNPoint == null)
                {
                    cogCalibNPointToNPoint = new CogCalibNPointToNPointTool();
                }

                _enableCheckerboard        = enableCheckerboard;
                _enableCalibNPointToNPoint = enableCalibNPointToNPoint;
                _cogCalibCheckerboard      = cogCalibCheckerboard;
                _cogCalibNPointToNPoint    = cogCalibNPointToNPoint;
                Text                        = titleText;
                _backupToolBlock            = backupToolBlock;
                _cogToolBlock               = cogToolBlock;
                _toolBlockId                = toolBlockId;
                cogToolBlockEditV21.Subject = _cogToolBlock;
                Show();
            }));
            //mod 20200918 by wangsizhe end
        }
Exemplo n.º 18
0
        public static void EditBlockInputParams(ObservableCollection <RectifiedParam> dataSource, List <Tuple <string, string> > nameMapping_fromTo, ref CogToolBlock block)
        {
            Debug.Assert(dataSource.Count == nameMapping_fromTo.Count);

            var dict = new Dictionary <string, double>();

            foreach (var d in dataSource)
            {
                dict.Add(d.Name, d.Value);
            }

            for (int i = 0; i < dataSource.Count; i++)
            {
                block.Inputs[nameMapping_fromTo[i].Item2].Value = dict[nameMapping_fromTo[i].Item1];
            }
        }
Exemplo n.º 19
0
 public void UpdateData(MyDefine Common)
 {
     mToolBlockProcess = CogSerializer.LoadObjectFromFile(Common.file_toolblock_process) as CogToolBlock;
     mIFTool.Operator.Open(Common.file_image_database, CogImageFileModeConstants.Read);
 }
Exemplo n.º 20
0
 private void DisplayData(CogToolBlock checker)
 {
     Wight       = Convert.ToDouble(checker.Outputs["Width"].Value);
     label2.Text = Wight.ToString("F2");
 }
Exemplo n.º 21
0
 public void RunToolBlock(CogToolBlock toolBlock)
 {
     RunToolBlock(toolBlock, InputImage, Brand, ImageIndex);
 }
Exemplo n.º 22
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            try
            {
                string loadMsg = string.Empty;


                string saveImage = GetValue("SaveImage");
                if (saveImage == "")
                {
                    saveImage = "true";
                    SetValue("SaveImage", saveImage);
                }
                isSaveImage = !bool.Parse(saveImage);
                tsbSaveImage_Click(null, null);

                imageSavePath = GetValue("SaveImagePath");
                if (imageSavePath == "")
                {
                    imageSavePath = Application.StartupPath + "\\图片";
                    SetValue("SaveImagePath", imageSavePath);
                }

                //订阅事件
                cognexAreaCamera.CameraStatusChange += CognexAreaCamera_CameraStatusChange;

                //载入相机
                string cameraPath = GetValue("CameraVppPath");
                if (cameraPath == "")
                {
                    cameraPath = Application.StartupPath + "\\Vpp\\acq.vpp";
                    SetValue("CameraVppPath", cameraPath);
                }
                //cognexAreaCamera.LoadCamera(1, cameraPath,out cameraLoadStatus,out loadMsg);
                acqFifoTool = (CogAcqFifoTool)CogSerializer.LoadObjectFromFile(cameraPath,
                                                                               new BinaryFormatter().GetType(), CogSerializationOptionsConstants.Minimum);
                if (acqFifoTool.Operator != null)
                {
                    crdLiveImage.StartLiveDisplay(acqFifoTool.Operator);
                    //runStart = true;
                    CognexAreaCamera_CameraStatusChange(1, true);
                    processEndStatus = true;
                }

                //if (cameraLoadStatus)
                //{
                //    crdLiveImage.StartLiveDisplay(cognexAreaCamera.AcqFifo);
                //    //runStart = true;
                //    processEndStatus = true;
                //}

                //载入Vpp
                string processVppPath = GetValue("ProcessVppPath");
                if (processVppPath == "")
                {
                    processVppPath = Application.StartupPath + "\\Vpp\\test.vpp";
                    SetValue("ProcessVppPath", processVppPath);
                }
                processToolBlock = (CogToolBlock)CogSerializer.LoadObjectFromFile(processVppPath,
                                                                                  new BinaryFormatter().GetType(), CogSerializationOptionsConstants.Minimum);

                if (processToolBlock != null)
                {
                    processThread              = new Thread(ThreadProcess);
                    processThread.Priority     = ThreadPriority.AboveNormal;
                    processThread.IsBackground = true;
                    processThread.Start();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("初始化软件异常:" + ex);
                Close();
            }
        }
Exemplo n.º 23
0
 private void FrmToolBlock_ToolBlockSave(int toolBlockId, CogToolBlock editTool, CogToolBlock backupTool, bool save)
 {
     if (save)
     {
         processToolBlock = editTool;
         CogSerializer.SaveObjectToFile(processToolBlock, GetValue("ProcessVppPath"));
     }
 }
Exemplo n.º 24
0
 /// <summary>
 /// 设置工具编辑器内容
 /// </summary>
 /// <param name="subject"></param>
 public void SetCogToolBlockEditSubject(CogToolBlock subject)
 {
     CogToolBlockEditV2.FilenameChanged -= CogToolBlockEditV2_FilenameChanged;
     CogToolBlockEditV2.Subject          = subject;
     CogToolBlockEditV2.FilenameChanged += CogToolBlockEditV2_FilenameChanged;
 }
Exemplo n.º 25
0
 /// <summary>
 /// 创建LoadedNewVppFileEventArgs新实例
 /// </summary>
 /// <param name="cogToolBlock">VPP ToolBlock实例</param>
 /// <param name="fileName">文件名</param>
 public NewVppFileLoadedEventArgs(CogToolBlock cogToolBlock, string fileName)
 {
     CogToolBlock = cogToolBlock;
     FileName     = fileName;
 }