49144839 vijeo cicode course v7
DESCRIPTION
Vijeo Cicode Course Vijeo Cicode CourseTRANSCRIPT
-
Cicode Programming
-
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
-
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
-
Agenda - Day 2 Conditional Executors Cicode Return Functions Arrays Debugging Your Code
-
Training Facilities
Emergency Exits
Ladies & Gents
Kitchen
Breaks / lunch
Mobile Phones
Compendium
-
Welcome
Introduce trainer Students introduce self
Name Employer Current Citect or SCADA experience Expected outcomes from training
-
Training Agreement
Its OK to. Express ideas Challenge the facilitator Offer examples Question Relax
-
Training Agreement
Trainers 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
-
Training Agreement
Your role
Be on time
Participate
Learn in your own way
Provide honest open feedback
Enjoy yourself
-
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
-
Introduction to Cicode Chapter 2
-
Introduction to Cicode
Chapter Overview Commands, Expressions and Functions Use Commands to Control Processes Display Data from Expressions
-
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: Its like any high-level language, but without complex
structures, pointers, recursion or inheritance
-
Cicode Project
Pre-configured project: Cicode_Milk
-
Pasteurisation Page
-
Chapters Page
-
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
-
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
-
Cicode Commands
Single statement or group of statements
-
Open Chapters Page
Create buttons to turn Silo Agitator off and on
-
Create 2 buttons in the Chapters Page
Compile and Test by switching to the Chapters Page to view results
-
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;
-
String Variables
-
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
-
Displaying Data Displayed Value changes as value of
expression changes
Expressionchanges
Valuechanges
-
Multiple Statements
Multiple statements can be separated by a semi-colon ;
Kettle_Temp=10 ;Oven_Temp=Kettle_Temp ;Batch_Name=Bread ;
-
Multiple statements Add a prompt
TIC_P4_PV = TIC_P1_PV + TIC_P2_PV ;Prompt("Calculation is Finished")
-
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
-
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
123 , 345
-
Enter Keyboard Key Definition
Change Misc1 properties
-
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
-
Calling functions
-
Function Information
Look up in online help
Prompt Shutdown PageDisplay
-
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
-
Add Key sequence to project RBUTTON_UP executes command anywhere on page
Not RBUTTON_CMD_UP
Search capability
-
Invoke external programs from within Vijeo Citect 1. Find Excel in
Windows Explorer
2. Clic
k & Dr
ag
to a
Comm
and
Window
3. Copy & Paste to Vijeo Citect
-
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
-
Passing Numeric Arguments
Both Integers and Floating Point numbers can be passed to a function
INT
REAL
-
AssWin("!Valve",580,150,512+8+1,Valve_Cool_CMD")
Name of Popup window
Location on screen
Mode of Popup window
Tag
-
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
-
DspStr(326, "ControlLimits", Recipe)
AN 326
-
Returning Data
Functions can return a value to the calling statement Success 0 Failure error numberor Data
As in:
date()Prompt(Hello, + FullName() )
Result of FullName used as a
parameter to Prompt
-
%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
-
Execute Function on Startup
Message(Startup,Hello World,64)Select
Custom Mode
Modify
-
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
-
Data Types Fred
Variable PLC variable Cicode variable
Fred String
Fred() Function
[Fred] Path substitution Array index
{Fred} Field definition Compile error context
-
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?
-
Introduction to CicodeChapter Summary Setting variables Using expressions Operator input Passing data to functions Returning data from functions
-
Variable Operators Chapter 3
-
Variable Operators
Chapter Overview Classes of Operators in Cicode Order of Precedence
-
Classes of Operators Mathematical
Operator Description+ Addition (for numeric value)
+ Concatenation (for string variables)
- Subtraction
* Multiplication
/ Division
MOD Modulus (Remainder)
-
IntToStr() function
Used where function only accepts strings Use a function like IntToStr()
Prompt( Value + IntToStr(Tag_1))
-
MOD Operator TIC_P2_PV = TIC_P4_PV MOD 10
Concatenation Message(P2" , TIC_P2_PV = " +
IntToStr(TIC_P2_PV) , 64)
-
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
-
Truth Tables
AND 0 1
0 0 0
1 0 1
OR 0 1
0 0 1
1 1 1
-
Truth Tables
XOR 0 1
0 0 1
1 1 0
NOT 0 11 0
-
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.
-
Create multi-state text object
-
Bit Operators Standard bit operators
11011AND 1101 = 01001
Operator Description
BITAND Bitwise AND
BITOR Bitwise OR
BITXOR Bitwise XOR
-
Relational Operators Tests the relationship between two values
Operator Description
= is equal to
is not equal to
< is less than
> is greater than
= is greater than or equal to
-
Create advanced alarm
-
Format Operator
Convert numeric values into formatted stringsTag1 : ###.#
Display tag1 as three digits before and one digit after the decimal point
Operator Description
: (colon) String Format
-
Format OperatorsSpecifier Description Function Use Example# The hash
characterThe 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
-
Format Operator
Message(P3" , TIC_P3_PV:###.##,64)
TAG Format
-
Operator order of Precedence
Order Operator
1 ()2 NOT3 * , / , MOD4 :5 + , -
6 < , > , =7 = , 8 AND9 OR10 BITAND, BITOR, BITXOR
-
Precedence Examples
Tag_1 OR Tag_2 AND NOT Tag_3
1. NOT Tag_32. AND Tag_23. OR Tag_1
(Tag_1 OR (Tag_2 AND (NOT Tag_3)))
-
Test Order of PrecedenceCentrifuge_Clar_V = NOT Agitator_Silo_V AND Agitator_Alfast_V
-
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?
-
Variable OperatorsChapter Summary Mathematical operators Logical operators Relational operators Order of precedence
-
The Cicode Editor Chapter 4
-
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
-
Starting the Cicode Editor
Click on Cicode Editor icon Select New Cicode page
-
Context Sensitive Help
MCursor
anywhere on Logout
termHit
Key
-
Open the Cicode Editor Save as Training
-
Compile & Run GoTo button provided
Provides line number where error occurred
Compile & Run Compile only
Error shown
GoTo error
-
GoTo Errors Compiler points to error Click GoTo Button
Error Condition
-
FUNCTIONChangeValue()
TagValue1=10END
FUNCTIONChangeValue()
TagValue1=10END
ERROR
-
New Editor Features Colour Coding Auto Indenting Comment / Uncomment feature
-
Enhanced File Navigation
Tabs give 3 different views View open Files
-
Changing Toolbars Click and drag to reposition toolbars Right Click toolbar area background
Adds New toolbars
-
Indent and Comment
Outdent Uncomment
Indent Comment
Select text
Click comment
icon
-
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 coursesFUNCTION DoThisAndThat() ! Function starts hereInt iCounter // Local loop counter
C-style block comments (dangerous! What about overlap?) C++ style comments Line comments
-
Bookmarks & Breakpoints
Clear Previous
Toggle BookmarkNext
Left Click - Breakpoint
Right Click - Bookmark
-
nAN = ANbyName(WebBrowser) ;DspSetTip(nAN, My Web Browser) ;Experiment with bookmarks comments and indents
Use Comments Liberally
-
List Functions Context sensitive function list
Select List Functions
Right Click in text
-
Intellisense Autoprompt
Typing function and opening bracket displays Autoprompt
Function list displays Autoprompt
-
REALFUNCTIONAreaOfCircle(REAL rRadius)
RETURN (3.141 * Pow(rRadius,2)) ;END_______________________________________FunctionTest()
AreaOfCircle(20)END
-
Preferences
Customising Cicode Editor
View | PreferencesTo change options
-
Cicode Preferences
-
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?
-
The Cicode EditorChapter Summary Starting the editor Goto errors File navigation Editing tools Function tools Preferences
-
Cicode Functions Chapter 5
-
Cicode Functions
Chapter Overview Simple Functions Structure of a Function Public & Private Functions Declaring & Naming Functions Statements Void Functions Cicode Variables Include Files
-
Simple Functions
PUBLICFUNCTIONIncCounter()
IF Count < 100 THENCOUNT=COUNT + 1;ELSECOUNTER = 0 ;END
END
Scope of Function Public or Private
Start of FunctionName of FunctionStart of Code
End of IF statementEnd of Code
-
Function Syntax Pseudocode
HELLOStandUp()
IF told THENStand Up ;
ELSERemain Seated;
FinishedGOODBYE
-
Function Elements
Scope Declaration Name Statement
-
Scope PUBLIC
Default Shared across Project
PRIVATE Only works within Cicode
file where written
-
Declaring Functions
Indicates beginning and end of function code
ScopeFUNCTIONFunctionName()Statement ;
END
-
Naming Functions Up to 32 characters
Do not use reserved words Case insensitive Use CamelCase
UpperCamelCase lowerCamelCase
ScopeFUNCTIONFunctionName()Statement ;
END
-
Statements
Perform the work in the function
PUBLICFUNCTIONStatementExample() IF MASH_PUMP THEN PROMPT(Mash Pump On); ELSE PROMPT(Mash Pump Off); ENDEND
Statements
-
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
-
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
-
FUNCTIONAverageEx1()
TIC_P2_PV = (TIC_P1_PV + TIC_P4_PV) / 2END
-
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
-
Declaring Cicode Variables
Like Variable Tags a Data Type must be specified for Cicode Variables
Global, Module, Local
-
Cicode Variable Syntax Syntax:
SCOPE DATATYPE NAME = INITIALVALUE
GLOBAL STRING sMyString = ! Null Value
GlobalModuleLocal
STRINGINT
REAL
Variable Name
Initialize Variable
-
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
-
Module Cicode Variables Specific to the file where it is declared Default for Cicode variables Declare before functions use it Multiplies maintenance issues
-
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
-
Local Cicode Variables
PUBLICINTFUNCTIONLocalExample()
INT iAverage ;iAverage=(TAG1 + TAG2) /2;RETURN iAverage
END
-
Variable Naming Standards Hungarian Notation
Initial (lowercase) letter describes variable usage Coined by Charles Simonyi of Microsoft
Applications Hungarian vs. System Hungarian
System Hungarian NotationPrefix Interpretation
i, n Integerr Reals Stringo Object (activeX)h Handle (int)
Apps Hungarian NotationPrefix Interpretation
p Pump (on/off)t Temperaturex Horizontal coordy Vertical coordc Control variable
-
FUNCTIONAudAlarm2(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
-
Converting Cicode Variables
Convert Data Types for further processing
IntToStr()RealToStr()StrToInt()StrToReal()
Input() StrToInt() Calculations+-*/
-
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
-
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
-
Display Time
Cent_RT is the accumulator
TimeToStr(Time, Format, UTC)
TimeToStr(Cent_RT,5)
-
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:
@DO Include
-
Create an Include file Use Notepad
AudAlarm2(C:\WINDOWS\Media\chimes.wav,Holding Tube, Holding Tube Too Cold)
-
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?
-
Cicode FunctionsChapter Summary Elements of a function Void functions Cicode variables Converting and formatting variables Include files
-
Conditional Executors Chapter 6
-
Conditional Executors
Chapter Overview Four conditional executors IF FOR WHILE SELECT CASE
-
IF Statement
Execute code based on result of a test
IF .. THEN or IF .. THEN .. ELSEIF test expression THEN
True Statements ;END
- Or -
IF test expression THENTrue Statements ;
ELSEFalse Statements ;
END
-
Use IF .. THEN .. ELSE statement
FUNCTIONIF_Example1()
IF Centrifuge_Clar_V = 1 THENMessage(Clarifier Status, Running,64)
ELSEMessage(Clarifier Status,Stopped,64)
ENDEND
-
Use IF THEN ELSE using Cicode variablesFUNCTION// 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
-
FOR Loop
Execute statements a number of times
FOR variable = expression1 TO expression2 DOStatements ;
END
Variable used as counter
Start Count Value
End Count Value
Count
Exp1++
++++
Exp2
Statements
-
Sleep & SleepMS
// Sleep for 1 secondSleep(1)
// Sleep for 500 millisecondsSleepMS(500)
-
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
-
FUNCTIONFOR_ExampleX()INT Counter;INT iSP;INT iPV;
iSP = LIC_Balance_SP;iPV = LIC_Balance_PV;
Use sleep(1) to delay the loop
-
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);END
END
-
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);END
END
-
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
-
WHILE Loop
Execute statements while condition is true
WHILE Expression DOStatements ;END
WHILE Trigger DOCount = Count + 1 ;Sleep(1) ;END
-
Decrement LIC_Balance_PV while Pump_Feed_CMD is true
Set LIC_Balance_PV to 100 when Pump_Feed_CMD is false
FUNCTIONWHILE_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
-
Select Case Statement
Executes one of a choice of statements
SELECT CASE ExpressionCASE CaseExpression1,CaseExpression2
Statements ;CASE CaseExpression3 TO CaseExpression4
Statements ;CASE IS > CaseExpression5 , IS < CaseExpression6
Statements ;CASE ELSE
Statements ; ! nothing satisfiedEND SELECT
-
Case ExpressionsCase Keyword Description Example
(none) Expression 6iTestValueMonday
, Multiple discrete matches 3, 5, 8iTestValue, iTestValue1apples, oranges
TO Specifies inclusive range of values. Smaller value placed before TO keyword.
3 TO iTestValueapples TO orangesFriday TO friday
IS Use with ,=,=, IS iTestValueIS < cherries
ELSE Catcher for when no other Case clause matches
-
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
-
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?
-
Conditional ExecutorsChapter Summary IF statement FOR loop WHILE loop SELECT CASE statement
-
More Cicode Functions Chapter 7
-
More Cicode Functions
Chapter Overview Return Functions Cicode Arrays Comments
-
Return Functions
Return functions return data to calling function
HowAreYou()RETURN(I am fine)
-
Return Functions Must declare the returning Data type
Function Called
Evaluate Statements & store
in memory
Result returned& Stored in Tag
or Variable
-
Functions Returning Values Return Values
PUBLICINTFUNCTIONReturnExample()Blah;Return(3);
END
Return Values
PUBLICSTRINGFUNCTIONCurrentRecipe() Blah; Return(Full Cream Milk);
END
Data Type
returned
Data Type
returned
-
Create FunctionFUNCTIONAverageEx1()
TIC_P2_PV = (TIC_P1_PV + TIC_P4_PV) /2END Return FunctionINT ! return data type is IntegerFUNCTIONAverageEx2()
RETURN (TIC_P1_PV + TIC_P4_PV) /2 ! return expression
END
-
Create Function AverageEx3()
INTFUNCTIONAverageEx3(INT iTagX, INT iTagY)
RETURN (iTagX + iTagY)/2END
-
Change OperatorInput() to a Return function
INTFUNCTIONEnterTagValue()STRING sTag
sTag=Input("ENTER","Enter a value","");RETURN StrToInt(sTag);
END
-
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
-
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
-
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
-
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
-
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
-
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:##.###)
-
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]
-
Arrays
INT MyArray[10]INT Count ;For Count = 0 to 9 do
MyArray[Count]=Count+1 ;END
-
Initialising an Array
STRING Array[5]=This,is,a,string,array;
Array is satisfied as:
Array[0]=ThisArray[1]=isArray[2]=aArray[3]=stringArray[4]=array
-
Array Dimensions
Arrays can have more than one dimension
INT MyArray[Dim1Size][Dim2Size][Dim3Size] = Values ;
STRING StrArray[5] ; ! ListREAL Result[5][2] ; ! 2-D TableINT IntArray[4][3][2] ; ! 3-D Table
-
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
-
Assign text description to numeric Tag
STRING sRecipeArray[5] = Full Cream", Lite", Sport", Skim", High protein";
STRING FUNCTIONRecipeSelection()
END
-
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 iRecipe
CASE 0 TO 4RETURN sRecipeArray[iRecipe];
CASE ELSEMessage("Error","Not a valid number",64);
END SELECTEND
-
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
-
Chapter 7 - Summary Questions What does a return function do?
What is an Array?
Why should comments be included in all Cicode files?
-
More Cicode FunctionsChapter Summary Return functions Debugging code Arrays Comments
-
Cicode Debugger Chapter 8
-
Cicode Debugger
Chapter Overview Starting the Debugger Debug Options Debug your Code
-
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
-
Cicode Editor in Debug Mode
Open Debug Toolbar Right-Click on blank area of
toolbar
-
Open and test Pizza page
Toggle Breakpoints
-
Find Errors From
DevFind(hDev,sPizzaNumber,NUMBER) ; To
DevFind(hDev,sPizzaNumber,NUM) ;
-
Advanced Stepping
-
Chapter 8 - Summary Questions Explain debug mode.
There are three tools to control stepping through functions. What are they?
-
Cicode DebuggerChapter Summary Cicode editor environment Advanced stepping
-
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
-
SCADA Training Roadmap
Upgrade & New Features
Networking & Architecture
Customisation & Design
Cicode Programming
Vijeo Citect Configuration
Tec
hnic
a l S
kill
Re q
uirem
ent
-
End of Course
Questions Certificates CCSE Certification Course evaluation
www.citect.com/evaluation
Cicode Programming ObjectivesAgenda - Day 1Agenda - Day 2Training FacilitiesWelcomeTraining AgreementSlide 8Slide 9ErgonomicsIntroduction to Cicode Chapter 2 Introduction to CicodeWhat is Cicode?Cicode Project Pasteurisation PageChapters PageRestore Milk ProjectCommandsCicode CommandsOpen Chapters PageSlide 21Setting VariablesString VariablesExpressionsDisplaying DataMultiple StatementsSlide 27Operator InputArgumentsSlide 30Calling FunctionsSlide 32Function InformationPassing Data to FunctionsSlide 35Slide 36Multiple ArgumentsPassing Numeric ArgumentsSlide 39Passing Variable ArgumentsSlide 41Returning DataSlide 43Execute Function on StartupSummary of VariablesData TypesChapter 2 - Summary QuestionsSlide 48Variable Operators Chapter 3 Variable OperatorsClasses of OperatorsIntToStr() functionSlide 53Logical OperatorsTruth TablesSlide 56Slide 57Slide 58Bit OperatorsRelational OperatorsSlide 61Format OperatorFormat OperatorsSlide 64Operator order of PrecedencePrecedence ExamplesSlide 67Chapter 3 - Summary QuestionsSlide 69The Cicode Editor Chapter 4 The Cicode EditorStarting the Cicode EditorContext Sensitive HelpSlide 74Compile & RunGoTo ErrorsSlide 77New Editor FeaturesEnhanced File NavigationChanging ToolbarsIndent and CommentCommentsBookmarks & BreakpointsSlide 84List FunctionsIntellisense AutopromptSlide 87PreferencesSlide 89Chapter 4 - Summary QuestionsSlide 91Cicode Functions Chapter 5 Cicode FunctionsSimple FunctionsFunction Syntax PseudocodeFunction ElementsScopeDeclaring FunctionsNaming FunctionsStatementsVoid FunctionsSlide 102Slide 103Cicode VariablesDeclaring Cicode VariablesCicode Variable SyntaxGlobal Cicode VariablesModule Cicode VariablesLocal Cicode VariablesSlide 110 Variable Naming Standards Hungarian Notation Slide 112Converting Cicode VariablesSlide 114Slide 115Slide 116Include FilesSlide 118Chapter 5 - Summary QuestionsSlide 120Conditional Executors Chapter 6 Conditional ExecutorsIF StatementSlide 124Slide 125FOR LoopSleep & SleepMSSlide 128Slide 129Slide 130Slide 131Slide 132WHILE LoopSlide 134Select Case StatementCase ExpressionsSlide 137Chapter 6 - Summary QuestionsSlide 139More Cicode Functions Chapter 7 More Cicode FunctionsReturn FunctionsSlide 143Functions Returning ValuesSlide 145Slide 146Slide 147Bugs Part 1Bugs Part 1, AnswersBugs Part 2Bugs Part 2, AnswersBugs Part 3Bugs Part 3, AnswersArraysSlide 155Initialising an ArrayArray DimensionsUsing ArraysSlide 159Slide 160Slide 161Chapter 7 - Summary QuestionsSlide 163Cicode Debugger Chapter 8 Cicode DebuggerCitect KernelCicode Editor in Debug ModeSlide 168Slide 169Slide 170Chapter 8 - Summary QuestionsSlide 172Did we Achieve the Objectives?SCADA Training RoadmapEnd of Course