




已阅读5页,还剩49页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
STLanguage BasicCourse 1 STLanguage KeywordIfthereisanyunclearoruncorrected pleasefeelfreetospeakout BasicCourse 2 Requirements HardwareTheprogramminglanguageSTisonlyavailableforfollowingprogrammablecontrollers pCO3SupernodepCO5pCOcompact BIOSTosupportSTlanguage biosversionmustgreaterthan5 0 SoftwareUseaversionof1tool 2 1 x 3 CreationofasolutionSTLanguage Choosing FBD theapplicationwillbe mixed itwillconsistofamainwithAtoms Macroblocks butyoucanuseroutines functionsandfunctionblocks writtenintheST ST theapplicationwillbedevelopedentirelyusing STlanguage 4 Basicconcepts WhenprogramminginST theapplicationcanbeorganisedusingthreefundamentalprogrammingelementsgenericallycalled ProgramOrganizationUnits POU PROGRAMFUNCTIONFUNCTIONBLOCK POU Note wecandefinemorefunctionsandfunctionblocks butonlyoneprogrammain 5 Thebasictypes Thefollowingtablelistsallthepropertiesofbasictypes IECType 6 DeclarationofGlobalvariables TherearetwowaystodeclareGlobalvariables VariableList Textualmode ofSTlanguage Note ifyouwanttoseethevariableinthepGD pleasedeclarethevariableintheVariableList 7 Assignmentoperator Syntax Assigntoavariable aconstantvaluethevalueofanothervariabletheresultofanexpression Varaible name expression Note thereisa intheendofstatement 8 Textualdeclaration TodeclarevariablesinSTyouhavetousethefollowing declarationblock Note 1 thereisno intheendofEND VAR 2 wecangivethedefaultvalueinthedeclaration 9 Rulesoftheidentifiers variablesname a z A Z 0 9 Thenameofanidentifier variableorconstant canbeanycombination seeExample ofthecharacterslistedbelow ExampleRulestocreateidentifiers 10 ThequalifierCONSTANT TextualdeclarationofConstants ThekeywordCONSTANTcandeclareaconstant TheconstantsdonotoccupyspaceinmemoryasthevariablesDuringcompilationinsteadoftheconstantisreplacedanumericvalue 11 Comments Commentusingkeyword REGION ENDREGION Youcanhideseverallinesofcodeusingthekeyword REGION ENDREGION Soincreasethereadabilityofthecodeonthescreen Thecodeisreplacedwithacomment Clickingoncommentitwillappearagainthecode ThecodecommentsYoucanusetwowaystomakeacommentTocommentasinglecodelineuse Tocommentmorecodelinesuse and Thereisno inbetweenENDandREGION 12 ThequalifierRETAIN TextualdeclarationofglobalvariablesREATAIN retentive Example DeclarationofretentiveGlobalvariables RETAINkeyworddeclaresavariableinT permanentmemory Organizationofthevariables Note payattentionofthedefaultvalue 13 CastFunctions Syntax Variable name TO value Theconversionfunctionsareusedtoconvertanyoftheelementarydatatypestoanyother Theymustbeusedtomakethedatatypeuniformbeforeafunction wherethisisrequired 14 SToperators Fortheevaluationofexpressions alwaysusebrackets thisavoidserrorsintheevaluationoftheexpressions Example Tableoftheoperatorspriority Anexpressionisexecutedonlyaftertheevaluationoftheoperatorspriority Theexecutionorderofanexpressionanditsresultareinfluencedbytheoperatorspriority Suggestion A NOTXANDYORNOTJ Increasesreadability A NOT X AND YOR NOTJ IfZ 0theothervariableshavenotbeenevaluated A ZANDYAND NOTJ 15 Conditionalstatements IF IF THEN ELSEstatementConditionalconstruct executesastatementblockdependingonwhetherornotcertainconditionsaresatisfied Syntax Exercize IfExpression TRUE statement blockisexecutedOtherwisetheconditionsintheELSIFblocksareevaluatedFinally iftheseareallfalse thestatementsintheELSEblockareexecuted Boolean AND OR NOT XOR Comparison Features IFexpressionTHENstatement block ELSIFexpressionTHENstatement block ELSEstatement block END IF Noteexpressioncontainstheoperators Managementofarange 550 950 CwithNTCprobe 16 Conditionalstatements CASE CASE OF statement Syntax Conditionalconstruct selectsthestatementstobeexecuteddependingonthevalueofanintegerexpression CASEexpressionOFselector 1 statement block selector 2 selector 3 statemnt block selector 4 selector 5 statemnt block selector 6 selector 7 selector 8 statemnt block ELSEstatemnt block END CASE Example Speedmanagementofafan 17 TheFunction Itcanbecomparabletoa Blackbox itworksonaInputparametersconfiguration anditalwaysproducesinOutputthesameresultforthesameInputs Itletsnotrepeatmanytimesthesamecodewithintheproject asinsteaditisformacroblocksinFBDenvironment Ateachinvocationofthefunction thesamecodewillbealwaysexecuted WhatdoesaFunctiondo ItreadInputs nooutputs butcanhaveareturnvalueItexecutesthecodeofthefunctionItwritestheresultinaReturnValueAfunctiondoesn thaveamemorystateItalwaysproducesthesameresultforthesameinputs ThefunctionAdd 3 WhatdoesaFunctioncontain ThelistofparametersthatarepassedasinputsProbableLocalvariables onlyforitsinternaluseThecodeofthefunction WhatisaFunction 18 FUNCTIONstatement Thetablebelowlistsallpropertiesofafunction Summary 19 Passbyvalue VAR INPUT InthepassbyvaluetheActualParametersarecopiedinFormalParameters ActualParameters FormalParameters Modificationsdon thaveeffectonActualParameters 20 PassbyReference VAR IN OUT PassbyReference ActualParameters FormalParameters Modification Sometimesitisnecessarytomodifythevariablevaluepassedtothefunction andrendersuchmodificationoutsideimmediatelyvisible Thismodalityiscalled PassbyReference anditisrealizedusingkeywordVAR IN OUT InPassbyReferencetheFormalParameterpointtothesamecellofmemorythatcontainsthevalueofActualParameter 21 Variablesscope 22 RETURNstatement Syntax TheRETURNstatementisusedtoexitfromaFunction FunctionBlockortheProgrambeforetheend FUNCTIONMy functionlist statements 1 RETURN list statements 2 END FUNCTION 1stExample 2sdExample InthecaseofaFunctionorFunctionBlock thestatementinterruptsexecutionafterlist statements 1 andpassescontroltothecallingPOUwithoutexecutinglist statements 2 InthecaseoftheProgram thestatementclosestheProgram 23 ARRAYstatement Syntax Exercize Array name ARRAY elem 1 elem n OFType where Simulation elem 1andelem nareINTnumbersorconstants theycannotbevariables andrepresentthelimitsofthearrayelem n elem 1 thedifference 1indicatesthenumberofelementsinthearrayTypeidentifiestheelementarydatatypeelementsinsidethearrayorStructuretype 24 ArrayBreakthrough exceededlimits Example Run TimeerroronSimulator Run TimeerroronpCOPlace2integervariablesona Mask relatedtolibraryfunctions ThepositionoferrorintheStrategyEditorST goinsimulationandthenpressinsertHighpartandLowpart Whenavariableisusedtoaccesstheelementsofanarray caremustbepaidtoensurethesizeofthearrayisnotexceeded Ifrun timetheindexvalueexceedsthesizeofthearray thiswillentailthere bootofthepCO NoteToreset errorvariables usethislibraryfunctions 25 Iterationstatements FOR FOR DO Statement FORvariable initial expressionTOfinal expression BYincrease expression DOstatement block END FOR FORloopexecutesastatementblockfromaninitialvaluetoafinalvalueofthecontrolvariable Syntax Example Counter 10 26 Iterationstatements WHILE WHILE DO Statement WHILEstatementexecutesastatementblockwhiletheexpressionistrue Syntax WHILEexpressionDOstatement block END WHILE Example Tosearchforanelementwithinanarray 27 Iterationstatements REPEAT REPEAT UNTIL Statement REPEATstatement block UNTILexpressionEND REPEAT Thestatementscontainedintheloopareexecutedatleastonce REPEATstatementexecutesastatementblockwhiletheexpressionistrue Theloopisexecutedatleastonce Syntax 28 Iterationstatements EXIT Syntax 1shExample EXITstatement Toexitbyforloop EXIT TheEXITstatementisusedexclusivelyinsideWHILE REPEAT andFORstatementstointerruptexecutionoftheloopandgotothestatementaftertheendoftheloop END FOR END WHILE END REPEAT 2sdExample Toexitbynestedforloop 29 Iterationstatements Note ComparestatementWhile DoandRepeat Until ComparestatementReturnandExit 30 n dimensionalArray Syntax Exercize Simulation Note Array name ARRAY el 1 el n el 1 el m OFType Therulesseenforone dimensionalarraysarevalidThesyntaxisusedtodeclareamatrixToaccessarrayelements nestedFORloopscanbeused seeexercize 31 Thefieldsofastructurecanbeofelementarytype oftypestructure Array n dimArray notArrayofstructuresAstructuremustbeinstanced beforetobeused insuchwaycomesreservedinmemorythenecessaryspacetoitsdata Thespaceoccupiedbyastructureisgivenbythesumofthespaceoccupiedbyeachsinglefields Inordertoaccess tomodifysinglefieldsofastructurethe isused e g Room Temp Temperature Itispossibletoassignastructuretoanother thusrealizingthecopyofthedata Rememberthetwoinstancesmustbeofthesametype suchastheArrays Thedatatype Structure Thestructuresareusedinordertocreatemorecomplexusertypes ofthenormalelementarytypes Astructureisadatatypethatcontainsapredefinednumberoffields usuallyofdifferenttypes 32 TYPE STRUCTstatement Allowstodefinethedatatype structure DefinitionsyntaxTYPEstructure type STRUCTfield 1 name data type field n name data type value END STRUCT END TYPE InstancedelarationsysntaxVAR GLOBALmy struct1 structure type my struct2 structure type field 1 name value fiel 2 name value END VAR Example Insimulationitispossibletovisualizetheinstances Buildtwostructure Cmpr Info 33 FUNCTIONBLOCK Itusesthepotentialitiesofafunctionandthoseofastructure Itcanbethoughtasa BlackBox endowedof InputParameters passbyValue orInput OutputParameters passbyReference OutputParametersLocalVariables accessibleonlywithintheFB ItisaobjectandhasainternalmemorystateNote Functionsdon thavememoryAFBmustbeinstancedbeforeuse insuchwaytheFBcomesstaticallyallocatedbythecontrollerinRamMemory inordertoreservethespaceforitsdataItispossibletodefinemoreinstancesofthesameFB butthecodecontainedintheapplicationisunique WhatisaFunctionBlock Example UseTONtimerinordertoactivaterelayn 1after2second Use toaccesstoFBelements Use towriteonavariabletheFBoutputs Use toassignvaluetotheinput 34 FUNCTIONBLOCK FunctionBlockinstanceLocalvariables VAR areallocate deallocateinsideStackateverycallingof ProgramFunctionAFunctionBlockinstanceshouldbedeclaredGlobal VAR GLOBAL andnotLocal VAR AinstanceofFBthatisdeclaredLocal VAR couldhaveadifferentbehaviourfromthatexpected ExampleInthisexampleaGlobaleandLocalinstanceofTONaredeclared TheLocalinstancewillneversucceedtofinishthecount becauseoftheinternalmanagementoftheLocalvariables 35 FUNCTION BLOCKinstance FUNCTION BLOCKfunctionblock name Input In Out andOutputvariablesdeclaration Localvariabledeclaration Implementationcode END FUNCTION BLOCK Definitionsynstax AFunctionBlock canbecalledmorethanonceinsideaProgram aFunctionoraFunctionBlockreceivesoneormoreinputvalues VAR INPUTorVAR IN OUT andunlikeFunctions givesoneormoreoutputvalues VAR OUTPUT thevaluesoftheLocalvariables VAR andtheinputandoutputparametersinFunctionBlocksaresavedinthememorybetweencallsofthefunctionblock andfromoneprogramcycletothenext inthelattercaseaslongasthefunctionblockinstancehasbeendeclaredasGlobal VAR GLOBAL InthecallingPOUtheinstanceofthefunctionblockmustbedeclaredFIRST soastoallocatethememoryrequiredtostorethevaluesoftheinternalvariables e g useVAR GLOBAL takecareifusingVAR Ifoneoftheinputparametersisomitted VAR INPUT thefunctionblockusesthedefaultvalue 0orFALSEinthefirstprogramcycle orthelastvalueusedinsidethefunctionblock ParametersdeclaredasVAR IN OUTcannotbeomitted Recursionisnotallowed 36 FUNCTION BLOCKinstance Recursion Recursionisnotallowed thatisaFunctionBlockcannot referdirectlyreferindirectlycallaFunctionorFunctionBlockinstancethatreferit Directrecursion Indirectrecursion 37 FUNCTION BLOCKinstance Variablesscope ThequalifierRETAIN IfaGlobalinstancehasthequalifierRETAIN dataaresavedinT permanentmemory 38 Thepropertiesofablockarelistedbelow FUNCTION BLOCK Summary 39 STeventisafunctionwiththefollowingrestrictions HasauniquenameHasnoReturnvalueHasnoInputparametersHasnoLocalvariablesCanonlymodifyGlobalvariables youcannotcallFunctionsorFunctionBlocksEventdiffersfromotherfunctions becausethenameisprecededbythereservedwordEvent e g Event incA Thereisnolimittothenumberofeventsthatyoucandefine SyntaxFUNCTIONEvent NameEvent CODEEND FUNCTIONFromMaskEditorispossibletoexecuteaSTevent specifingintheKeyFunctionEditor Do ST Event statement ExampleWhenthePRGbuttonispressed increaseavariable 3How IntheStartegyEditorSTdefinetheeventIntheKeyFunctionEditorwith DO ST Event statementcalltheevent STEvent 40 Howtousethe Add 3 inFBD Inthe SolutionExplorer addapageto SubroutineST nodeEdit Add 3 functioncode payingattentiontotypesofInputparametersandReturnvalue Inthe Dependencies nodeof SolutionExplorer add Core ST library InsideFBDenvironmentFrom Core ST libraryselect ST Call atomtocall Add 3 functioninsideFDBenvironment Finallyconnectvariablestopins FBDandSTenvironment RemindersonFBDenvironmentFBDEnvironmentusesonlythebasictypes Boolean Integer Analog TheSTlanguageissupportedbysomecontrollers pCO3 Suprnodo 41 FBDandSTenvironment HowdoyouchangefirmofyourFunctionorFunctionBlockinFBDStrategyEditor InFBDStartegyEditorIhaveplacedMy Addfunction butihavetoaddanotherparameterYouhavetoaddthenewparametertoMy Addfunction andthen youhavetoselect Updatefromfirm inFBDStrategyEditor 1ststepAddIn3toMy Addfunction 2sdstepInFBDStrategyEditor Updatefromfirm 3rdstepInFBDStrategyEditorconnect In3variable 42 Systemvariable STLanguageusesspecificlibraryfunctions inordertoaccesstosystemvariablesoftype BooleanIntegerSyntaxSet SystemVariableName Vaule Variable Get SystemVariableName 1stExample Boolean Set KEY PRESSED 1 Alarms Get GLOBAL ALARM 2sdExample Integer Set KEY PRESSED 1 BMSAddr Get BMS ADDRESS LibraryaccessToaccesslibraryfunctionspress CONTROL SPACE 43 Base2 Base8andBase16 Anumbercanberepresentedalsointhebases Binary Base2 Octal Base8 Hexadecimal Base16 SyntaxVariable Base Value Examplea 2 10110001 a 8 767 a 16 AF0 Moreover itispossibletoseparatethefigureswithofoptional inordertoincreasethereadabilitya 2 1011 0001 a 8 7 6 7 a 16 AF0 a 16 A F 0 44 Arithmetcstatements STlanguagecanusethefollowingarithmeticoperations 2sdEsempioTheuseofdivisionoperator 1stExampleArithmeticoperator 45 Numericalstatements Vedianche LanguageSTallowstousethefollowingnumericalstatements 46 Debug Therearetwotypes ConditionalBreakpointBreakpointDuringthesimulationBreakpointsarenotactiveon FunctionsnevercallVariables InstancesneveruseExample Fordebuggingtheapplicationusethebreakpoint DebuggingkeysF5 goestonextbreakpointControl F10 StepoverControl F11 StepintoControl Shift F11 Stepout 47 Exercises Ex1 在ST中进行浮点数运算 控制逻辑 对数学表达式进行运算 A IN1 1 IN2 1 B 0 024263A2 0 8638A 0 16655Vw 0 0922B2 1 154B具体要求 在SubroutineST中编写一个函数块 最终在FBD中调用该函数 分别给IN1和IN2赋两组数据 看最终Vw的值是否为计算的最终结果 参考 需要用到的相关语句 INT TO REAL REAL TO INT 48 Exercises Ex2 使用ST语言写出机组开关机的功能块 控制要求 以功能块 Functionblock 的形式编写该模块在FBD中调用该功能块具体要求功能块的输入根据机组启动请求来管理机组状态 机组启动的选择方式如下 通过键盘Keyboard OnOff通过planpLan OnOff通过数字量输入Dig In OnOff En Dig In OnOff通过时间段Schedule OnOff En Sched OnOff通过上位机Superv OnOff En Superv OnOff通过报警状态Alarms功能块的输出变量Unit OnOff表示机组的状态 仅当上述功能全部启用 即以下全部条件均为真时 Unit OnOff 1 Keyboard OnOff 1pLan OnOff或En PLan Onoff 0Dig In OnOff 1或En Dig In OnOff 0Schedule OnOff 1或En Sched OnOff 0Superv OnOff 1或En Superv OnOff 0Alarms 0功能块的输入Manual对机组状态不起作用 仅对输出Unit Status起作用 功能块的输出Unit Status表示机组的运行状态 Unit Status的值状态0机组开启
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工业园区规划设计思路
- 工业排污处理的智能化改造与物联网
- 工业安全与防护在智能车间的实施要点
- 工业污染源的环境监测与治理策略
- 工业机器人与节能生产技术探讨
- 工业机器人技术的进步与应用领域
- 工业绿色制造技术
- 工业物联网的构建与优化
- 工业级智能穿戴设备的应用与发展趋势
- 工业节能减排技术解决方案
- 备战中考生物专项练习题-心脏和血液循环(全国通用-含答案)-
- 《国际汉语教师证书》考试汉办真题
- 室内装修工程应急预案范本
- 往年广东中考高频词汇总结范文(全国中考阅读及完型高频词)
- 学校(幼儿园)每周食品安全排查治理报告(整学期16篇)
- 延期交房起诉状开发商违约金起诉状
- 心内科用药安全管理课件
- GB/T 20453-2022柿子产品质量等级
- 赣美2011版三年级美术下册《瓜果飘香》教案及教学反思
- 维修改造工程施工组织设计
- 执行力案例分享与解析课件
评论
0/150
提交评论