Vijeo Cicode Course v7
-
Upload
hakan-erkmen -
Category
Documents
-
view
1.295 -
download
71
Transcript of Vijeo Cicode Course v7
![Page 1: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/1.jpg)
Cicode Programming <Instructor’s Name>
![Page 2: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/2.jpg)
Objectives
Good Understanding & Competent in Use of Cicode
Be Able to Use Cicode in Commands and Expressions
Apply Learning to Your Own Site or Project Be Able to Write Your Own Cicode Functions Know How to Debug Your Own Cicode
Functions
This Presentation is © 2005 – 2007 Citect Pty Ltd
![Page 3: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/3.jpg)
Agenda - Day 1
Welcome Introduction to Cicode Variable Operators Used in Cicode The Cicode Editor Writing Simple Functions Using Cicode Variables Conversion Functions Include Files
![Page 4: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/4.jpg)
Agenda - Day 2
Conditional Executors Cicode Return Functions Arrays Debugging Your Code
![Page 5: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/5.jpg)
Training Facilities
Emergency Exits
Ladies’ & Gents’
Kitchen
Breaks / lunch
Mobile Phones
Compendium
![Page 6: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/6.jpg)
Welcome
Introduce trainer Students introduce self
Name Employer Current Citect or SCADA experience Expected outcomes from training
![Page 7: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/7.jpg)
Training Agreement
It’s OK to…. Express ideas Challenge the facilitator Offer examples Question Relax
![Page 8: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/8.jpg)
Training Agreement
Trainer’s role Start and end on time Professionally facilitate the exchange of
information and knowledge Allow time for (and encourage) input Listen non-defensively Help you learn
![Page 9: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/9.jpg)
Training Agreement
Your role Be on time Participate Learn in your own way Provide honest open feedback Enjoy yourself
![Page 10: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/10.jpg)
Ergonomics
Desks and chairs Adjust to your comfort level Relocate screen, keyboard, mouse as required
Environmental conditions Lighting Air conditioning
Rest and relaxation Regular movement Eye strain
![Page 11: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/11.jpg)
Introduction to Cicode Chapter 2
![Page 12: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/12.jpg)
Introduction to Cicode
Chapter Overview Commands, Expressions and Functions Use Commands to Control Processes Display Data from Expressions
![Page 13: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/13.jpg)
What is Cicode? A programming language!
A means of extending the functionality of Vijeo Citect projects Interact with variable tags Exchange data with external sources Create complex formulae
Why do we need it? When we are unable to achieve the required outcome by
configuring graphics pages
For the programmers in the audience: It’s like any high-level language, but without complex
structures, pointers, recursion or inheritance
![Page 14: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/14.jpg)
Cicode Project
Pre-configured project: Cicode_Milk
![Page 15: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/15.jpg)
Pasteurisation Page
![Page 16: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/16.jpg)
Chapters Page
![Page 17: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/17.jpg)
Restore Milk Project Restore Milk project
from the folder supplied by your facilitator
Compile the project and then run the Computer Setup Wizard (express)
Run Milk project
Test Pasteurisation page
View Chapters page
![Page 18: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/18.jpg)
Commands
Cicode Commands can be issued:
Manually Operator types in commands Clicking on a button or object on a graphics page
Automatically Operator logs in or out of the runtime system A graphics page is opened or closed An alarm is triggered In a report When an event is triggered
![Page 19: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/19.jpg)
Cicode Commands
Single statement or group of statements
![Page 20: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/20.jpg)
Open Chapters Page
Create buttons to turn Silo Agitator off and on
![Page 21: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/21.jpg)
Create 2 buttons in the Chapters Page
Compile and Test by switching to the Chapters Page to view results
![Page 22: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/22.jpg)
Setting Variables
Execute Command Digital Tag
Change status of Tag
Analog Tag Set value of Tag
Variable1=value Variable1=Variable2
Plant1_Pump=1 ;
Plant1_Pump=0 ;
Oven_Temp=10 ;
Oven_Temp=Kettle_Temp;
![Page 23: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/23.jpg)
String Variables
Set variable
BATCH_NAME = “Bread”
Literal strings must be enclosed in quotation marks
![Page 24: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/24.jpg)
Expressions
Any combination of variables, operators, and statements which evaluate to some result
8 + 4 Motor_Speed / 5
Calculations in a Cicode statement Result = Operand1 + Operand2 – Operand3
![Page 25: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/25.jpg)
Displaying Data
Displayed Value changes as value of expression changes
Expressionchanges
Valuechanges
![Page 26: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/26.jpg)
Multiple Statements
Multiple statements can be separated by a
semi-colon ;
Kettle_Temp=10 ;
Oven_Temp=Kettle_Temp ;
Batch_Name=“Bread” ;
![Page 27: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/27.jpg)
Multiple statements Add a prompt
TIC_P4_PV = TIC_P1_PV + TIC_P2_PV ;
Prompt("Calculation is Finished")
![Page 28: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/28.jpg)
Operator Input Define keyboard Command as a Key sequence
Key Sequence ending in ENTERAllows up to 3
characters to be entered
F2 signals start ofKey Sequence
![Page 29: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/29.jpg)
Arguments
Arg1 provides input to variables by Keyboard entry Conveyor_Speed=Arg1
Conveyor_Speed=ArgValue1
DoThisThenDoThat(Arg1,Arg2)
Variable Argument #1
Argument #1Checks for Numeric value
Argument #1 Argument #2
<F2> 123 , 345 <enter>
![Page 30: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/30.jpg)
Enter Keyboard Key Definition
Change Misc1 properties
![Page 31: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/31.jpg)
Calling Functions
Definition Function A general term used for a subroutine Parentheses identifies statement as function FunctionName(Arg1,Arg2 …)
Prompt(“Shutdown”) Shutdown()
Arguments passedto the functionName of the Function
![Page 32: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/32.jpg)
Calling functions
![Page 33: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/33.jpg)
Function Information
Look up in online help
Prompt Shutdown PageDisplay
![Page 34: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/34.jpg)
Passing Data to Functions
Functions can support 0,1 or many arguments
Prompt(“Press F1 for Help”)
JunkFunction(“1st Argument”,“2nd Argument”)
Arguments passedto the functionPlace double quotes around any string passed
to a function
![Page 35: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/35.jpg)
Add Key sequence to project RBUTTON_UP executes command anywhere on page
Not RBUTTON_CMD_UP
Search capability
![Page 36: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/36.jpg)
Invoke external programs from within Vijeo Citect 1. Find Excel in
Windows Explorer
2. Click & Drag
to a
Command
Window
3. Copy & Paste to Vijeo Citect
![Page 37: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/37.jpg)
Multiple Arguments
All arguments must be listed
Separate arguments with a comma , Argument order is important Strings are “quoted” Login(“Manager”, “ABC”)
Login ID Password
![Page 38: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/38.jpg)
Passing Numeric Arguments
Both Integers and Floating Point numbers can be passed to a function
INT
REAL
![Page 39: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/39.jpg)
AssWin("!Valve",580,150,512+8+1,“Valve_Cool_CMD")
Name of Popup window
Location on screen
Mode of Popup
windowTag
![Page 40: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/40.jpg)
Passing Variable Arguments
When variables are used as arguments Value of variable is passed, not variable string itself
DspStr - Displays a string at a specified AN DspStr(25,”TextFont”, COAL_LEVEL);
DspStr(25,”TextFont”, “COAL_LEVEL”);
Animation Point
number
Display using this
font
Value of COAL_LEVEL variable will Display
COAL_LEVEL string will Display – as its “quoted”
![Page 41: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/41.jpg)
DspStr(326, "ControlLimits", Recipe)
AN 326
![Page 42: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/42.jpg)
Returning Data
Functions can return a value to the calling statement Success 0 Failure error number
or Data
As in:
date()
Prompt(“Hello,” + FullName() )
Result of ‘FullName’ used as a
parameter to ‘Prompt’
![Page 43: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/43.jpg)
%Tag%=FormNumPad("Enter",%Tag%,0)
Pass Value from num-pad into Tag
variable
Title given to number
pad
Value passed if cancelled
Mode – standard in this case
![Page 44: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/44.jpg)
Execute Function on Startup
Message(“Startup”,“Hello World”,64)Select
Custom Mode
Modify
![Page 45: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/45.jpg)
Summary of Variables
Digital (a.k.a. Boolean or Logical) Digital_Variable = 0 Digital_Variable = 1 Digital_Variable1 = Digital_Variable2
Integer (-32768 - +32767) Integer_Variable = 34 Integer_Variable = -1274 Integer_Variable1 = Integer_Variable2 + 3
Strings (Up to 255 characters) String_Variable = “apple” String_Variable = “string variable” String_Variable1 = String_variable2 + “more text”
Datatypes MUST match during assignments
![Page 46: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/46.jpg)
Data Types Fred
Variable PLC variable Cicode variable
“Fred” String
Fred() Function
[Fred] Path substitution Array index
{Fred} Field definition Compile error context
![Page 47: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/47.jpg)
Chapter 2 - Summary Questions What are the two mechanisms to activate a
command?
What is a Cicode expression?
What character is used to combine several tasks?
What is the syntax to call a function?
What is the result of enclosing a tag in double-quotes?
How do you set a system start-up function?
![Page 48: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/48.jpg)
Introduction to Cicode
Chapter Summary Setting variables Using expressions Operator input Passing data to functions Returning data from functions
![Page 49: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/49.jpg)
Variable Operators Chapter 3
![Page 50: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/50.jpg)
Variable Operators
Chapter Overview Classes of Operators in Cicode Order of Precedence
![Page 51: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/51.jpg)
Classes of Operators
Mathematical
Operator Description
+ Addition (for numeric value)
+ Concatenation (for string variables)
- Subtraction
* Multiplication
/ Division
MOD Modulus (Remainder)
![Page 52: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/52.jpg)
IntToStr() function
Used where function only accepts strings Use a function like IntToStr()
Prompt(“ Value ” + IntToStr(Tag_1))
![Page 53: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/53.jpg)
MOD Operator TIC_P2_PV = TIC_P4_PV MOD 10
Concatenation Message(”P2" , ”TIC_P2_PV = " +
IntToStr(TIC_P2_PV) , 64)
![Page 54: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/54.jpg)
Logical Operators
Operator ‘True’ returns 1 Operator ‘False’ returns 0
Operator Description Operator
AND Logical AND Binary
OR Logical OR Binary
NOT Logical NOT Unary
XOR Logical XOR Binary
![Page 55: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/55.jpg)
Truth Tables
AND 0 1
0 0 0
1 0 1
OR 0 1
0 0 1
1 1 1
![Page 56: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/56.jpg)
Truth Tables
XOR 0 1
0 0 1
1 1 0
NOT 0 1
1 0
![Page 57: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/57.jpg)
Agitator_Silo_V = Agitator_Alfast_V AND Centrifuge_Clar_V
Agitator_Silo_V will be turned on ONLY when both Agitator_Alfast_V and Centrifuge_Clar_V are turned on.
![Page 58: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/58.jpg)
Create multi-state text object
![Page 59: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/59.jpg)
Bit Operators Standard bit operators
11011AND 1101 = 01001
Operator Description
BITAND Bitwise AND
BITOR Bitwise OR
BITXOR Bitwise XOR
![Page 60: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/60.jpg)
Relational Operators
Tests the relationship between two values
Operator Description
= is equal to
<> is not equal to
< is less than
> is greater than
<= is less than or equal to
>= is greater than or equal to
![Page 61: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/61.jpg)
Create advanced alarm
![Page 62: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/62.jpg)
Format Operator
Convert numeric values into formatted strings
Tag1 : ###.#
Display tag1 as three digits before and one digit after the decimal point
Operator Description
: (colon) String Format
![Page 63: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/63.jpg)
Format OperatorsSpecifier Description Function Use Example
# The hash character
The number of characters to display to the right of the AN
#### + 23
+472213
0 Zero Padding #0## +0023
- Minus Justification #-### +23
. Period Decimal notation
###.## + 23.54
EU Engineering units
#.##EU
S Exponential notation
#s### +1.234e+012
![Page 64: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/64.jpg)
Format Operator
Message(“P3" , TIC_P3_PV:###.##,64)
TAG Format
![Page 65: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/65.jpg)
Operator order of Precedence
Order Operator
1 ()
2 NOT
3 * , / , MOD
4 :
5 + , -
6 < , > , <= , >=
7 = , <>
8 AND
9 OR
10 BITAND, BITOR, BITXOR
![Page 66: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/66.jpg)
Precedence Examples
Tag_1 OR Tag_2 AND NOT Tag_3
1. NOT Tag_3
2. AND Tag_2
3. OR Tag_1
(Tag_1 OR (Tag_2 AND (NOT Tag_3)))
![Page 67: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/67.jpg)
Test Order of Precedence
Centrifuge_Clar_V = NOT Agitator_Silo_V AND Agitator_Alfast_V
![Page 68: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/68.jpg)
Chapter 3 - Summary Questions Name two of the classes of operators used in
Cicode.
How do you test the relationship between two values?
How do you convert numeric values into formatted strings?
Why are brackets used in formulas?
![Page 69: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/69.jpg)
Variable Operators
Chapter Summary Mathematical operators Logical operators Relational operators Order of precedence
![Page 70: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/70.jpg)
The Cicode Editor Chapter 4
![Page 71: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/71.jpg)
The Cicode Editor
Chapter Overview Starting the Cicode Editor Compile, Run and Debug Your Code File Navigation Features Code Editing Tools Dockable Windows and Toolbars Changing Preferences
![Page 72: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/72.jpg)
Starting the Cicode Editor
Click on Cicode Editor icon Select New Cicode page
![Page 73: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/73.jpg)
Context Sensitive Help
MCursor
anywhere on ‘Logout’
termHit <F1>
Key
![Page 74: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/74.jpg)
Open the Cicode Editor Save as Training
![Page 75: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/75.jpg)
Compile & Run GoTo button provided
Provides line number where error occurred
Compile & Run Compile only
Error shown
GoTo error
![Page 76: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/76.jpg)
GoTo Errors
Compiler points to error Click GoTo Button
Error Condition
![Page 77: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/77.jpg)
FUNCTION
ChangeValue()
TagValue1=10
END
FUNCTIONChangeValue()
TagValue1=10END
ERROR
![Page 78: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/78.jpg)
New Editor Features
Colour Coding Auto Indenting Comment / Uncomment feature
![Page 79: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/79.jpg)
Enhanced File Navigation
Tabs give 3 different views View open Files
![Page 80: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/80.jpg)
Changing Toolbars
Click and drag to reposition toolbars Right Click toolbar area background
Adds New toolbars
![Page 81: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/81.jpg)
Indent and Comment
Outdent Uncomment
Indent Comment
Select text
Click comment
icon
![Page 82: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/82.jpg)
Comments Comment your code constantly Preface every Cicode file with
/*DESCRIPTION: Function to do this and thatMore description here*/
// REV DATE AUTHOR DESCRIP// 1.0 02/12/04 B.Bob Original// 2.0 01/04/05 I.Rabbitt Add BlowUpIkea() function
//// NOTES: All functions will be written in Cicode // project given in the courses
FUNCTION DoThisAndThat()! Function starts here
Int iCounter // Local loop counter
C-style ‘block comments’ (dangerous! What about overlap?) C++ style comments Line comments
![Page 83: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/83.jpg)
Bookmarks & Breakpoints
Clear Previous
Toggle BookmarkNext
Left Click - Breakpoint
Right Click - Bookmark
![Page 84: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/84.jpg)
nAN = ANbyName(“WebBrowser”) ;
DspSetTip(nAN, “My Web Browser”) ;
Experiment with bookmarks comments and indents
Use Comments Liberally
![Page 85: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/85.jpg)
List Functions
Context sensitive function list <ctrl> <space>
Select List Functions
Right Click in text
![Page 86: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/86.jpg)
Intellisense Autoprompt
Typing function and opening bracket displays Autoprompt
Function list displays Autoprompt
![Page 87: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/87.jpg)
REAL
FUNCTION
AreaOfCircle(REAL rRadius)
RETURN (3.141 * Pow(rRadius,2)) ;
END
_______________________________________
Function
Test()
AreaOfCircle(20)
END
![Page 88: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/88.jpg)
Preferences
Customising Cicode Editor
View | PreferencesTo change options
![Page 89: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/89.jpg)
Cicode Preferences
![Page 90: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/90.jpg)
Chapter 4 - Summary Questions How can you view files easily?
Why use bookmarks and breakpoints?
How can you change the look of the code window?
![Page 91: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/91.jpg)
The Cicode Editor
Chapter Summary Starting the editor Goto errors File navigation Editing tools Function tools Preferences
![Page 92: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/92.jpg)
Cicode Functions Chapter 5
![Page 93: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/93.jpg)
Cicode Functions
Chapter Overview Simple Functions Structure of a Function Public & Private Functions Declaring & Naming Functions Statements Void Functions Cicode Variables Include Files
![Page 94: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/94.jpg)
Simple Functions
PUBLIC
FUNCTION
IncCounter()
IF Count < 100 THEN
COUNT=COUNT + 1;
ELSE
COUNTER = 0 ;
END
END
Scope of Function Public or Private
Start of Function
Name of Function
Start of Code
End of IF statement
End of Code
![Page 95: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/95.jpg)
Function Syntax – Pseudocode
HELLOStandUp()
IF told THENStand Up ;
ELSERemain Seated;
Finished
GOODBYE
![Page 96: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/96.jpg)
Function Elements
Scope Declaration Name Statement
![Page 97: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/97.jpg)
Scope PUBLIC
Default Shared across Project
PRIVATE Only works within Cicode
file where written
![Page 98: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/98.jpg)
Declaring Functions
Indicates beginning and end of function code
Scope
FUNCTION
FunctionName()
Statement ;
END
![Page 99: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/99.jpg)
Naming Functions
Up to 32 characters Do not use reserved words Case insensitive Use CamelCase
UpperCamelCase lowerCamelCase
Scope
FUNCTION
FunctionName()
Statement ;
END
![Page 100: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/100.jpg)
Statements
Perform the “work” in the function
PUBLICFUNCTIONStatementExample() IF MASH_PUMP THEN PROMPT(“Mash Pump On”);
ELSE PROMPT(“Mash Pump Off”);
ENDEND
Statements
![Page 101: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/101.jpg)
Void Functions
Do not return any data to the calling function
PUBLICFUNCTIONVoidExample() IF MASH_PUMP THEN PROMPT(“Mash Pump On”);
ELSE PROMPT(“Mash Pump Off”);
ENDEND
![Page 102: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/102.jpg)
PUBLICFUNCTIONMyDateTime()
MISC1=Date(3);MISC2=Time(1);
END
PUBLICFUNCTIONAudAlarm()
DspPlaySound(“[RUN]:Tada.wav”,0);Message(“Alarm”,”Holding Tube too Hot”,48);
END
HTA.H OR HTA.HH
![Page 103: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/103.jpg)
FUNCTION
AverageEx1()
TIC_P2_PV = (TIC_P1_PV + TIC_P4_PV) / 2
END
![Page 104: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/104.jpg)
Cicode Variables
Located in Computer memory Temporary data storage Data Types
Strings - STRING Integers - INT Real Numbers - REAL
SILO_LEVEL value
OVEN_TEMP value
STRING_TAG value
iAverage
rArea
sMyName
PLC Registers Computer Memory
![Page 105: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/105.jpg)
Declaring Cicode Variables
Like Variable Tags – a Data Type must be specified for Cicode Variables
Global, Module, Local
![Page 106: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/106.jpg)
Cicode Variable Syntax
Syntax:
SCOPE DATATYPE NAME = INITIALVALUE
GLOBAL STRING sMyString = “” ! Null Value
GlobalModuleLocal
STRINGINT
REAL
Variable Name
Initialize Variable
![Page 107: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/107.jpg)
Global Cicode Variables Valid across all Cicode files and all include
projects Maintenance more difficult Local variables preferred
GLOBAL STRING gsDefaultPage = “MIMIC” ;INTFUNCTIONGlobalExample(String sPage)
INT iStatus ;iStatus = PageDisplay(sPage) ;
IF iStatus <> 0 THENPageDisplay(gsDefaultPage) ;
ENDRETURN iStatus ;
END
![Page 108: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/108.jpg)
Module Cicode Variables
Specific to the file where it is declared Default for Cicode variables Declare before functions use it Multiplies maintenance issues
![Page 109: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/109.jpg)
Local Cicode Variables
Specific to function where declared Any variable defined within a function
is local by default (no prefix required) Only valid while function executes Local variables take precedence if
name conflict occurs
![Page 110: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/110.jpg)
Local Cicode Variables
PUBLIC
INT
FUNCTION
LocalExample()
INT iAverage ;
iAverage=(TAG1 + TAG2) /2;
RETURN iAverage
END
![Page 111: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/111.jpg)
Variable Naming Standards Hungarian Notation
Initial (lowercase) letter describes variable usage Coined by Charles Simonyi of Microsoft
Applications Hungarian vs. System Hungarian
System Hungarian Notation
Prefix Interpretation
i, n Integer
r Real
s String
o Object (activeX)
h Handle (int)
Apps Hungarian Notation
Prefix Interpretation
p Pump (on/off)
t Temperature
x Horizontal coord
y Vertical coord
c Control variable
![Page 112: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/112.jpg)
FUNCTION
AudAlarm2(STRING sFile, STRING sTitle, STRING sMessage)
DspPlaySound(sFile,0);
Message(sTitle,sMessage,48);
END
AudAlarm2("C:\WINDOWS\Media\chimes.wav", “Oven Temp", “Holding Tube Too Cold")
Button
![Page 113: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/113.jpg)
Converting Cicode Variables
Convert Data Types for further processing
IntToStr()
RealToStr()
StrToInt()
StrToReal()
Input() StrToInt() Calculations+-*/
![Page 114: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/114.jpg)
Use RealToStr function Need to convert number to string for use by message()
function
RealToStr(Number, Width, Places) Number: The floating-point number to convert Width: The width of the entire string Places: Number of decimal places in the string
Message(“Holding Tube”,RealToStr(TIC_HOLD_PV,6,3),64)
Eg the specification 6,3 can store 12.345
![Page 115: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/115.jpg)
Enter a value into a Tag
FUNCTIONOperatorInput()STRING sTag//sTag is a stringsTag=Input("ENTER","Enter a value","");// Displays dialog box, operator can input a // single value (Title, Prompt, Default)LIC_Silo_PV=StrToInt(sTag);// Convert sTag value to string and place in // LIC_Silo_PV variableEND
![Page 116: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/116.jpg)
Display Time
Cent_RT is the accumulator
TimeToStr(Time, Format, UTC)
TimeToStr(Cent_RT,5)
![Page 117: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/117.jpg)
Include Files
Command field limited to 128 Characters
Include Files accommodate a single complex statement sequence
Any valid DOS filename Convention: Filename.cii Referenced by:
@<filename>
DO Include <>
![Page 118: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/118.jpg)
Create an Include file Use Notepad <Alarms.cii>
AudAlarm2(C:\WINDOWS\Media\chimes.wav,“Holding Tube”, “Holding Tube Too Cold”)
![Page 119: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/119.jpg)
Chapter 5 - Summary Questions How many built-in functions are supplied with Vijeo Citect?
What are the four basic elements of Functions?
How and why use the Private function attribute?
What is ‘declaring a function?’
How many characters can be used in a function name?
What is ‘the statement?’
What are Void functions?
What is a Cicode variable?
What is an include file?
![Page 120: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/120.jpg)
Cicode Functions
Chapter Summary Elements of a function Void functions Cicode variables Converting and formatting variables Include files
![Page 121: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/121.jpg)
Conditional Executors Chapter 6
![Page 122: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/122.jpg)
Conditional Executors
Chapter Overview Four conditional executors IF FOR WHILE SELECT CASE
![Page 123: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/123.jpg)
IF Statement
Execute code based on result of a test
IF .. THEN or IF .. THEN .. ELSE
IF test expression THENTrue Statements ;
END
- Or -
IF test expression THENTrue Statements ;
ELSEFalse Statements ;
END
![Page 124: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/124.jpg)
Use IF .. THEN .. ELSE statement
FUNCTION
IF_Example1()
IF Centrifuge_Clar_V = 1 THEN
Message(“Clarifier Status”, “Running”,64)
ELSE
Message(“Clarifier Status”,”Stopped”,64)
END
END
![Page 125: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/125.jpg)
Use IF THEN ELSE using Cicode variables
FUNCTION// set data types for variables in this functionIF_Example2(INT iTag1, STRING sTitle, STRING sOnMessage, STRING
sOffMessage)// If Tag1 is on then display ‘On’ popup
IF iTag1 = 1 THENMessage(sTitle , sOnMessage ,64)
ELSE// Tag is 0 – display ‘Off’ Popup
Message(sTitle , sOffMessage ,64)// End of IF statement
END// End of FunctionEND
![Page 126: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/126.jpg)
FOR Loop
Execute statements a number of times
FOR variable = expression1 TO expression2 DO
Statements ;
END
Variable used as counter
Start Count Value
End Count Value
Count
Exp1++
++++
Exp2
Statements
![Page 127: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/127.jpg)
Sleep & SleepMS
// Sleep for 1 second
Sleep(1)
// Sleep for 500 milliseconds
SleepMS(500)
![Page 128: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/128.jpg)
FOR Loop
Execute statements a number of times
FUNCTIONIncrementLevel()// Counter is an IntegerINT Counter ; // Set Counter to count 10 levels
FOR Counter = 0 TO 9 DO// Add 1 to counter
TagX = tagX + 1; Sleep(2);
// End of FOR loopEND
END
![Page 129: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/129.jpg)
FUNCTIONFOR_ExampleX()INT Counter;INT iSP;INT iPV;
iSP = LIC_Balance_SP;iPV = LIC_Balance_PV;
Use sleep(1) to delay the loop
![Page 130: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/130.jpg)
Increase LIC_Balance_PV
FUNCTIONFOR_Example1()INT Counter;INT iSP;INT iPV;
iSP = LIC_Balance_SP;iPV = LIC_Balance_PV;
FOR Counter = iPV TO iSP - 1 DO LIC_Balance_PV = LIC_Balance_PV + 1;SleepMS(300);
ENDEND
![Page 131: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/131.jpg)
Decrease LIC_Balance_PV
FUNCTIONFOR_Example2()INT Counter;INT iSP;INT iPV;
iSP = LIC_Balance_SP;iPV = LIC_Balance_PV;
FOR Counter = iSP TO iPV - 1 DO LIC_Balance_PV = LIC_Balance_PV - 1;SleepMS(300);
ENDEND
![Page 132: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/132.jpg)
FUNCTIONFOR_Example3()INT Counter;INT iSP;INT iPV;
iSP = LIC_Balance_SP;iPV = LIC_Balance_PV;
IF LIC_Balance_PV > LIC_Balance_SP THENFOR Counter = iSP TO iPV - 1 DO LIC_Balance_PV = LIC_Balance_PV - 1; SleepMS(300);END
ELSEFOR Counter = iPV TO iSP-1 DO LIC_Balance_PV = LIC_Balance_PV + 1; SleepMS(300);
ENDEND
END
![Page 133: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/133.jpg)
WHILE Loop
Execute statements while condition is true
WHILE Expression DO
Statements ;
END
WHILE Trigger DO
Count = Count + 1 ;
Sleep(1) ;
END
![Page 134: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/134.jpg)
Decrement LIC_Balance_PV while Pump_Feed_CMD is true Set LIC_Balance_PV to 100 when Pump_Feed_CMD is false
FUNCTION
WHILE_Example1()
WHILE Pump_Feed_CMD = 1 AND LIC_Balance_PV > 20 DO
LIC_Balance_PV = LIC_Balance_PV -1;
SleepMS(500);
END
LIC_Balance_PV = 100
Pump_Feed_CMD = 0 !optional
END
![Page 135: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/135.jpg)
Select Case Statement
Executes one of a choice of statements
SELECT CASE Expression
CASE CaseExpression1,CaseExpression2
Statements ;
CASE CaseExpression3 TO CaseExpression4
Statements ;
CASE IS > CaseExpression5 , IS < CaseExpression6
Statements ;
CASE ELSE
Statements ; ! nothing satisfied
END SELECT
![Page 136: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/136.jpg)
Case ExpressionsCase Keyword Description Example
(none) Expression
6
iTestValue
“Monday”
, Multiple discrete matches
3, 5, 8
iTestValue, iTestValue1
“apples”, “oranges”
TOSpecifies inclusive range of values. Smaller value placed before TO keyword.
3 TO iTestValue
“apples” TO “oranges”
“Friday” TO “friday”
ISUse with <,>,<=,>=,=,<>
IS <=14
IS > iTestValue
IS < “cherries”
ELSE‘Catcher’ for when no other Case clause matches
![Page 137: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/137.jpg)
FUNCTIONWhatDayIsIt()
SELECT CASE Delivery_Day CASE 0
MISC2 = "SUNDAY"; CASE 1
MISC2 = "MONDAY"; CASE 2
MISC2 = "TUESDAY"; CASE 3
MISC2 = "WEDNESDAY"; CASE 4
MISC2 = "THURSDAY"; CASE 5
MISC2 = "FRIDAY"; CASE 6
MISC2 = "SATURDAY";CASE ELSE
Message(" Invalid ",“Not a valid number",64);END SELECT
END
![Page 138: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/138.jpg)
Chapter 6 - Summary Questions What are the two formats of the IF statement?
Why is the FOR loop used?
Why is the WHILE loop used?
Which statement is used to execute one of several groups of statements, depending on the result of an expression?’
![Page 139: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/139.jpg)
Conditional Executors
Chapter Summary IF statement FOR loop WHILE loop SELECT CASE statement
![Page 140: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/140.jpg)
More Cicode Functions Chapter 7
![Page 141: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/141.jpg)
More Cicode Functions
Chapter Overview Return Functions Cicode Arrays Comments
![Page 142: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/142.jpg)
Return Functions
Return functions return data to calling function
HowAreYou()
RETURN(“I am fine”)
![Page 143: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/143.jpg)
Return Functions
Must declare the returning Data type
Function Called
Evaluate Statements & store
in memory
Result returned& Stored in Tag
or Variable
![Page 144: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/144.jpg)
Functions Returning Values Return Values
PUBLIC
INT
FUNCTION
ReturnExample()
Blah;
Return(3);
END
Return Values
PUBLIC
STRING
FUNCTION
CurrentRecipe()
Blah;
Return(“Full Cream Milk”);
END
Data Type
returned
Data Type
returned
![Page 145: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/145.jpg)
Create Function
FUNCTION
AverageEx1()
TIC_P2_PV = (TIC_P1_PV + TIC_P4_PV) /2
END Return Function
INT ! return data type is Integer
FUNCTION
AverageEx2()
RETURN (TIC_P1_PV + TIC_P4_PV) /2 ! return expression
END
![Page 146: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/146.jpg)
Create Function – AverageEx3()
INT
FUNCTION
AverageEx3(INT iTagX, INT iTagY)
RETURN (iTagX + iTagY)/2
END
![Page 147: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/147.jpg)
Change OperatorInput() to a Return function
INT
FUNCTION
EnterTagValue()
STRING sTag
sTag=Input("ENTER","Enter a value","");
RETURN StrToInt(sTag);
END
![Page 148: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/148.jpg)
Bugs – Part 1
// Return the area of a circle into Pizza_Area given the// radius in Pizza_Size// Note the use of local variables and database variables
FUNCTIONAreaofPizza()
rArea = pi()* POW(Pizza_Size,2); Pizza_Area = rArea;
END
![Page 149: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/149.jpg)
Bugs – Part 1, Answers
// Return the area of a circle into Pizza_Area given the// radius in Pizza_Size// Note the use of local variables and database variables
FUNCTIONAreaofPizza()
real rArea; rArea = pi()* POW(Pizza_Size,2); Pizza_Area = rArea;
END
What about Pizza_Area & Pizza_Size?
Probably a Variable tag or a global variable, judging by the usage
![Page 150: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/150.jpg)
Bugs – Part 2
// This function will convert the diameter of the variable// tag from inches to centimetres// This is a RETURN function.
FUNCTIONInchToCent(REAL a)
REAL rCent rCent=a*2.54
END
![Page 151: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/151.jpg)
Bugs – Part 2, Answers
// This function will convert the diameter of the variable// tag from inches to centimetres// This is a RETURN function.
REALFUNCTIONInchToCent(REAL a)
REAL rCent; rCent=a*2.54;
RETURN(rCENT)
END
![Page 152: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/152.jpg)
Bugs – Part 3
// Show the value of Pizza_Area on the prompt line.
FUNCTIONPromptPizza(REAL rRealValue)
Prompt("The area of the Pizza is " + rRealValue); Sleep(3); Prompt("");
END
![Page 153: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/153.jpg)
Bugs – Part 3, Answers
// Show the value of Pizza_Area on the prompt line.
FUNCTIONPromptPizza(REAL rRealValue)
Prompt("The area of the Pizza is " + RealToStr(rRealValue,6,3));
Sleep(3); Prompt("");
END
Alternate: ...Pizza is " + rRealValue:##.###)
![Page 154: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/154.jpg)
Arrays Arrays hold equally-sized data elements, of the same data type.
Individual elements are accessed by index using a consecutive range of integers
INT Apartment[4] Unit A … Apartment[0] Unit B … Apartment[1] Unit C … Apartment[2] Unit D … Apartment[3]
A B C D
Index[0]Index[1]Index[2]Index[3]
![Page 155: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/155.jpg)
Arrays
INT MyArray[10]
INT Count ;
For Count = 0 to 9 do
MyArray[Count]=Count+1 ;
END
![Page 156: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/156.jpg)
Initialising an Array
STRING Array[5]=“This”,”is”,”a”,”string”,”array”;
Array is satisfied as:
Array[0]=“This”
Array[1]=“is”
Array[2]=“a”
Array[3]=“string”
Array[4]=“array”
![Page 157: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/157.jpg)
Array Dimensions
Arrays can have more than one dimension
INT MyArray[Dim1Size][Dim2Size][Dim3Size] = Values ;
STRING StrArray[5] ; ! List
REAL Result[5][2] ; ! 2-D Table
INT IntArray[4][3][2] ; ! 3-D Table
![Page 158: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/158.jpg)
Using Arrays
Arrays are declared as Module or Global (cannot be declared locally)
Placed at the beginning of a Cicode file Do not exceed the bounds of the array You cannot pass an entire array into a
Cicode function
![Page 159: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/159.jpg)
Assign text description to numeric Tag
STRING sRecipeArray[5] = “Full Cream", “Lite", “Sport", “Skim", “High protein";
STRING FUNCTION
RecipeSelection()
END
![Page 160: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/160.jpg)
STRING sRecipeArray[5] = “Full Cream", “Lite", “Sport", “Skim", “High protein";
STRINGFUNCTIONRecipeSelection()STRING sRecipe;INT iRecipe;
sRecipe = Input("Recipe Number","Enter a number between 0 and 4","");iRecipe = StrToInt(sRecipe);
SELECT CASE iRecipeCASE 0 TO 4
RETURN sRecipeArray[iRecipe];CASE ELSE
Message("Error","Not a valid number",64);END SELECT
END
![Page 161: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/161.jpg)
Comments
Comment ,Comment and Comment again
! Single Line CommentFunction()/* Multiple Line commentsCan extend over several linesEnd comment block with a delimiter- Cannot be started on the same line as a statement*/Function2()// Another style of comment// Begin each line with forward slashes
![Page 162: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/162.jpg)
Chapter 7 - Summary Questions What does a return function do?
What is an Array?
Why should comments be included in all Cicode files?
![Page 163: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/163.jpg)
More Cicode Functions
Chapter Summary Return functions Debugging code Arrays Comments
![Page 164: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/164.jpg)
Cicode Debugger Chapter 8
![Page 165: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/165.jpg)
Cicode Debugger
Chapter Overview Starting the Debugger Debug Options Debug your Code
![Page 166: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/166.jpg)
Citect Kernel
Covered in Intermediate Course Core of the Vijeo Citect system Low-level diagnostic and debugging
Use with extreme care Secure access – over-rides all other security
measures Command Line interface
![Page 167: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/167.jpg)
Cicode Editor in Debug Mode
Open Debug Toolbar Right-Click on blank area of
toolbar
![Page 168: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/168.jpg)
Open and test Pizza page
Toggle Breakpoints
![Page 169: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/169.jpg)
Find Errors From
DevFind(hDev,sPizzaNumber,”NUMBER”) ;
To
DevFind(hDev,sPizzaNumber,”NUM”) ;
![Page 170: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/170.jpg)
Advanced Stepping
![Page 171: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/171.jpg)
Chapter 8 - Summary Questions Explain debug mode.
There are three tools to control stepping through functions. What are they?
![Page 172: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/172.jpg)
Cicode Debugger
Chapter Summary Cicode editor environment Advanced stepping
![Page 173: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/173.jpg)
Did we Achieve the Objectives?
Good Understanding & Competent in Use of Cicode
Be Able to Use Cicode in Commands and Expressions
Apply Learning to Your Own Site or Project Be Able to Write Your Own Cicode Functions Know How to Debug Your Own Cicode
Functions
![Page 174: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/174.jpg)
SCADA Training Roadmap
Upgrade & New Features
Networking & Architecture
Customisation & Design
Cicode Programming
Vijeo Citect Configuration
Tech
nic
al Skill
Requ
irem
ent
![Page 175: Vijeo Cicode Course v7](https://reader033.fdocuments.net/reader033/viewer/2022061401/551c687349795907568b471c/html5/thumbnails/175.jpg)
End of Course
Questions Certificates CCSE Certification Course evaluation
www.citect.com/evaluation