'!TITLE "PacScriptTest1"

Sub Main 
	
	Dim caoCtrl As Object

	Set caoCtrl = cao.AddController("caoCtrl", "CaoProv.HALCON", "localhost")

	Dim Hobj As Object
	Dim Htpl As Object

	Set Hobj = caoCtrl.AddVariable("@HOBJ")
	Set Htpl = caoCtrl.AddVariable("@HTPL")

	Dim time1 As Integer
	Dim time2 As Integer
	
	time1 = timer()

	Htpl.ID = 1
	Htpl.Value = "DirectShow"
	Htpl.ID = 2
	Htpl.Value = 1
	Htpl.ID = 3
	Htpl.Value = 1
	Htpl.ID = 4
	Htpl.Value = 0
	Htpl.ID = 5
	Htpl.Value = 0
	Htpl.ID = 6
	Htpl.Value = 0
	Htpl.ID = 7
	Htpl.Value = 0
	Htpl.ID = 8
	Htpl.Value = "default"
	Htpl.ID = 9
	Htpl.Value = -1
	Htpl.ID = 10
	Htpl.Value = "default"
	Htpl.ID = 11
	Htpl.Value = -1
	Htpl.ID = 12
	Htpl.Value = "false"
	Htpl.ID = 13
	Htpl.Value = "default"
	Htpl.ID = 14
	Htpl.Value = "0"
	Htpl.ID = 15
	Htpl.Value = -1
	Htpl.ID = 16
	Htpl.Value = -1

	time2 = timer() 

	PrintDbg "引数設定のオーバヘッド : " & Str((time2-time1)) & "[ms]"

	Call caoCtrl.Execute("close_all_framegrabbers", Array("", "", "", "") )

	Call caoCtrl.Execute("open_framegrabber", Array( "", "", Array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ), 17 ) )

	Htpl.ID = 1
	Htpl.Value = "frame_rate"
	Htpl.ID = 2
	Htpl.Value = 30.0
	Call caoCtrl.Execute("set_framegrabber_param", Array("", "", Array(17, 1, 2), "" ) )

	Call caoCtrl.Execute("grab_image", Array( "", 1, 17, "" ) )

        ' 画像サイズなどの属性情報を取得
    Call caoCtrl.Execute("get_image_pointer3", Array(1, "", "", Array("", "", "", "", 18, 19)))

    ' caoCtrlCONオブジェクト(region, xld)描画用の仮想ウィンドウの生成（実際にウィンドウは開きません）
    Htpl.ID = 1
    Htpl.Value = 0
    Htpl.ID = 2
    Htpl.Value = 0
    Htpl.ID = 3
    Htpl.Value = 0
    Htpl.ID = 4
    Htpl.Value = "visible"
    Htpl.ID = 5
    Htpl.Value = ""

	Htpl.ID = 18
	Dim Width As Variant
	Width = Htpl.Value

	Htpl.ID = 19
	Dim Height As Variant
	Height = Htpl.Value

	PrintDbg "サイズ : " & Str(Width) & "*" & Str(Height)

    Call caoCtrl.Execute("open_window", Array("", "", Array(1, 2, 18, 19, 3, 4, 5), 21))

	Htpl.ID = 1
	Htpl.Value = 0
	Htpl.ID = 2
	Htpl.Value = 0

    Call caoCtrl.Execute("set_part", Array("", "", Array(21, 1, 2, 19, 18), ""))

	Htpl.ID = 1
	Htpl.Value = -1

	time1 = timer()

	Dim iLoop As Long
	Dim iLoopMax As Long = 100
	For iLoop = 1 To iLoopMax

		Call caoCtrl.Execute("grab_image_async", Array( "", 1, Array( 17, 1 ), "" ) )
		Call caoCtrl.Execute("disp_obj", Array(1, "", 21, "") )

	Next

	time2 = timer()

	PrintDbg "呼び出しのオーバヘッド : " & Str((time2-time1) / iLoopMax) & "[ms]"

	Call caoCtrl.Execute("grab_image_async", Array( "", 1, Array( 17, 1 ), "" ) )

	Call caoCtrl.Execute("get_image_pointer3", Array( 1, "", "", Array("", "", "", "", 18, 19 ) ) )

	Htpl.ID = 18
	Width = Htpl.Value

	Htpl.ID = 19
	Height = Htpl.Value

	PrintDbg "サイズ : " & Str(Width) & "*" & Str(Height)

	Htpl.ID = 1
	Htpl.Value = "frame_rate"
	Call caoCtrl.Execute("get_framegrabber_param", Array("", "", Array(17, 1), 20 ) )

	Htpl.ID = 20
	PrintDbg "撮影設定 : " & Str(Htpl.Value) & "[fps]"
	PrintDbg "撮影性能 : " & Str(1000 / ( (time2-time1) / iLoopMax ) ) & "[fps]"

	Call caoCtrl.Execute("close_framegrabber", Array( "", "", 17, "") )
    Call caoCtrl.Execute("close_window", Array("", "", 21, ""))

	caoCtrl.Variables.Remove Hobj.Index
	Set Hobj = Nothing

	caoCtrl.Variables.Remove Htpl.Index
	Set Htpl = Nothing
	
	cao.Controllers.Remove caoCtrl.Index
	Set caoCtrl = Nothing

End Sub