Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
122 views
PLC Structured Text Programing (ST)
PLCPLC Structured Text Programing (ST)B
Uploaded by
dekin22249
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save PLC Structured Text Programing (ST) For Later
Download
Save
Save PLC Structured Text Programing (ST) For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
122 views
PLC Structured Text Programing (ST)
PLCPLC Structured Text Programing (ST)B
Uploaded by
dekin22249
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save PLC Structured Text Programing (ST) For Later
Carousel Previous
Carousel Next
Save
Save PLC Structured Text Programing (ST) For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 70
Search
Fullscreen
1 1-Programming_Besics_{Structured_Text)_n200180_eng PLC Programming Basics (Structured Text) This course covers how to create basic programs used to control MELSEC programmable controllers Structured text (ST) is used for program descriptions i course. his Copyright ©2015 Mitsubishi Electric Corporation. All Rights Reserved LewayooTageNGI 1-Programming_Basics_{Structured_Text)_ne00189_eng elec! Can Purpose of the course ; nee ‘This course explains how to create control programs in structured text (ST) for MELSEC programmable controllers Completion of the following course or having equivalent knowledge is a prerequisite prior to taking this course: Programming Basics Having knowledge or experience with C or BASIC programming language can help understand the contents of this course.1 1-Programming_Besics_{Structured_Text)_n200180_eng rn Uy Course structure ‘The contents of this course are as follows. Chapter 2 - Overview of structured text This chapter describes the features and suitable applications of structured text (ST). Chapter 2 - Basic rules of ST programs This chapter describes the basic rules used to create programs in ST. Chapter 3 - Creating 1/0 control programs This chapter describes how to create /O control programs. Chapter 4 Arithmetic operations This chapter describes how to create arithmetic operation programs. Chapter 5 - Conditional branching This chapter describes conditional branching, Chapter 6 - Storage and handling of data This chapter describes how to write concise programs to store and handle data, Chapter 7 - Handling of string data This chapter describes the methods to handle string data. Final Test Pass grade: 60% or higherI 1-Programming_Basics_{Structured_Text)_ne00189_eng elec! Can How to use this e-Learning tool ) coc ut) Cee RS Terr se Ec ee} Go to the next page. Back to the previous page. "Table of Contents" will be displayed, enabling you to navigate to the desired page. Exit the learning,I 1-Programming_Basics_{Structured_Text)_ne00189_eng elec! [introduction | Cautions for use , nee Safety precautions ‘When you learn based on using actual products, please carefully read the safety precautions in the corresponding manuals. Precautions in this course The displayed screens of the MELSOFT engineering software that you use may differ from those in this course. This course uses the ladder symbols of MELSOFT GX Works3 to create programs.1 1-Programming_Besics_{Structured_Text)_n200180_eng Overview of structured text ‘This chapter describes the features and suitable applications of structured text (ST). 11 Control programs 12 Features of ST and comparison with other IEC programming languages1 1-Programming_Besics_{Structured_Text)_n200180_eng Control rams: ‘The following figure illustrates the configuration of a programmable controller system. Programmable controllers operate according to control programs. The operation of programmable controllers can be configured as desired by creating control programs. Control program (Ladder) Pushbutton sertch Lamp wD HO Lays} ‘By writing a control program, the lamp wil um on Jn response to the status of the pushbutton switch. Input module CPU module Output module Personal computer ‘The programming languages for programmable controllers are defined by the international standard developed by the Intemational Electrotechnical Commission (EC).AG 1-Programming Besics_(Structured_Text)_na00189_eng Features of ST and comparison th ot TEC programming language: IEC 61131 is an international standard for programmable controller systems. Programming languages for programmable controllers are standardized by IEC 6131-3. ST is one of the standard programming languages. Each language has different features to accommodate your application and programmers’ skill The follov Programming language Ladder Diagram (LD) 19 table lists features of the IEC 6131-3 programming languages. Fes ‘Symbols for contacts and cols are used to create a program resembling an electrical reuit Program flow is easy to follow and understand, even for beginners. Structured Text (ST) Programs ate written in text (character) ST's easy to lear for those with experience in writing programs in C or BASIC programming language. Calculation formulas ae similar to mathematical expressions, which are easy to understand. ST's suitable for data handling. Function Block Diagram (FD) Programs are written by arranging blocks with different functions and indicating relationships between the blocks. FBD Improves readabiliy asthe entre operation can be easily seen Sequential Function Chart sO Conditions and processes are written 2s flowcharts Program flow is easy to understand. Instruction Ls) IL similar to machine language. IL rarely used today, ‘This course describes how to write basic control programs using ST. eo} aa1 1-Programming_Besics_{Structured_Text)_n200180_eng elec! ==? ‘The contents of this chapter are: + Relationship between programmable controller systems and control programs + International standard for control programs + Features of ST Important points to consider Relationship between Programmable controllers operate according to control programs. Cece dcons Mae neue) = The operation of programmable controllers can be configured as desied by creating So control programs. ene ee Lea) = STis one ofthe IEC programming languages Ces (Other IEC programming languages include LD, F8D, SFC, and IL, each of which has diferent feetures to accommodate your application and programmers’ sil Pore ‘STs easy to leatn for those vith experience writing programs in C or BASIC langus Calculations such 2s adaition and subtaccion can be written as typically used ‘mathematical expressions which are easy to understand. STs sultable for data handling,1 1-Programming_Besics_{Structured_Text)_n200180_eng 4 Ba: ST ‘This chapter describes the basic rules used to create programs in ST. rules of rams 2.1 Basic program example (VO control statement) 2.2 Basic program example (Assignment statement) 2.3 Numerical notation 2.4 Program execution sequence1 1-Programming_Besics_{Structured_Text)_n200180_eng rogram example (I/O control statement) This section illustrates an example of a basic ST program. With the following example program, the output YO tus on when the input X10 turns on, and YO turns off when X10 turns off. putida Argument |] Argument ‘An instruction defines the operation to execute. ‘Arguments are written in parentheses after an instruction. Arguments are used to describe variables, arithmetic expressions, and constant values. ‘With MELSEC programmable controllers, devices of the CPU module can be used as variables. ‘The number of arguments depends on the instruction. Multiple arguments are separated with commas () “The one line shown above represents one statement. Each statement is ended with a semicolon (). ‘A program is written by combining statements.1 1-Programming_Besics_{Structured_Text)_n200180_eng ‘4 Ba: rogram example (Assignment statement) ooo ‘The next example illustrates a program that uses an assignment statement. The following statement assigns the decimal constant °5" to the variable "D10". (* Assigns the constant "5" as the initial value.*) ene cod ere cis ‘An assignment operator (:=) is used for this assignment statement, Note that a colon () is placed to the left of the equal sign (=). ‘An assignment operator assigns the right side value to the left side. ‘Adding @ comment to a program makes the operation more understandable. Enclose comments between two asterisks (**)AG 1-Programming Besics_(Structured_Text)_na00189_eng Numerical notation With the example program on the previous page, @ decimal value was assigned to a variable. Sometimes values other than decimal such as binary and hexadecimal are used for sequential control. The following table lists the types of numerical notation used in ST used far MELSEC programmable controllers. Pro: ee es Binary Add apreficof'2e, | 2ei1010 Octal Addaprofixof"ae | 832 Decimal Direct input 2% ‘Add a prefiof"®. K25 Hexadecimal ‘Add a prefixof "16%. | 16814 Add a prefixof H" HIA D10: D10 : D10 : 8#32; K26; H1A; 1gram examples to assign values to variables are shown below.1 1-Programming_Besics_{Structured_Text)_n200180_eng (EEE Bit notation ) Gao Bits represent true/false conditions such as on/off states of signals. Bits also represent establishment/non- establishment of conditions In ST, bits cannot be written as "ON" and "OFF". These are expressed as * expressed as "TRUE" and “FALSE”. (ON) and "0" (OFF). Bits can also be ‘The following table lists the different types of notation Here are some examples of assigning values to bit-type variables. Numeric notation True/false notation X0:=1; XO := TRUE; Numeric notation True/false notation X0:= 0; = FALSE;rogramming_Basics_{Structured_Text)_n200180_eng ram execution sequence coc ST statements are executed in order from top to bottom. ST program example (XO OR X1) AND X2; (* Executed first *) X3 AND X4; (* Executed second *) repeats X3 AND X5; _¢ fxecuted third Does not require an END statement atthe end *) — “Though an END statement is necessary at the end of the program in LD, its unnecessary in ST. ‘The following ladder program represents the same operation as the ST program example above. WW +H + 6 Repetitive . execution Asis the case in LD, instructions in ST are repeatedly executed by returning to the first instruction after reaching to the last instruction,Idi t-Prograrmming_Basics_(Structured_Text)_ne00189_eng a ‘The contents of this chapter are: * Basic ST program + Assignment statement format + Numerical notation + Program execution sequence + Comment Important points to consider: al ce ee ee elena Cee Cee eed oe + Asstatement is the minimum element of ST programs. + An assignment operator + Aswith LD programs, ST programs process repetitively returning to the beginning of the ‘Adding 2 comment to pragram makes the operation more understandable, Each statement is ended with a semicolon () is used for assignments Types of numerical notation in ST "and "0" are used for bit vais in ST instead of the “ON” and “OFF” notation Bit values canbe also stated as "TRUE" and "FALSE" in ST. Programs crested in ST are executed in order from top ta bottom, program once the end of the process has bean reached. Comments are enclosed between two asterisks (**)1 1-Programming_Besics_{Structured_Text)_n200180_eng Creating I/O control rams ‘This chapter describes how to create 1/O control programs in ST. 3.1/0 control programs 3.2. Combining multiple conditions 3.3 Defining meaning to variables1 1-Programming_Besics_{Structured_Text)_n200180_eng 1/0 control programs ooo The following is a program example for /O control of a programmable controller. od eer ca instruction (argument) (argument) "OUT" is the output instruction. An argument specifies an execution condition and the device to which output is directed. ‘When the execution condition X0 is satisfied, the device Y10 tums on, Click the input switch shown below. The input switch XO tums on, ‘+ When the input switch X0 turns on, the output lamp Y10 turns on. + When the input switch X0 turns off, the output lamp Y10 tums off, Example of 0 contol program writtan in ST Input snitch XO Output amp Y10 OUT(XOJY10); ) 3 pe _______________ o ‘The same program writen in LDrogramming_Basics_{Structured_Text)_n200180_eng Y/0 control programs Similar to LD, there are many instructions available besides the QUT instruction such as 1/O control instructions and data processing instructions. Refer to the programming manual of your programmable controller for more information on the instructions available in ST. Note that writing "OUT(XO, Y1 as “Y10 := XO," produces the same operation, X0; (* Same operat1 1-Programming_Besics_{Structured_Text)_n200180_eng Coml le condi ns The following ladder program represents a self-retaining circuit. Pad” ‘The same program can be written in ST as follows, Y70 := (XO lor Y70) AND] NOT X1. ea As shown above, logical operators are used to combine multiple conditions in ST. The following table lists the logical operators. Cr Cn) OR Logical OR AND Logical AND NOT, Logical negation OR Exclusive OR 1rogramming_Basics_{Structured_Text)_n200180_eng Defining meaning to variables Using ST with MELSEC programmable controllers, both devices and labels can be assigned as aliases to variables. Users can use labels according to the applications. ‘When a label related to the application is assigned, the operation is easier to understand. Y10 = (XO OR X1) AND X2; —(* Written using device names *) 4 Lamp := (SwitchO OR Switch1) AND Switch2; _(* Written using labels *) Labels can be named using the MELSOFT engineering software Subsequent program examples in this course are described using labels.I 1-Programming_Basics_{Structured_Text)_ne00189_eng elec! € A | Summary ) cao ‘The contents of this chapter are: WO control program examples + Logical operators are used to combine multiple conditions in ST. + Device names and labels can be used as variable names. Important points to consider ‘Combining multiple conditions Logical operators are used to combine conditions in ST. Defining meaning to variables ‘When label related to the application is assigned, the operation is easier to understand.1 1-Programming_Besics_{Structured_Text)_n200180_eng Arithmetic operations This chapter describes how to create arithmetic operation programs. + Describing arithmetic operations + Specifying data types corresponding to the numeric ranges + Naming variables to avoid data type inconsistencies 4.1 Basic arithmetic operations 42 Data types of variables 4.3 Variable names that represent data types‘ogramming_Basics_{Structured|_Text ne00189_eng cm Basic arithmetic operations ) cao ‘This example program totals the production volume of two separate production lines. ‘The right side of an equation is an arithmetic operation containing variables and arithmetic operators. eer Riera Example arithmetic program written in ST ut dah TotalProduction := Line1Production| [4] Line2Production|4 Waster; (* Total the production volume of two production lines, subtract the number of defective products from the total, and assign the obtained value. *) The same program written in LD is as shown below. eg Ura retain —TotsPratacton ‘As shown above, the program must be written by using 3 lines in Ladder, but with ST, it can be written in 1 fine. The following table lists the basic arithmetic operators. Coe + Adcition g Subtraction * Multiplication 1 Dhision1 1-Programming_Besics_{Structured_Text)_n200180_eng Data types of variables ‘A data type must be specified for each variable to define the range of the values to be handled. ‘The data types for numeric values used in ST are bit, integer, and real number types. ‘Among the data types used in ST, the table below shows the data types used in this course. Bit ‘ON/OFF state of bit devices and true/false state of execution results Integer Word (unsigned) 065,535 Word (signed) ~32,768 - 32,767 Doubleward (unsigned) | 0-4,296,967,295 Double-word (signed) 2.147483 648 - 2147 483,647 ‘When using the integer type, select the word or double-word type according to the data range, and select the signed or unsigned type according to the necessity to handle negative values Specify the data type of a variable when the label name is set using the MELSOFT engineering software.AG 1-Programming Basics_(Structured_Text)_ne00180_eng el Variable names that represent data types coc Using different data types on the left and right sides of an assignment equation may cause a compiling error or unexpected result. Below is an example of such a case ValueA := ValueB; _(* ValueA: Word integer ValueB: Double-word integer *) ‘A double-word integer cannot be assigned to a word integer. However in this case, the data type is not recognizable Prefixes that represent the data type can be added to variable names to make data types to be visually identifiable. This kind of variable naming is known as Hungarian notation, Ee Dota range Ene Bit ON/OFF state of bit devices and Ps ‘buo/false state of execution rosults Integer | Word (unsigned) 0- 65,535 unsigned word ‘Word (signed) “32,768 - 32767 signed word Doubleword (unsigned) | 0-4,294,967,295, ‘ae ast Double word (signed) “ZA7AB3,648 - 2,147 483,647 signed double-word The example program on top of this page can be written as follows using Hungarian notation: wValueA := dValueB; (* Double-word variable cannot be assigned to a word variable. *) By using Hungarian notation, data type inconsistencies can be identified in the process of writing a program. In the rest of the course, variable names in example are written in Hungarian notation.1 1-Programming_Besics_{Structured_Text)_n200180_eng ‘The contents of this chapter are: + Describing arithmetic operations + Specifying data types corresponding to the numeric ranges + Adding variable names that represent data types Important points to consider: ead Cee ead eta ed Operators common to general programming languages can be used in ST to express cakeuations. ‘A data type must be specified for each variable to define the range of the values to be handled Describing variable nares using Hungarian notation enables inconsistencies invariable data ‘types to be identified when writing programs.I 1-Programming_Basics_{Structured_Text)_ne00189_eng ohh Conditional branchin Control programs also contain sections of code in which actual processing changes in accordance with specified conditions. This chapter describes conditional branching, 5.1 Conditional branching (IF) 5.2 Conditional branching according to integer values (CASE)AG 1-Programming Basics_(Structured_Text)_ne00180_eng el Conditional branching (IF) ooo IF statements are used for conditional branching. IF statements are described as follows. Execution statement; (Statement is executed if conditional expression is satisfied. END (END_IF, must be placed at the end of the IF statements. >) In this example program, a statement is executed when the conditional expression is satisfied, The statement is not executed when the conditional expression is not satisfied The following figure ilustrates the operation flow in this example program. The following exemple illustrates branching of the program by comparing values of variables. In the example program, the heater tums on when the temperature in the control panel falls Conan stint below 0 degrees. Ge IF wTemperature < 0 THEN Heater := 1; (* The heater is turned on when the temperature in the control panel falls below 0 degrees. *) ENDIF;I 1-Programming_Basics_{Structured_Text)_ne00189_eng eh Wi ‘The previous page described a conditional expression of "wTemperature < 0", which means "when the value of variable Temperature is less than 0°. Like this expression, conditional expressions use comparison operators to represent relationship between variables and values to compare. ing conditional expressions == i] wIemperature Ney ‘Comparison operator On the left and right sides of an comparison operator, values are written as variables or constants for comparison, In addition to comparing variables and constants, conditional expressions can be written to compare variables, and perform logical operations of comparison results or bit-type variables. Comparing variables ‘The following table lists the types of comparison operators. Logical operation for two comparison results > Greater than * (10 < uValue) AND (uValue <= 50) & Kas tein. Logical operation for two bit-type variables eS + bswitcho OR bSwitch1 Less than ar equal to 7 Equals 2 Does not equal1 1-Programming_Besics_{Structured_Text)_n200180_eng Exceptional branching for IF statement (ELSE) ooo Simple IF statements (see 5.1) are used to execute a statement when the conditional expression is satisfied. To execute a different statement when the conditional expression is not satisfied, an ELSE statement is used. Execution statement 1; (¢ Statement 1 is executed if conditional expression is satisfied. Execution statement 2; END IF; (Staten nt 2 is executed if conditional expression is not satisfied ) The following figure illustrates the operation flow when using an ELSE statement. ‘Satisfied Not slised Conditional a oo ‘Statement 2 The following example program executes different statements depending on whether the condition is satisfied. The example program in 5.1 had a drawback that the heater keeps raising the temperature even after it reaches 0 degrees. However, the following program tums off the heater when "wTemperature" exceeds 0 degrees. IF wTemperature < 0 THEN bHeater = 1; (* Tums on the heater when the temperature falls below 0 degrees. *) ELSE bHeater = 0; (* Turns off the heater when the temperature reaches or exceeds 0 degrees) ENDIF;)_n200189_eng el for IF statement (ELSIF) coc [i 1-Programming_Basics_{Structured_Text Add ELSE statements are used to execute a different statement when the conditional expression is not satisfied. Another conditional branching can be added by using ELSIF statements, which mean that ifthe previous conditional expression is not satisfied, then another conditional expression is checked. nal branc! JF Conditional expression 1 THEN txection statement I; __( Stlement Ib exeaited I condlionl epresion Ub satisfied) ] ELSIF Conditional expression 2 THEN Execution statement 2; ( Statement 2 is executed if concitional expression 1.6 not satisfied and conditional expression 2 is satisfied ELSE Execution statement 3; (* Statement 3 is executed if conditional expressions 1 and 2 are not satisfied *) ENDIF; The following figure illustrates the operation flow ‘when using an ELSEIF statement. ELSIF statement is added to the program example illustrated in 5.1.2 to cope with the case when the temperature exceeds 40 degrees. Not satisfied IF. wTemperature < 0 THEN bHeater:= 2; Turns on the heater when the temperature falls below 0 degrees. *) LbCooler = 0; + Tums off the coter when the temperature fls below 0 degrees. *) Not stinfiad ELSIF 40 < wTemperature THEN Heater: 0; ¢ Turns off the heater the temperature exceeds 40 degrees *) bCooler: 1; ("Turns onthe cooler if the temperature exceeds 40 degrees“) Conditional |] ELSE epression3 || bHeater:= 0; ¢ Tums off the heater if none ofthe previous conditions are satisfied. *) bCooler := 0; ¢ Tus of the cooler if none ofthe previous conditions are satisied.*) ENDIF; sea | [ samenI 1-Programming_Basics_{Structured_Text)_ne00189_eng el Condi nal branching according to integer values (CASE) IF statements are used for branching depending on whether or not conditional expressions are satisfied. CASE statements are used for branching according to integer values The following figure illustrates how a CASE statement is written, ASE Variable OF, a when the variable Integer value 2: Execution statement 2: (Statement 2 is executed when the variable matches integer value 2.*) Integer value 3: Execution statement 3; (¢ Statement 3 is executed when the variable matches integer value 3.°) ELSE Execution statement 4; (Statement 4 is executed if the variable does not match any of the integer values. *) END_CASE; (*"END_CASE;* must be placed at the end of the CASE statement. *) The following figure illustrates the operation flow when using a CASE statement. Imager value 1 Integer value 2 Intager value’3 Dees not match integers 1-3‘ogramming_Basics_{Structured|_Text ne00189_eng Example pro: Click (BE) to proceed tothe next page To watch the animation agai, click the “Play button, (Pey CASE wWeight OF 0.20: Size := 21.30: Size USize uSize for CASE statement ‘The CASE statement execution is described using the example program operation. con Weigt uSize Eo Oto 20kg 1 M Alto 30kg 2 L 3110 40kg 3 x 41 kg and over 4 Oversize1 1-Programming_Besics_{Structured_Text)_n200180_eng ‘The contents of this chapter are: + Conditional branching with IF statements + Writing conditional expressions + Conditional branching according to integer valves (CASE statement) Sey Cad ‘With an IF statement, the program is branched when a conditional expression is satisfied + AN ELSE statornent is used for branching when the conditional expression isnot satisied. + ANELSIF statement is used to add another branching when the concitional expression in the IF staternent isnot satisfied * Conditional espressions represent relationship between variables and values to compare using comparison operators. + CASE statements are used for branching according to integer values.1 1-Programming_Besics_{Structured_Text)_n200180_eng of data coc ‘As well as for /O control applications, nowadays programmable controllers are used to process large amounts of data as the core of productions systems. To process large amounts of data, data must be stored and then read as necessary. This chapter describes how to write concise programs to store and process data Storage and hand! + Arrays are used to sequence and organize variables, + Data structures are used to organize related variables. + Loop-processing programs effectively process arrays using FOR statements. Concise programs to store and handle data can be created by using arrays, data structures, and FOR statements, 6.1 Sequencing and storing data (Array) 62 Looping (FOR) 63 Storing related data (Structures)1 1-Programming_Besics_{Structured_Text)_n200180_eng eo} aa Sequencing and storing data (Array) By using arrays, multiple values can be handled by one variable. In the following example, the production volume data in an automotive manufacturing plant is stored by destination county. er eT The production volume data by destination country is assigned to a variable. Without using arrays, one variable must be created for each destination, By using arrays, however, the production volume for multiple destinations can be assigned to and stored in one variable. Not using array va sing array vuProductionA uProduction3 | =m | uProduction uProductionC Individual variables in the array are specified using element numbers. Element numbers start from zero {0 [uProductior|{0]|] =p Ce Countrya [101 35 Destination-y County | Bl 75 (row) Country | BI 65 In the following program example, the variable of the planned production volume for Country A is assigned. uShowProductionPlan := uProduction| ( Specifies the element number for country A. *1 1-Programming_Besics_{Structured_Text)_n200180_eng Matrix array Next, paint color data is used in addition to the destination data. S Paint color (column) Ret oUF Ey Plt) Dore 5 EC co Ey Pa 30 10 volume Fes Peioko Ce As illustrated in the following table, data can be separated and stored by paint color (column) for each destination country (row), Blue al al al county [OT 4° 5 , Fence Destination 4 county s [TH ys [BAT ap | HAD oo resell (row) Country ¢ | [2.01 25 al 30 2] 10 Arrays that organize data into rows and columns in this way are known as matrix arrays. Element numbers that represent the rows and columns are separated by commas. Seed en rts Array variable (matrix array) [Production aja1 1-Programming_Besics_{Structured_Text)_n200180_eng Mat Using matrix arrays, the following example program assigns the number of cars to be urgently manufactured in addition to the planned production volume of yellow automobiles for Country B. array assignment uAdditionalProduction = 5; uProduction{1,1] := uProduction[1,1] + uAdditionalProduction; (* Adds the additional amount of production (5 units) to the initially planned production volume. *) Destination : Panton | ED SED ED Ee Cored Rati Err 65 in total Red " Blue Country A | 101 fou. ma, Destination J Country | [1 a5 TEN 49-5 45 | 21 55 (row) Country | 201 95 Bl 39 Ra 451 1-Programming_Besics_{Structured_Text)_n200180_eng eo} aa Proces: information stored in matrix arrays Using matrix arrays, the following example program calculates the total production volume planned for all paint colors for Country C and assigns the value to a variable, Production[2,0] + uProduction(2,1] +uProduction[2,21; uProductionToday ( Calculates the total production volume planned for today for all paint calors for Country C and assigns the value to “uProductionToday’. *) Paint color Eur Cc “Red. Blue [0.01 Toa} (oa) Country A. io § ie Destination 3 Country | (Ol, Gal as iat 20 (row) | a Country | [201 55 al 55 Bal 5 SSI 1-Programming_Basics_{Structured_Text)_ne00189_eng el Looping (FOR) The example program on the previous page (the planned production volume for today is assigned) is shown below again. uProductionToday := uProduction{2,0] + uProduction{2,1] + uProduction|2,2}; With this program example, when the number of paint colors increases, more variables will be added. Then, the expression becomes longer, making it more difficult to read. uProductionTeday := uProduction[2,0] + uProduction[2,1] + uProduction[2,2] + uProduction[2,3] + uProduction[2,4] + uProduction(2,5] .. In this case, loop statements can be used to create cleaner code. Loop statements include the FOR, WHILE, and REPEAT statements, This course covers FOR statements. FOR statements are described as follows. FOR variable := initial value TO final value BY increments DO Execution statement; (* Statement is executed in a loop until the variable reaches the final value. *) END_FOR; (* END_FOR; must be placed at the end of the FOR statements. *) The statement is repeated until the final value of the variable is reached and the "END_FOR;" code is executed.1 1-Programming_Besics_{Structured_Text)_n200180_eng (FOR) Using @ FOR statement, the following example program obtains the planned production volume for all paint colors for Country C. Loo, friable) Variable value final value) of increase Se initial value uProdugtionTody : (* Initializes the variable. *) uProductionToday := uProductionToday + uProduction[2,wColorf; (* Adds the planned production volume. *) END_FOR; Using the FOR statement, the "wColor" variable increases by one starting from the initial value of zero and the statement is repeated until the variable reaches the final value of two. ‘The "wColor” variable is specified as the second element number in the "uProduction* array described in the execution statement. ‘The value of the "wColor” variable increases each time the statement is repeated. The planned production volume for each paint color is added each time to obtain the total ‘This example program is executed in a loop three times. (Fist time: red [0] = > Second time: yellow [1] => Third time: blue [2)) ‘The operation of this program is illustrated on the next page.‘ogramming_Basics_{Structured|_Text ne00189_eng Looping (FOR) ‘The execution of the FOR statement is described using the operation of the program example. ‘Array of estimated production volume Red Blue counryal 9 19 ] Wal 5 | Wal 99 cick CB) to proceed tothe next page Country} 15 Dal as 21 20 Towatth the animation again, click the “Play” buton, Country C 25 Bab 30 10 ed UProductionTaday:= 0; Number of repetition of the loop: 3 FOR wColor := 0 TO 2 BY 1 DO Z uProductionToday END_FOR; = uProducionToday + uProduction(2wColor;I 1-Programming_Basics_{Structured_Text)_ne00189_eng elec! eal Storing related data (Structure) ) ooo A structure enables one variable name to represent multiple related variables. In the following example, the status of an automobile production line is displayed on Andon (display board). ‘The following table lists the variable names, values, and the data types corresponding to mi the displayed items. em Variablename Value riable Data Type ‘Mode! sModel ST TRUCK —_| Text sting ‘Status Status “in production’ | Bittype Target production | uPlangty "100 Integer type Word volume for today (unsigned) Current production | wActualQty | ‘88 Integer type Word volume (unsigned) Ifa structure is not used, the variable names must be changed for each line when multiple production lines exist. ‘The following shows examples of variable names by the production line First production line Second production line slstlineModel s2ndLineModel bistLineStatus b2ndLineStatus eo50e uistLinePlanQty u2ndLinePlanQty uistLineActualQty u2ndLineActualQty ‘When the number of production line increases, the number of variables to be handled will also increase. Then, the program becomes longer and more difficult to read.1 1-Programming_Besics_{Structured_Text)_n200180_eng Storing related data (Structure) ooo Using structures enables one variable name to represent multiple variables related to one production line. Like this, structures are used to organize, store, and handle data in a batch for conditions and specifications of physical objects such as devices, equipment and workpieces. Structure Multiple variables = Seid sistLineModel Multiple variables bistLineStatus defined in a structure sModel ulstLinePlanQty bStatus ulstLineActualQty uPlanQty uActualQty ‘The structure variable contains a prefix of "st" to represent that this is a structure. The individual variables defined by the structure are known as members. Data types of each member can be different. Each member of structure arrays can be specified after the element number of the array using a dot before the member name, Reese) ististLin In the following example program, a constant is assigned to!a member of the structure variable for the first production line. stistLine.uPlanQty := 15 (* Sets the today's target production of the first production line to 150. *)‘ogramming_Basics_{Structured|_Text n200189_eng el Storing structure arrays coc Structures can be created as arrays. In the following example, the production status is stored by date. Structure arranged’ by date * In this aray the element number starts from (sProductionByDate) Day (column) Day Day 21 javory a | aM be Eales an Structure to which the production Structure that stores the status om status on July 21 is assigned ofthe first production line Month Seen (rou) sModel sModel july | a) . oo | ran | bStatus Pia) bStatus uPlanQty uPlanQty uActualQty uActualQty stProductionByDate[7,21] := st1stLine; (* The production status on July 21 is stored in the structure arranged by date (stProductionByDate). *) Like this, members do not need to be individually specified for structure assignment.n200189_eng el ‘ogramming_Basics_{Structured|_Text Reading structure arrays In the following example, the production volume is read from a structure arranged by date and then assigned to a variable. Structure arranged by date (tProductionByDate) pay (column) Daya > Structure to which the production jonvay| oa [oa] . |. [| status on June Lis stored pa | = = = J =a Month (row) sModel i a — = bStatus Variable to which the 5 = uPlanQty production volume is assigned UPastProduction uPastProduction := stProductionByDate[6,1].uActualQty; (* Assigns the production volume on June 1 to the uPastProduction variable. *) Each member of the structure arrays can be specified by appending a dot () and a member name to the element number of the array.I 1-Programming_Basics_{Structured_Text)_ne00189_eng a —_ ‘The contents of this chapter are: + Overview and usage of arrays + Loop processing using FOR statements + Overview and use of structures Important points to consider: ‘Muitipie vlues cen be handled by one variable by using arrays. Individual variables in arrays ace specified by element numbers added to the end of variable Loop statements are used in programs when repetitive operation is desired FOR statements are used to repeat operation untl the conditions forthe end of the loop ‘operation are satisfied. The statement before the ‘END_FOR‘ statement are executed repeatedly, ‘Structures enable one variable name to represent multiple related variables. Structures can include variables of different datatypes. Individual variables, or members, defined in structures are specfed by adding a dot and the ‘member name after the structure variable name1 1-Programming_Besics_{Structured_Text)_n200180_eng (CEES Handling of string data ) sao In some cases, programmable controllers use string data to send commands to or receive feedback from connected devices such as barcode readers, temperature controllers, or electronic scales. For such purposes, it is necessary to join or extract string data as required. ‘This chapter describes how to handle string data, 7.1 Example of string data handling 7.2 String assignment 7.3 Extracting strings (LEFT) 7.4 Extracting strings (MID)rogramming_Basics_{Structured_Text)_n200180_eng Example of string data handl cao ‘As an example of string processing, the example illustrates a scenario in which data is read from a barcode reader. Functions (a type of instructions) are used to process strings. As illustrated below, strings read by the barcode reader contain a 4-character fixed-length error code and 8-character fixed-length month, date, time and minute data The string processing program example will be described using this system. Example string data read from a barcode reader 12091458 Barcode reader mt An error code is extracted. ‘The error occurrence date and time (14:58, December 9) is extracted, 7.3 Extracting strings (LEFT) 7,4 Extracting strings (MID)1 1-Programming_Besics_{Structured_Text)_n200180_eng String assignment Before explaining about how to extract strings, this section describes the data types for strings. ‘The data types for strings that can be used with programmable controllers are listed in the following table. Data type acter type can be processed ees Soe ‘Stings of alphanumeric characters and Sting rhumbers (ASC or Japanese (Shift) . =a) Sein) | Sung many trent angsge and 7 iene corresponding language. ‘This chapter describes different types of text strings. sDefaull 'e112,1209145: (* String assignment *) ‘The type of string to be used depends on the device being connected to the programmable controller or the ‘When a string type string is assigned to a string variable, enclose the string in single-quotation marks ().ne00189_eng rogramming_Basics_{Structured_ Extracting strings (LEFT) ‘The error code "e112" is extracted from the string variable "sBarcodeData’” that contains the string "e112,12091458" oo Sr sBarcodeData 12091458 The LEFT function extracts only the specified number of characters starting from the left side of the input string, The following illustrates an example program. Ped re ee ( sBarcodeData (* Extracts 4 characters of error code from the left *) Four characters are extracted from the left. A value "e112", which is the string representing the error code, is assigned to the left siderogramming_Basics_{Structured_Text)_n200180_eng Extracting strings (MID) ‘The error generation time "12091458" is extracted from the string variable "sBarcodeData’ that contains the string "e112,12091458" able name sBarcodeData e112,}12091458 ‘The MID function extracts the specified number of characters from the specified start position in the input string. The following illustrates an example program. Number of extracted characters | Position of fist character to be extracted sErrorDate (* Extracts 8 characters starting from the sixth character from the left. *) In this example, an 8-character string is extracted starting from the sixth character. A value "12091458", which is the string representing the error occurrence time, is assigned to the left side.I 1-Programming_Basics_{Structured_Text)_ne00189_eng els ms | Summary 2 == ‘The contents of this chapter are: + Methods of assigning strings to string variables + Functions that extract strings (LEFT and MID) Important points to consider: ey + To astigh a sting & @ string variable, enclose the string in single-quotation marks () Use either ofthe string type or the string [Unicodel type according to the device being connactad tothe programmable controler or the correspancing language Functions are ured to handle stings. Functions for handing strings [i1 1-Programming_Besics_{Structured_Text)_n200180_eng Course summa ‘This course covered the basics on how to create programs in ST. This brings us to the end of this e-learning course. ST programs are created using the MELSOFT engineering software, For the details of the specific steps such as entering data, editing, saving, and compiling programs with the MELSOFT engineering software, refer to the following. + Mitsubishi FA e-Learning Course "MELSOFT GX Works3 (Structured Text)” (to be released soon) * Operating manual of your MELSOFT engineering software For further information on ST, refer to the following. + Programming guidebook of your programmable controller For the information on instructions and functions for your application, refer to the following, + Programming manual of your programmable controller1 1-Programming_Besics_{Structured_Text)_n200180_eng elec! Final Test Now that you have completed all of the lessons of the Programming Basics (Structured Text) course, you are ready to take the final test. If you are unclear on any of the topics covered, please take this opportunity to review those topics. There are a total of 12 questions (20 items) in this Final Test. You can take the final test as many times as you lke. How to score the test After selecting the answer, make sure to click the Answer button. Your answer will be lost if you proceed without clicking the Answer button. (Regarded as unanswered question) Score results The number of correct answers, the number of questions, the percentage of correct answers, and the pass/fail result will appear on the score page. Comectanswers: 2 Total Questions 9 To pass the test, you have to answer 60% of the questions comrect. Percentage 22% Proceed | [Review | [ Retry | + Click the Proceed button to exit the test. + Click the Review button to review the test. (Correct answer check) + Click the Retry button to retake the test again.I 1-Programming_Basics_{Structured_Text)_ne00189_eng ooo ST is easy to learn far thase with experience writing programs in C or BASIC language. Calculations such as addition and subtraction can be written as typically used mathematical expressions. © Symbols for contacts and coils are used to create a program resembling an electrical circuit. ©. STis suitable for data handling. ‘Answer [Back1 1-Programming_Besics_{Structured_Text)_n200180_eng is al Test 2 nee ° uPraduetion := 15: © uProduetion » 15; Production = 15;1 1-Programming_Besics_{Structured_Text)_n200180_eng ez al Test 3 ooo Assigns a value of 1 to the variable. (* Assigns a value of 1 to the variable. *) {Assigns a value of 1 to the variable. }
bStatus st3rdLine[bStatus] st3rdLine[] [Back — [Answer | as al Test 11 ooo[@ 1-Programming_Basics_{Structured_Text)_n200189_eng oe (GSE Final test 12 ooo sData != MID(sBarcodeData4),|4) ; (* Extracts the text string from "e3211151602". *) 1151 © 1602 0321 @ 1115 ‘Answor Backsgramming_Basics_{Structured_Text)_n200180_eng eo} io =e ‘You have completed the Final Test, You results area as follows. ‘To end the Final Test, proceed to the next page. Conectanswers: 12 Total questions: 12 Percentage 100% Proceed | | _ Review Congratulations. You passed the test.1 1-Programming_Besics_{Structured_Text)_n200180_eng You have completed the Programming Basics (Structured Text) course. Thank you for taking this course. \We hope you enjoyed the lessons and the information you acquired in this course will be useful in the future. You can review the course as many times as you want. | Review | | Close |
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6125)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (932)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8214)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2922)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Tóibín
3.5/5 (2061)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2530)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Steve Jobs
From Everand
Steve Jobs
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Yes Please
From Everand
Yes Please
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel