'!TITLE "Robot program"

Sub Main
	TakeArm Keep = 0
	
	Dim ctrl as object ' cam provider handle

	Dim machtes as integer 'count of matches
	Dim it as integer ' iterator 
	Dim pos as position 'position of selected target

	'Init Cam
	ctrl = Cao.AddController("Sick1", "CaoProv.SickAG.PLOC2D", "","@EventDisable=false,Device=Inspector,IP=192.168.0.1,Port=1223,Timeout=2000")

	'Init needed variables
	CAll ctrl.AddVariable("@X", "")
	CAll ctrl.AddVariable("@Y", "")
	CAll ctrl.AddVariable("@RZ", "")
	CAll ctrl.AddVariable("@MATCHES", "")
	
	' locate all targets for job 7 an get match count
	Call ctrl.Execute("LocateTargets", "7") ' Job 7
	machtes = ctrl.Variables("@MATCHES").Value ' get match count

	' iterate all matches
	For it = 1 to machtes

		'get target coordinate by selecting
		CAll ctrl.Execute("SelectTarget", "7," & it)
		 	
		' map data to pos
		pos = P(ctrl.Variables("@X").Value, ctrl.Variables("@Y").Value, 0, 0, 0, ctrl.Variables("@RZ").Value)
		
		' do anything with postion (e.g. move robot)
		'Move L, @0 pos

	next

	'relese cam provider
	call ctrl.Variables.Remove(ctrl.Variables("@X").Index)
	call ctrl.Variables.Remove(ctrl.Variables("@Y").Index)
	call ctrl.Variables.Remove(ctrl.Variables("@RZ").Index)
	call ctrl.Variables.Remove(ctrl.Variables("@MATCHES").Index)
	cao.Controllers.Remove ctrl.Index

End Sub
