VisionPro · C# · 加载与保存取像工具


VisionPro 项目程序设计,取像工具可被包含在工具包内被调用,一般,为了满足程序取像可以实现单次取像,循环取像,实时取像等多方面应用,会将取像工具独立打包。

加载代码:

 1 using System;
 2 using System.Windows.Forms;
 3 using Cognex.VisionPro;
 4 using Cognex.VisionPro.ToolBlock;
 5         /// 
 6         /// 加载取像工具
 7         /// 
 8         /// 
 9         /// 
10         public CogAcqFifoTool LoadFiFoTool(string VppFilePath)
11         {
12             string mPath = VppFilePath;
13             CogAcqFifoTool fifoTool = null;
14             try
15             {
16                 if (File.Exists(mPath))
17                 {
18                     fifoTool = (CogAcqFifoTool)CogSerializer.LoadObjectFromFile(mPath);
19                     GC.Collect();
20                 }
21                 else
22                 {
23                     MessageBox.Show("取像工具文件不存在,请检查路径!");
24                 }
25             }
26             catch (Exception ex)
27             {
28                 MessageBox.Show("加载取像工具文件失败:" + ex.Message);
29             }
30             return fifoTool;
31         }

保存代码:

using System;
using System.Windows.Forms;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;

        /// 
        /// 保存取像工具
        /// 
        /// 取像工具
        /// 取像工具vpp路径
        public void SaveFiFoTool(CogAcqFifoTool fifoTool, string VppFilePath)
        {
            try
            {
                CogSerializer.SaveObjectToFile(fifoTool, VppFilePath);
            }
            catch (Exception ex)
            {
                MessageBox.Show("取像工具保存失败:" + ex.Message);
            }
        }

参考链接: