'!TITLE "Sample program with EYE+ provider"

Sub Main
' Start Communication by creating the EYE+ provider
	Dim Eyeplus as Object
	Eyeplus = cao.AddController("eyeplus", "CaoProv.Asyril.Eyeplus","","conn=TCP:192.168.0.50:7171,Timeout=30")

	Set IO[24] ' Open Gripper

	'Start EYE+ in production using correct recipe identifier
	Dim response as String
	response = Eyeplus.Execute("start production 12345")
	If response = "200" Then
		'Start pick and place scenario
		Dim it as Integer
		For it = 0 to 2000
			'Move robot out of field of view
			Move P, @P J[out_of_view]

			'Get one part coordinates
			response = Eyeplus.Execute("get_part")
			If Mid(response, 0, 3) = "200" Then
				'Set pick position
				Call SetPositionNumber(42, response)

				'Move on the part
				Approach P, P[42], 50
				Move L, P[42]

				Reset IO[24] 'Close Gripper

				'Move on place position
				Depart 50
				Approach P, P[place_position], 50
				Move L, P[place_position]

				Set IO[24] ' Open Gripper

				'Move to above place position
				Depart 50
			End If
		Next
	End If

	' Stop EYE+ production state
	response = Eyeplus.Execute("stop production")

	' Stop communication
	cao.Controllers.Remove Eyeplus.Index
	Eyeplus = Nothing
End Sub

Sub SetPositionNumber(ByRef num as Integer, ByVal response as string)
	' Implement your method to extract the coordinates and set the desired point position
    ' for example if response = "200 x=12345.12345 y=12.89742 rz=128.42"
    ' You must get the following position for rx=180
    P[42] = P(12345.12345,12.89742,0,180,0,128.42)
End Sub
