'!TITLE "Cognex_Calibration"


' Attention
' 1. Load the attached file "3PointCal.job" into In-Sight
' 2. Assign an IP address to the file then input the IP address to "IPAddress" shown below
' 3. Open the TP panel after executing this PacScript

' Specify a Camera IP of In-Sight
#define IPAddress "192.168.0.2"

#define CalJobName "3PointCal.job"

Sub Main
	Dim caoCtrl as Object
	Dim bmp as Object
	Dim vntResult as Variant
	Dim lCount as Long
	Dim vntFileLists as Variant
	Dim bFlag as Long
	Dim VResult as Vector

	' Connecting to In-Sight
	caoCtrl = cao.AddController("CognexIn-sight", "caoProv.Cognex.In-Sight", "", "conn=eth:" & IPAddress & ", Timeout = 1000")
	bmp = caoCtrl.AddVariable("@BITMAP")

	' Confirm whether the Job file is loaded
	vntFileLists = caoCtrl.GetFileList
	bFlag = -1
	For lCount= 0 to Ubound(vntFileLists)
		If (vntFileLists(lCount) = CalJobName) Then
			bFlag = 0
		End If
	Next
	if (bFlag) Then
		PrintDbg "Job not found."
		PrintDbg "Plese Set ["& CalJobName &"]."
		Exit Sub
	End if

	' Switching to Offline 
	caoCtrl.SetOnline 0

	' Reading the Job file
	caoCtrl.LoadFile CalJobName
	Delay 1000

	' Switching to Online
	caoCtrl.SetOnline 1
	Delay 1000

	Do
		' Obtaining the image processing result by executing trigger
		On Error Resume Next
		vntResult = caoCtrl.SendMessageAndWait
		VResult = "V(" & vntResult & ")"
		vars.ItemValue(3) = POSX(VResult)
		vars.ItemValue(4) = POSY(VResult)	
		On Error Goto 0

		' Writing variable to pass the result and image to the TP panel
		vars.ItemValue(0) = bmp.Value
		Delay 500
	Loop

End Sub


