Using the Tool Display ControlCognex VisionPro

The Cognex Tool Display control displays images, graphics, and other state information associated with a vision tool's records. It uses the CogRecord and the tool's ICogTool interface to connect images and graphics to a CogDisplay.

The following figure shows the Tool Display control showing a current InputImage:

Display Images Walkthrough Use Display Control Howto Use the Tool Display Control splash 1

The following figure shows the Tool Display control showing a Blob tool's last run image with graphics:

Display Images Walkthrough Use Display Control Howto Use the Tool Display Control splash 2

Images List

The control's CogComboBox lists the images and graphics from the current record and its subrecords. You can click on the list and select which image or graphic to display. If the record hierarchy contains only one image, the CogComboBox is disabled, but displays the images name. If no images are available, the CogComboBox is empty and disabled. The list of images and graphics is refreshed whenever a new Subject record is set or the tool's inspection records change.

Display Area

The CogDisplay area of the control displays the currently selected image and its associated graphics. You manipulate this display as you would a CogDisplay control.

Properties and Methods

The Tool Display control has the following properties, methods, and events:

Table 1. Tool Display Properties
PropertyDescription
SelectedRecordKey

Returns the key of the currently-selected inspection record, or selects a different record using the given key string. When you change the SelectedRecordKey property, it fires a RecordChange event.

Subject

Returns or sets a reference to the top-level CogRecord object for the set of inspection records to display. If you set the Tool property to a specific vision tool, the Subject is automatically set. Otherwise, you must set Subject to a specific CogRecord object. You can also set Subject to NULL to disconnect the Tool Display control from the inspection records. Whenever you set this property, the control's list of inspection records and displayable images is updated.

Tool

Returns or sets a reference to the VisionPro tool associated with this Tool Display control. If the Tool property is set, the control obtains its Subject inspection record automatically from the tool using its CreateCurrentRecord and CreateLastRunRecord methods. If you do not set the Tool property, you must set the control's Subject property to a specific CogRecord object.

Table 2. Tool Display Methods
MethodDescription
Refresh

Updates the control's list of images and graphics that are contained in the current inspection record.

Table 3. Tool Display Events
EventDescription
RecordChange

Fires when the selected inspection record changes.

Using the Tool Display Control

You can use the Cognex Tool Display control in either of two modes:

  • automatic mode
  • manual mode

The next section describes how to use each of these modes.

Automatic Mode

In automatic mode, you set the control's Tool property to the vision tool for which you want to display record information. The control obtains CogRecord objects from the tool's CreateCurrentRecord and CreateLastRunRecord methods, and uses the record to set its Subject property. Whenever the tool fires a Changed event, indicating that its inspection records have changed, the control obtains new records, and automatically displays the record information. For example, if you call the tool's Run or Train methods, the control displays the new record information. The following code shows how to use the Tool Display control in automatic mode.

CogToolDisplay mToolDisplay = new CogToolDisplay();

mToolDisplay.Tool = myVisionTool;
Manual Mode

In manual mode, you set the control's Subject property to the specific CogRecord object that contains the hierarchy of tool information to display. Manual mode is suitable for applications in which a record is generated by your custom code. The underlying CogRecords will typically be generated by vision tools, but the top-level record need not be. In order to display new record information, you must programmatically set theSubject property to a new CogRecord. The following code shows how to use the Tool Display control in manual mode.

Dim LastRunRecord As CogRecord
Set LastRunRecord = myVisionTool.CreateLastRunRecord
Dim InputImageRecord As CogRecord
Set InputImageRecord = LastRunRecord("InputImage")
Set ToolDisplay.Subject = InputImageRecord