Download presentation
Presentation is loading. Please wait.
Published byMyles Colin Dean Modified over 8 years ago
1
Think Automation and beyond… FT1A Script Programming
2
Think Automation and beyond… 2 Areas to use Script How Device is defined in Display Function Internal PLC device [#Dxxxx] where # signified internal PLC Internal HMI device [LDRxxxx] External Host (PLC) device [0:Dxxxx] where 0 is defined as station number How Device is defined in Control Function Device is defined as [Dxxxx] In FT1A Touch, Scripts can be utilized in both Control (Ladder) and Display areas The difference is how Device address inside the [ ] brackets are defined For the rest of this PPT, we’ll mainly focus on Script in Display function and internal PLC device
3
Think Automation and beyond… Program Syntax Each line of code needs to be ended with a semicolon “ ; ” 1 set of characters ended with semicolon is called a statement Each statement is executed from top to bottom. Device is specified within square brackets […]
4
Think Automation and beyond… Available Operators Order of Operation OperatorDescription High( ) Commands inside parenthesis get executed first ! ~ - Reverse the logic, Reverse logic each bit, negative * / % Multiply, Divide, Remainder + - Addition, Subtraction > Shift bit left, Shift bit right & And ^ Calculates the exclusive logical sum of each bit | Calculates the logical sum (OR) of each bit >= Compare greater, equal or less, less, equal greater == != Compare equal to, Compare Not equal to && Calculates the logical product || Calculates the logical sum Low= Copy
5
Think Automation and beyond… Constants Constants can be expressed in Decimal or Hexadecimal Decimal Numbers can be expressed in the following form: 1234 -1234 (negative value) 12.34 (floating point value) Hexadecimal Numbers can be expressed in the following form: 0x12AB (“0” zero and letter “x” at the beginning of the value) 12ABh (“h” at the end of the value)
6
Think Automation and beyond… How Script Works - Basic Equal sign (=) specifies that data is copied from right-hand to left-hand side device. In this case, 1234 is stored to D100. Another example, [D50] = [D70]; value in D70 is copied to D50. Multiple operators can be used in 1 statement. In this example, values stored in D300, D400, and D500 are added and then divided by 3. Result is stored in D200.
7
Think Automation and beyond… Flow Control Statements Flow control is also called “Branching” or “Looping” The following statements can be used: Conditional Branch If, Else, Else If, Switch-case Repeat While Halt and Exit Break, Return
8
Think Automation and beyond… Branching – Example 1 if ([#D30] > 500) { [#D100] = [#D100] +1; } The statements within curly brackets are executed only when D30 is greater than 500. In this case, D100 is increment by 1 at every Scan time. The condition within parenthesis is checked. If the condition is true, statements within the curly brackets are executed IF statement
9
Think Automation and beyond… Branching – Example 2 IF - ELSE statement if ([#D30] > 500) { [#D100] = [#D100] +1; } else { [#D100] = [#D100] -1; } The statements within curly brackets are executed when D30 is greater than 500. The statements within curly brackets are executed when D30 is less than or equal to 500.
10
Think Automation and beyond… Branching – Example 3 IF - ELSE IF – ELSE statement if ([#D30] > 500) { [#D100] = [#D100] +1; } else if ([#D30] > 400) { [#D101] = [#D101] +1; } else if ([#D30] > 300) { [#D102] = [#D102] +1; } else { [#D103] = [#D103] +1; } ELSE IF can be used as many time as you want The statements within curly brackets are executed when D30 is greater than 400 and less than or equal to 500. The statements within curly brackets are executed when D30 is less than or equal to 300. The statements within curly brackets are executed when D30 is greater than 300 and less than or equal to 400. The statements within curly brackets are executed only when D30 is greater than 500. Note: If this condition is met, the following else if clauses are NOT executed.
11
Think Automation and beyond… Branching – Example 4 Nested IF statement if ([#D102]) { if ([#D103]) { [#D104] = 100; } else { [#D104] = 200; } When both D102 and D103 are greater than 0, 100 is stored in D104. When both D102 is greater than 0 but D103 is 0, 200 is stored in D104.
12
Think Automation and beyond… Looping – Example 1 WHILE statement [#D100] = 10; [#D102] = 10; while ([#D100] > 0) { [#D102] = [#D102] + 1; [#D100] = [#D100] - 1; } Those statements within curly brackets are repeatedly executed while D100 is greater than 0. Once D100 becomes 0, execution of while loop is terminated. The condition within parenthesis is checked. While the condition is true, statements within the curly brackets are repeatedly executed
13
Think Automation and beyond… Looping – Caution [#D100] = 10; while (0 != [#D100]) { [#D200] = [#D200] + 1; } This condition is always true and while loop never ends, resulting in watchdog timeout error. Caution – Infinite Loop You need to make sure that the condition will be false after the intended loop operations are executed.
14
Think Automation and beyond… Looping – Example 2 [#D100] = 0; [#D102] = 3; [#D103] = 5; while ([#D100] == 0) { [#D102] = [#D102] + 1; if ([#D103] == [#D102] ) { SET ([#M0000]); break; } Loop with Break Once the execution reaches break; statement, the execution goes out of while loop. If D103 is equal to D102, M0 is turned on and the while loop is ended with break statement.
15
Think Automation and beyond… Other Functions TypeCommand BITSET, RST, REV ARITHMETICMAX, MIN, EXP, LOGE, LOG10, POW, ROOT, SIN, COS, TAN, ASIN, ACOS, ATAN, RAD, DEG DATA TYPE CONVERSION BCD2BIN, BIN2BCD, FLOAT2BIN, BIN2FLOAT, DEC2ASCII, ASCII2DEC DATA COMPARISON & COPY MEMCMP, MEMCPY, BITS2BITS, BITS2WORD, WORD2BITS OFFSET
16
Think Automation and beyond… Offset – Example 1 OFFSET is a powerful function used for indirect read & write. It’s quite important when you use while loop. [#D0300] = OFFSET ([#D0010], [#D0020]); When the value stored in D20 is 8, the value in D18 (D10 + 8), is read and stored in D300.
17
Think Automation and beyond… Offset – Example 2 Indirect Write OFFSET ([#D0010], [#D0020]) = 1234; When the value stored in D20 is 3, a constant 1234 is moved to D13 (D10 + 3).
18
Think Automation and beyond… Offset – Example 3 Indirect Write and Read using While statement // Transfer D10 through D19 to D100 through D109 // Initialize offset value [#D0000] = 0; // Loop 10 times while ([#D0000] < 10) { // Transfer 1 word by indirect assignment OFFSET ([#D0100], [#D0000]) = OFFSET ([#D0010], [#D0000]); // Increment indirect value [#D0000] = [#D0000] + 1; }
19
Think Automation and beyond… Data Type Data type can be selected from Word, Integer, Double, Long, and Float Once data type is selected, all devices are handled as the selected data type. In above case, both D118 and D521 are handled as Float. Data Type Limitation: only 1 data type for each script
20
Think Automation and beyond… Temporary Device In Script, temporary memory is provided for storing temporary data. Benefit: you don’t have to use data registers to pass values from 1 calculation to another. Below is just an example: @1 = [#D1] / 10 * 8 + [#D1] % 10; @2 = [#D2] / 10 * 8 + [#D2] % 10; [#D10] = @1 - @2; [#D11] = (@1 + @2) / 2;
21
Think Automation and beyond… Comments All comments start with // Comment data is not executed Comment data is also restored when program is uploaded from PLC. Comment can be described in the same line with a statement. To make the script descriptive, you can add comments which will not get executed
22
Think Automation and beyond… How Script is Executed Display Function Script in Display area is available in Script Command and Global script Script Command executes in accordance with trigger conditions and only in the screens where it is placed. Multiple scripts can be set for each screen Global script is executed regardless of which screen is being displayed Only 1 script can be set for the project
23
Think Automation and beyond… How Script is Executed Display Function Global Script 1.Under Configuration tab, select Global Script and check Use Global Script 2.Click and create your script in Script Manager 3.Click Trigger Condition tab and select trigger type 1 2 3
24
Think Automation and beyond… How Script is Executed Display Function Command Script 1.Under Home tab, click Commands Script Command and click on the screen 2.Click and create your script in Script Manager 3.Click Trigger Condition tab and select trigger device 1 3 2
25
Think Automation and beyond… How Script is Executed Control Function When M11 is turned on, Script 4 is executed. Use SOTU/SOTD if you want to execute script only once.
26
Think Automation and beyond… Script Comparison HG Touch Screen FT1A Touch Display FT1A Controller FT1A Touch Controller Temporary devices16 (@1 to @16)32 (@1 to @32) Data typeWord, Integer, Double, Long, Float, BCD4, BCD8 Word, Integer, Double, Long, Float Number of scripts65,535255 How to useGlobal script, Script Command SCRPT instruction/Function Block ProgrammingWindO/I-NV2 and WindO/I-NV3 WindLDR
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.