使用脚本可以:
- 根据运行的结果有条件的执行其它工具
- 对结果执行额外的计算
- 创建用户自己可重复使用的工具
有三个地方可用使用脚本
-
ToolGroup scripts lets you control the behavior of a tool group.
-
Job scripts gives you access to the acquisition process for a QuickBuild Job.
-
CogToolBlock scripts allow you customize and extend the capabilities of any of the vision tools the CogToolBlock contains, or to add additional logic to the results generated by the vision tools.
-
ToolGroup脚本可用控制一个tool group的behavior
-
Job脚本使你可用接触到一个QuickBuild Job的采集过程
-
CogToolBlock允许你定制和扩展视觉工具包含的能力,或者对结果增加额外的逻辑
Tool Group脚本
在ToolGroup中定义输入输出端口
在Initialize方法中调用DefineScriptTerminal
public override void Initialize(CogToolGroup host)
{
// DO NOT REMOVE - Call the base class implementation first - DO NOT REMOVE
base.Initialize(host);
Int32 res = 0;
this.toolGroup.DefineScriptTerminal(res,"Result",false);
this.toolGroup.DefineScriptTerminal(res,"Input1",true);
this.toolGroup.DefineScriptTerminal(res,"Input2",true);
}
在GroupRun中调用GetScriptTerminalData获取输入,调用SetScriptTerminalData设置输出
// Multiply the values of the two input terminals and place the result on the output terminal
Int32 m1 = (Int32) this.toolGroup.GetScriptTerminalData("Input1");
Int32 m2 = (Int32) this.toolGroup.GetScriptTerminalData("Input2");
this.toolGroup.SetScriptTerminalData("Result",m1*m2);