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 .

     Express ideas Challenge the facilitator Offer examples Question Relax .Training Agreement  It’s OK to….

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  Lighting  Air conditioning   Environmental conditions  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 .

but without complex structures.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. recursion or inheritance . pointers.

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  .

.  Analog Tag  Set value of Tag   Variable1=value Variable1=Variable2 Oven_Temp=10 . Oven_Temp=Kettle_Temp. Plant1_Pump=0 .Setting Variables  Execute Command  Digital Tag  Change status of Tag Plant1_Pump=1 .

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 .

345 <enter> .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 .

  Enter Keyboard Key Definition Change Misc1 properties .

Arg2 …) Name of the Function Arguments passed to the function   Prompt(“Shutdown”) Shutdown() .Calling Functions     Definition Function A general term used for a subroutine Parentheses identifies statement as function FunctionName(Arg1.

 Calling functions .

Function Information  Look up in online help  Prompt  Shutdown  PageDisplay .

1 or many arguments  Prompt(“Press F1 for Help”)  Arguments passed Place double to the function any string passed quotes around to a function JunkFunction(“1st Argument”.“2nd Argument”) .Passing Data to Functions  Functions can support 0.

  Add Key sequence to project RBUTTON_UP executes command anywhere on page Not RBUTTON_CMD_UP Search capability .

ma w m Co indo W rag D 1. Copy & Paste to Vijeo Citect . Invoke external programs from within Vijeo Citect k& lic a d C to n 2. Find Excel in Windows Explorer 3.

“ABC”) Login ID Password .  Argument order is important  Strings are “quoted”  Login(“Manager”.Multiple Arguments  All arguments must be listed  Separate arguments with a comma .

Passing Numeric Arguments  Both Integers and Floating Point numbers can be passed to a function INT REAL .

150.“Valve_Cool_CMD") Name of Popup window Location on screen Mode of Popup window Tag .512+8+1. AssWin("!Valve".580.

“COAL_LEVEL”). COAL_LEVEL).”TextFont”.”TextFont”.Passing Variable Arguments   When variables are used as arguments  Value of variable is passed. not variable string itself DspStr . Animation Point number Display using this font Value of COAL_LEVEL variable will Display  DspStr(25.Displays a string at a specified AN  DspStr(25. COAL_LEVEL string will Display – as its “quoted” .

 DspStr(326. "ControlLimits". Recipe) AN 326 .

” + FullName() ) .Returning Data  Functions can return a value to the calling statement  Success 0  Failure error number Result of ‘FullName’ used as a parameter to ‘Prompt’ or  Data  As in: date() Prompt(“Hello.

%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 .

64) Custom Mode Modify .“Hello Select World”.Execute Function on Startup Message(“Startup”.

Summary of Variables  Digital (a.+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 .k.a. Boolean or Logical)  Digital_Variable = 0  Digital_Variable = 1  Digital_Variable1 = Digital_Variable2  Integer (-32768 .

Data Types  Fred  Variable  PLC variable  Cicode variable    “Fred”     String Function Path substitution Array index Field definition Compile error context Fred() [Fred]  {Fred}   .

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 doublequotes? How do you set a system start-up function?      .Chapter 2 .

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 + + * / MOD Description Addition (for numeric value) Concatenation (for string variables) Subtraction Multiplication Division Modulus (Remainder) .

IntToStr() function  Used where function only accepts strings  Use a function like IntToStr() Prompt(“ Value ” + IntToStr(Tag_1)) .

”TIC_P2_PV = " + IntToStr(TIC_P2_PV) . MOD Operator  TIC_P2_PV = TIC_P4_PV MOD 10  Concatenation  Message(”P2" . 64) .

Logical Operators Operator AND OR NOT XOR Description Logical AND Logical OR Logical NOT Logical XOR Operator Binary Binary Unary Binary  Operator ‘True’ returns  Operator ‘False’ returns 1 0 .

Truth Tables AND 0 0 0 1 0 OR 0 0 0 1 1 1 0 1 1 1 1 .

Truth Tables XOR 0 0 0 1 1 NOT 0 1 1 0 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 BITAND BITOR BITXOR Description Bitwise AND Bitwise OR 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 String Format : (colon) .

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

TIC_P3_PV:###.##.64) . Format Operator TAG Format Message(“P3" .

/ .< . <> AND OR BITAND. <= . MOD : +. BITOR. > . >= = .Operator order of Precedence Order 1 2 3 4 5 6 7 8 9 10 Operator () NOT * . BITXOR .

Precedence Examples  Tag_1 OR Tag_2 AND NOT Tag_3 1. NOT Tag_3 2. OR Tag_1  (Tag_1 OR (Tag_2 AND (NOT Tag_3))) . AND Tag_2 3.

 Test Order of Precedence Centrifuge_Clar_V = NOT Agitator_Silo_V AND Agitator_Alfast_V .

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?    .Chapter 3 .

Variable Operators Chapter Summary     Mathematical operators Logical operators Relational operators Order of precedence .

The Cicode Editor Chapter 4 .

Run and Debug Your Code File Navigation Features Code Editing Tools Dockable Windows and Toolbars Changing Preferences .The Cicode Editor Chapter Overview       Starting the Cicode Editor Compile.

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 .

Rabbitt Add BlowUpIkea() function NOTES: All functions will be written in Cicode project given in the courses ! Function starts here // Local loop counter FUNCTION DoThisAndThat() Int iCounter    C-style ‘block comments’ (dangerous! What about overlap?) C++ style comments Line comments .Comments Comment your code constantly Preface every Cicode file with   /* DESCRIPTION: Function to do this and that More description here */ // // // // // // REV 1.0 DATE AUTHOR DESCRIP 02/12/04 B.Bob Original 01/04/05 I.0 2.

Bookmarks & Breakpoints Left Click .Bookmark Toggle Bookmark Next Clear Previous .Breakpoint Right Click .

nAN = ANbyName(“WebBrowser”) . Experiment with bookmarks comments and indents Use Comments Liberally . “My Web Browser”) . DspSetTip(nAN.

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 .

141 * Pow(rRadius.REAL FUNCTION AreaOfCircle(REAL rRadius) RETURN (3.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 .

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 .Simple Functions PUBLIC FUNCTION IncCounter() IF Count < 100 THEN COUNT=COUNT + 1.

Function Syntax – Pseudocode HELLO StandUp() IF told THEN Stand Up . ELSE Remain Seated. Finished GOODBYE .

Function Elements     Scope Declaration Name Statement .

Scope  PUBLIC  Default  Shared across Project  PRIVATE  Only works within Cicode file where written .

END .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 .

Statements  Perform the “work” in the function PUBLIC FUNCTION StatementExample()  IF MASH_PUMP THEN  PROMPT(“Mash Pump On”).  ELSE  PROMPT(“Mash Pump Off”).  END END Statements .

 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”).

”Holding Tube too Hot”.HH PUBLIC FUNCTION AudAlarm() DspPlaySound(“[RUN]:Tada.PUBLIC FUNCTION MyDateTime() MISC1=Date(3).0).wav”.H OR HTA. END HTA. MISC2=Time(1).48). END . Message(“Alarm”.

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 .REAL PLC Registers SILO_LEVEL value OVEN_TEMP value STRING_TAG value Computer Memory iAverage rArea sMyName .STRING  Integers .INT  Real Numbers .

Module.Declaring Cicode Variables  Like Variable Tags – a Data Type must be specified for Cicode Variables  Global. Local .

Cicode Variable Syntax  Syntax: SCOPE DATATYPE NAME = INITIALVALUE Global Module Local STRING INT REAL Variable Name Initialize Variable GLOBAL STRING sMyString = “” ! Null Value .

INT FUNCTION GlobalExample(String sPage) INT iStatus . END .Global Cicode Variables  Valid across all Cicode files and all include projects  Maintenance more difficult  Local variables preferred GLOBAL STRING gsDefaultPage = “MIMIC” . iStatus = PageDisplay(sPage) . END RETURN iStatus . IF iStatus <> 0 THEN PageDisplay(gsDefaultPage) .

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 .

iAverage=(TAG1 + TAG2) /2.Local Cicode Variables PUBLIC INT FUNCTION LocalExample() INT iAverage . RETURN iAverage END .

n r s o h Integer Real String Object (activeX) Handle (int) p t x y c Pump (on/off) Temperature Horizontal coord Vertical coord Control variable . System Hungarian System Hungarian Notation Prefix Interpretation Apps Hungarian Notation Prefix Interpretation i.Variable Naming Standards Hungarian Notation   Initial (lowercase) letter describes variable usage Coined by Charles Simonyi of Microsoft  Applications Hungarian vs.

0). “Oven Temp".wav". STRING sMessage) DspPlaySound(sFile.FUNCTION AudAlarm2(STRING sFile. “Holding Tube Too Cold") .48). END Button AudAlarm2("C:\WINDOWS\Media\chimes. Message(sTitle.sMessage. STRING sTitle.

Converting Cicode Variables  Convert Data Types for further processing Input() StrToInt() Calculations +-*/ IntToStr() RealToStr() StrToInt() StrToReal() .

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”.345 .3 can store 12. Width.64) Eg the specification 6.3).RealToStr(TIC_HOLD_PV. Use RealToStr function  Need to convert number to string for use by message() function  RealToStr(Number.6.

 Enter a value into a Tag FUNCTION OperatorInput() STRING sTag //sTag is a string sTag=Input("ENTER"."Enter a value". operator can input a // single value (Title.""). // Convert sTag value to string and place in // LIC_Silo_PV variable END . Default) LIC_Silo_PV=StrToInt(sTag). Prompt. // Displays dialog box.

UTC) TimeToStr(Cent_RT. Format.Display Time  Cent_RT is the accumulator  TimeToStr(Time.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 <> .

“Holding Tube”.cii> AudAlarm2(C:\WINDOWS\Media\chimes.wav. “Holding Tube Too Cold”) . Create an Include file  Use Notepad  <Alarms.

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

sOnMessage . STRING sOnMessage. Use IF THEN ELSE using Cicode variables FUNCTION // set data types for variables in this function IF_Example2(INT iTag1. STRING sOffMessage) // If Tag1 is on then display ‘On’ popup IF iTag1 = 1 THEN Message(sTitle . sOffMessage .64) ELSE // Tag is 0 – display ‘Off’ Popup Message(sTitle . STRING sTitle.64) // End of IF statement END // End of Function END .

END Exp1 + + ++ + + Exp2 Count Statements .FOR Loop  Execute statements a number of times Variable used as counter Start Count Value End Count Value FOR variable = expression1 TO expression2 DO Statements .

Sleep & SleepMS // Sleep for 1 second Sleep(1) // Sleep for 500 milliseconds SleepMS(500) .

// End of FOR loop END END . // Set Counter to count 10 levels FOR Counter = 0 TO 9 DO // Add 1 to counter TagX = tagX + 1.FOR Loop  Execute statements a number of times FUNCTION IncrementLevel() // Counter is an Integer INT Counter . Sleep(2).

iPV = LIC_Balance_PV. iSP = LIC_Balance_SP. INT iPV. INT iSP.FUNCTION FOR_ExampleX() INT Counter. Use sleep(1) to delay the loop .

iSP = LIC_Balance_SP. SleepMS(300). FOR Counter = iPV TO iSP . END END . INT iSP.1 DO LIC_Balance_PV = LIC_Balance_PV + 1. INT iPV. iPV = LIC_Balance_PV. Increase LIC_Balance_PV FUNCTION FOR_Example1() INT Counter.

1. FOR Counter = iSP TO iPV . iPV = LIC_Balance_PV. INT iPV. SleepMS(300). END END . iSP = LIC_Balance_SP.1 DO LIC_Balance_PV = LIC_Balance_PV . INT iSP. Decrease LIC_Balance_PV FUNCTION FOR_Example2() INT Counter.

FUNCTION FOR_Example3() INT Counter. SleepMS(300). iPV = LIC_Balance_PV. END ELSE FOR Counter = iPV TO iSP-1 DO LIC_Balance_PV = LIC_Balance_PV + 1. INT iPV.1. IF LIC_Balance_PV > LIC_Balance_SP THEN FOR Counter = iSP TO iPV .1 DO LIC_Balance_PV = LIC_Balance_PV . SleepMS(300). iSP = LIC_Balance_SP. INT iSP. 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

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

CASE 5 MISC2 = "FRIDAY". CASE 3 MISC2 = "WEDNESDAY". CASE 2 MISC2 = "TUESDAY". END SELECT END .64). CASE 4 MISC2 = "THURSDAY".FUNCTION WhatDayIsIt() SELECT CASE Delivery_Day CASE 0 MISC2 = "SUNDAY". CASE ELSE Message(" Invalid ".“Not a valid number". CASE 6 MISC2 = "SATURDAY". CASE 1 MISC2 = "MONDAY".

depending on the result of an expression?’ .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.Chapter 6 .

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 PUBLIC STRING FUNCTION CurrentRecipe() Blah. END PUBLIC INT FUNCTION ReturnExample() Blah. Return(“Full Cream Milk”). END Data Type returned . Return(3).

 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 .

""). END . Change OperatorInput() to a Return function INT FUNCTION EnterTagValue() STRING sTag sTag=Input("ENTER". RETURN StrToInt(sTag)."Enter a value".

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. Pizza_Area = rArea. END .2).

rArea = pi()* POW(Pizza_Size. END What about Pizza_Area & Pizza_Size? Probably a Variable tag or a global variable. judging by the usage .2). Pizza_Area = rArea.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.

54 END . FUNCTION InchToCent(REAL a) REAL rCent rCent=a*2.Bugs – Part 2 // This function will convert the diameter of the variable // tag from inches to centimetres // This is a RETURN function.

rCent=a*2.54. RETURN(rCENT) END . Answers // This function will convert the diameter of the variable // tag from inches to centimetres // This is a RETURN function.Bugs – Part 2. REAL FUNCTION InchToCent(REAL a) REAL rCent.

Prompt(""). FUNCTION PromptPizza(REAL rRealValue) Prompt("The area of the Pizza is " + rRealValue). END . Sleep(3).Bugs – Part 3 // Show the value of Pizza_Area on the prompt line.

.6. FUNCTION PromptPizza(REAL rRealValue) Prompt("The area of the Pizza is " + RealToStr(rRealValue..3)).Pizza is " + rRealValue:##. Prompt("").Bugs – Part 3. Answers // Show the value of Pizza_Area on the prompt line.###) . END Alternate: . Sleep(3).

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 Unit Unit Unit A B C D … … … … Apartment[0] Apartment[1] Apartment[2] Apartment[3] A B C D Index[0] Index[1] Index[2] Index[3] .

For Count = 0 to 9 do MyArray[Count]=Count+1 . END .Arrays INT MyArray[10] INT Count .

”string”.”a”.”is”.Initialising an Array STRING Array[5]=“This”.  Array is satisfied as: Array[0]=“This” Array[1]=“is” Array[2]=“a” Array[3]=“string” Array[4]=“array” .”array”.

! List ! 2-D Table ! 3-D Table . INT IntArray[4][3][2] . STRING StrArray[5] . REAL Result[5][2] .Array Dimensions  Arrays can have more than one dimension INT MyArray[Dim1Size][Dim2Size][Dim3Size] = Values .

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 .

STRING FUNCTION RecipeSelection() END . “Lite". Assign text description to numeric Tag STRING sRecipeArray[5] = “Full Cream". “Skim". “High protein". “Sport".

STRING FUNCTION RecipeSelection() STRING sRecipe. “Lite". sRecipe = Input("Recipe Number". iRecipe = StrToInt(sRecipe)."Enter a number between 0 and 4".STRING sRecipeArray[5] = “Full Cream".64)."Not a valid number". “High protein". “Sport". CASE ELSE Message("Error". END SELECT END . “Skim". INT iRecipe. SELECT CASE iRecipe CASE 0 TO 4 RETURN sRecipeArray[iRecipe]."").

Cannot be started on the same line as a statement */ Function2() // Another style of comment // Begin each line with forward slashes .Comment and Comment again ! Single Line Comment Function() /* Multiple Line comments Can extend over several lines End comment block with a delimiter .Comments  Comment .

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 .

”NUM”) .sPizzaNumber.sPizzaNumber.”NUMBER”) . . Find Errors   From To DevFind(hDev. DevFind(hDev.

 Advanced Stepping .

There are three tools to control stepping through functions.Chapter 8 .Summary Questions   Explain debug mode. 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 & Design Technical Skill Requirement Networking & Architecture Upgrade & New Features Cicode Programming Vijeo Citect Configuration .

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

Sign up to vote on this title
UsefulNot useful