1、工控资料网iFIX经典问题问答1:iFIX中如何使用vba开启和停止wsqlodc和alarmsODBC?DescriptionTheabilitytostoporstarttheSQLtask,wsqlodc,andtopauseorcontinuethealarmstoODBCtaskusedtoonlybeavailablebylaunchingMissionControlandmanuallycontrollingthem.TheabilitytoperformthiscontrolprogrammaticallyusingVBAwasaddedaspartofaSIMforiFix2
2、.5.Thefunctioncallstoallowthisarenotwidelydocumentedandareshownbelow:-ResolutionDeclareFunctionTurnOnSqlTaskLibmissionvba(ByValcmd$)AsLongTurnsonaSQLtask.Thecmd$parameteristhecommandlinepassedtotheSQLtaskReturnof0isasuccess.Currentloggedinusermusthavesecurityrightstoturnon/offSAC.Ifanon-zeroerrorcod
3、eisreturned,youcanusetheerr2strutilityinthefixbasedirectorytotranslatetheerrortoastringDeclareFunctionTurnOffSqlTaskLibmissionvba()AsLongTurnsoffaSQLtask.Returnof0isasuccess.Currentloggedinusermusthavesecurityrightstoturnon/offSAC.Ifanon-zeroerrorcodeisreturned,youcanusetheerr2strutilityinthefixbase
4、directorytotranslatetheerrortoastringDeclareFunctionPauseAlarmODBCLibmissionvba()AsLongPausestheAlarmODBCtask.Returnof0isasuccess.CurrentloggedinuserdoesNOThavetohavesecurityrights.ThisfunctionwillexecuteregardlessoftheAllowOperatortoPauseAlarmLoggingSettingfoundintheiFIXODBCAlarmServiceConfigurator
5、oftheSystemConfigurationUtility.PrivateDeclareFunctionContinueAlarmODBCLibmissionvba()AsLongResumestheAlarmODBCtask.Returnof0isasuccess.CurrentloggedinuserdoesNOThavetohavesecurityrights.ThisfunctionwillexecuteregardlessoftheAllowOperatortoPauseAlarmLoggingSettingfoundintheiFIXODBCAlarmServiceConfig
6、uratoroftheSystemConfigurationUtility.Allofthesefunctionswillblockuntiltherequestiscompleted.2:iFIX如何使用vba开启和停止基于时间和事件的调度?Description:Thissolutionshowshowtostartandstopatime-basedorevent-basedschedulerunninginthebackground.Resolution:STOP/STARTaEVENTBASEDSCHEDULEToStart:PrivateSubCommandButton1_Clic
7、k()DimVar1AsObjectDimVar2AsObjectSetVar1=GetObject(,FixBackGroundServer.Application)SetVar2=Var1.System.FindObject(SchedTest1.FIXEvent1)Var2.StartEventEndSubToStop:PrivateSubCommandButton1_Click()DimVar1AsObjectDimVar2AsObjectSetVar1=GetObject(,FixBackGroundServer.Application)SetVar2=Var1.System.Fin
8、dObject(SchedTest1.FIXEvent1)Var2.StopEventEndSubSTOP/STARTaTIMEBASEDSCHEDULEToStoptheTimerObject:PrivateSubCommandButton1_Click()DimVar1AsObjectDimVar2AsObjectSetVar1=GetObject(,FixBackGroundServer.Application)SetVar2=Var1.System.FindObject(Sched1.Timer1)Var2.TimerEnabled=FalseEndSubToStarttheTimer
9、Object:PrivateSubCommandButton2_Click()DimVar1AsObjectDimVar2AsObjectSetVar1=GetObject(,FixBackGroundServer.Application)SetVar2=Var1.System.FindObject(sched.Timer1)Var2.TimerEnabled=TrueVar2.StartTimerEndSub3:iFIX如何使用vba进行网络打印机打印?Description:ThefollowingisanexampleofprintinganExcelDocumenttoaNetwork
10、Printeroraprinterotherthanthedefaultprinteronthemachine.DimobjXLAsObjectDimmyDocAsObjectSetobjXL=CreateObject(Excel.Application)SetmyDoc=objXL.Workbooks.Open(C:testfile.xls,True)myDoc.Printoutcopies:=1,preview:=False,ActivePrinter:=SERVERPRINTER,printtofile:=False,collate:=TruemyDoc.CloseSetobjXL=No
11、thingSetmyDoc=NothingReferencesIfthisscriptisusedinabackgroundschedulewithFixBackgroundServerconfiguredtorunasaService,theFixservicemustrununderauseraccountthathasprintersdefined.SeeKnowledgeBaseArticlei013417formoreinformationonthisconfiguration.ThePrintoutcommandcanbeusedforotherdocumenttypes(Word
12、,PowerPoint,etc),howeverdifferentsyntaxisrequired,refertoforotherexamples.4:iFIX报警状态代码以及意义?Description:FIXdisplaysalarmstatuscodesforeachalarmintheAlarmSummaryLink.Whatisthemeaningofeachofthesecodes?ResolutionPriority-AlarmType-Description1-COMM-CommunicationError(BADvalue)1-OCD-Opencircuitdetected1
13、-OVER-OverRange1-UNDER-UnderRange1-ERROR-AnyStatisticalDatablockalarm2-CFN-Changefromnormalalarm(digitalblocksonly)2-COS-ChangeofStatealarm(digitalblocksonly)2-HIHI-BlockinHIHIalarmstate2-LOLO-BlockinLOLOalarmstate3-RATE-Valueexceedsrate-of-changesetting3-HI-BlockinHIalarmstate3-LO-BlockinLOalarmsta
14、te4-DEV-DeviationAlarm5-OK-Blockinnormalstate5:如何禁止和使能7X驱动标签点(对驱动自动禁止特别有用)?DimopcDriverAsNewOPCDrv.OPCServerDimobjDriverAsObjectDimstrDRVAcronymAsStringDimstrProgIdAsStringVariablesforGetChannelDimlngNumChannelsAsLongDimlngChanHandlesDimstrChanNamesVariablesforGetDevicesDimlngNumDevicesAsLongDimlngD
15、eviceHandlesDimstrDeviceNamesVariablesforGetDataBlocksDimlngNumDataBlocksAsLongDimlngDataBlockHandlesDimstrDataBlockNamesDimiAsIntegerDimjAsIntegerDimlngErrorsDimmyvarAsLongDimreadEnablestrDRVAcronym=InputBox(Pleaseenterthedriversthreeletteracronym?&vbCrLf&(ForExample:EnterABRfortheABRDriver),WhatDr
16、iverareyouusing?)strProgId=Intellution.&strDRVAcronym&drvstrProgId=Matrikon.OPC.Simulation.1SetobjDriver=CreateObject(strProgId)lngNumChannels=opcDriver.GetChannels(lngChanHandles,strChanNames)BuildVariablesforSetPropertyDatafunction.lngHandle=lngDataBlockHandles(0)varProperties=EnabledvarProperyDat
17、a=1opcDriver.GetPropertyDatalngChanHandles(1),varProperties,readEnable对服器1置真IfreadEnable=0ThenlngErrors=opcDriver.SetPropertyData(lngChanHandles(1),varProperties,varProperyData)EndIflngNumDevices=opcDriver.GetDevices(lngChanHandles(1),lngDeviceHandles,strDeviceNames)lngNumDataBlocks=opcDriver.GetDat
18、aBlocks(lngDeviceHandles(0),lngDataBlockHandles,strDataBlockNames)lngHandle=lngDataBlockHandles(0)读工作组opcDriver.GetPropertyDatalngDeviceHandles(0),varProperties,readEnableIfreadEnable=0ThenlngErrors=opcDriver.SetPropertyData(lngDeviceHandles(0),varProperties,varProperyData)EndIf处理工作块opcDriver.GetPro
19、pertyDatalngDataBlockHandles(0),varProperties,readEnableIfreadEnable=0ThenFori=0To1lngErrors=opcDriver.SetPropertyData(lngDataBlockHandles(i),varProperties,varProperyData)NextiEndIfSetopcDriver=Nothing6:iFIX_如何使用脚本实现驱动(7x)的启动和停止?DescriptionThefollowingsolutionexplainshowtoStartandStopa7.xdriverthrou
20、ghVBAcode.ThisexampleusestheABRdriver.Toimplementthiswithanother7.xdriver,changetheABRtothethreeletteracronymoftheotherdriverandswitchthereferencetothatdriver.ResolutionThiscodewillonlyworkwith7.xdrivers.IfyouwanttoimplementthisiscodeinanewpictureyouneedtosetareferencetoIntellutionABRDrvOPCServer7.2
21、0Library.Tosetareference,usethefollowingsteps:1)OntheToolsmenuintheVBEditorchooseReferences.2)SelecttheIntellutionABRDrvOPCServer7.20Libraryfromthelist.AddtwocommandbuttonstoyourpictureandnamethemcmdStart_ClickandcmdStop_Click.Thenpastethefollowingcodeintothepicture:PrivateSubcmdStart_Click()DimABRD
22、riverAsNewABRDrv.ABRServerABRDriver.StopSetABRDriver=NothingEndSubPrivateSubcmdStop_Click()DimABRDriverAsNewABRDrv.ABRServerABRDriver.StartSetABRDriver=NothingEndSub7:iFIX_如何使用脚本实现驱动(6x)的启动和停止?DescriptionThisarticlesdescribeshowtocontrol(startorstop)the6.xdriversthroughVBA,CommandScript,orDOSrathert
23、haninMissionControl.ResolutionTheattachedapplicationDCTRL61.EXEenablesyoutodothis.Belowaretheusageinstructions.Usage:DCTRLcommanddriveracronymdelaysleepwherecommandis:START-startthedriverSTOP-stopthedriverfrompollingSTOP_EXIT-stoppollingandexitSLEEP-setnewsleeptime(period)STATUS-displayscurrentvalue
24、sDELAY-WaitaNumberofmillisecondsbeforeexecutingthiscommand(1000=1second).Thethedctrl61.exemustbelocatedintheFIX32orDynamicsdirectory.ThecommandanddriveracronymmustbeinALLCAPS.ExamplefromtheDOSprompt:dctrl60STARTMBRExamplefromaiFIXVBA:Shellc:fix32dctrl60STARTMBRExamplefromaFIX32script:Runtaskc:fix32d
25、ctrl60STARTMBR8:iFIX_脚本进行调度的启动和关闭方法?DescriptionThissolutionshowshowtostartandstopatime-basedorevent-basedschedulerunninginthebackground.ResolutionSTOP/STARTaEVENTBASEDSCHEDULEToStart:PrivateSubCommandButton1_Click()DimVar1AsObjectDimVar2AsObjectSetVar1=GetObject(,FixBackGroundServer.Application)SetV
26、ar2=Var1.System.FindObject(SchedTest1.FIXEvent1)Var2.StartEventEndSubToStop:PrivateSubCommandButton1_Click()DimVar1AsObjectDimVar2AsObjectSetVar1=GetObject(,FixBackGroundServer.Application)SetVar2=Var1.System.FindObject(SchedTest1.FIXEvent1)Var2.StopEventEndSubSTOP/STARTaTIMEBASEDSCHEDULEToStoptheTi
27、merObject:PrivateSubCommandButton1_Click()DimVar1AsObjectDimVar2AsObjectSetVar1=GetObject(,FixBackGroundServer.Application)SetVar2=Var1.System.FindObject(Sched1.Timer1)Var2.TimerEnabled=FalseEndSubToStarttheTimerObject:PrivateSubCommandButton2_Click()DimVar1AsObjectDimVar2AsObjectSetVar1=GetObject(,
28、FixBackGroundServer.Application)SetVar2=Var1.System.FindObject(sched.Timer1)Var2.TimerEnabled=TrueVar2.StartTimerEndSub9:iFIX_excel报表实现的方法?PrivateSubCommandButton1_Click()注释:1。该程序需要安装ADO2.0目标库并在本机注册2。MicrosoftActiveXDataObjects2.1Library必须被引用(Office2000)3。MicrosoftExcel9.0objectlibraries必须被引用(Office
29、2000)4。划=处可根据具体报表修改DimstrQueryAvgAsStringDimcAsIntegerDimrAsIntegerDimIntyexcelAsExcel.ApplicationDimMyDate,MyMonth,MyDay,MyHour,MyMinute,MySecondDimStartTime,EndTime,Duration,DisplayDay,DisplayMonthAsString+=报表中的TAGDimTag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7,Tag8AsStringDimItemsAsIntegerTag1=TESTTag2=TES
30、T1Tag3=Tag4=Tag5=Tag6=Tag7=Tag8=从历史库中取得域项,2-DATATIME,VALUE,TAG共三项Items=2-=MyDate=Now()MyMonth=Month(MyDate)MyDay=Day(MyDate)MyHour=Hour(MyDate)MyMinute=Minute(MyDate)MySecond=Second(MyDate)StartTime=2000&-&MyMonth&-&MyDay-1&00:00:00EndTime=2000&-&MyMonth&-&MyDay-1&23:00:00+=查询,根据报表修改strQueryAvg=Sele
31、ctDATETIME,VALUE,TAGFROMFIX&_WHEREMODE=AVERAGEand(TAG=&Tag1&orTAG=&Tag2&_orTAG=&Tag3&orTAG=&Tag4&orTAG=&Tag5&_orTAG=&Tag6&orTAG=&Tag7&orTAG=&Tag8&)&_andINTERVAL=01:00:00and&_(DATETIME=ts&StartTime&and&_DATETIME=ts&EndTime&)-=DimcnADOAsNewADODB.ConnectionDimrsADOAsRecordsetSetcnADO=NewADODB.Connectio
32、ncnADO.ConnectionString=DSN=FIXDynamicsHistoricalData;UID=sa;PWD=;cnADO.OpenFIXDynamicsHistoricalData,sa,SetrsADO=NewADODB.RecordsetrsADO.OpenstrQueryAvg,cnADO,adOpenForwardOnly,adLockBatchOptimistic如果执行上面的语句出错的话,则最大的可能性就是SQL语句有错误!r=1SetIntyexcel=NewExcel.ApplicationIntyexcel.Visible=False+=打开的报表文件名
33、DimOutReportFileAsStringDimInReportFileAsStringInReportFile=C:DynamicsAppHIST1Intyexcel.Workbooks.OpenInReportFile&.XLSIntyexcel.Sheets(Sheet2).SelectIntyexcel.Columns(A:Z).SelectIntyexcel.Selection.ClearContentsIntyexcel.Range(A1).SelectWhilersADO.EOFTrueWithIntyexcel.Worksheets(2)Forc=0ToItemsIfrs
34、ADO(c)Then.Cells(r,c+1).Value=rsADO(c)Nextcr=r+1rsADO.MoveNextEndWithWendIntyexcel.Sheets(Sheet1).SelectIntyexcel.ActiveSheet.PageSetup.Orientation=xlPortraitxlLandscapeIntyexcel.ActiveSheet.PageSetup.PaperSize=xlPaperA4Intyexcel.ActiveSheet.PrintOutIntyexcel.DisplayAlerts=FalseIntyexcel.ActiveWorkb
35、ook.SaveOutReportFile=InReportFile&_00&MyMonth&MyDayIntyexcel.ActiveWorkbook.SaveAsOutReportFileIntyexcel.QuitIntyexcel.DisplayAlerts=TrueSetIntyexcel=NothingSetcnADO=NothingEndSub10:IFIX中对事件调度有没什么限制?曾经用过用500个事件调度没事。11:IFIX中求模拟量一段时间平均值?Dimstrvalue1AsVariantDimstrvalue2AsVariantDimstrvalue3AsVariantD
36、imstrvalue4AsVariantDimstrvalue5AsVariantDimstrvalue6AsVariantDimstrvalue7AsVariantDimstrvaluepAsVariantPrivateSubFixTimer4_OnTimeOut(ByVallTimerIdAsLong)计算平均值strvalue7=strvalue6strvalue6=strvalue5strvalue5=strvalue4strvalue4=strvalue3strvalue3=strvalue2strvalue2=strvalue1strvalue1=Fix32.Fix.J001.a_cvstrvaluep=(Val(strvalue1)+Val(strvalue2)+Val(strvalue3)+Val(strvalue4)+Val(strvalue5)+Val(strvalue6)+Val(strvalue7)/7)user.J001.CurrentValue=strvaluepENDSUB12:在IFIX中如何显示用户信息?在FIX32产品中,FIX内含一系列系统变量,存储当前系统信息,包括当前用户的注册信息,如#GS_LOGIN.NAME。在IFIX中可通过VBA代码,实现显示或获得用户的注册信息。代码如下:Private