VP02 5 BuildingApp-Lab5
VP02 5 BuildingApp-Lab5
VP02 5 BuildingApp-Lab5
The following may be used as a reference on the basic steps for building a VisionPro application in Microsoft
Visual Basic .NET. This should be used in conjunction with the notes presented in Section 2 of the class.
Objectives:
chkShowTrain.Enabled = False
chkShowTrain.Enabled = False
chkShowTrain.Enabled = True
Double‐click on the “Show Training Image” CheckBox and add the following code:
If (chkShowTrain.Checked) Then
btnRunOnce.Enabled = False
chkContinuous.Enabled = False
btnRetrain.Enabled = True
Else
btnRunOnce.Enabled = True
chkContinuous.Enabled = True
btnRetrain.Enabled = False
End If
Imports Cognex.VisionPro.ToolGroup
Imports Cognex.VisionPro.PMAlign
Else
stlStatus.Text = "There is no input image to load as a train image."
End If
This code drills into the CJM to extract the “TrainImage” inspection record from the PMAlignTool.
This record is shown in the display.
When the user pushes the “Show Training Image” button for a second time, we should erase the
training image.
In chkShowTrain_CheckedChanged(), below the ELSE add:
For extra credit: Add a label to your application that always displays the “Trained”, or “Not Trained”
status of the PMAlignPattern in the CJM.
Complete Solution
Imports Cognex.VisionPro
Imports Cognex.VisionPro.QuickBuild
Imports Cognex.VisionPro.ToolGroup
Imports Cognex.VisionPro.PMAlign
End Sub
'Initialize variable
myJob = myJobManager.Job("CogJob1")
myIndependentJob = myJob.OwnedIndependent
'Flush queues
myJobManager.UserQueueFlush()
myJobManager.FailureQueueFlush()
myJob.ImageQueueFlush()
myIndependentJob.RealTimeQueueFlush()
End Sub
Catch ex As Exception
'If there is a problem show the error message
MessageBox.Show(ex.Message)
End Try
End Sub
Return
End If
End Sub
End Sub
Return
End If
End Sub
If (chkShowTrain.Checked) Then
'User toggles "Show Train Image" down
btnRunOnce.Enabled = False
chkContinuous.Enabled = False
btnRetrain.Enabled = True
Else
stlStatus.Text = "There is no input image to load as a train image."
End If
Else
'User toggles "Show Train Image" down
btnRunOnce.Enabled = True
chkContinuous.Enabled = True
btnRetrain.Enabled = False
End If
End Sub