DoEvents "将控制让给其他程序。
Loop
OpenDigitalPoint"Fix32.FIX.DDD.F_CV"
3、显示通讯状态
IsthereawaytoviewcommunicationstatusofthedriverwithoutusingMissionControl?
Resolution
Usingadigitalinputblockreadingahardwareregister,theA_cualmfieldwillbeutilized.ChaintheDIblocktoaneventactionblocktoadigitaloutputtagusingtheSIMdriver.Intheeventactionblockusethefollowingscript:
IFtheA_cualm=com
ThensetDO=1
ElsesettheDO=0
AdatalinkcanbemadetotheSimblock.Thevalueofthisblockwilldeterminethestatusofthecommuncation.
4、用VBA脚本打开和关闭调度
为了打开和关闭调度,必须用下列方法:
打开一个名字为“ddd”的调度:
Application.Documents.Open"C:
\Dynamics\pdb\ddd.evs"
关闭一个名字为“ddd”的调度:
Application.Documents("ddd").Close
注意:
关闭调度时不用扩展名.evs。
5、在后台调度中访问画面中的对象
在调度中中的脚本不能直接访问画面中的对象。
办法:
使用FindObject方法:
DimAppObjasObject
DimPicObjasObject
setAppObj=GetObject("","Workspace.Application")
setPicObj=AppObj.System.FindObject("Pic.Obj")
PicObj.Value=5
Pic为画面的名字,picObj为所用的对象的属性或方法。
6、怎样用程序控制7.X版本的驱动程序的datablocks,devices,orchannels扫描的启停
在应用过程中可能希望灵活的控制驱动程序中的某一个Channel或Device或Datablock,以下介绍两种方法:
6.1.通过编写脚本:
本例子是用脚本来控制第一个Channel的第一个Device的第一个Datablock的,如果你想控制Channel或Device,只需将channelhandle或devicehandle象本例中的Datablock赋给SetPropertyDatafunction即可:
DimobjDriverAsObject
DimstrDRVAcronymAsString
DimstrProgIdAsString
"VariablesforGetChannel
DimlngNumChannelsAsLong
DimlngChanHandles
DimstrChanNames
"VariablesforGetDevices
DimlngNumDevicesAsLong
DimlngDeviceHandles
DimstrDeviceNames
"VariablesforGetDataBlocks
DimlngNumDataBlocksAsLong
DimlngDataBlockHandles
DimstrDataBlockNames
DimlngErrors
DimmyvarAsLong
strDRVAcronym=InputBox("Pleaseenterthedriver""sthreeletteracronym?
"&vbCrLf&"(ForExample:
EnterABRfortheABRDriver)","WhatDriverareyouusing?
")
strProgId="Intellution."&strDRVAcronym&"drv"
SetobjDriver=CreateObject(strProgId)
lngNumChannels=objDriver.GetChannels(lngChanHandles,strChanNames)
lngNumDevices=objDriver.GetDevices(lngChanHandles(0),lngDeviceHandles,strDeviceNames)
lngNumDataBlocks=objDriver.GetDataBlocks(lngDeviceHandles(0),lngDataBlockHandles,strDataBlockNames)
""BuildVariablesforSetPropertyDatafunction.
lngHandle=lngDataBlockHandles(0)
varProperties="Enabled"
varProperyData="1"
lngErrors=objDriver.SetPropertyData(lngHandle,varProperties,varProperyData)
SetobjDriver=Nothing
6.2.大多7.X的驱动程序都有一些特殊的控制地址可以用来控制驱动程序中的Server,group,item的扫描状态,可以查看相应驱动程序的帮助中以"惊叹号"开头的一些特殊地址:
!
MODE-Enablespollingtotheserver,group,oritemspecifiedwhenavalueof1iswrittentoaDigitalOutputblock(AnalogOutputblocksarenotsupported).Disablingaspecifiedobjectoccurswhenavalueof0iswrittentoaDigitalOutputblock.
Youcancreateadatabaseblockwiththeaddress!
MODE:
Datablock1andtriggeritmanually,throughVBAcode,orthroughaProgramBlock.
7、用VBA在一个基于时间的后台调度中计算偏差的例子
你可能想计算在一个指定的时间段内开始时间和结束时间的偏差,在后台调度中用一个定时器来实现
方法:
本例为怎么样取在一个特定时间的开始和结束时的值并计算差值。
它用了两个全局变量和一个基于时间的后台的调度:
1.创建两个全局变量:
"StartSample"和"Initialized"".
2.设置变量的属性:
"StartSample"--"Long";"Initialized"--"Boolean"。
其中"Initialized"初始值为"False"。
3.创建一个基于时间的调度,时间间隔为00:
00:
10。
4.用自定义脚本并写入以下脚本。
5.确认改变tagreference到相应的node和tag。
6.脚本写好后保存调度并设置为用后台运行调度。
7.例子启动后会弹出对话框表面例子初始化了。
8.之后该对话框会显示起始值,终止值和该段时间两者的差值。
注意:
不要忘了将FixBackgroundServer.exe加到启动任务配置中去。
脚本:
-----------------------------------------------------------------------------------------------------------
PrivateSubFixTimer3_OnTimeOut(ByVallTimerIdAsLong)
DimobjWrkSpcAsObject
DimobjStartVarAsObject
DimobjInitAsObject
DimlngEndVarAsLong
DimlngDeltaAsLong
’getWorkspaceobjectandglobalvariablescontainedinworkspace
SetobjWrkSpc=GetObject("","Workspace.Application")
SetobjStartVar=objWrkSpc.Documents("User").Page.FindObject("StartSample")
SetobjInit=objWrkSpc.Documents("User").Page.FindObject("Initialized")
"Checktoseeifthisisthefirsttimethescriptisbeingfired.
"Ifso,initializetheStartSamplevariablewithavaluefromthedesiredtag
"andsettheInitializedflagtotrue.Ifthescripthasbeenfiredoncethen
"taketheendsample,calculatethedifferenceandthenstoreanewstartsample.
IfobjInit.CurrentValue=TrueThen
lngEndVar=readvalue("Fix32.NODE.TAG.F_CV")
lngDelta=lngEndVar-objStartVar.CurrentValue
MsgBox"START:
"&objStartVar.CurrentValue&"END:
"&lngEndVar&_
"DIFFERENCE:
"&lngDelta
objStartVar.CurrentValue=readvalue("Fix32.NODE.TAG.F_CV")
Else
objStartVar.CurrentValue=readvalue("Fix32.NODE.TAG.F_CV")
MsgBox"StartSampleinitializedto"&objStartVar.CurrentValue
objInit.CurrentValue=True
EndIf
"Destroyobjects
SetobjWrkSpc=Nothing
SetobjStartVar=Nothing
SetobjInit=Nothing
EndSub
8、VB中读取iFIX点
ThissamplecodewillreaddatafromaniFIXtag.
"declareafewobjects
DimobjWorkspaceAsObject
DimobjDataItemAsObject
"getreferencetotheworkspace
SetobjWorkspace=CreateObject("Workspace.Application")
"usetheworkspace.systemobjecttoobtaintheOODBdataitem
SetobjDataItem=objWorkspace.System.FindObject("Fix32.FIX.AI1.F_CV")
"displaythevalueinamsgbox
MsgBoxobjDataItem.Value
objDataItem.Value="75"
9、有没有办法使客户端浏览节点上的画面加载速度加快?
回答:
通过调整FixUserPreferences.ini文件中的参数设置可以让你精确调整VBA脚本语言的运行性能,并加快画面在浏览节点上的打开速度。
FixUserPreferences.ini文件在目录\Dynamics\Local下,在此文件的[Scripting]部分参数ScriptIdleTimeProcessingDelayCount缺省值设置在–1。
在这一缺省设置下,你的VBA脚本语言的执行将优先于画面的打开,若将此设定改为0或1,你可以提高画面的打开速度。
你可以使用的一个办法是在你的SCADA节点上将参数设为–1,使VBA脚本运行速度较快,而在客户端将参数设为0或1,加快画面的打开速度。
注意:
不要将参数设为大于1,这并不能提高你的系统性能。
10、语音报警
大多数时候大家都是在调度里面做,另一个方法是:
在ALARMSYUMMAYR控件中,启动报警。
在ALARMSYUMMAYR控件启用newalarm事件,可以在这个时间里实现语音报警。
在大量语音报警的情况下,比用调度省事多了。
选择异步函数,可以在多个报警同时来临时,把所有的语音都报出来。
11、调用API
很多时候调用API函数,比自己编方便多了,如Sleep。
在某些情况下,你或许要使用共享内存,这样的话,使用API是最好的选择了。