C# 将单元写入 In-Sight Explorer (cognex)

标签 c# cognex

我发现此页面有一个从 Insight-Explorer 提取单元格信息的示例,但是...如何从 C# 应用程序写入单元格?

C# extract Cell Information from In-Sight Explorer (Cognex)

最佳答案

如果您想使用 C# 控制 In-Sight 相机当前作业文件中的单元,这里是对我有用的方法。请注意,我使用的是 In-Sight Explorer v5.9.0,但我也在早期版本上对此进行了测试,它仍然有效。

注意:如果没有 Cognex In-Sight SDK 许可证,您将无法在 Visual Studio 中运行此应用程序。您必须构建项目,然后直接运行可执行文件。

  1. 打开Visual Studio
  2. 创建新的控制台应用 (.NET Framework) 项目
  3. 我使用的是.NET Framework 4.7.2
  4. 右键单击解决方案资源管理器中的项目,然后添加对 Cognex.InSight.dll 文件的引用(该文件通常位于此处:C:\Program Files (x86))\Common Files\Cognex\In-Sight\5.x.x.x\Cognex.InSight.dll)
  5. 将目标平台设置为 x86
  6. 将下面的代码粘贴到您的项目中
  7. 更改用户名密码ip地址变量以匹配您的相机设置
  8. 构建
  9. 转到调试文件夹并找到构建项目后创建的可执行文件
  10. 双击可执行文件来运行它
using System;
using Cognex.InSight;

namespace ChangeInSightCellValue2
{
    class Program
    {
        static void Main(string[] args)
        {
            string username = "admin";
            string password = "";
            string ipAddress = "127.0.0.1";

            // Create camera object and connect to it
            CvsInSight camera = LogIntoCamera(ipAddress, username, password, true, false);

            // Define which cell you want to modify
            CvsCellLocation cell = new CvsCellLocation(2, 'C');

            // Modify the cell expression
            camera.SetExpression(cell, "Filter($A$0,0,0,0,80,100,320,440,0,0,3,3,1,128,128,128,1,1,0)", true);
        }

        // Log into camera
        private static CvsInSight LogIntoCamera(string sCamIP, string sCamUsername, string sCamPassword, bool forceConnect, bool connectAsynchronous)
        {
            // Create camera object
            CvsInSight insight = new CvsInSight();
            Console.WriteLine("Object created");

            IAsyncResult result;
            // Try logging into the camera on a different thread to prevent locking this one up
            Action action = () =>
            {
                // Connect to camera
                insight.Connect(sCamIP, sCamUsername, sCamPassword, forceConnect, connectAsynchronous);
            };

            result = action.BeginInvoke(null, null);

            if (result.AsyncWaitHandle.WaitOne(5000))
                return insight;

            else
                return insight;
        }
    }
}

注意:如果您在运行此应用程序时使用 In-Sight Explorer 连接到相机,则 In-Sight Explorer 将与相机断开连接,然后在应用程序连接完毕后尝试重新连接。与相机断开连接。

关于C# 将单元写入 In-Sight Explorer (cognex),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42732839/

相关文章:

c# - "Unable to create a constant value of type [MyClass]. Only primitive types are supported in this context."

c# - 在 SignalR hub 中存储特定客户端的连接 ID

vb.net - Cognex Insight SetComment 不持久

C# 从 In-Sight Explorer (Cognex) 中提取细胞信息

c# - 错误4无效的表达词 'else'

C# 如何将 OrderBy 与嵌套类的属性一起使用?

c# - 是否可以在纯托管代码中生成/产生 c0000005 访问冲突异常?