Sie sind auf Seite 1von 175

Cicode Programming

<Instructor’s Name>
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

 It’s OK to….
 Express ideas
 Challenge the facilitator
 Offer examples
 Question
 Relax
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
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:


 It’s 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  Run Milk project
from the folder supplied
 Test Pasteurisation page
by your facilitator
 View Chapters page
 Compile the project and
then run the Computer
Setup Wizard (express)
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
Plant1_Pump=1 ;
 Digital Tag
 Change status of Tag
Plant1_Pump=0 ;

 Analog Tag Oven_Temp=10 ;


 Set value of Tag Oven_Temp=Kettle_Temp;
 Variable1=value
 Variable1=Variable2
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
Value
changes

Expression
changes
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

F2 signals start of
Key Sequence

Key Sequence
ending in ENTER
Allows up to 3
characters to be
entered
Arguments
 Arg1 provides input to variables by Keyboard entry
 Conveyor_Speed=Arg1
Variable Argument #1

 Conveyor_Speed=ArgValue1
Argument #1
Checks for Numeric value

 DoThisThenDoThat(Arg1,Arg2)

Argument #1 Argument #2

<F2> 123 , 345 <enter>


 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 …)

Arguments passed
Name of the Function
to the function

 Prompt(“Shutdown”)
 Shutdown()
 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”)

Arguments passed
Place double to
quotes around any string passed
the function
to a function
 JunkFunction(“1st Argument”,“2nd Argument”)
 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
rag
D
&
l ick a
C to nd
2. a
ommdow
C in
W

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 Location on Mode of


window screen Popup Tag
window
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);

Animation Display Value of


Point using this COAL_LEVEL variable
number font will Display

 DspStr(25,”TextFont”, “COAL_LEVEL”);

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 number
Result of
or ‘FullName’
used as a
 Data parameter to
 As in: ‘Prompt’

date()
Prompt(“Hello,” + FullName() )
%Tag%=FormNumPad("Enter",%Tag%,0)
Pass Value from Title given Value Mode –
num-pad into Tag to number passed if standard in
variable pad cancelled this case
Execute Function on Startup
Message(“Startup”,“Hello
Select World”,64)
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 Cicode
Chapter 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 Description Operator

AND Logical AND Binary

OR Logical OR Binary

NOT Logical NOT Unary

XOR Logical XOR Binary

 Operator ‘True’ returns 1


 Operator ‘False’ returns 0
Truth Tables

AND 0 1 OR 0 1

0 0 0 0 0 1

1 0 1 1 1 1
Truth Tables

XOR 0 1 NOT 0 1
1 0
0 0 1

1 1 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
Operator Description

BITAND Bitwise AND

BITOR Bitwise OR

BITXOR Bitwise XOR


11011
AND 1101
= 01001
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
 Create advanced alarm
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


Format Operators
Specifier Description Function Use Example
# The hash The number of #### + 23
character characters to
display to the +472213
right of the AN
0 Zero Padding #0## +0023
- Minus Justification #-### +23
. Period Decimal notation ###.## + 23.54
EU Engineering #.##EU
units
S Exponential #s### +1.234e+012
notation
 Format Operator
TAG Format

Message(“P3" , TIC_P3_PV:###.##,64)
Operator order of Precedence
Order Operator

1 ()
2 NOT
3 * , / , MOD
4 :
5 +,-
6 < , > , <= , >=
7 = , <>
8 AND
9 OR
10 BITAND, BITOR, BITXOR
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)))


 Test Order of Precedence
Centrifuge_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 Operators
Chapter 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

M
Cursor
anywhere
on ‘Logout’
term
Hit <F1>
Key
 Open the Cicode Editor
 Save as Training
Compile & Run
 GoTo button provided
 Provides line number where error occurred

Error
shown

GoTo
error

 Compile & Run


 Compile only
GoTo Errors
 Compiler points to error
 Click GoTo Button

Error Condition
FUNCTION
ChangeValue()
TagValue1=10
END

FUNCTION
ChangeValue()
TagValue1=10
END
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
Indent Comment
Select text

Click
comment
icon

Outdent Uncomment
Comments
Comment your code constantly
Preface every Cicode file with


/*
DESCRIPTION: Function to do this and that
More 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
Bookmarks & Breakpoints
Left Click - Breakpoint

Right Click - Bookmark

Toggle Bookmark
Next

Clear Previous
nAN = ANbyName(“WebBrowser”) ;
DspSetTip(nAN, “My Web Browser”) ;
Experiment with
bookmarks comments and
indents
Use Comments Liberally
List Functions
 Context sensitive function list
 <ctrl> <space>

Right Click
in text
Select List
Functions
Intellisense Autoprompt

 Typing function and opening bracket displays


Autoprompt
 Function list displays Autoprompt
REAL
FUNCTION
AreaOfCircle(REAL rRadius)
RETURN (3.141 * Pow(rRadius,2)) ;
END
_______________________________________
Function
Test()
AreaOfCircle(20)
END
Preferences
 Customising Cicode Editor

View | Preferences
To 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 Editor
Chapter 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
Scope of Function Public or
PUBLIC Private
FUNCTION Start of Function
IncCounter() Name of Function
IF Count < 100 THEN Start of Code
COUNT=COUNT + 1;
ELSE
COUNTER = 0 ;
END End of IF statement
END End of Code
Function Syntax – Pseudocode

HELLO
StandUp()
IF told THEN
Stand Up ;
ELSE
Remain Seated;
Finished
GOODBYE
Function Elements

 Scope
 Declaration
 Name
 Statement
Scope
 PUBLIC  PRIVATE
 Default  Only works within Cicode
 Shared across Project file where written
Declaring Functions

 Indicates beginning and end of function code

Scope
FUNCTION
FunctionName()
Statement ;
END
Naming Functions
 Up to 32 characters
 Do not use reserved words
 Case insensitive
 Use CamelCase
 UpperCamelCase
 lowerCamelCase

Scope
FUNCTION
FunctionName()
Statement ;
END
Statements
 Perform the “work” in the function

PUBLIC
FUNCTION
StatementExample()
 IF MASH_PUMP THEN
 PROMPT(“Mash Pump On”);
 ELSE
Statements
 PROMPT(“Mash Pump Off”);
 END
END
Void Functions
 Do not return any data to the calling function

PUBLIC
FUNCTION
VoidExample()
 IF MASH_PUMP THEN
 PROMPT(“Mash Pump On”);
 ELSE
 PROMPT(“Mash Pump Off”);
 END
END
PUBLIC HTA.H OR HTA.HH
FUNCTION
MyDateTime()
MISC1=Date(3);
MISC2=Time(1);
END

PUBLIC
FUNCTION
AudAlarm()
DspPlaySound(“[RUN]:Tada.wav”,0);
Message(“Alarm”,”Holding Tube too Hot”,48);
END
FUNCTION
AverageEx1()
TIC_P2_PV = (TIC_P1_PV + TIC_P4_PV) / 2
END
Cicode Variables
 Located in Computer memory
 Temporary data storage
 Data Types
 Strings - STRING
 Integers - INT
 Real Numbers - REAL

PLC Registers Computer Memory

SILO_LEVEL value iAverage

OVEN_TEMP value rArea

STRING_TAG value sMyName


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 Variable Initialize


Module INT Name Variable
Local REAL

GLOBAL STRING sMyString = “” ! Null Value


Global Cicode Variables
 Valid across all Cicode files and all include projects
 Maintenance more difficult
 Local variables preferred

GLOBAL STRING gsDefaultPage = “MIMIC” ;


INT
FUNCTION
GlobalExample(String sPage)

INT iStatus ;
iStatus = PageDisplay(sPage) ;
IF iStatus <> 0 THEN
PageDisplay(gsDefaultPage) ;
END
RETURN 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

PUBLIC
INT
FUNCTION
LocalExample()
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 Notation Apps Hungarian Notation


Prefix Interpretation Prefix Interpretation
i, n Integer p Pump (on/off)
r Real t Temperature
s String x Horizontal coord
o Object (activeX) y Vertical coord
h Handle (int) c Control variable
FUNCTION
AudAlarm2(STRING sFile, STRING sTitle, STRING
sMessage)
DspPlaySound(sFile,0);
Message(sTitle,sMessage,48);
END

Button

AudAlarm2("C:\WINDOWS\Media\chimes.wav", “Oven
Temp", “Holding Tube Too Cold")
Converting Cicode Variables

 Convert Data Types for further processing

Input() StrToInt() Calculations


+-*/

IntToStr()
RealToStr()
StrToInt()
StrToReal()
 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

FUNCTION
OperatorInput()
STRING sTag
//sTag is a string
sTag=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 variable
END
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:
@<filename>
DO Include <>
 Create an Include file
 Use Notepad
 <Alarms.cii>

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 Functions
Chapter 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 .. ELSE

IF test expression THEN


True Statements ;
END

- Or -

IF test expression THEN


True Statements ;
ELSE
False Statements ;
END
 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
 Use IF THEN ELSE using Cicode variables
FUNCTION
// set data types for variables in this function
IF_Example2(INT iTag1, STRING sTitle, STRING sOnMessage, STRING
sOffMessage)
// If Tag1 is on then display ‘On’ popup
IF iTag1 = 1 THEN
Message(sTitle , sOnMessage ,64)
ELSE
// Tag is 0 – display ‘Off’ Popup
Message(sTitle , sOffMessage ,64)
// End of IF statement
END
// End of Function
END
FOR Loop

 Execute statements a number of times


Variable used Start Count End Count
as counter Value Value

FOR variable = expression1 TO expression2 DO


Statements ;
END

Exp1
+
+
++ Count Statements
+
+
Exp2
Sleep & SleepMS

// Sleep for 1 second


Sleep(1)

// Sleep for 500 milliseconds


SleepMS(500)
FOR Loop

 Execute statements a number of times


FUNCTION
IncrementLevel()
// Counter is an Integer
INT 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 loop
END
END
FUNCTION
FOR_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

FUNCTION
FOR_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

FUNCTION
FOR_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
FUNCTION
FOR_Example3()
INT Counter;
INT iSP;
INT iPV;
iSP = LIC_Balance_SP;
iPV = LIC_Balance_PV;

IF LIC_Balance_PV > LIC_Balance_SP THEN


FOR Counter = iSP TO iPV - 1 DO
LIC_Balance_PV = LIC_Balance_PV - 1;
SleepMS(300);
END
ELSE
FOR Counter = iPV TO iSP-1 DO
LIC_Balance_PV = LIC_Balance_PV + 1;
SleepMS(300);
END
END
END
WHILE Loop

 Execute statements while condition is true

WHILE Expression DO
Statements ;
END

WHILE Trigger DO
Count = 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

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
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
Case Expressions
Case Keyword Description Example
(none) Expression 6
iTestValue
“Monday”
, Multiple discrete matches 3, 5, 8
iTestValue, iTestValue1
“apples”, “oranges”
TO Specifies inclusive range of 3 TO iTestValue
values. Smaller value placed “apples” TO “oranges”
before TO keyword. “Friday” TO “friday”
IS Use with <,>,<=,>=,=,<> IS <=14
IS > iTestValue
IS < “cherries”
ELSE ‘Catcher’ for when no other Case
clause matches
FUNCTION
WhatDayIsIt()

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 Executors
Chapter 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  Return Values
Data
Type
PUBLIC PUBLIC
returned
INT STRING
FUNCTION FUNCTION
ReturnExample() CurrentRecipe()
Blah;
Blah;
Return(3);
Return(“Full Cream
END Milk”);
END
 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
 Create Function – AverageEx3()

INT
FUNCTION
AverageEx3(INT iTagX, INT iTagY)
RETURN (iTagX + iTagY)/2
END
 Change OperatorInput() to a Return function
INT
FUNCTION
EnterTagValue()
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

FUNCTION
AreaofPizza()

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

FUNCTION
AreaofPizza()
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.

FUNCTION
InchToCent(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.

REAL
FUNCTION
InchToCent(REAL a)

REAL rCent;
rCent=a*2.54;
RETURN(rCENT)

END
Bugs – Part 3
// Show the value of Pizza_Area on the prompt line.

FUNCTION
PromptPizza(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.

FUNCTION
PromptPizza(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

A B C D
 INT Apartment[4]
 Unit A … Apartment[0]
 Unit B … Apartment[1]
 Unit C … Apartment[2] Index[0]
 Unit D … Apartment[3] 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]=“This”
Array[1]=“is”
Array[2]=“a”
Array[3]=“string”
Array[4]=“array”
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
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 FUNCTION
RecipeSelection()

END
STRING sRecipeArray[5] = “Full Cream", “Lite", “Sport", “Skim", “High
protein";

STRING
FUNCTION
RecipeSelection()
STRING sRecipe;
INT iRecipe;

sRecipe = Input("Recipe Number","Enter a number between 0 and


4","");
iRecipe = StrToInt(sRecipe);

SELECT CASE iRecipe


CASE 0 TO 4
RETURN sRecipeArray[iRecipe];
CASE ELSE
Message("Error","Not a valid number",64);
END SELECT
END
Comments

Comment ,Comment and Comment again


! Single Line Comment


Function()
/*
Multiple Line comments
Can extend over several lines
End 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 Functions
Chapter 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 Debugger
Chapter 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

Customisation Networking &


& Design Architecture
Technical Skill Requirement

Upgrade &
New Features

Cicode Vijeo Citect


Programming Configuration
End of Course
 Questions
 Certificates
 CCSE Certification
 Course evaluation
 www.citect.com/evaluation

Das könnte Ihnen auch gefallen