![老外写的语言教程很详细_第1页](http://file4.renrendoc.com/view/029c3941dcae179f3f4dbca9519e86dd/029c3941dcae179f3f4dbca9519e86dd1.gif)
![老外写的语言教程很详细_第2页](http://file4.renrendoc.com/view/029c3941dcae179f3f4dbca9519e86dd/029c3941dcae179f3f4dbca9519e86dd2.gif)
![老外写的语言教程很详细_第3页](http://file4.renrendoc.com/view/029c3941dcae179f3f4dbca9519e86dd/029c3941dcae179f3f4dbca9519e86dd3.gif)
![老外写的语言教程很详细_第4页](http://file4.renrendoc.com/view/029c3941dcae179f3f4dbca9519e86dd/029c3941dcae179f3f4dbca9519e86dd4.gif)
![老外写的语言教程很详细_第5页](http://file4.renrendoc.com/view/029c3941dcae179f3f4dbca9519e86dd/029c3941dcae179f3f4dbca9519e86dd5.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
老外写的语言教程很详细演示文稿当前1页,总共52页。老外写的语言教程很详细当前2页,总共52页。3STLanguageKeywordIfthereisanyunclearoruncorrected,pleasefeelfreetospeakout
BasicCourse当前3页,总共52页。4RequirementsHardwareTheprogramminglanguageSTisonlyavailableforfollowingprogrammablecontrollers:
pCO3SupernodepCO5pCOcompactBIOSTosupportSTlanguage,biosversionmustgreaterthan5.0SoftwareUseaversionof1tool>=2.1.x
pCO3pCO5Supernode当前4页,总共52页。5CreationofasolutionSTLanguageChoosing:-FBD,theapplicationwillbe'mixed’,itwillconsistofamainwithAtoms,Macroblocks...butyoucanuseroutines(functionsandfunctionblocks)writtenintheST-ST,theapplicationwillbedevelopedentirelyusing‘STlanguage’
当前5页,总共52页。6BasicconceptsWhenprogramminginST,theapplicationcanbeorganisedusingthreefundamentalprogrammingelements
genericallycalled‘ProgramOrganizationUnits’(POU):PROGRAMFUNCTIONFUNCTIONBLOCKPOUtypeKeywordDescriptionProgramPROGRAMmainEND_PROGRAMMainprogramthatincludes:read/writeI/OdefinitionoflocalvariablescallstoFunctionsorFunctionBlocksFunctionFUNCTIONEND_FUNCTIONSTstatementsblockwithinputvariables,localvariables,andifspecifiedareturnvalue.Thiscanbecalledatdifferentpointsoftheprogram.Recursionisnotallowed.FunctionblockFUNCTION_BLOCKEND_FUNCTION_BLOCKSTstatementsblockwithinputvariables,localvariables,andoutputvariables.Thiscanbecalledatdifferentpointsoftheprogram.Recursionisnotallowed.POUNote:wecandefinemorefunctionsandfunctionblocks,butonlyoneprogrammain当前6页,总共52页。7ThebasictypesKeywordDatatypeLowerlimitUpperlimitMemorySpaceBOOLBooleanFALSE(0)TRUE(1)8BitBYTEBitstring02558BitWORDBitstring06553516BitDWORDBitstring04.294.967.29532BitSINTShortInteger-1281278BitUSINTUnsignedShortInteger02558BitINTInteger-327683276716BitUINTUnsignedInteger06553516BitDINTDoubleInteger-2^31(2^31)-132BitUDINTUnsignedDoubleInteger02^32-132BitREALRealNumber-10^3810^3832BitBitstringIntegersThefollowingtablelistsallthepropertiesofbasictypes(IECType):当前7页,总共52页。8DeclarationofGlobalvariablesTherearetwowaystodeclareGlobalvariables:
‘VariableList’‘Textualmode’ofSTlanguageButton‘User’Button‘Extend’‘IECType’BOOLINT…REAL‘IECType’BOOLINT…REALVariableListTextualmode‘CarelType’BooleanInteger/AnalogGlobalvariablesdeclarationUsableinanyenvironmentUsableonlyintheStrategyEditorST
(no:
MASK,FBDStrategyEditor)Youdon’tseethesevariablesinVariableListNote:ifyouwanttoseethevariableinthepGD,pleasedeclarethevariableintheVariableList当前8页,总共52页。9Assignmentoperator:=SyntaxAssigntoavariable:Inassignmentoperations“:=”
thevariablesinvolvedmustallbethesametype,eachstatementmustuse“;”asthestatementterminator.
InassignmentoperationswithBOOLvalues,1or
TRUE,or0or
FALSEcanbeusedindifferently.
aconstantvalue
thevalueofanothervariable
theresultofanexpression.Varaible_name:=expression;AssignmentoperatorStatementterminatorNote:thereisa;intheendofstatement当前9页,总共52页。10Textualdeclaration
TodeclarevariablesinSTyouhavetousethefollowing‘declarationblock’:GlobalvariablesdeclaredintextmodewillnotbevisibleintheVariableList.TypeSyntaxDescritionGloabalVAR_GLOBALEND_VARDeclaresagroupofglobalvariables,sharedbyprogram,functionsorfunctionblocks.LocalVAREND_VARDeclaresagroupoflocalvariablestoaprogram,functionorfunctionblock.Note:1.thereisno;intheendofEND_VAR;2.wecangivethedefaultvalueinthedeclaration.当前10页,总共52页。11Rulesoftheidentifiers(variablesname)‘a’..‘z’,‘A’..‘Z’‘0’..‘9’‘_’ValididentifiersInvalididentifiersNoteMn22MnThe1stcharactermustnotbenumeric._3exit_3exit.1“.”isnotincludedinthesetofcharacters.Enrg_offEnrgoffSpacesarenotallowed._Drill__DrillOnlysingleunderscores“_”areallowed.Valve,VALVENotcase-sensitive.
Thevariablenamesarenotcase-sensitive‘Valve’,‘VaLVe’e‘VALVE’arethesamevariable.
Thenameofanidentifier(variableorconstant)canbeanycombination(seeExample)ofthecharacterslistedbelow:ExampleRulestocreateidentifiers.当前11页,总共52页。12ThequalifierCONSTANT
TextualdeclarationofConstants
ThekeywordCONSTANTcandeclareaconstant.
TheconstantsdonotoccupyspaceinmemoryasthevariablesDuringcompilationinsteadoftheconstantisreplacedanumericvalue.TypeSyntaxDescriptionCostantiLocaliVARCONSTANTEND_VARDeclaresagroupoflocalconstantstoaprogram,functionorfunctionblock.CostantiGlobaliVAR_GLOBALCONSTANTEND_VARDeclaresagroupofglobalconstants,sharedbyprogram,functionsorfunctionblocks.当前12页,总共52页。13CommentsCommentusingkeyword{REGION…ENDREGION}Youcanhideseverallinesofcodeusingthekeyword{REGION…ENDREGION}.Soincreasethereadabilityofthecodeonthescreen.
Thecodeisreplacedwithacomment.Clickingoncommentitwillappearagainthecode.ThecodecommentsYoucanusetwowaystomakeacommentTocommentasinglecodelineuse“\\”Tocommentmorecodelinesuse“(*”and“*)”Thereisno_inbetweenENDandREGION当前13页,总共52页。14ThequalifierRETAINTextualdeclarationofglobalvariablesREATAIN(retentive)ExampleDeclarationofretentive
Global
variables.RETAINkeyworddeclaresavariableinT-permanentmemory.TypeSyntaxDescriptionGlobalRetentiveVAR_GLOBALRETAINEND_VARDeclaresagroupofretainglobalvariables,sharedbyprogram,functionsorfunctionblocks.Itisnotpossibletoinitializearetainvariabletoadefaultvalueatthetimeofdeclaration.TheinitialisationofavariableinT-memorymustbeperformedusingtheVariableWizard,whichimpliescreationofthe.DEVfile.Organizationofthevariables.Note:payattentionofthedefaultvalue当前14页,总共52页。15CastFunctionsSyntaxParameterDescriptionVariable_nameVariablethatholdstheresultoftheconversion.*_TO_**Conversionfunction.'*'indicatesthedatatypeofthevariablebeingtoconvert.'**'indicatestheconverteddatatype(e.g.:
INT_TO_REAL)valueValueorvariabletobeconverted.SymboloDescription*_TO_BOOLconversionfromtype*totypeBOOL*_TO_BYTEconversionfromtype*totypeBYTE*_TO_WORDconversionfromtype*totypeWORD*_TO_DWORDconversionfromtype*totypeDWORD*_TO_SINTconversionfromtype*totypeSINT*_TO_USINTconversionfromtype*totypeUSINT*_TO_INTconversionfromtype*totypeINT*_TO_UINTconversionfromtype*totypeUINT*_TO_DINTconversionfromtype*totypeDINT*_TO_UDINTconversionfromtype*totypeUDINT*_TO_REALconversionfromtype*totypeREALVariable_name
:=*_TO_**(value);Theconversionfunctionsareusedtoconvertanyoftheelementarydatatypestoanyother.Theymustbeusedtomakethedatatypeuniformbeforeafunction,wherethisisrequired.当前15页,总共52页。16SToperatorsFortheevaluationofexpressions,alwaysusebrackets,thisavoidserrorsintheevaluationoftheexpressions.ExampleTableoftheoperatorspriorityPrioritàOperatoreDescrizione1(...)Expressioninbrackets.2nome_POU(...);Callafunctionorfunctionblock.3**Raisetothepower.4-NOTNegationBooleancomplement5*/MODMultiplicationDivisionModule6+-AdditionSubtraction7<,<=,>,>=Comparisonoperators8=<>EqualityInequality9ANDBooleanAND10XORBooleanXOR11ORBooleanORInthecaseofBooleanAND,ORboolean(notbitwise),iftheresultoftheoperationcanalreadybedeterminedafterhavingevaluatedthefirstoperand,thesecondisnotevaluated(Short-CircuitBooleanExpressions).
Anexpressionisexecutedonlyaftertheevaluationoftheoperatorspriority.Theexecutionorderofanexpressionanditsresultareinfluencedbytheoperatorspriority.
SuggestionA:=NOTXANDYORNOTJ;Increasesreadability:
A:=NOT(X)AND(YOR(NOTJ));IfZ=0theothervariableshavenotbeenevaluated.A:=ZANDYAND(NOTJ);当前16页,总共52页。17Conditionalstatements:IFIF..THEN..ELSEstatement
Conditionalconstruct:executesastatementblockdependingonwhetherornotcertainconditionsaresatisfied.SyntaxExercizeShort-CircuitBooleanExpressionsIfExpression=TRUE,statement_blockisexecuted
OtherwisetheconditionsintheELSIF
blocksareevaluated
Finally,iftheseareallfalse,thestatementsintheELSE
blockareexecuted.
Boolean(AND,OR,NOT,XOR)Comparison
(=,<>,>,>=,<,<=).
FeaturesIF
expression
THEN
statement_block;
{ELSIF
expression
THEN
statement_block;
}
{ELSE
statement_block;}END_IF;Note
expressioncontainstheoperators:
Managementofarange[-550,950]°CwithNTCprobe.Optional当前17页,总共52页。18Conditionalstatements:CASECASE..OF..statementSyntaxConditionalconstruct:selectsthestatementstobeexecuteddependingonthevalueofanintegerexpression.CASE
expression
OF
selector_1:
statement_block;
selector_2,selector_3:
statemnt_block;
selector_4..selector_5:
statemnt_block;selector_6,selector_7..selector_8: statemnt_block;{ELSE
statemnt_block;}END_CASE;
Ifthevalueoftheexpressiondoesnotcorrespondtoanycondition,andanELSEstatementispresent,thestatement_blockassociatedwiththeELSEkeywordisexecuted.ParameterTypeDescriptionExpressionSINT,USINT,INT,UINT,DINT,UDINTVariableorExpressionwhoseresultisaninteger.Thisnumberwillbecomparedwithselector_xtodecidewhichstatementstoexecute.selector_1selector_2...selector_nSINT,USINT,INT,UINT,DINT,UDINTSignedorunsignedintegervaluesthatcomparedwiththeresultofexpressiondeterminethestatementstobeexecuted.Thesemaybe:anindividualvalue,aseriesofvaluesseparatedbycommas,aninterval,separatedby“..”acombinationofpreviusExampleSpeedmanagementofafan.
当前18页,总共52页。19TheFunctionItcanbecomparabletoa‘Blackbox':itworksonaInputparametersconfiguration,anditalwaysproducesinOutputthesameresultforthesameInputs.Itletsnotrepeatmanytimesthesamecodewithintheproject,asinstead
itisformacroblocksinFBDenvironment.Ateachinvocationofthefunction,thesamecodewillbealwaysexecuted.WhatdoesaFunctiondo?ItreadInputs,nooutputs,butcanhaveareturnvalueItexecutesthecodeofthefunctionItwritestheresultinaReturnValueAfunctiondoesn’thaveamemorystateItalwaysproducesthesameresultforthesameinputs.InputsReturnValueThefunctionAdd_3WhatdoesaFunction
contain?ThelistofparametersthatarepassedasinputsProbableLocalvariables,onlyforitsinternaluseThecodeofthefunctionThetypeofReturnValueReturnValueWhatisaFunction?
FunctioncodeLacalVariablesInputsReturnValueOnlyforinternaluseFun_A当前19页,总共52页。20FUNCTIONstatement
FunctionDeclarationThedeclarationmustbemadeintwoway:using“SubroutineST”nodebeforethePROGRAMstatementFUNCTIONfunction_name...END_FUNCTIONInstanceFunctionsareneverinstanced.CallAfunctioncanbecalledoneormoretimesinaProgram,FunctionBlockorinanotherFunction.Recursionisnotallowed.MemoryWheneverthefunctioniscalled,RAMisallocatedforlocalvariablesandparameters.ThevaluesarestoredinthememorytillcompletionofthecallingPOU.UseExtemporaneousfunctions(e.g.:calculations)InputparametersTheparametersaresenttothefunctionbyvalueorreference.Thepositionoftheparametersinthecallmustcorrespondtothepositionoftheparametersinthedeclaration.Noparametermaybeomitted.Afunctioncanbedefinedwithoutinputparameters.OutputparametersFunctionsreturnjustoneornooutputparameter:thevaluereturnedbythefunctionortheresultofthefunction.Theoutputparametercanonlybeanelementarydatatypeandcanbeomitted.Afunctioncanbedefinedwithoutareturnvalue.Thetablebelowlistsallpropertiesofafunction.
Summary当前20页,总共52页。21Passbyvalue(VAR_INPUT)InthePassbyvaluethevaluesoftheActualParametersarecopiedintheFormalParameters,eventualmodificationswithinthefunctionoftheFormalParametersdonothaveeffect
ontheActualParameters.InthepassbyvaluetheActualParametersarecopiedinFormalParameters.
ActualParametersFormalParametersModificationsdon’thaveeffectonActualParameters.
当前21页,总共52页。22PassbyReference(VAR_IN_OUT)PassbyReferenceInPassbyReference,
eventualmodificationswithinthefunctionoftheFormalParameters
haveimmediateeffectonActualParameters.ActualParametersmustbeonlyvariables.ActualParametersFormalParametersModification50Memory25Sometimesitisnecessarytomodifythevariablevaluepassedtothefunction,andrendersuchmodificationoutsideimmediatelyvisible.Thismodalityiscalled‘PassbyReference’anditisrealizedusingkeywordVAR_IN_OUT.InPassbyReferencetheFormalParameterpointtothesamecellofmemorythatcontainsthevalueofActualParameter.ActualPar.In1FormalPar.I150Memory25ActualPar.In2FormalPar.I2当前22页,总共52页。23VariablesscopeTypeofvariableAccessbycallingPOUAccessinsidethefunctionNoteMemoryVARNoRWVisibleonlytothefunctionwhereitwasdeclared.NoVAR_INPUTWRAninputvariableisvisibletothecallingPOUandisreadbyit.Insidethefunctionwhereinputvariableisdefined,itsvalueshouldnotbechanged.NoVAR_IN_OUTRWRWAninput/outputvariablecombinesthecharacteristicsoftheVAR_INPUTandVAR_OUTPUTvariables:bothvisibleandcanbereadandmodifiedinsideoroutsideofthefunctionwhereitisdefined.
NoVAR_GLOBALRWRWSTglobalvariablesareaccessiblefromallPOUs.YesItispossible(butnotrecommended)todeclareaLocalvariableinaprogramwiththesameidentifierasanGlobalvariable.InsidetheprogramtheprocessorwillconsidertheLocalvariable(whosevalueisinitialisedbetweenoneprogramcycleandthenext)andnottheGlobalvariable.当前23页,总共52页。24RETURNstatementSyntaxTheRETURN
statementisusedtoexitfromaFunction,FunctionBlockortheProgrambeforetheend.FUNCTION
My_function
list_statements_1;
RETURN;
list_statements_2;END_FUNCTIONNovalueisreturnedtothecallingPOU.Ifthefunctionorthefunctionblockreturnanoutputparameter,thiswillbeinitialisedatthedefaultvalue(basedonthedatatype).1stExample2sdExampleInthecaseofaFunctionorFunctionBlock,thestatementinterruptsexecutionafterlist_statements_1,andpassescontroltothecallingPOUwithoutexecutinglist_statements_2.InthecaseoftheProgram,thestatementclosestheProgram.当前24页,总共52页。25ARRAYstatementSyntaxExercize5101520
-1012IndexVetArray_name:ARRAY[elem_1..elem_n]OF
Type;where:
Declarationandinitialisationoftheelements.Declarationofthearray.Assigningavaluetotheindex1and10.
CopyoftheVetarrayonNewVet:musthavethesamesize.SimulationRepetitions(Value)TheCONSTANTqualifierisnotallowed.ArraysaredatatypesbutmustbedeclaredbetweenVAR*statementsandnotinsidetheTYPEconstruct.TheRETAINqualifierisaccepted.Thedeclaredsizeofthearray
cannotbevaried
run-time.ConsidermemoryoccupationwhenanarrayislocaltoaProgram,FunctionorFunctionBlock.
elem_1andelem_nare
INTnumbersorconstants(theycannotbevariables)andrepresentthelimitsofthearrayelem_n>=elem_1,thedifference+1indicatesthenumberofelementsinthearrayTypeidentifiestheelementarydatatypeelements
insidethearrayorStructuretype当前25页,总共52页。26ArrayBreakthrough(exceededlimits)Thistypeoferrorisnotdetectableatcompiletimebythecompiler.Theerrorcanbedetectedonlyatrun-time.ExampleRun-TimeerroronSimulatorRun-TimeerroronpCOPlace2integervariablesona‘Mask’related
tolibraryfunctions:
Thepositionoferrorinthe
StrategyEditorST:goinsimulationandthenpressinsertHighpartandLowpartWhenavariableisusedtoaccesstheelementsofanarray,caremustbepaidtoensurethesizeofthearrayisnotexceeded.
Ifrun-timetheindexvalueexceedsthesizeofthearray,thiswillentailthere-bootofthepCO.
Exceedsthesizeofthearray.NoteToreset‘errorvariables’usethislibraryfunctions:当前26页,总共52页。27Iterationstatements:FORFOR..DO..StatementFOR
variable:=
initial_expression
TO
final_expression
{BY
increase_expression}DO
statement_block;END_FOR;FORloopexecutesastatementblockfromaninitialvaluetoafinalvalueofthecontrolvariable.SyntaxParameterTypeDescriptionVariableSINT,INT,DINTControlvariablethatisincreased/decreasedbyincrease_expression.initial_expressionSINT,INT,DINTExpressionthatinitialisesthecontrolvariable.final_expressionSINT,INT,DINTFinalvalueofthecontrolvariable.increase_expressionSINT,INT,DINTExpressionprocessedeachcyclethatincreases(ifresult>0)ordecreases(ifresult<0)thecontrolvariable.Ifomittedisequalto1bydefault.Ifequaltozero,theloopisavoidedcompletelyandthestatementafterEND_FORisexecuted.statement_block-Listofstatementstobeexecuted.ExampleCounter=10当前27页,总共52页。28Iterationstatements:WHILEWHILE..DO..
StatementWHILEstatementexecutesastatementblockwhiletheexpressionistrue.SyntaxWHILE
expression
DO
statement_block;END_WHILE;ExampleTosearchforanelementwithinanarray.ParameterTypeDescriptionexpressionBOOLBooleanexpressionthatdeterminestheexecutionofstatement_block.IntheexpressionallBooleanorcomparisonoperatorscanbeused.statement_blockisexecutedwhileexpressionistrue.Ifexpressionisfalse,theloopisinterruptedandthestatementfollowingEND_WHILEisexecuted.statement_block-ListofstatementstobeexecutedwhileBooleanexpressionistrue.
IfonfirstexecutionoftheWHILEloopexpressionisfalse,statement_blockisneverexecuted.
ThetermofaWHILEloopmustnotexceed9seconds,otherwisethewatchdogcausesthere-bootofthepCO.当前28页,总共52页。29Iterationstatements:REPEATREPEAT..UNTIL..
StatementREPEAT
statement_block;
UNTIL
expressionEND_REPEAT;Thestatementscontainedintheloopareexecutedatleastonce.REPEATstatementexecutesastatementblockwhiletheexpressionistrue.Theloopisexecutedatleastonce.SyntaxParameterTypeDescriptionstatement_block-ListofstatementstobeexecutedwhileBooleanexpressionistrue.expressionBOOLBooleanexpressionthatdeterminestheexecutionofstatement_block.Intheexpression,allBooleanoperatorscanbeused.IfexpressionisTRUE,theloopcontinuestobeexecuted.IfexpressionisFALSE,theloopisinterruptedandthestatementfollowingEND_REPEATisexecuted.
IfduringthefirstexecutionoftheREPEATloopexpressionisfalse,statement_blockisexecutedjustonce.
ThetermofaWHILEloopmustnotexceed9seconds,otherwisethewatchdogcausesthere-bootofthepCO.当前29页,总共52页。30Iterationstatements:EXITSyntax
1shExampleEXITstatementToexitbyforloop.EXIT;TheEXITstatementisusedexclusivelyinsideWHILE,
REPEAT,andFORstatementstointerruptexecutionoftheloopandgotothestatementaftertheendoftheloop(END_FOR,END_WHILE,END_REPEAT).2sdExampleToexitbynestedforloop.当前30页,总共52页。31IterationstatementsNote: ComparestatementWhile…DoandRepeat…Until; ComparestatementReturnandExit.当前31页,总共52页。32n-dimensionalArraySyntaxExercizeSimulationRowIndexColumnIndex5Note:
Array_name:ARRAY[el_1..el_n,el_1..el_m
]OF
Type;
Therulesseenforone-dimensionalarraysarevalid
Thesyntaxisusedtodeclareamatrix
Toaccessarrayelements,nestedFORloopscanbeused(seeexercize)NestedFORloops当前32页,总共52页。33Thefieldsofastructurecanbeofelementarytype,oftypestructure,Array,n-dim
Array,notArrayofstructuresAstructuremustbeinstanced,beforetobeused,insuchwaycomesreservedinmemorythenecessaryspacetoitsdata.Thespaceoccupiedbyastructureisgivenbythesumofthespaceoccupiedbyeachsinglefields.Inordertoaccess/tomodifysinglefieldsofastructurethe‘.’isused(e.g.:Room_Temp.Temperature).Itispossibletoassignastructuretoanother,thusrealizingthecopyofthedata.Rememberthetwoinstancesmustbeofthesametype(suchastheArrays).Thedatatype‘Structure’Thestructuresareusedinordertocreatemorecomplexusertypes,ofthenormalelementarytypes.
Astructureisadatatypethatcontainsapredefinednumberoffields,usuallyofdifferenttypes.StructureinstanceTemperaturePressure
HumidtyRoom_TempFieldRoom_Temp_2Room_Temp_1StructureinstanceCmpr_InfoFieldRunning_HoursCmpr_N当前33页,总共52页。34TYPE…STRUCTstatementAllowstodefinethedatatype‘structure’.DefinitionsyntaxTYPE
structure_type:
STRUCT
field_1_name:data_type;
field_n_name:data_type{:=value};
END_STRUCT;END_TYPEInstancedelarationsysntaxVAR_GLOBAL
my_struct1:structure_type;
my_struct2:structure_type
:={(field_1_name:=value,fiel_2_name:=value)};END_VARExampleInsimulationitispossibletovisualizetheinstancesBuildtwostructure‘Cmpr_Info’.Fieldinitialization.Structureinitialization.CopyStructureinstanceCmpr_InfoFieldRunning_HoursCmpr_N当前34页,总共52页。35FUNCTIONBLOCKPTTONINETQTimerOnDelayInstanceInternalmemorystateMy_timer_1Itusesthepotentialitiesofafunctionandthoseofastructure.
Itcanbethoughtasa‘BlackBox’endowedof:InputParameters(passbyValue)orInput_Output
Parameters(passbyReference)Output
ParametersLocalVariables(accessibleonlywithintheFB)ItisaobjectandhasainternalmemorystateNote:Functionsdon’thavememoryAFBmustbeinstancedbeforeuse,insuchwaytheFBcomesstaticallyallocatedbythecontrollerinRamMemory,inordertoreservethespaceforitsdataItispossibletodefinemoreinstancesofthesameFB,butthecodecontainedintheapplicationisunique.WhatisaFunctionBlock?ExampleUseTONtimerinordertoactivaterelayn°1after2second.Use‘.’toaccesstoFBelements:GlobalinstanceofTONstaticallyallocatedinRam,tostoreFBdata.Use‘=>’towriteonavariabletheFBoutputs.INPTQETLocalVarMemoryMy_Timer_1Use‘:=’toassignvaluetotheinput.当前35页,总共52页。36FUNCTIONBLOCKFunctionBlockinstanceLocalvariables(VAR),areallocate/deallocateinsideStackateverycallingof:ProgramFunction
AFunctionBlockinstanceshouldbedeclaredGlobal(VAR_GLOBAL)andnotLocal(VAR).AinstanceofFBthatisdeclaredLocal(VAR)couldhaveadifferentbehaviourfromthatexpected.Itdoesn’tcountcorrectlyExampleInthisexampleaGlobaleandLocalinstanceofTONaredeclared.TheLocalinstancewillneversucceedtofinishthecount,becauseoftheinternalmanagementoftheLocalvariables.LocalinstanceallocatedintheStackGlobalinstanceallocatedinRam当前36页,总共52页。37FUNCTION_BLOCKinstanceFUNCTION_BLOCK
functionblock_name
(*Input,In_Out,andOutputvariablesdeclaration*)
(*Localvariabledeclaration*)
(*Implementationcode*)END_FUNCTION_BLOCKDefinitionsynstaxAFunctionBlock:canbecalledmorethanonceinsideaProgram,aFunctionoraFunctionBlockreceivesoneormoreinputvalues(VAR_INPUTorVAR_IN_OUT)andunlikeFunctions,givesoneormoreoutputvalues(VAR_OUTPUT).thevaluesoftheLocalvariables(VAR)andtheinputandoutputparametersinFunctionBlocksaresavedinthememorybetweencallsofthefunctionblock,andfromoneprogramcycletothenext;inthelattercaseaslongasthefunctionblockinstancehasbeendeclaredasGlobal(VAR_GLOBAL).11201525
OffsetMy_FB1In1In2Out_1Out_2VisibleonlyinsideFB.InthecallingPOUtheinstanceofthefunctionblockmustbe
declaredFIRST,
soastoallocatethememoryrequiredtostorethevaluesoftheinternalvariables(e.g.:useVAR_GLOBAL;takecareifusingVAR).Ifoneoftheinputparametersisomitted(VAR_INPUT),thefunctionblockusesthedefaultvalue(0orFALSEinthefirstprogramcycle)orthelastvalueusedinsidethefunctionblock.ParametersdeclaredasVAR_IN_OUTcannotbeomitted.Recursionisnotallowed.当前37页,总共52页。38FUNCTION_BLOCKinstanceRecursionRecursionisnotallowed,thatisaFunctionBlockcannot:referdirectlyreferindirectlycallaFunctionorFunctionBlockinstancethatreferit.DirectrecursionIndirectrecursion当前38页,总共52页。39FUNCTION_BLOCKinstanceTypeofvariableAccessbycallingPOUAccessinsidethefunctionNoteMemoryVARNoRWVisibleonlytothefunctionwhereitwasdeclared.YesVAR_INPUTRWRAninputvariableisvisibletothecallingPOUandiswrittenbyit.Insidethefunctionwhereitisdefined,itsvalueisnotmodified.YesVAR_OUTPUTRWAnoutputvariableisvisibletothecallingPOUandcanonlybereadbythis.ItcanbereadandwritteninsidetheFunctionBlockYesVAR_IN_OUTRWRWAninput/outputvariablecombinesthecharacteristicsoftheVAR_INPUTandVAR_OUTPUTvariables:bothvisibleandcanbereadandmodifiedinsideoroutsideofthefunctionwhereitisdefined.YesVAR_GLOBALRWRWGlobalvariablesareaccessiblefromallPOUs.YesItispossible(butnotrecommended)todeclareaLocalvariablei
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度国际贸易合同主体欺诈风险监测与预警系统
- 2025年度海洋工程劳务分包合同范本-@-1
- 2025年度化工石油工程智能化生产系统设计合同
- 2025年度新能源电池组装合作加工合同范本
- 2025年度高科技研发成果转让合同(含担保及收益分成)
- 2025年度日化用品包装设计与印刷服务合同
- 2025年度融资租赁合同单方面终止的条件与法律责任合同
- 2025年度海洋船舶租赁保险服务合同
- 2025年度宁波舟山港综合物流枢纽运营管理合同
- 2025年度金蝶企业资源计划系统全面升级支持服务合同
- (2024年)剪映入门教程课件
- 《宠物饲养》课程标准
- 快餐品牌全案推广方案
- 环境卫生整治推进行动实施方案
- 口腔医院感染预防与控制1
- 绪论中国文化概论张岱年
- 发生输液反应时的应急预案及处理方法课件
- 中国旅游地理(高职)全套教学课件
- 数字货币的匿名性与反洗钱
- 门脉高压性消化道出血的介入治疗课件
- 民航保密培训课件
评论
0/150
提交评论