'!TITLE "VWXG_Calibration"

' Attention
' 1. Set the EtherNet communication port for outputting result of KEYENCE XG to the same value of the line number 9 
' 2. Set the IP Address of the line number to that of KEYENCE XG
' 3. Open the TP panel after executing this PacScript 

' IP Address of the device
#define IPAddress "192.168.0.2"

Sub Main 
	Dim ctrl as object
	Dim VResult as Vector

	' Forcedly closing the result output port 
	comm.Close -1

	' Opening the result output port 
	comm.Open 9

	ctrl = Cao.AddController( "VWXG", "CaoProv.KEYENCE.VWXG", "", "conn=eth:" & IPAddress)

	Do
		' Trigger on
		ctrl.Trigger -1
		
		On Error Resume Next

		' Waiting to obtain results 
		VResult = "V(" & comm.Input(9, 1000) & ")" 
		
		' Converting results to variables so as to pass them to the TP panel
		vars.ItemValue(3) = POSX(VResult)
		vars.ItemValue(4) = POSY(VResult)
	
		On Error Goto 0
	
		Delay 500
	Loop
End Sub


