您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > 【灵冰肌】CAPL编程语言基础学习
1CAPLProgramming-BasicsPreparedBy百度灵冰肌.Date:2015-06-022OverviewOfCAPL•ForCAN-basednetworks,modules,anddistributedembeddedsystems,CommunicationApplicationProgrammingLanguage,CAPL,makesitpossibletoprogramtheCANalyzerfordeveloper-specificapplicationsthatusetheCANprotocol.•CAPLmayalsobeusedintheCANoetoolfordistributedproductdevelopment.•ThesyntaxisC-like,butthereareanumberofsupplementalfeaturesnotincludedinC:–Amissingresulttypeisinterpretedasvoid–AnemptyparameterlistispermittedasinC++–Overloadingoffunctions(i.e.multiplefunctionswiththesamenamebutdifferentparameterlists)ispossibleasinC++–AparametercheckisperformedasinC++–Arraysofarbitrarydimensionandsizemaybepassed–CAPLprovidesyouwithalibraryofintrinsicfunctions.3ApplicationUsesforCAPL•CreateandmodifythebehavioroftheCANalyzermeasurementenvironment.•Designacustommoduletester.•Createablackboxtosimulatetherestofthenetwork.•Createamodulesimulator.•Createacustommodulemanufacturingtester.•Createacustommodulediagnosticorservicetool.•Createprogramstoperformcustomizedanalysisofnetworklogging(playback)files.•Createcomplexloggingfilters.•Createacomprehensivemessageordatacontentgenerationtesterformodule/networkvalidation.•CreateafunctionalgatewaybetweentodifferentCANnetworks.4SimulationUsesforCAPL•SimulatenodeorsystembehaviorusingreadableEnglishratherthanhex.•Simulateeventmessages,periodicmessages,orconditionallyrepetitivemessages.•SimulatehumaneventslikebuttonpressesusingthePCkeyboard•Simulatetimednodeornetworkevents.•Simulatemultipletimeeventseachwithitsownprogrammablebehavior.•Simulatenormaloperation,diagnosticoperation,ormanufacturingoperation.•Simulatechangesinphysicalparametersorsymbolicvalues(“ON”,“OFF”).•GenerateCANerrorframestoevaluatemodulenetworksoftwarestrategy.•Simulatemoduleandnetworkandnetworkfaultstoevaluatelimitedoperationstrategy.•Simulatesimpleorcomplexfunctions(sin,cos).5CAPL–EventDrivenSoftware6CAPLProgrammingEnvironment7CAPLEVENTS8CANalyzer–CAPLProgrammingEnvironment9CANoe–CAPLProgrammingEnvironment10CAPLProgramOrganization•1.GlobalVariableDeclarations–Inthissection,youdeclarevariablesthatcanbereadorchangedbyanypartofyourCAPLprogram.–Itisagoodideatodeclaremessagesandtimersinthissection.•2.EventProcedures–Eventproceduresareblocksofcodethatareexecutedwhenaneventoccurs.–CAPLallowsyoutodefineeventproceduresforseveraldifferentkindsofevents.–Mostofyourprogramcodewillbeineventprocedures,sincemostactionsareperformedafteranevent,suchasamessagebeingreceivedontheCANbus.–Eventprocedurescannotreturnavalue.•3.User-DefinedFunctions–YourprogramscancontainproceduresthatcanbeusedtocomplementCAPL’sbuilt-infunctions.–TheseprocedurescancontainanylegalCAPLcodeandaregloballyaccessible.–Puttingfrequently-usedcodeinaproceduremakesprogramsmoreefficient.–User-definedfunctionscanreturnavalueofanysimpletype.11CAPLBrowser-Organization12CAPLFileTypes•CAPLutilizestwotypesoffiles.•Sourcecodefiles(*.CAN)containCAPLprogramsaswellasspecialformattingcodesusedbytheCAPLBrowser.•ThesefilesareinASCIItextformat.•Whenyoucompilea.CANfileintheCAPLBrowser,CANalyzer,orCANoeabinaryfilewiththeextension.CBF(CAPLBinaryFile)iscreated.•ThesebinaryfilescanonlybeinterpretedandexecutedbyaCANalyzerorCANoesimulation.13CAPL–DataTypes14CAPL-Operators15ControlStatements–if&if-else16ControlStatements–switch17ControlStatements–while18ControlStatements–(do-while)19ControlStatements–For20ControlStatements–Break&Continue21ControlStatements–Return&“this”Keyword22Functionoverloadingisallowed•CAPLhastheabilitytooverloadfunctions,similartothewayC++does.•Thismeansthatmultiplefunctionscanhavethesamenamebutdifferentparameterlists.•Thefunctionthatiscalleddependsontheparametersthatarepassed.•Forexample,wecouldcreatetwofunctionsthatusewrite()tooutputdifferenttypesofnumbers:voidprint(doublenum){write(“Floatingpoint%f”,num);}voidprint(intnum,charunits[]){write(“%d%s”,num,units);}•Aftersettingthesefunctionsup,wegettheseresults:print(5.7);“Floatingpoint5.700000”print(2.5,“angstroms”,22);“2angstroms”23Localvariablesarestatic•InaCAPLfunction,incontrasttoC,alllocallydeclaredvariablesarestatic.Thismeansthatonceavariableisdeclaredandassignedavalueduringoneiterationofafunction,thevariableretainsthatvaluethenexttimethefunctioniscalled.ThiscancauseconfusiontoprogrammersaccustomedtotheCsemantic.•Forexample:voidmyFunc(){bytevalue=10;write(“value=%d”,value);value=35;}•ThefirsttimemyFunciscalled,itwillprint“value=10”asexpected.However,thesecondandallsubsequenttimesthefunctioniscalled,itwillprint“value=35”.Duetothissemantic,thepreferredwaytoinitializenon-staticvariablesistouseaseparateassignmentafterthevariableshasbeendeclared.Inthisexample,thevariablesareresettotheirinitialvaluesatthebeginningofeveryiterationofthefunction:•voidmyFunc(){//Variabledeclarationsbytevalue;intx,y;//Variableinitializationsvalue=10;x=0;y=5;//Maincodeofthefunction...}24VariableandObjectTypesandDeclarationsExamplesofvariabledeclarations:intj,k=2;/*j=0implicitly*/doublex=33.7;charp;Examplesofarraydeclarations:longdata[10];intvector[5]={0,1,2,3,4};intmatrix[2][4]={{2,4,6
本文标题:【灵冰肌】CAPL编程语言基础学习
链接地址:https://www.777doc.com/doc-5012524 .html