老外寫的語(yǔ)言教程很詳細(xì)_第1頁(yè)
老外寫的語(yǔ)言教程很詳細(xì)_第2頁(yè)
老外寫的語(yǔ)言教程很詳細(xì)_第3頁(yè)
老外寫的語(yǔ)言教程很詳細(xì)_第4頁(yè)
老外寫的語(yǔ)言教程很詳細(xì)_第5頁(yè)
已閱讀5頁(yè),還剩47頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

老外寫的語(yǔ)言教程很詳細(xì)演示文稿當(dāng)前1頁(yè),總共52頁(yè)。老外寫的語(yǔ)言教程很詳細(xì)當(dāng)前2頁(yè),總共52頁(yè)。3STLanguageKeywordIfthereisanyunclearoruncorrected,pleasefeelfreetospeakout

BasicCourse當(dāng)前3頁(yè),總共52頁(yè)。4RequirementsHardwareTheprogramminglanguageSTisonlyavailableforfollowingprogrammablecontrollers:

pCO3SupernodepCO5pCOcompactBIOSTosupportSTlanguage,biosversionmustgreaterthan5.0SoftwareUseaversionof1tool>=2.1.x

pCO3pCO5Supernode當(dāng)前4頁(yè),總共52頁(yè)。5CreationofasolutionSTLanguageChoosing:-FBD,theapplicationwillbe'mixed’,itwillconsistofamainwithAtoms,Macroblocks...butyoucanuseroutines(functionsandfunctionblocks)writtenintheST-ST,theapplicationwillbedevelopedentirelyusing‘STlanguage’

當(dāng)前5頁(yè),總共52頁(yè)。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當(dāng)前6頁(yè),總共52頁(yè)。7ThebasictypesKeywordDatatypeLowerlimitUpperlimitMemorySpaceBOOLBooleanFALSE(0)TRUE(1)8BitBYTEBitstring02558BitWORDBitstring06553516BitDWORDBitstring04.294.967.29532BitSINTShortInteger-1281278BitUSINTUnsignedShortInteger02558BitINTInteger-327683276716BitUINTUnsignedInteger06553516BitDINTDoubleInteger-2^31(2^31)-132BitUDINTUnsignedDoubleInteger02^32-132BitREALRealNumber-10^3810^3832BitBitstringIntegersThefollowingtablelistsallthepropertiesofbasictypes(IECType):當(dāng)前7頁(yè),總共52頁(yè)。8DeclarationofGlobalvariablesTherearetwowaystodeclareGlobalvariables:

‘VariableList’‘Textualmode’ofSTlanguageButton‘User’Button‘Extend’‘IECType’BOOLINT…REAL‘IECType’BOOLINT…REALVariableListTextualmode‘CarelType’BooleanInteger/AnalogGlobalvariablesdeclarationUsableinanyenvironmentUsableonlyintheStrategyEditorST

(no:

MASK,FBDStrategyEditor)Youdon’tseethesevariablesinVariableListNote:ifyouwanttoseethevariableinthepGD,pleasedeclarethevariableintheVariableList當(dāng)前8頁(yè),總共52頁(yè)。9Assignmentoperator:=SyntaxAssigntoavariable:Inassignmentoperations“:=”

thevariablesinvolvedmustallbethesametype,eachstatementmustuse“;”asthestatementterminator.

InassignmentoperationswithBOOLvalues,1or

TRUE,or0or

FALSEcanbeusedindifferently.

aconstantvalue

thevalueofanothervariable

theresultofanexpression.Varaible_name:=expression;AssignmentoperatorStatementterminatorNote:thereisa;intheendofstatement當(dāng)前9頁(yè),總共52頁(yè)。10Textualdeclaration

TodeclarevariablesinSTyouhavetousethefollowing‘declarationblock’:GlobalvariablesdeclaredintextmodewillnotbevisibleintheVariableList.TypeSyntaxDescritionGloabalVAR_GLOBALEND_VARDeclaresagroupofglobalvariables,sharedbyprogram,functionsorfunctionblocks.LocalVAREND_VARDeclaresagroupoflocalvariablestoaprogram,functionorfunctionblock.Note:1.thereisno;intheendofEND_VAR;2.wecangivethedefaultvalueinthedeclaration.當(dāng)前10頁(yè),總共52頁(yè)。11Rulesoftheidentifiers(variablesname)‘a(chǎn)’..‘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.當(dāng)前11頁(yè),總共52頁(yè)。12ThequalifierCONSTANT

TextualdeclarationofConstants

ThekeywordCONSTANTcandeclareaconstant.

TheconstantsdonotoccupyspaceinmemoryasthevariablesDuringcompilationinsteadoftheconstantisreplacedanumericvalue.TypeSyntaxDescriptionCostantiLocaliVARCONSTANTEND_VARDeclaresagroupoflocalconstantstoaprogram,functionorfunctionblock.CostantiGlobaliVAR_GLOBALCONSTANTEND_VARDeclaresagroupofglobalconstants,sharedbyprogram,functionsorfunctionblocks.當(dāng)前12頁(yè),總共52頁(yè)。13CommentsCommentusingkeyword{REGION…ENDREGION}Youcanhideseverallinesofcodeusingthekeyword{REGION…ENDREGION}.Soincreasethereadabilityofthecodeonthescreen.

Thecodeisreplacedwithacomment.Clickingoncommentitwillappearagainthecode.ThecodecommentsYoucanusetwowaystomakeacommentTocommentasinglecodelineuse“\\”Tocommentmorecodelinesuse“(*”and“*)”Thereisno_inbetweenENDandREGION當(dāng)前13頁(yè),總共52頁(yè)。14ThequalifierRETAINTextualdeclarationofglobalvariablesREATAIN(retentive)ExampleDeclarationofretentive

Global

variables.RETAINkeyworddeclaresavariableinT-permanentmemory.TypeSyntaxDescriptionGlobalRetentiveVAR_GLOBALRETAINEND_VARDeclaresagroupofretainglobalvariables,sharedbyprogram,functionsorfunctionblocks.Itisnotpossibletoinitializearetainvariabletoadefaultvalueatthetimeofdeclaration.TheinitialisationofavariableinT-memorymustbeperformedusingtheVariableWizard,whichimpliescreationofthe.DEVfile.Organizationofthevariables.Note:payattentionofthedefaultvalue當(dāng)前14頁(yè),總共52頁(yè)。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.當(dāng)前15頁(yè),總共52頁(yè)。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);當(dāng)前16頁(yè),總共52頁(yè)。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當(dāng)前17頁(yè),總共52頁(yè)。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.

當(dāng)前18頁(yè),總共52頁(yè)。19TheFunctionItcanbecomparabletoa‘Blackbox':itworksonaInputparametersconfiguration,anditalwaysproducesinOutputthesameresultforthesameInputs.Itletsnotrepeatmanytimesthesamecodewithintheproject,asinstead

itisformacroblocksinFBDenvironment.Ateachinvocationofthefunction,thesamecodewillbealwaysexecuted.WhatdoesaFunctiondo?ItreadInputs,nooutputs,butcanhaveareturnvalueItexecutesthecodeofthefunctionItwritestheresultinaReturnValueAfunctiondoesn’thaveamemorystateItalwaysproducesthesameresultforthesameinputs.InputsReturnValueThefunctionAdd_3WhatdoesaFunction

contain?ThelistofparametersthatarepassedasinputsProbableLocalvariables,onlyforitsinternaluseThecodeofthefunctionThetypeofReturnValueReturnValueWhatisaFunction?

FunctioncodeLacalVariablesInputsReturnValueOnlyforinternaluseFun_A當(dāng)前19頁(yè),總共52頁(yè)。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當(dāng)前20頁(yè),總共52頁(yè)。21Passbyvalue(VAR_INPUT)InthePassbyvaluethevaluesoftheActualParametersarecopiedintheFormalParameters,eventualmodificationswithinthefunctionoftheFormalParametersdonothaveeffect

ontheActualParameters.InthepassbyvaluetheActualParametersarecopiedinFormalParameters.

ActualParametersFormalParametersModificationsdon’thaveeffectonActualParameters.

當(dāng)前21頁(yè),總共52頁(yè)。22PassbyReference(VAR_IN_OUT)PassbyReferenceInPassbyReference,

eventualmodificationswithinthefunctionoftheFormalParameters

haveimmediateeffectonActualParameters.ActualParametersmustbeonlyvariables.ActualParametersFormalParametersModification50Memory25Sometimesitisnecessarytomodifythevariablevaluepassedtothefunction,andrendersuchmodificationoutsideimmediatelyvisible.Thismodalityiscalled‘PassbyReference’anditisrealizedusingkeywordVAR_IN_OUT.InPassbyReferencetheFormalParameterpointtothesamecellofmemorythatcontainsthevalueofActualParameter.ActualPar.In1FormalPar.I150Memory25ActualPar.In2FormalPar.I2當(dāng)前22頁(yè),總共52頁(yè)。23VariablesscopeTypeofvariableAccessbycallingPOUAccessinsidethefunctionNoteMemoryVARNoRWVisibleonlytothefunctionwhereitwasdeclared.NoVAR_INPUTWRAninputvariableisvisibletothecallingPOUandisreadbyit.Insidethefunctionwhereinputvariableisdefined,itsvalueshouldnotbechanged.NoVAR_IN_OUTRWRWAninput/outputvariablecombinesthecharacteristicsoftheVAR_INPUTandVAR_OUTPUTvariables:bothvisibleandcanbereadandmodifiedinsideoroutsideofthefunctionwhereitisdefined.

NoVAR_GLOBALRWRWSTglobalvariablesareaccessiblefromallPOUs.YesItispossible(butnotrecommended)todeclareaLocalvariableinaprogramwiththesameidentifierasanGlobalvariable.InsidetheprogramtheprocessorwillconsidertheLocalvariable(whosevalueisinitialisedbetweenoneprogramcycleandthenext)andnottheGlobalvariable.當(dāng)前23頁(yè),總共52頁(yè)。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.當(dāng)前24頁(yè),總共52頁(yè)。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當(dāng)前25頁(yè),總共52頁(yè)。26ArrayBreakthrough(exceededlimits)Thistypeoferrorisnotdetectableatcompiletimebythecompiler.Theerrorcanbedetectedonlyatrun-time.ExampleRun-TimeerroronSimulatorRun-TimeerroronpCOPlace2integervariablesona‘Mask’related

tolibraryfunctions:

Thepositionoferrorinthe

StrategyEditorST:goinsimulationandthenpressinsertHighpartandLowpartWhenavariableisusedtoaccesstheelementsofanarray,caremustbepaidtoensurethesizeofthearrayisnotexceeded.

Ifrun-timetheindexvalueexceedsthesizeofthearray,thiswillentailthere-bootofthepCO.

Exceedsthesizeofthearray.NoteToreset‘errorvariables’usethislibraryfunctions:當(dāng)前26頁(yè),總共52頁(yè)。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當(dāng)前27頁(yè),總共52頁(yè)。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.當(dāng)前28頁(yè),總共52頁(yè)。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.當(dāng)前29頁(yè),總共52頁(yè)。30Iterationstatements:EXITSyntax

1shExampleEXITstatementToexitbyforloop.EXIT;TheEXITstatementisusedexclusivelyinsideWHILE,

REPEAT,andFORstatementstointerruptexecutionoftheloopandgotothestatementaftertheendoftheloop(END_FOR,END_WHILE,END_REPEAT).2sdExampleToexitbynestedforloop.當(dāng)前30頁(yè),總共52頁(yè)。31IterationstatementsNote: ComparestatementWhile…DoandRepeat…Until; ComparestatementReturnandExit.當(dāng)前31頁(yè),總共52頁(yè)。32n-dimensionalArraySyntaxExercizeSimulationRowIndexColumnIndex5Note:

Array_name:ARRAY[el_1..el_n,el_1..el_m

]OF

Type;

Therulesseenforone-dimensionalarraysarevalid

Thesyntaxisusedtodeclareamatrix

Toaccessarrayelements,nestedFORloopscanbeused(seeexercize)NestedFORloops當(dāng)前32頁(yè),總共52頁(yè)。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當(dāng)前33頁(yè),總共52頁(yè)。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當(dāng)前34頁(yè),總共52頁(yè)。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.當(dāng)前35頁(yè),總共52頁(yè)。36FUNCTIONBLOCKFunctionBlockinstanceLocalvariables(VAR),areallocate/deallocateinsideStackateverycallingof:ProgramFunction

AFunctionBlockinstanceshouldbedeclaredGlobal(VAR_GLOBAL)andnotLocal(VAR).AinstanceofFBthatisdeclaredLocal(VAR)couldhaveadifferentbehaviourfromthatexpected.Itdoesn’tcountcorrectlyExampleInthisexampleaGlobaleandLocalinstanceofTONaredeclared.TheLocalinstancewillneversucceedtofinishthecount,becauseoftheinternalmanagementoftheLocalvariables.LocalinstanceallocatedintheStackGlobalinstanceallocatedinRam當(dāng)前36頁(yè),總共52頁(yè)。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.當(dāng)前37頁(yè),總共52頁(yè)。38FUNCTION_BLOCKinstanceRecursionRecursionisnotallowed,thatisaFunctionBlockcannot:referdirectlyreferindirectlycallaFunctionorFunctionBlockinstancethatreferit.DirectrecursionIndirectrecursion當(dāng)前38頁(yè),總共52頁(yè)。39FUNCTION_BLOCKinstanceTypeofvariableAccessbycallingPOUAccessinsidethefunctionNoteMemoryVARNoRWVisibleonlytothefunctionwhereitwasdeclared.YesVAR_INPUTRWRAninputvariableisvisibletothecallingPOUandiswrittenbyit.Insidethefunctionwhereitisdefined,itsvalueisnotmodified.YesVAR_OUTPUTRWAnoutputvariableisvisibletothecallingPOUandcanonlybereadbythis.ItcanbereadandwritteninsidetheFunctionBlockYesVAR_IN_OUTRWRWAninput/outputvariablecombinesthecharacteristicsoftheVAR_INPUTandVAR_OUTPUTvariables:bothvisibleandcanbereadandmodifiedinsideoroutsideofthefunctionwhereitisdefined.YesVAR_GLOBALRWRWGlobalvariablesareaccessiblefromallPOUs.YesItispossible(butnotrecommended)todeclareaLocalvariablei

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論