我发现这个页面上有一个从Insight-Explorer中提取单元格信息的示例,但是...如果从c#应用程序写入单元格呢?
发布于 2020-09-14 05:08:25
如果你想用C#控制摄像机当前作业文件中的单元格,下面的方法对我很管用。请注意,我使用的是In-Sight Explorerv5.9.0,但我也在早期版本上测试过它,它仍然有效。
注释:如果没有Cognex In-Sight SDK许可证,您将无法在Visual Studio中运行此应用程序。您必须构建项目,然后直接运行可执行文件。
<代码>G247
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将断开与相机的连接,然后在应用程序从相机断开连接后尝试重新连接。
发布于 2017-05-26 11:39:11
您可以使用本地模式命令在In-Sight Explorer中设置电子表格中控件的值(如您链接到的问题中所讨论的)。请注意,您不能将数据写入任何单元格-您只能写入包含EditInt()
、EditFloat()
、EditString()
、CheckBox()
等函数的单元格。通过套接字连接将命令以文本形式发送到摄像机端口23。在建立连接时,您需要向摄像机发送用户名和密码。
发布于 2017-05-26 13:27:07
如果您使用的是Cognex SDK,请使用以下函数
CvsInSight.SetFloat(...)
设置列表控件valuesCvsInSight.SetInteger(...)
设置EditFloat控件valuesCvsInSight.SetListBoxIndex(...)
选择列表中的项boxesCvsInSight.SetString(...)
设置EditString控件valuesCvsInSight.SetCheckBox(...)
更改CheckBox控件的状态
https://stackoverflow.com/questions/42732839
复制相似问题