Skip to Main Content
Cognex 지원 허브
LogoLogo

How To Handle Failed Tools Inside a TB

Here are 2 ways to handle results from tools that could not run because of a failed tool before them.

2025. 03. 11.

Details

Issue:

Sometimes tools that run early in a tool chain might fail, yet this could still be a situation where it is important that later tools still run. Here are 2 ways to handle results from tools that could not run because of a failed tool before them.

Resolution #1: Pre-setting the outputs with a dummy value

For this to work, "AbortRunOnToolFailure" has to be TRUE. Let’s assume we have a terminal output that contains the inspection result we want to output, and which we need to take care to hold a current value, not from an older run of the TB. We need to put this at the top of the GroupRun() function, because in this case the script might not finish to the end.

    mToolBlock.AbortRunOnToolFailure = true;
   mToolBlock.Outputs["Blobs_Count"].Value = -1;

Resolution #2: Counting tools with errors

For this to work, "AbortRunOnToolFailure" has to be FALSE. If tools failed, the bool output “ToolsFailed” will be TRUE and this can be used as a signal to ignore the results and treat the total result as FAIL. All tools in the TB will still run though.

 mToolBlock.AbortRunOnToolFailure = false;   
   int ToolsFailed = 0;
   foreach(ICogTool tool in mToolBlock.Tools)
   {
     mToolBlock.RunTool(tool, ref message, ref result);
     if (tool.RunStatus.Result == CogToolResultConstants.Error)
     {
       ToolsFailed++;
     }
   }
   mToolBlock.Outputs["ToolsFailed"].Value = (ToolsFailed > 0);

관련 자원