SherLock GUI 开发函数详解
中文版 V1.0
Custom GUI Architecture
The Sherlock 7开发GUI需要一下两个控件:
1. Sherlock Engine – IpeEngCtrl module
2. Sherlock Image control – IpeDspCtrl
Initializing the Sherlock Engine加载引擎举例
Private WithEvents objIpeEngCtrl As IpeEngCtrlLib.Engine
Dim nReturn As IpeEngCtrlLib.I_ENG_ERROR
Private Sub CreateSherlockEngine()
Dim IpeEngCtrlType As Type
IpeEngCtrlType = Type.GetTypeFromProgID("IpeEngCtrl.Engine")
objIpeEngCtrl = Activator.CreateInstance(IpeEngCtrlType)
nReturn = objIpeEngCtrl.EngInitialize()
End Sub
Terminating the Sherlock Engine销毁引擎举例
Private Sub HaltSherlockEngine(ByRef objIpeEngCtrl As IpeEngCtrlLib.Engine)
nReturn = objIpeEngCtrl.InvModeSet(
IpeEngCtrlLib.I_MODE.I_EXE_MODE_HALT_AFTER_ITERATION)
Dim mode As IpeEngCtrlLib.I_MODE
Do
nReturn = objIpeEngCtrl.InvModeGet(mode)
Application.DoEvents()
Loop While (mode <> IpeEngCtrlLib.I_MODE.I_EXE_MODE_HALT)
End Sub
Here is another approach, in which the Do/While loop is replaced with a call
Private Sub HaltSherlockEngine(ByRef objIpeEngCtrl As IpeEngCtrlLib.Engine)
nReturn = objIpeEngCtrl.InvModeSet(
IpeEngCtrlLib.I_MODE.I_EXE_MODE_HALT_AFTER_ITERATION)
InvModeWaitForHalt ()
End Sub
加载Sherlock .ivs文件
from the directory: \Programs.nReturn = objIpeEngCtrl.InvLoad("Simple0.ivs")
显示图像窗口
'connect display
AxIpeDspCtrl1.ConnectEngine(objIpeEngCtrl.GetEngineObj())
AxIpeDspCtrl1.ConnectImgWindow("imgA")
AxIpeDspCtrl1 is an IpeDspCtrl created by dropping IpeDspCtrl on the form.
objIpeEngCtrl is the Sherlock Engine control.
“imgA” is the name of a Sherlock image window that exists in the previously-loaded
Sherlockinvestigation.
读写变量
„ Read the value of the Sherlock number variable varCount
„ into the local VB variable dblCount
Dim dblCount as Double
nReturn = objIpeEngCtrl.VarGetDouble("varCount", dblCount)
„ Set the Sherlock number variable varThreshold to 110
nReturn = objIpeEngCtrl.VarSetDouble("varThreshold", 110)
**************************************引擎控制参数
EngExecuteSub (BSTR bstrSub) 执行sub 程序
Parameters
bstrSub subroutine name
Returns:I_OK on success
EngInitialize ()加载
Initialize the Engine. Must be called after creating the engine object.
Returns:I_OK on success
EngSetAcqIni (BSTR bstrFile) 设置采集参数,一般保存在Drivers.ini
Parameters
bstrName drivers ini file
Returns:I_OK on success
Example
'create the engine
IpeEngCtrlType = Type.GetTypeFromProgID("IpeEngCtrl.Engine")
objIpeEngCtrl = Activator.CreateInstance(IpeEngCtrlType
'load a Drivers.ini file specific to an investigation
nReturn = objIpeEngCtrl.EngSetAcqIni("Drivers_Part_47B.ini")
'initialize the engine
nReturn = objIpeEngCtrl.EngInitialize
'load the investigation
nReturn = objIpeEngCtrl.InvLoad("Part_47B.ivs")
EngTerminate ()结束
Returns:I_OK on success
GetEngineObj (LONG * pnEngObj) 获取对象
Parameters
pnEngObj internal engine handle
Returns I_OK on success
*****************************程序管理
InvGetLastLoaded (BSTR * pbstrName)获取最后一次加载程序的名称
Parameters
pbstrName the name of the last successfully loaded investigation
Returns:I_OK on success
InvGetName (BSTR * pbstrName)获取现在运行的程序名称
Parameters
pbstrName the returned name of the currently-loaded investigation
Returns
I_OK on success
InvLoad (BSTR bstrFile)加载程序
Parameters
bstrFile file name
Returns:I_OK on success
InvLoadComp (BSTR bstrFile, BSTR bstrPwd)加载加密文件 ivx
Parameters
bstrFile file name
bstrPwd the password that was supplied when the compressed investigation was created
Returns:I_OK on success
InvModeGet (I_MODE * pnMode)获取当前运行的模式
Parameters
pnMode the current engine run mode
Returns:I_OK on success
InvModeSet (I_MODE nMode) 设置运行模式
I_EXE_MODE_ONCE - 运行一次
I_EXE_MODE_CONT -一直运行
I_EXE_MODE_CALIB -”运行校正程序
I_EXE_MODE_HALT - 遇到问题就终止
I_EXE_MODE_HALT_AFTER_ITERATION -在完成当前迭代停止调查
I_EXE_MODE_HALT: 从这个调用返回后的引擎将停止。因为引擎可能需要一些时间来完全停止,需
要等到InvModeGet回报I_EXE_MODE_HALT.
I_EXE_MODE_HALT_AFTER_ITERATION: 触发收购需要特别注意,因为引擎可能永远等待触
发器。
Parameters
nMode run mode
Returns:I_OK on success
InvModeWaitForHalt ()等待状态
Returns:I_OK on success
InvSave (BSTR bstrFile)保存文件
Parameters
bstrFile full file name
Returns:I_OK on success
InvSaveComp (BSTR bstrFile, BSTR bstrPwd) 带密码的保存文件
Parameters
bstrFile file name
bstrPwd password
Returns:I_OK on success
*****************************************指令管理
InstrCommand (BSTR bstrName, long cmd, VARIANT val) 执行指令
Parameters
bstrName instruction name
cmd command to execute
val a variant containing an optional value for the command
Returns:I_OK on success
Example
'Display the parameters dialog for Grayscale OCR being invoked from
' rectA
nReturn = objIpeEngCtrl. InstrCommand("rectA.Grayscale OCR", _
INSTR_SHOW_PARMS_DLG, 0)
InstrGetParam (BSTR bstrName, long paramId, VARIANT * pVal)获取一条指令参数
Parameters
bstrName instruction name
paramId the ordinal used to identify the parameter
pVal the parameter's value
Returns:I_OK on success
InstrSetParam (BSTR bstrName, long paramId, VARIANT val)设置指令的参数
Parameters
bstrName instruction name
paramId the ordinal used to identify the parameter
val the value for the parameter
Returns:I_OK on success
**************************************相机管理
CamAcqAbort ()终止相机采集
Returns:I_OK on success
CamCountGet (long * pnVal)获取相机个数
Parameters
pnVal the returned number of cameras
Returns:I_OK on success
CamSizeGet (long nCam, long * pnWidth, long * pnHeight) 相机尺寸设置
Parameters
nCam zero based camera index
pnWidth the returned camera‟s width (pixels)
pnHeight the returned camera‟s height (pixels)
Returns:I_OK on success
**************************************IO管理
DigInIOCountGet获取输入点个数
DigInIOCountGet (long * pnVal)
Parameters
pnVal the number of inputs
Returns:I_OK on success
DigInIOGet获得现在的出入点状态
DigInIOGet (long nChannel, long * pnVal)
Parameters
nChannel input index
pnVal the input state, 0 or 1
Returns:I_OK on success
DigInIOWaitForPulse 等待相应的脉冲
DigInIOWaitForPulse (long nChannel, BOOL bHighPulse, long nTimeout, BOOL *
bTimeoutDetected)
Parameters
nChannel input index
bHighPulse direction of pulse : TRUE: high_low; FALSE: low_high
nTimeout maximum wait time in milliseconds (-1 for an infinite wait)
bTimeoutDetected TRUE if timeout occurred before the requested pulse occurred,
FALSE if the requested pulse occurred before timeout occurred
Returns:I_OK on success
DigInIOWaitForState 等待相应的状态信号
DigInIOWaitForState (long nChannel, BOOL bVal, long nTimeout, BOOL *
bTimeoutDetected)
Parameters
nChannel input index
bVal input state to wait for, TRUE or FALSE
nTimeout maximum wait time in milliseconds (-1 for an infinite wait)
bTimeoutDetected TRUE if timeout occurred before the requested state was detected,
FALSE if the requested state was detected before timeout occurred
Returns:I_OK on success
DigOutIOAsyncPulse异步脉冲数字输出
DigOutIOAsyncPulse (long nChannel, BOOL bHighPulse, long nPulseWidth)
Parameters
nChannel channel index
bHighPulse pulse polarity : TRUE for high-low , FALSE for low-high
nPulseWidth pulse width in milliseconds
Returns:I_OK on success
DigOutIOCountGet获取输出点个数
DigOutIOCountGet (long * pnVal)
Parameters
pnVal output count
Returns:I_OK on success
DigOutIOGet获取输出点状态
DigOutIOGet (long nChannel, long * pnVal)
Parameters
nChannel channel index
pnVal output value, 0 or 1
Returns:I_OK on success
DigOutIOPulse脉冲数字输出
DigOutIOPulse (long nChannel, BOOL bHighPulse, long nPulseWidth)
Parameters
nChannel channel index
bHighPulse pulse polarity : TRUE for high-low , FALSE for low-high
nPulseWidth pulse width in milliseconds
Returns:I_OK on success
DigOutIOScheduleAsyncPulse安排一个异步脉冲开始nDelay毫秒执行后调用
DigOutIOScheduleAsyncPulse (long nChannel, BOOL bHighPulse, long nDelay, long
nPulseWidth)
Parameters
nChannel channel index
bHighPulse pulse polarity : TRUE for high-low , FALSE for low-high
nDelay delay before starting the pulse
nPulseWidth pulse width in milliseconds
Returns:I_OK on success
DigOutIOSet设置一个数字输出值。
DigOutIOSet (long nChannel, long nVal)
Parameters
nChannel channel index
nVal output value, 0 or 1
Returns:I_OK on success
*************************************变量管理
VarGetBool (BSTR bstrName, VARIANT_BOOL * pval)
VarGetBoolArray (BSTR bstrName, SAFEARRAY(VARIANT_BOOL)* paval)
VarGetDouble (BSTR bstrName, double * pval)
VarGetDoubleArray (BSTR bstrName, SAFEARRAY(double)* paval)
VarGetLine (BSTR bstrName, I_LINE * pval)
VarGetLineArray (BSTR bstrName, SAFEARRAY(I_LINE)* paval)
VarGetNames (SAFEARRAY(BSTR)* paval)
VarGetPoint (BSTR bstrName, I_POINT * pval)
VarGetString (BSTR bstrName, BSTR * pval)
VarGetStringArray (BSTR bstrName, SAFEARRAY(BSTR)* paval)
VarGetTypes (SAFEARRAY(I_VAR_TYPE)* paval)
VarSetBool (BSTR bstrName, VARIANT_BOOL val)
VarSetBoolArray (BSTR bstrName, SAFEARRAY(VARIANT_BOOL)* paval)
VarSetDouble (BSTR bstrName, double val)
VarSetDoubleArray (BSTR bstrName, SAFEARRAY(double)* paval)
VarSetLine (BSTR bstrName, I_LINE * pval)
VarSetLineArray (BSTR bstrName, SAFEARRAY(I_LINE)* paval)
VarSetPoint (BSTR bstrName, I_POINT * pval)
VarSetPointArray (BSTR bstrName, SAFEARRAY(I_POINT)* paval)
VarSetString (BSTR bstrName, BSTR val)
VarSetStringArray (BSTR bstrName, SAFEARRAY(BSTR)* paval)
******************************图像窗口管理
SoCameraGet 获取图像窗口对应的相机编号
SoCameraGet (BSTR bstrSo, long * pnCam)
Parameters
bstrSo image window name
pnCam camera index
Returns:I_OK on success
SoCameraSet设置相机到对应的窗口
SoCameraSet (BSTR bstrSo, long nCam)
Parameters
bstrSo image window name.
Returns:I_OK on success
SoCamSnap获得单一的图像从图像窗口图像源
SoCamSnap (BSTR bstrSo)
Parameters
bstrSo image window name
Returns:I_OK on success
SoGetNames获得图像的所有窗口的名称
SoGetNames (SAFEARRAY(BSTR)* paval)
Parameters
paval array of image window names
Returns:I_OK on success
SoGetSize得到一个图像窗口的图像尺寸
SoGetSize (BSTR bstrSo, long * pnWidth, long * pnHeight)
Parameters
bstrSo image window name
pnWidth image window width
pnHeight image window height
Returns:I_OK on success