WinCC V62 SP2 VBS for Creating Procedures and Actions.docx
《WinCC V62 SP2 VBS for Creating Procedures and Actions.docx》由会员分享,可在线阅读,更多相关《WinCC V62 SP2 VBS for Creating Procedures and Actions.docx(13页珍藏版)》请在冰豆网上搜索。
WinCCV62SP2VBSforCreatingProceduresandActions
SIMATICHMI
WinCCV6.2SP2
VBSforCreatingProceduresand
Actions
1.VBSforCreatingProceduresandActions
Contents
WinCCprovidesthepossibilityofdynamizingtheRuntimeenvironmentusingtheVisual
BasicScript.ItispossibletouseVBStoprogramglobalactionsandproceduresaswellas
dynamizinggraphicobjectsandtriggeringactionsinRuntime.
Thischapterwillshowyou
•HowtoworkwithVBScripteditors
•Howtocreateandeditprocedures
•Howtocreateandeditactions
•HowtoactivateVBScriptsinRuntime
•Howtoexecutediagnosticsonscripts
•TheobjectmodelofgraphicRuntimes
•DetailedexamplesonusingVBScript
2.UsingVisualBasicScriptinWinCC
Introduction
InadditiontotheCscript,WinCCalsoprovidestheVBScriptprogramlanguageasaprogramminginterfaceinordertomaketheWinCCRuntimeenvironmentdynamic.
TargetGroupoftheDocumentation
ThisdocumentationisaimedatprojectengineerswithexperienceofVisualBasicorWinCCScriptings(C)usedtodate.
ApplicationOptions
VBScript(VBS)providesaccesstotagsandobjectsofthegraphicalRuntimesystematRuntimeandcanexecutepicture-independentfunctions:
•Tags:
Tagvaluescanbereadandwritteninorder,forexample,tospecifytagvaluesforthePLCbyclickingthemousewhenpositionedonabutton.
•Objects:
Objectpropertiescanbemadedynamicusingactionsandactionscanbetriggeredbyeventsinfluencingobjects.
•Picture-independentActions:
Picture-independentactionscanbetriggeredcyclicallyoraccordingtotagvalues,e.g.forthedailytransferofvaluesintoanExceltable.
VBScanbeusedatthefollowingpointsinWinCC:
•IntheGlobalScriptEditor:
Thisisusedtoconfigurepicture-independentactionsandprocedures.Theprocedurescanbeusedinpicture-dependentandpicture-independentactions.Severalproceduresarecompiledinatopic-relatedmodule.
•InGraphicsDesigner:
Picture-dependentactionscanbeconfiguredwithwhichthepropertiesofgraphicobjectscanbemadedynamicorcausedtorespondtoeventsinRuntime.
ApplicationScenarios
VBScanbeusedinRuntime,forexample:
•toconfiguresetpointvaluespecificationfortagsfortheoperationofagraphicobjectin
ordertodefineavalueforthePLCbyclickingamouse,forexample.
•toconfigureswitchingtheRuntimelanguagefortheoperationofagraphicobject.
•toconfigurethechangeofcolor,e.g.cyclically(flashing)ortodisplaystatuses(motoron).
ApartfromthespecificWinCCapplications,thegeneralfunctionalityofVBScanalsobe
usedtocustomizetheWindowsenvironment,e.g.:
•totransferdatatoanotherapplication(e.g.Excel).
•tostartexternalapplicationsfromWinCC.
•tocreatefilesandfolders.
Theautomationobjectsinyourenvironmentareavailablewithwhichtocustomizethe
Windowsenvironment.
Note
AlltheobjectssuppliedwiththeWindowsScriptHost(WSH)fromMicrosoftcanbe
integratedintheenvironmentusingthestandardVBSmethodCreateObject.However,there
isnodirectaccesstotheWSHobjectitselfusingVBSfromWinCC.
ThereisnoguaranteenorWinCCsupportfortheVBSfunctionalitywithregardtoits
adaptationtotheWindowsenvironment.
LimitstoOtherProgrammingLanguagesinWinCC
VBSandC
VBScriptcanbeusedinWinCCparalleltoC-Script,butdonotmixthescripttypes:
•VBScriptsandC-scriptscanbeconfiguredwithinapictureandproject.
•C-scriptscannotbeinvokedinVBScriptsandviceversa.
•VBSprovidesinternalinterfacestotagsandpictureobjectswhiletheCenvironmentenablesaccesstootherWinCCsubsystems(e.g.thereportsystem).
VBSandVBA
VBAisusedinWinCCConfigurationduringtheconfigurationinordertoadaptGraphicsDesignertoyourindividualrequirementsandtosimplifyandautomateconfiguration.VBAprogramsonlyrunintheWinCCconfigurationenvironment.
AsopposedtoVBA,VBscriptsonlyruninWinCCRuntimeand,fromthere,enableaccesstographicobjectsandtags.ObjectsandpicturescanbeneithercreatednormodifiedonapermanentbasisinVBS,asopposedtoVBA.
Themainlanguage-relateddifferencesbetweenVBAandVBSaree.g.:
•VBSwasdevelopedforuseinInternet,VBAfortheautomationofsoftwareapplications.
•ThedatatypeofVBStagsisalwaysVARIANT.VBA,ontheotherhand,differentiatestheindividualdatatypessuchasINT,DOUBLE,STRING,etc.
•CertainlanguageconstructsfromVBAhavebeenremovedfromoraddedtoVBS.
•ErrorsarehandleddifferentlyinVBScomparedtoVBA.
AcompletelistofthedifferencesbetweenVBAandVBSisprovidedintheAppendixin"BasicPrinciplesofVBScript".
Procedures,ModulesandActions
VBSinWinCCallowstheuseofprocedures,modulesandactionstomaketheRuntimeenvironmentdynamic:
•Procedures:
Codesarestoredinprocedureswhicharethenusedatseveralpointsintheconfiguration.Retrievethecodeoranotherprocedureinanactionbyinvokingtheprocedurename.ProcedurescanbecreatedinWinCCwithorwithoutreturnvalues.
Proceduresdonothavetheirowntrigger,theyarealwaysretrievedbyanaction.
•Modules:
Itisadvantageoustocompilerelatedprocedurestounitsinmodules.Createmodulesforprocedures,forexample,whichmustbeusedinaspecificpictureorbelongtoaspecifictopic,suchasauxiliarymathematicalfunctionsordatabaseaccessfunctions.
•Actions:
Actionsarealwaysactivatedbyatrigger,namelyatriggeringevent.Actionsareconfiguredingraphicobjectproperties,ineventswhichoccuronagraphicobjectorgloballyinaproject.Codesusedseveraltimescanbecalled,intheformofprocedures,inactions.
3.ModulesandProcedures
Introduction
Proceduresareusedtomakecodes,createdonlyonce,availableatseveralpointsinaproject.Insteadofenteringthecodeseveraltimes,simplycallinthecorrespondingprocedure.Thecodeisclearerandeasiertomaintain.
Relatedproceduresshouldbestoredinmodules.WhenacertainprocedureisretrievedviaanactioninRuntime,themodulethatcontainsthatprocedureisloaded.Observethefollowingwhenstructuringthemodulesandprocedures:
•Themoremodulesthatmustbeloadedwhenapictureiscalledin,theworsetheperformanceinRuntime.
•Thelargeramodule,themoreproceduresarecontainedand,thus,thelongertheloadingtimeforthemodule.
Organizethemodulessensibly,e.g.amodulewithproceduresforaspecificsystempart/picture.
Anothertypeofstructuringofproceduresinmodulesisthefunctionalstructuring,e.g.amodulecontainingmathematicalfunctions.Usethisstructure,forexample,formoduleswhichshouldbeusedgloballyforprojects.Thefollowingexampleillustratesamodulecontainingmathematicalfunctionsderivedfromthestandardfunctions:
ProcedureFeatures
TheproceduresinWinCChavethefollowingproperties:
•Theyarecreatedandmodifiedbytheuser.
•Theycanbeprotectedagainstmodificationandviewingbymeansofapassword.
•Theydonothaveatrigger.
•Theyarestoredinamodule.
WinCCdoesnotprovidepredefinedprocedures,butdoesprovidecodetemplatesandIntellisense,forexample,tosimplifyprogramming.Proceduresdifferaccordingtomoduleassignmentin:
•Standardproceduresapplygloballytoprojectslocatedonthecomputeronwhichthey
werecreated.
•Projectprocedurescanonlybeusedintheprojectinwhichtheywerecreated.
ModuleFeatures
Amoduleisafileinwhichoneorproceduresisstored.ThemodulesinWinCChavethe
followingproperties:
•Theycanbeprotectedagainstmodificationandviewingbymeansofapassword.
•Thehavethefileextension*.bmo.
Modulesdifferaccordingtothevalidityoftheirproceduresin:
•StandardModules:
Containprocedureswhicharegloballyavailabletotheproject.StandardmodulesarestoredintheWinCCfilesystemunder:
\ApLib\ScriptLibStd\.bmo
•ProjectModules:
Containproject-specificprocedures.ProjectmodulesarestoredintheWinCCfilesystemunder:
\ScriptLib\.bmo.Sincetheprojectmodulesarestoredintheprojectdirectory,theyarecopiedwhentheWinCCprojectiscopied.
Note
IfWinCCmustbereinstalledandthestandardproceduresandmodulesneedtobeusedagain,savethemodulefilespriortothereinstallationinadifferentdirectoryandcopythemintherelevantWinCCdirectoryafterthereinstallationhasbeencompleted.Otherwise,thestandardmodulesintheWinCCinstallationdirectoryaredeletedduringtheinstallationroutine.
UsingProceduresandModules
Proceduresareusedin:
•Actions(inGraphicsDesignerandGlobalScript)
•Otherprocedures(inGlobalScript)
Proceduresarestructuredinmodules.
4.Actions
Introduction
Anactionisalwaysstartedbyatrigger.Anaction,forexample,istriggeredinRuntimewhenanobjectisoperatedbyamouseclick,acertaintimehasoccurredorataghasbeenmodified.
ActionFeatures
ActionsaredefinedonceinGlobalScriptandthenavailableindependentofthepicture.
GlobalScriptactionsareonlyvalidintheprojectinwhichtheyweredefined.Actionslinkedtoagraphicobjectareonlyvalidinthepictureinwhichtheyweredefined.
Note
VBSdoesnotcurrentlyallowthecreationofcomputer-specificactions.
Thefollowingappliesforclientsinamulti-usersystem:
Allglobalactionsconfiguredona
serverarealsoexecutedonaclientwhenaprojectisopened.
Thefollowingappliestoclientsinadistributedsystem:
Ifactionsshouldbeusedonaclient
computer,copyalltheactionfilesinthecorrespondingprojectdirectoryonthe