




免费预览已结束,剩余48页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1 STLanguage BasicCourse 2 STLanguage KeywordIfthereisanyunclearoruncorrected pleasefeelfreetospeakout BasicCourse 3 Requirements HardwareTheprogramminglanguageSTisonlyavailableforfollowingprogrammablecontrollers pCO3SupernodepCO5pCOcompact BIOSTosupportSTlanguage biosversionmustgreaterthan5 0 SoftwareUseaversionof1tool 2 1 x 4 CreationofasolutionSTLanguage Choosing FBD theapplicationwillbe mixed itwillconsistofamainwithAtoms Macroblocks butyoucanuseroutines functionsandfunctionblocks writtenintheST ST theapplicationwillbedevelopedentirelyusing STlanguage 5 Basicconcepts WhenprogramminginST theapplicationcanbeorganisedusingthreefundamentalprogrammingelementsgenericallycalled ProgramOrganizationUnits POU PROGRAMFUNCTIONFUNCTIONBLOCK POU Note wecandefinemorefunctionsandfunctionblocks butonlyoneprogrammain 6 Thebasictypes Thefollowingtablelistsallthepropertiesofbasictypes IECType 7 DeclarationofGlobalvariables TherearetwowaystodeclareGlobalvariables VariableList Textualmode ofSTlanguage Note ifyouwanttoseethevariableinthepGD pleasedeclarethevariableintheVariableList 8 Assignmentoperator Syntax Assigntoavariable aconstantvaluethevalueofanothervariabletheresultofanexpression Varaible name expression Note thereisa intheendofstatement 9 Textualdeclaration TodeclarevariablesinSTyouhavetousethefollowing declarationblock Note 1 thereisno intheendofEND VAR 2 wecangivethedefaultvalueinthedeclaration 10 Rulesoftheidentifiers variablesname a z A Z 0 9 Thenameofanidentifier variableorconstant canbeanycombination seeExample ofthecharacterslistedbelow ExampleRulestocreateidentifiers 11 ThequalifierCONSTANT TextualdeclarationofConstants ThekeywordCONSTANTcandeclareaconstant TheconstantsdonotoccupyspaceinmemoryasthevariablesDuringcompilationinsteadoftheconstantisreplacedanumericvalue 12 Comments Commentusingkeyword REGION ENDREGION Youcanhideseverallinesofcodeusingthekeyword REGION ENDREGION Soincreasethereadabilityofthecodeonthescreen Thecodeisreplacedwithacomment Clickingoncommentitwillappearagainthecode ThecodecommentsYoucanusetwowaystomakeacommentTocommentasinglecodelineuse Tocommentmorecodelinesuse and Thereisno inbetweenENDandREGION 13 ThequalifierRETAIN TextualdeclarationofglobalvariablesREATAIN retentive Example DeclarationofretentiveGlobalvariables RETAINkeyworddeclaresavariableinT permanentmemory Organizationofthevariables Note payattentionofthedefaultvalue 14 CastFunctions Syntax Variable name TO value Theconversionfunctionsareusedtoconvertanyoftheelementarydatatypestoanyother Theymustbeusedtomakethedatatypeuniformbeforeafunction wherethisisrequired 15 SToperators Fortheevaluationofexpressions alwaysusebrackets thisavoidserrorsintheevaluationoftheexpressions Example Tableoftheoperatorspriority Anexpressionisexecutedonlyaftertheevaluationoftheoperatorspriority Theexecutionorderofanexpressionanditsresultareinfluencedbytheoperatorspriority Suggestion A NOTXANDYORNOTJ Increasesreadability A NOT X AND YOR NOTJ IfZ 0theothervariableshavenotbeenevaluated A ZANDYAND NOTJ 16 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 17 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 18 TheFunction Itcanbecomparabletoa Blackbox itworksonaInputparametersconfiguration anditalwaysproducesinOutputthesameresultforthesameInputs Itletsnotrepeatmanytimesthesamecodewithintheproject asinsteaditisformacroblocksinFBDenvironment Ateachinvocationofthefunction thesamecodewillbealwaysexecuted WhatdoesaFunctiondo ItreadInputs nooutputs butcanhaveareturnvalueItexecutesthecodeofthefunctionItwritestheresultinaReturnValueAfunctiondoesn thaveamemorystateItalwaysproducesthesameresultforthesameinputs ThefunctionAdd 3 WhatdoesaFunctioncontain ThelistofparametersthatarepassedasinputsProbableLocalvariables onlyforitsinternaluseThecodeofthefunction WhatisaFunction 19 FUNCTIONstatement Thetablebelowlistsallpropertiesofafunction Summary 20 Passbyvalue VAR INPUT InthepassbyvaluetheActualParametersarecopiedinFormalParameters ActualParameters FormalParameters Modificationsdon thaveeffectonActualParameters 21 PassbyReference VAR IN OUT PassbyReference ActualParameters FormalParameters Modification Sometimesitisnecessarytomodifythevariablevaluepassedtothefunction andrendersuchmodificationoutsideimmediatelyvisible Thismodalityiscalled PassbyReference anditisrealizedusingkeywordVAR IN OUT InPassbyReferencetheFormalParameterpointtothesamecellofmemorythatcontainsthevalueofActualParameter 22 Variablesscope 23 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 24 ARRAYstatement Syntax Exercize Array name ARRAY elem 1 elem n OFType where Simulation elem 1andelem nareINTnumbersorconstants theycannotbevariables andrepresentthelimitsofthearrayelem n elem 1 thedifference 1indicatesthenumberofelementsinthearrayTypeidentifiestheelementarydatatypeelementsinsidethearrayorStructuretype 25 ArrayBreakthrough exceededlimits Example Run TimeerroronSimulator Run TimeerroronpCOPlace2integervariablesona Mask relatedtolibraryfunctions ThepositionoferrorintheStrategyEditorST goinsimulationandthenpressinsertHighpartandLowpart Whenavariableisusedtoaccesstheelementsofanarray caremustbepaidtoensurethesizeofthearrayisnotexceeded Ifrun timetheindexvalueexceedsthesizeofthearray thiswillentailthere bootofthepCO NoteToreset errorvariables usethislibraryfunctions 26 Iterationstatements FOR FOR DO Statement FORvariable initial expressionTOfinal expression BYincrease expression DOstatement block END FOR FORloopexecutesastatementblockfromaninitialvaluetoafinalvalueofthecontrolvariable Syntax Example Counter 10 27 Iterationstatements WHILE WHILE DO Statement WHILEstatementexecutesastatementblockwhiletheexpressionistrue Syntax WHILEexpressionDOstatement block END WHILE Example Tosearchforanelementwithinanarray 28 Iterationstatements REPEAT REPEAT UNTIL Statement REPEATstatement block UNTILexpressionEND REPEAT Thestatementscontainedintheloopareexecutedatleastonce REPEATstatementexecutesastatementblockwhiletheexpressionistrue Theloopisexecutedatleastonce Syntax 29 Iterationstatements EXIT Syntax 1shExample EXITstatement Toexitbyforloop EXIT TheEXITstatementisusedexclusivelyinsideWHILE REPEAT andFORstatementstointerruptexecutionoftheloopandgotothestatementaftertheendoftheloop END FOR END WHILE END REPEAT 2sdExample Toexitbynestedforloop 30 Iterationstatements Note ComparestatementWhile DoandRepeat Until ComparestatementReturnandExit 31 n dimensionalArray Syntax Exercize Simulation Note Array name ARRAY el 1 el n el 1 el m OFType Therulesseenforone dimensionalarraysarevalidThesyntaxisusedtodeclareamatrixToaccessarrayelements nestedFORloopscanbeused seeexercize 32 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 33 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 34 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 35 FUNCTIONBLOCK FunctionBlockinstanceLocalvariables VAR areallocate deallocateinsideStackateverycallingof ProgramFunctionAFunctionBlockinstanceshouldbedeclaredGlobal VAR GLOBAL andnotLocal VAR AinstanceofFBthatisdeclaredLocal VAR couldhaveadifferentbehaviourfromthatexpected ExampleInthisexampleaGlobaleandLocalinstanceofTONaredeclared TheLocalinstancewillneversucceedtofinishthecount becauseoftheinternalmanagementoftheLocalvariables 36 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 37 FUNCTION BLOCKinstance Recursion Recursionisnotallowed thatisaFunctionBlockcannot referdirectlyreferindirectlycallaFunctionorFunctionBlockinstancethatreferit Directrecursion Indirectrecursion 38 FUNCTION BLOCKinstance Variablesscope ThequalifierRETAIN IfaGlobalinstancehasthequalifierRETAIN dataaresavedinT permanentmemory 39 Thepropertiesofablockarelistedbelow FUNCTION BLOCK Summary 40 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 41 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 42 FBDandSTenvironment HowdoyouchangefirmofyourFunctionorFunctionBlockinFBDStrategyEditor InFBDStartegyEditorIhaveplacedMy Addfunction butihavetoaddanotherparameterYouhavetoaddthenewparametertoMy Addfunction andthen youhavetoselect Updatefromfirm inFBDStrategyEditor 1ststepAddIn3toMy Addfunction 2sdstepInFBDStrategyEditor Updatefromfirm 3rdstepInFBDStrategyEditorconnect In3variable 43 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 44 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 45 Arithmetcstatements STlanguagecanusethefollowingarithmeticoperations 2sdEsempioTheuseofdivisionoperator 1stExampleArithmeticoperator 46 Numericalstatements Vedianche LanguageSTallowstousethefollowingnumericalstatements 47 Debug Therearetwotypes ConditionalBreakpointBreakpointDuringthesimulationBreakpointsarenotactiveon FunctionsnevercallVariables InstancesneveruseExample Fordebuggingtheapplicationusethebreakpoint DebuggingkeysF5 goestonextbreakpointControl F10 StepoverControl F11 StepintoControl Shift F11 Stepout 48 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 49 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 S
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025福建厦门红宝石投资管理有限公司社会招聘1人笔试历年参考题库附带答案详解
- 2025河南南阳财和投资有限公司招聘(第七号)笔试历年参考题库附带答案详解
- 2025年福建省晋江水务集团有限公司招聘项目制工作人员11人笔试历年参考题库附带答案详解
- 2025年江西上饶市信州区国瑞投资控股有限公司招聘(补录)1人(第一次)笔试历年参考题库附带答案详解
- 2025四川绵阳市九州电子科技股份有限公司招聘智能制造工程师测试笔试历年参考题库附带答案详解
- 2025年福建省龙岩市武平县事业单位招聘5人考前自测高频考点模拟试题有完整答案详解
- 2025年河北唐山芦台经济开发区事业编制教师人员2名模拟试卷及参考答案详解
- 2025呼伦贝尔农垦集团有限公司校园招聘44人模拟试卷及答案详解(名校卷)
- 2025江西南昌动物园百花园管理所招聘3人考前自测高频考点模拟试题及答案详解(历年真题)
- 2025年河北沧州南皮县中医医院公开招聘工作人员16名考前自测高频考点模拟试题及答案详解(名校卷)
- 2024年新高考Ⅰ卷英语真题(原卷+答案)
- 2025山东东营公安招录辅警392人考试参考试题及答案解析
- 中职高教版(2023)语文职业模块-第五单元:走近大国工匠(一)展示国家工程-了解工匠贡献【课件】
- 电力各种材料重量表总
- 樊荣-《医疗质量管理办法》核心制度要点解析与案
- 男性不育症诊治指南课件
- 《声声慢》省赛一等奖
- 消防安全教育培训记录表
- 国家开放大学《实用管理基础》形考任务1-4参考答案
- 2023混凝土结构耐久性电化学修复技术规程
- 食品有限公司制冷机安全风险分级管控清单
评论
0/150
提交评论