版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1,ST Language,Basic Course,2,ST Language,Key word If there is any unclear or uncorrected, please feel free to speak out,Basic Course,3,Requirements,Hardware The programming language ST is only available for following programmable controllers:,pCO3 Supernode pCO5 pCO compact,BIOS To support ST langua
2、ge, bios version must greater than 5.0,Software Use a version of 1tool = 2.1.x,4,Creation of a solution ST Language,Choosing : - FBD, the application will be mixed, it will consist of a main with Atoms, Macroblocks . but you can use routines (functions and function blocks) written in the ST - ST, th
3、e application will be developed entirely using ST language,5,Basic concepts,When programming in ST, the application can be organised using three fundamental programming elements generically called Program Organization Units (POU): PROGRAM FUNCTION FUNCTION BLOCK,POU,Note: we can define more function
4、s and function blocks, but only one program main,6,The basic types,The following table lists all the properties of basic types (IECType):,7,Declaration of Global variables,There are two ways to declare Global variables: Variable List Textual mode of ST language,Note: if you want to see the variable
5、in the pGD, please declare the variable in the Variable List,8,Assignment operator :=,Syntax,Assign to a variable:,a constant value the value of another variable the result of an expression.,Varaible_name := expression ;,Note: there is a ; in the end of statement,9,Textual declaration,To declare var
6、iables in ST you have to use the following declaration block:,Note: 1. there is no ; in the end of END_VAR; 2. we can give the default value in the declaration.,10,Rules of the identifiers (variables name),a.z, A.Z 0.9 _,The name of an identifier (variable or constant) can be any combination (see Ex
7、ample) of the characters listed below:,Example Rules to create identifiers.,11,The qualifier CONSTANT,Textual declaration of Constants,The keyword CONSTANT can declare a constant. The constants do not occupy space in memory as the variables During compilation instead of the constant is replaced a nu
8、meric value.,12,Comments,Comment using keyword REGION ENDREGION You can hide several lines of code using the keyword REGION ENDREGION. So increase the readability of the code on the screen. The code is replaced with a comment. Clicking on comment it will appear again the code.,The code comments You
9、can use two ways to make a comment To comment a single code line use “” To comment more code lines use “(*” and “*)”,There is no _ in between END and REGION,13,The qualifier RETAIN,Textual declaration of global variables REATAIN (retentive),Example,Declaration of retentive Global variables.,RETAIN k
10、eyword declares a variable in T-permanent memory.,Organization of the variables.,Note: pay attention of the default value,14,Cast Functions,Syntax,Variable_name := *_TO_*(value);,The conversion functions are used to convert any of the elementary data types to any other. They must be used to make the
11、 data type uniform before a function, where this is required.,15,ST operators,For the evaluation of expressions, always use brackets, this avoids errors in the evaluation of the expressions.,Example,Table of the operators priority,An expression is executed only after the evaluation of the operators
12、priority. The execution order of an expression and its result are influenced by the operators priority.,Suggestion,A:= NOT X AND Y OR NOT J; Increases readability: A:= NOT(X) AND (Y OR (NOT J);,If Z=0 the other variables have not been evaluated. A := Z AND Y AND (NOT J);,16,Conditional statements: I
13、F,IF . THEN . ELSE statement Conditional construct: executes a statement block depending on whether or not certain conditions are satisfied.,Syntax,Exercize,If Expression=TRUE, statement_block is executed Otherwise the conditions in the ELSIF blocks are evaluated Finally, if these are all false, the
14、 statements in the ELSE block are executed.,Boolean (AND, OR, NOT, XOR) Comparison (=, , , =, to write on a variable the FB outputs.,Use := to assign value to the input.,35,FUNCTION BLOCK,Function Block instance Local variables (VAR), are allocate/deallocate inside Stack at every calling of: Program
15、 Function A Function Block instance should be declared Global (VAR_GLOBAL) and not Local (VAR). A instance of FB that is declared Local (VAR) could have a different behaviour from that expected.,Example In this example a Globale and Local instance of TON are declared. The Local instance will never s
16、ucceed to finish the count, because of the internal management of the Local variables.,36,FUNCTION_BLOCK instance,FUNCTION_BLOCK functionblock_name (* Input, In_Out, and Output variables declaration *) (* Local variable declaration *) (* Implementation code*) END_FUNCTION_BLOCK,Definition synstax,A
17、Function Block:,can be called more than once inside a Program, a Function or a Function Block receives one or more input values (VAR_INPUT or VAR_IN_OUT) and unlike Functions, gives one or more output values (VAR_OUTPUT). the values of the Local variables (VAR) and the input and output parameters in
18、 Function Blocks are saved in the memory between calls of the function block, and from one program cycle to the next; in the latter case as long as the function block instance has been declared as Global (VAR_GLOBAL).,In the calling POU the instance of the function block must be declared FIRST, so a
19、s to allocate the memory required to store the values of the internal variables (e.g.: use VAR_GLOBAL; take care if using VAR). If one of the input parameters is omitted (VAR_INPUT), the function block uses the default value (0 or FALSE in the first program cycle) or the last value used inside the f
20、unction block. Parameters declared as VAR_IN_OUT cannot be omitted. Recursion is not allowed.,37,FUNCTION_BLOCK instance,Recursion,Recursion is not allowed, that is a Function Block cannot:,refer directly refer indirectly call a Function or Function Block instance that refer it.,Direct recursion,Ind
21、irect recursion,38,FUNCTION_BLOCK instance,Variables scope:,The qualifier RETAIN,If a Global instance has the qualifier RETAIN, data are saved in T-permanent memory.,39,The properties of a block are listed below.,FUNCTION_BLOCK: Summary,40,ST event is a function with the following restrictions: Has
22、a unique name Has no Return value Has no Input parameters Has no Local variables Can only modify Global variables, you can not call Functions or Function Blocks Event differs from other functions, because the name is preceded by the reserved word Event_ (e.g.: Event_incA) There is no limit to the nu
23、mber of events that you can define. Syntax FUNCTION Event_NameEvent /CODE END_FUNCTION From Mask Editor is possible to execute a ST event, specifing in the Key Function Editor Do_ST_Event statement. Example When the PRG button is pressed, increase a variable. 3 How? In the Startegy Editor ST define
24、the event In the Key Function Editor with DO_ST_Event statement call the event,ST Event,41,How to use the Add_3 in FBD? In the Solution Explorer add a page to Subroutine ST node Edit Add_3 function code, paying attention to types of Input parameters and Return value. In the Dependencies node of Solu
25、tion Explorer add Core_ST library. Inside FBD environment From Core_ST library select ST_Call atom to call Add_3 function inside FDB environment. Finally connect variables to pins.,FBD and ST environment,Reminders on FBD environment FBD Environment uses only the basic types (Boolean, Integer/Analog)
26、 The ST language is supported by some controllers (pCO3, Suprnodo, ),42,FBD and ST environment,How do you change firm of your Function or Function Block in FBD Strategy Editor? In FBD Startegy Editor I have placed My_Add function, but i have to add an other parameter You have to add the new paramete
27、r to My_Add function, and then, you have to select “Update from firm” in FBD Strategy Editor,1st step Add In3 to My_Add function,2sd step In FBD Strategy Editor “Update from firm”,3rd step In FBD Strategy Editor connect _In3 variable,43,System variable,ST Language uses specific library functions, in
28、 order to access to system variables of type: Boolean Integer Syntax Set_SystemVariableName (Vaule); Variable := Get_SystemVariableName ( ); 1st Example (Boolean) Set_KEY_PRESSED(1); Alarms:= Get_GLOBAL_ALARM( ); 2sd Example (Integer) Set_KEY_PRESSED(1); BMSAddr := Get_BMS_ADDRESS( ); Library access
29、 To access library functions press CONTROL+SPACE,44,Base 2, Base 8 and Base 16,A number can be represented also in the bases: Binary (Base 2) Octal (Base 8) Hexadecimal (Base 16) Syntax Variable := Base#Value; Example a:=2#10110001; a:=8#767; a:=16#AF0; Moreover, it is possible to separate the figur
30、es with of optional _ , in order to increase the readability a:=2#1011_0001; a:=8#7_6_7; a:=16#AF0; a:=16#A_F_0;,45,Arithmetc statements,ST language can use the following arithmetic operations:,2sd Esempio The use of division operator.,1st Example Arithmetic operator:,46,Numerical statements,Vedi an
31、che,Language ST allows to use the following numerical statements:,47,Debug,There are two types: Conditional Breakpoint Breakpoint During the simulation Breakpoints are not active on: Functions never call Variables/Instances never use Example,For debugging the application use the breakpoint.,Debuggin
32、g keys F5: goes to next breakpoint Control+F10: Step over Control+F11: Step into Control+Shift+F11: Step out,48,Exercises,Ex1: 在ST中进行浮点数运算。 控制逻辑: 对数学表达式进行运算: A= (IN1+1) / (IN2+1) B= -0.024263A2 + 0.8638A + 0.16655 Vw= -0.0922B2 + 1.154B 具体要求: 在Subroutine ST中编写一个函数块,最终在FBD中调用该函数。分别 给IN1和IN2赋两组数据,看最终V
33、w的值是否为计算的最终结果。 参考: 需要用到的相关语句:+,-,*,/, *, INT_TO_REAL,REAL_TO_INT.,49,Exercises,Ex2: 使用ST语言写出机组开关机的功能块。 控制要求: 以功能块(Function block)的形式编写该模块 在FBD中调用该功能块 具体要求 功能块的输入 根据机组启动请求来管理机组状态,机组启动的选择方式如下: 通过键盘Keyboard_OnOff 通过plan pLan_OnOff 通过数字量输入Dig_In_OnOff,En_Dig_In_OnOff 通过时间段Schedule_OnOff,En_Sched_OnOff 通
34、过上位机Superv_OnOff,En_Superv_OnOff 通过报警状态 Alarms 功能块的输出 变量Unit_OnOff 表示机组的状态。仅当上述功能全部启用,即以下全部条件均为真时(Unit_OnOff=1): Keyboard_OnOff=1 pLan_OnOff 或En_PLan_Onoff=0 Dig_In_OnOff=1 或 En_Dig_In_OnOff=0 Schedule_OnOff=1 或 En_Sched_OnOff=0 Superv_OnOff=1 或 En_Superv_OnOff=0 Alarms=0 功能块的输入Manual 对机组状态不起作用,仅对输出
35、 Unit_Status 起作用。 功能块的输出 Unit_Status 表示机组的运行状态。 Unit_Status 的值状态0机组开启(Unit_OnOff=1)1Alarms=02机组因报警而关闭(Alarms=1)3机组通过plan关闭( pLan_OnOff 且En_PLan_Onoff)4机组通过上位机关闭(Superv_OnOff=0 且 En_Superv_OnOff=1)5机组通过时间段关闭(Schedule_OnOff=0 且 En_Sched_OnOff=1)6机组通过数字量输入关闭(Dig_In_OnOff=0 且 En_Dig_In_OnOff=1)7通过本地键盘关闭机组(KeyBoard_OnOff=0)8手动操作(Manual=1)请注意,如果同时出现 2 个或多个上述情况,输出 Unit_Status 将取最大值。例如,如果机组由于报警关闭,并同时通过数字量输入关闭,则 Unit_Status 的值为 6。 功能块的输出 Led_OnOff 提供 LED 的状态,该 LED 表示机组状态。 LED_OnOff 的值状态0通过键盘关闭机组 (KeyBoard_OnOff=0)1机组开启 0/1在每个程序周期中,该值从 0 变为 1,再从 1 变为 0。机组由于报警关闭,Plan关闭或通过上位机、时间段或
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年临床执业医师 考试《病理学》模拟题及答案(卷九)
- 2026年农村宅基地管理业务考试试题及答案
- 2026年普法真题及参考答案详解(模拟题)
- 2026年人工智能应用工程师认证考试真题(高级)
- 麦肯锡 -清理混合废料:借助循环模式实现铝产业脱碳 Cleaning up mixed scrap Decarbonizing aluminum through circularity
- 2026年校招:证券经纪人题库及答案
- 2026年校招:中国海洋石油题库及答案
- 2026年校招:中国建设银行笔试题及答案
- 2026年校招:中国节能环保题库及答案
- 2026年校招:中国铝业试题及答案
- 产后母乳喂养技巧与问题解决
- 中远海运内部职级制度
- 慢性创面课件
- 中核集团在线测评试题
- T-CIAS 8-2025 模块化金属看台建造技术标准
- 常用量具培训知识课件
- 无机实验室安全知识培训课件
- 听说课AI课件教学课件
- DB42∕T 1934-2022 湖北省水利工程白蚁防治概算定额
- 湖南省衡阳市2025年七年级上学期月考数学试题附答案
- GB/T 27043-2025合格评定能力验证提供者能力的通用要求
评论
0/150
提交评论