Cicode Programming
This Presentation is 2005 2007 Citect Pty Ltd
ObjectivesGood Understanding & Competent in Use of CicodeBe Able to Use Cicode in Commands and ExpressionsApply Learning to Your Own Site or ProjectBe Able to Write Your Own Cicode FunctionsKnow How to Debug Your Own Cicode FunctionsThis Presentation is 2005 2007 Citect Pty Ltd
This Presentation is 2005 2007 Citect Pty Ltd
Agenda - Day 1WelcomeIntroduction to CicodeVariable Operators Used in CicodeThe Cicode EditorWriting Simple FunctionsUsing Cicode VariablesConversion FunctionsInclude Files
This Presentation is 2005 2007 Citect Pty Ltd
Agenda - Day 2Conditional ExecutorsCicode Return FunctionsArraysDebugging Your Code
This Presentation is 2005 2007 Citect Pty Ltd
Training Facilities
Emergency ExitsLadies & GentsKitchenBreaks / lunchMobile PhonesCompendium
This Presentation is 2005 2007 Citect Pty Ltd
Welcome
Introduce trainerStudents introduce selfNameEmployerCurrent Citect or SCADA experienceExpected outcomes from training
This Presentation is 2005 2007 Citect Pty Ltd
Training AgreementIts OK to.Express ideasChallenge the facilitatorOffer examplesQuestion Relax
This Presentation is 2005 2007 Citect Pty Ltd
Training AgreementTrainers roleStart and end on timeProfessionally facilitate the exchange of information and knowledge Allow time for (and encourage) inputListen non-defensivelyHelp you learn
This Presentation is 2005 2007 Citect Pty Ltd
Training AgreementYour roleBe on timeParticipateLearn in your own wayProvide honest open feedbackEnjoy yourself
This Presentation is 2005 2007 Citect Pty Ltd
ErgonomicsDesks and chairsAdjust to your comfort levelRelocate screen, keyboard, mouse as requiredEnvironmental conditionsLightingAir conditioningRest and relaxationRegular movementEye strain
This Presentation is 2005 2007 Citect Pty Ltd
Introduction to Cicode Chapter 2
This Presentation is 2005 2007 Citect Pty Ltd
Introduction to CicodeChapter OverviewCommands, Expressions and FunctionsUse Commands to Control ProcessesDisplay Data from Expressions
This Presentation is 2005 2007 Citect Pty Ltd
What is Cicode?A programming language!
A means of extending the functionality of Vijeo Citect projectsInteract with variable tagsExchange data with external sourcesCreate 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
This Presentation is 2005 2007 Citect Pty Ltd
Cicode Project Pre-configured project: Cicode_Milk
This Presentation is 2005 2007 Citect Pty Ltd
Pasteurisation Page
This Presentation is 2005 2007 Citect Pty Ltd
Chapters Page
This Presentation is 2005 2007 Citect Pty Ltd
Restore Milk ProjectRestore 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
This Presentation is 2005 2007 Citect Pty Ltd
CommandsCicode Commands can be issued:
ManuallyOperator types in commandsClicking on a button or object on a graphics page
AutomaticallyOperator logs in or out of the runtime systemA graphics page is opened or closedAn alarm is triggeredIn a reportWhen an event is triggered
This Presentation is 2005 2007 Citect Pty Ltd
Cicode CommandsSingle statement or group of statements
This Presentation is 2005 2007 Citect Pty Ltd
Open Chapters PageCreate buttons to turn Silo Agitator off and on
This Presentation is 2005 2007 Citect Pty Ltd
Create 2 buttons in the Chapters Page
Compile and Test by switching to the Chapters Page to view results
This Presentation is 2005 2007 Citect Pty Ltd
Setting VariablesExecute CommandDigital TagChange status of Tag
Analog TagSet value of TagVariable1=valueVariable1=Variable2Plant1_Pump=1 ;Plant1_Pump=0 ;Oven_Temp=10 ;Oven_Temp=Kettle_Temp;
This Presentation is 2005 2007 Citect Pty Ltd
String VariablesSet variable
BATCH_NAME = Bread
Literal strings must be enclosed in quotation marks
This Presentation is 2005 2007 Citect Pty Ltd
ExpressionsAny combination of variables, operators, and statements which evaluate to some result
8 + 4Motor_Speed / 5
Calculations in a Cicode statementResult = Operand1 + Operand2 Operand3
This Presentation is 2005 2007 Citect Pty Ltd
Displaying DataDisplayed Value changes as value of expression changesExpressionchangesValuechanges
This Presentation is 2005 2007 Citect Pty Ltd
Multiple StatementsMultiple statements can be separated by a semi-colon ; Kettle_Temp=10 ;Oven_Temp=Kettle_Temp ;Batch_Name=Bread ;
This Presentation is 2005 2007 Citect Pty Ltd
Multiple statementsAdd a prompt
TIC_P4_PV = TIC_P1_PV + TIC_P2_PV ;Prompt("Calculation is Finished")
This Presentation is 2005 2007 Citect Pty Ltd
Operator InputDefine keyboard Command as a Key sequenceKey Sequence ending in ENTERAllows up to 3 characters to be enteredF2 signals start ofKey Sequence
This Presentation is 2005 2007 Citect Pty Ltd
ArgumentsArg1 provides input to variables by Keyboard entry Conveyor_Speed=Arg1
Conveyor_Speed=ArgValue1
DoThisThenDoThat(Arg1,Arg2)VariableArgument #1Argument #1Checks for Numeric valueArgument #1Argument #2 123 , 345
This Presentation is 2005 2007 Citect Pty Ltd
Enter Keyboard Key DefinitionChange Misc1 properties
This Presentation is 2005 2007 Citect Pty Ltd
Calling FunctionsDefinitionFunction A general term used for a subroutineParentheses identifies statement as functionFunctionName(Arg1,Arg2 )
Prompt(Shutdown)Shutdown()Arguments passedto the functionName of the Function
This Presentation is 2005 2007 Citect Pty Ltd
Calling functions
This Presentation is 2005 2007 Citect Pty Ltd
Function InformationLook up in online help PromptShutdownPageDisplay
This Presentation is 2005 2007 Citect Pty Ltd
Passing Data to FunctionsFunctions can support 0,1 or many argumentsPrompt(Press F1 for Help)
JunkFunction(1st Argument,2nd Argument)
Arguments passedto the functionPlace double quotes around any string passed to a function
This Presentation is 2005 2007 Citect Pty Ltd
Add Key sequence to projectRBUTTON_UP executes command anywhere on pageNot RBUTTON_CMD_UPSearch capability
This Presentation is 2005 2007 Citect Pty Ltd
Invoke external programs from within Vijeo Citect1. Find Excel in Windows Explorer2. Click & Drag to a CommandWindow3. Copy & Paste to Vijeo Citect
This Presentation is 2005 2007 Citect Pty Ltd
Multiple ArgumentsAll arguments must be listedSeparate arguments with a comma ,Argument order is importantStrings are quotedLogin(Manager, ABC)
Login IDPassword
This Presentation is 2005 2007 Citect Pty Ltd
Passing Numeric ArgumentsBoth Integers and Floating Point numbers can be passed to a functionINTREAL
This Presentation is 2005 2007 Citect Pty Ltd
AssWin("!Valve",580,150,512+8+1,Valve_Cool_CMD")Name of Popup windowLocation on screenMode of Popup windowTag
This Presentation is 2005 2007 Citect Pty Ltd
Passing Variable ArgumentsWhen variables are used as argumentsValue of variable is passed, not variable string itselfDspStr - Displays a string at a specified AN DspStr(25,TextFont, COAL_LEVEL);
DspStr(25,TextFont, COAL_LEVEL);Animation Point numberDisplay using this fontValue of COAL_LEVEL variable will DisplayCOAL_LEVEL string will Display as its quoted
This Presentation is 2005 2007 Citect Pty Ltd
DspStr(326, "ControlLimits", Recipe)AN 326
This Presentation is 2005 2007 Citect Pty Ltd
Returning DataFunctions can return a value to the calling statementSuccess 0 Failure error numberorDataAs in: date()Prompt(Hello, + FullName() )Result of FullName used as a parameter to Prompt
This Presentation is 2005 2007 Citect Pty Ltd
%Tag%=FormNumPad("Enter",%Tag%,0)Pass Value from num-pad into Tag variableTitle given to number padValue passed if cancelledMode standard in this case
This Presentation is 2005 2007 Citect Pty Ltd
Execute Function on StartupMessage(Startup,Hello World,64)Select Custom Mode
Modify
This Presentation is 2005 2007 Citect Pty Ltd
Summary of VariablesDigital (a.k.a. Boolean or Logical)Digital_Variable = 0Digital_Variable = 1Digital_Variable1 = Digital_Variable2
Integer (-32768 - +32767)Integer_Variable = 34Integer_Variable = -1274Integer_Variable1 = Integer_Variable2 + 3
Strings (Up to 255 characters)String_Variable = appleString_Variable = string variableString_Variable1 = String_variable2 + more text
Datatypes MUST match during assignments
This Presentation is 2005 2007 Citect Pty Ltd
Data TypesFredVariablePLC variableCicode variableFredStringFred()Function[Fred]Path substitutionArray index{Fred}Field definitionCompile error context
This Presentation is 2005 2007 Citect Pty Ltd
Chapter 2 - Summary QuestionsWhat 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?
This Presentation is 2005 2007 Citect Pty Ltd
Introduction to CicodeChapter SummarySetting variablesUsing expressionsOperator inputPassing data to functionsReturning data from functions
This Presentation is 2005 2007 Citect Pty Ltd
Variable Operators Chapter 3
This Presentation is 2005 2007 Citect Pty Ltd
Variable OperatorsChapter OverviewClasses of Operators in CicodeOrder of Precedence
This Presentation is 2005 2007 Citect Pty Ltd
Classes of OperatorsMathematical
This Presentation is 2005 2007 Citect Pty Ltd
IntToStr() functionUsed where function only accepts stringsUse a function like IntToStr()
Prompt( Value + IntToStr(Tag_1))
This Presentation is 2005 2007 Citect Pty Ltd
MOD Operator TIC_P2_PV = TIC_P4_PV MOD 10
ConcatenationMessage(P2" , TIC_P2_PV = " + IntToStr(TIC_P2_PV) , 64)
This Presentation is 2005 2007 Citect Pty Ltd
Logical OperatorsOperator True returns1Operator False returns0
OperatorDescriptionOperatorANDLogical ANDBinaryORLogical ORBinaryNOTLogical NOTUnaryXORLogical XORBinary
This Presentation is 2005 2007 Citect Pty Ltd
Truth Tables
This Presentation is 2005 2007 Citect Pty Ltd
Truth Tables
This Presentation is 2005 2007 Citect Pty Ltd
Agitator_Silo_V = Agitator_Alfast_V AND Centrifuge_Clar_VAgitator_Silo_V will be turned on ONLY when both Agitator_Alfast_V and Centrifuge_Clar_V are turned on.
This Presentation is 2005 2007 Citect Pty Ltd
Create multi-state text object
This Presentation is 2005 2007 Citect Pty Ltd
Bit OperatorsStandard bit operators
11011AND 1101 = 01001
This Presentation is 2005 2007 Citect Pty Ltd
Relational OperatorsTests the relationship between two values
OperatorDescription=is equal tois not equal tois greater than=is greater than or equal to
This Presentation is 2005 2007 Citect Pty Ltd
Create advanced alarm
This Presentation is 2005 2007 Citect Pty Ltd
Format OperatorConvert numeric values into formatted stringsTag1 : ###.#
Display tag1 as three digits before and one digit after the decimal point
OperatorDescription: (colon)String Format
This Presentation is 2005 2007 Citect Pty Ltd
Format Operators
This Presentation is 2005 2007 Citect Pty Ltd
Format Operator
Message(P3" , TIC_P3_PV:###.##,64)TAGFormat
This Presentation is 2005 2007 Citect Pty Ltd
Operator order of Precedence
OrderOperator1()2NOT3* , / , MOD4:5+ , -6< , > , =7= , 8AND9OR10BITAND, BITOR, BITXOR
This Presentation is 2005 2007 Citect Pty Ltd
Precedence ExamplesTag_1 OR Tag_2 AND NOT Tag_3 NOT Tag_3AND Tag_2OR Tag_1 (Tag_1 OR (Tag_2 AND (NOT Tag_3)))
This Presentation is 2005 2007 Citect Pty Ltd
Test Order of Precedence
Centrifuge_Clar_V = NOT Agitator_Silo_V AND Agitator_Alfast_V
This Presentation is 2005 2007 Citect Pty Ltd
Chapter 3 - Summary QuestionsName 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?
This Presentation is 2005 2007 Citect Pty Ltd
Variable OperatorsChapter SummaryMathematical operatorsLogical operatorsRelational operatorsOrder of precedence
This Presentation is 2005 2007 Citect Pty Ltd
The Cicode Editor Chapter 4
This Presentation is 2005 2007 Citect Pty Ltd
The Cicode EditorChapter OverviewStarting the Cicode EditorCompile, Run and Debug Your CodeFile Navigation FeaturesCode Editing ToolsDockable Windows and ToolbarsChanging Preferences
This Presentation is 2005 2007 Citect Pty Ltd
Starting the Cicode EditorClick on Cicode Editor iconSelect New Cicode page
This Presentation is 2005 2007 Citect Pty Ltd
Context Sensitive HelpM
Cursor anywhere on Logout termHit Key
This Presentation is 2005 2007 Citect Pty Ltd
Open the Cicode EditorSave as Training
This Presentation is 2005 2007 Citect Pty Ltd
Compile & RunGoTo button providedProvides line number where error occurred
Compile & RunCompile onlyError shown
GoTo error
This Presentation is 2005 2007 Citect Pty Ltd
GoTo ErrorsCompiler points to errorClick GoTo ButtonError Condition
This Presentation is 2005 2007 Citect Pty Ltd
FUNCTIONChangeValue()TagValue1=10ENDFUNCTIONChangeValue()TagValue1=10ENDERROR
This Presentation is 2005 2007 Citect Pty Ltd
New Editor FeaturesColour CodingAuto IndentingComment / Uncomment feature
This Presentation is 2005 2007 Citect Pty Ltd
Enhanced File NavigationTabs give 3 different viewsView open Files
This Presentation is 2005 2007 Citect Pty Ltd
Changing ToolbarsClick and drag to reposition toolbarsRight Click toolbar area backgroundAdds New toolbars
This Presentation is 2005 2007 Citect Pty Ltd
Indent and CommentOutdentUncommentIndentCommentSelect textClick comment icon
This Presentation is 2005 2007 Citect Pty Ltd
CommentsComment your code constantlyPreface every Cicode file with
/*DESCRIPTION:Function to do this and thatMore description here*///REVDATEAUTHORDESCRIP//1.002/12/04B.BobOriginal//2.001/04/05I.RabbittAdd BlowUpIkea() function////NOTES:All functions will be written in Cicode //project given in the courses
FUNCTION DoThisAndThat()! Function starts here
Int iCounter// Local loop counterC-style block comments (dangerous! What about overlap?)C++ style commentsLine comments
This Presentation is 2005 2007 Citect Pty Ltd
Bookmarks & BreakpointsClearPreviousToggle BookmarkNextLeft Click - BreakpointRight Click - Bookmark
This Presentation is 2005 2007 Citect Pty Ltd
nAN = ANbyName(WebBrowser) ;DspSetTip(nAN, My Web Browser) ;Experiment with bookmarks comments and indentsUse Comments Liberally
This Presentation is 2005 2007 Citect Pty Ltd
List FunctionsContext sensitive function list Select List Functions
Right Click in text
This Presentation is 2005 2007 Citect Pty Ltd
Intellisense AutopromptTyping function and opening bracket displays AutopromptFunction list displays Autoprompt
This Presentation is 2005 2007 Citect Pty Ltd
REALFUNCTIONAreaOfCircle(REAL rRadius)RETURN (3.141 * Pow(rRadius,2)) ;END_______________________________________FunctionTest()AreaOfCircle(20)END
This Presentation is 2005 2007 Citect Pty Ltd
PreferencesCustomising Cicode EditorView | PreferencesTo change options
This Presentation is 2005 2007 Citect Pty Ltd
Cicode Preferences
This Presentation is 2005 2007 Citect Pty Ltd
Chapter 4 - Summary QuestionsHow can you view files easily?
Why use bookmarks and breakpoints?
How can you change the look of the code window?
This Presentation is 2005 2007 Citect Pty Ltd
The Cicode EditorChapter SummaryStarting the editorGoto errorsFile navigationEditing toolsFunction toolsPreferences
This Presentation is 2005 2007 Citect Pty Ltd
Cicode Functions Chapter 5
This Presentation is 2005 2007 Citect Pty Ltd
Cicode FunctionsChapter OverviewSimple FunctionsStructure of a FunctionPublic & Private FunctionsDeclaring & Naming FunctionsStatementsVoid FunctionsCicode VariablesInclude Files
This Presentation is 2005 2007 Citect Pty Ltd
Simple FunctionsPUBLICFUNCTIONIncCounter()IF Count < 100 THENCOUNT=COUNT + 1;ELSECOUNTER = 0 ;ENDENDScope of Function Public or PrivateStart of FunctionName of FunctionStart of Code
End of IF statementEnd of Code
This Presentation is 2005 2007 Citect Pty Ltd
Function Syntax PseudocodeHELLOStandUp()IF told THENStand Up ;ELSERemain Seated;FinishedGOODBYE
This Presentation is 2005 2007 Citect Pty Ltd
Function ElementsScopeDeclarationNameStatement
This Presentation is 2005 2007 Citect Pty Ltd
ScopePUBLICDefaultShared across ProjectPRIVATEOnly works within Cicode file where written
This Presentation is 2005 2007 Citect Pty Ltd
Declaring FunctionsIndicates beginning and end of function code
ScopeFUNCTIONFunctionName()Statement ;END
This Presentation is 2005 2007 Citect Pty Ltd
Naming FunctionsUp to 32 charactersDo not use reserved wordsCase insensitiveUse CamelCaseUpperCamelCaselowerCamelCase
ScopeFUNCTIONFunctionName()Statement ;END
This Presentation is 2005 2007 Citect Pty Ltd
StatementsPerform the work in the function
PUBLICFUNCTIONStatementExample()IF MASH_PUMP THENPROMPT(Mash Pump On);ELSE PROMPT(Mash Pump Off); ENDEND
Statements
This Presentation is 2005 2007 Citect Pty Ltd
Void FunctionsDo not return any data to the calling function
PUBLICFUNCTIONVoidExample()IF MASH_PUMP THENPROMPT(Mash Pump On);ELSE PROMPT(Mash Pump Off); ENDEND
This Presentation is 2005 2007 Citect Pty Ltd
PUBLICFUNCTIONMyDateTime()MISC1=Date(3);MISC2=Time(1);END
PUBLICFUNCTIONAudAlarm()DspPlaySound([RUN]:Tada.wav,0);Message(Alarm,Holding Tube too Hot,48);ENDHTA.H OR HTA.HH
This Presentation is 2005 2007 Citect Pty Ltd
FUNCTIONAverageEx1()TIC_P2_PV = (TIC_P1_PV + TIC_P4_PV) / 2END
This Presentation is 2005 2007 Citect Pty Ltd
Cicode VariablesLocated in Computer memoryTemporary data storageData TypesStrings - STRINGIntegers - INTReal Numbers - REALPLC RegistersComputer Memory
This Presentation is 2005 2007 Citect Pty Ltd
Declaring Cicode VariablesLike Variable Tags a Data Type must be specified for Cicode Variables
Global, Module, Local
This Presentation is 2005 2007 Citect Pty Ltd
Cicode Variable SyntaxSyntax: SCOPE DATATYPE NAME = INITIALVALUE
GLOBAL STRING sMyString = ! Null Value GlobalModuleLocalSTRINGINTREALVariable NameInitialize Variable
This Presentation is 2005 2007 Citect Pty Ltd
Global Cicode VariablesValid across all Cicode files and all include projectsMaintenance more difficultLocal variables preferred
GLOBAL STRING gsDefaultPage = MIMIC ;INTFUNCTIONGlobalExample(String sPage)
INT iStatus ;iStatus = PageDisplay(sPage) ;IF iStatus 0 THENPageDisplay(gsDefaultPage) ;ENDRETURN iStatus ;END
This Presentation is 2005 2007 Citect Pty Ltd
Module Cicode VariablesSpecific to the file where it is declaredDefault for Cicode variablesDeclare before functions use itMultiplies maintenance issues
This Presentation is 2005 2007 Citect Pty Ltd
Local Cicode VariablesSpecific to function where declaredAny variable defined within a function is local by default (no prefix required)Only valid while function executesLocal variables take precedence if name conflict occurs
This Presentation is 2005 2007 Citect Pty Ltd
Local Cicode Variables
PUBLICINTFUNCTIONLocalExample()INT iAverage ;iAverage=(TAG1 + TAG2) /2;RETURN iAverageEND
This Presentation is 2005 2007 Citect Pty Ltd
Variable Naming Standards Hungarian Notation Initial (lowercase) letter describes variable usageCoined by Charles Simonyi of MicrosoftApplications Hungarian vs. System Hungarian
This Presentation is 2005 2007 Citect Pty Ltd
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
This Presentation is 2005 2007 Citect Pty Ltd
Converting Cicode VariablesConvert Data Types for further processing
IntToStr()RealToStr()StrToInt()StrToReal()
Input()StrToInt()Calculations+-*/
This Presentation is 2005 2007 Citect Pty Ltd
Use RealToStr functionNeed to convert number to string for use by message() functionRealToStr(Number, Width, Places) Number: The floating-point number to convertWidth: The width of the entire stringPlaces: 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
This Presentation is 2005 2007 Citect Pty Ltd
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
This Presentation is 2005 2007 Citect Pty Ltd
Display Time
Cent_RT is the accumulator TimeToStr(Time, Format, UTC)
TimeToStr(Cent_RT,5)
This Presentation is 2005 2007 Citect Pty Ltd
Include FilesCommand field limited to 128 CharactersInclude Files accommodate a single complex statement sequenceAny valid DOS filename Convention: Filename.cii Referenced by:@DO Include
This Presentation is 2005 2007 Citect Pty Ltd
Create an Include fileUse Notepad
AudAlarm2(C:\WINDOWS\Media\chimes.wav, Holding Tube, Holding Tube Too Cold)
This Presentation is 2005 2007 Citect Pty Ltd
Chapter 5 - Summary QuestionsHow 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?
This Presentation is 2005 2007 Citect Pty Ltd
Cicode FunctionsChapter SummaryElements of a functionVoid functionsCicode variablesConverting and formatting variablesInclude files
This Presentation is 2005 2007 Citect Pty Ltd
Conditional Executors Chapter 6
This Presentation is 2005 2007 Citect Pty Ltd
Conditional ExecutorsChapter OverviewFour conditional executorsIFFORWHILESELECT CASE
This Presentation is 2005 2007 Citect Pty Ltd
IF StatementExecute 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
This Presentation is 2005 2007 Citect Pty Ltd
Use IF .. THEN .. ELSE statement FUNCTIONIF_Example1()IF Centrifuge_Clar_V = 1 THENMessage(Clarifier Status, Running,64)ELSEMessage(Clarifier Status,Stopped,64)ENDEND
This Presentation is 2005 2007 Citect Pty Ltd
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 popupIF iTag1 = 1 THENMessage(sTitle , sOnMessage ,64)ELSE// Tag is 0 display Off PopupMessage(sTitle , sOffMessage ,64)// End of IF statementEND// End of FunctionEND
This Presentation is 2005 2007 Citect Pty Ltd
FOR LoopExecute statements a number of times
FOR variable = expression1 TO expression2 DOStatements ;ENDVariable used as counterStart Count ValueEnd Count ValueCountExp1++ ++++Exp2Statements
This Presentation is 2005 2007 Citect Pty Ltd
Sleep & SleepMS// Sleep for 1 secondSleep(1)
// Sleep for 500 millisecondsSleepMS(500)
This Presentation is 2005 2007 Citect Pty Ltd
FOR LoopExecute 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 counterTagX = tagX + 1; Sleep(2);// End of FOR loopENDEND
This Presentation is 2005 2007 Citect Pty Ltd
FUNCTIONFOR_ExampleX()INT Counter;INT iSP;INT iPV;iSP = LIC_Balance_SP;iPV = LIC_Balance_PV; Use sleep(1) to delay the loop
This Presentation is 2005 2007 Citect Pty Ltd
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
This Presentation is 2005 2007 Citect Pty Ltd
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
This Presentation is 2005 2007 Citect Pty Ltd
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);ENDELSEFOR Counter = iPV TO iSP-1 DO LIC_Balance_PV = LIC_Balance_PV + 1; SleepMS(300); ENDENDEND
This Presentation is 2005 2007 Citect Pty Ltd
WHILE LoopExecute statements while condition is true
WHILE Expression DOStatements ;END
WHILE Trigger DOCount = Count + 1 ;Sleep(1) ;END
This Presentation is 2005 2007 Citect Pty Ltd
Decrement LIC_Balance_PV while Pump_Feed_CMD is trueSet 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 !optionalEND
This Presentation is 2005 2007 Citect Pty Ltd
Select Case StatementExecutes one of a choice of statements
SELECT CASE ExpressionCASE CaseExpression1,CaseExpression2Statements ;CASE CaseExpression3 TO CaseExpression4Statements ;CASE IS > CaseExpression5 , IS < CaseExpression6Statements ;CASE ELSEStatements ; ! nothing satisfiedEND SELECT
This Presentation is 2005 2007 Citect Pty Ltd
Case Expressions
This Presentation is 2005 2007 Citect Pty Ltd
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 ELSEMessage(" Invalid ",Not a valid number",64);END SELECTEND
This Presentation is 2005 2007 Citect Pty Ltd
Chapter 6 - Summary QuestionsWhat 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?
This Presentation is 2005 2007 Citect Pty Ltd
Conditional ExecutorsChapter SummaryIF statementFOR loopWHILE loopSELECT CASE statement
This Presentation is 2005 2007 Citect Pty Ltd
More Cicode Functions Chapter 7
This Presentation is 2005 2007 Citect Pty Ltd
More Cicode FunctionsChapter OverviewReturn FunctionsCicode ArraysComments
This Presentation is 2005 2007 Citect Pty Ltd
Return FunctionsReturn functions return data to calling function
HowAreYou()RETURN(I am fine)
This Presentation is 2005 2007 Citect Pty Ltd
Return FunctionsMust declare the returning Data typeFunction CalledEvaluate Statements & store in memoryResult returned& Stored in Tag or Variable
This Presentation is 2005 2007 Citect Pty Ltd
Functions Returning ValuesReturn Values
PUBLICINTFUNCTIONReturnExample()Blah;Return(3);END
Return Values
PUBLICSTRINGFUNCTIONCurrentRecipe() Blah; Return(Full Cream Milk);ENDData Type returnedData Type returned
This Presentation is 2005 2007 Citect Pty Ltd
Create FunctionFUNCTIONAverageEx1()TIC_P2_PV = (TIC_P1_PV + TIC_P4_PV) /2ENDReturn FunctionINT ! return data type is IntegerFUNCTIONAverageEx2()RETURN (TIC_P1_PV + TIC_P4_PV) /2 ! return expressionEND
This Presentation is 2005 2007 Citect Pty Ltd
Create Function AverageEx3() INTFUNCTIONAverageEx3(INT iTagX, INT iTagY)RETURN (iTagX + iTagY)/2END
This Presentation is 2005 2007 Citect Pty Ltd
Change OperatorInput() to a Return function INTFUNCTIONEnterTagValue()STRING sTagsTag=Input("ENTER","Enter a value","");RETURN StrToInt(sTag);END
This Presentation is 2005 2007 Citect Pty Ltd
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
This Presentation is 2005 2007 Citect Pty Ltd
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
This Presentation is 2005 2007 Citect Pty Ltd
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
This Presentation is 2005 2007 Citect Pty Ltd
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
This Presentation is 2005 2007 Citect Pty Ltd
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
This Presentation is 2005 2007 Citect Pty Ltd
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:##.###)
This Presentation is 2005 2007 Citect Pty Ltd
ArraysArrays 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]
ABCDIndex[0]Index[1]Index[2]Index[3]
This Presentation is 2005 2007 Citect Pty Ltd
ArraysINT MyArray[10]INT Count ;For Count = 0 to 9 doMyArray[Count]=Count+1 ;END
This Presentation is 2005 2007 Citect Pty Ltd
Initialising an ArraySTRING Array[5]=This,is,a,string,array;
Array is satisfied as:
Array[0]=ThisArray[1]=isArray[2]=aArray[3]=stringArray[4]=array
This Presentation is 2005 2007 Citect Pty Ltd
Array DimensionsArrays 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
This Presentation is 2005 2007 Citect Pty Ltd
Using ArraysArrays are declared as Module or Global (cannot be declared locally)Placed at the beginning of a Cicode fileDo not exceed the bounds of the arrayYou cannot pass an entire array into a Cicode function
This Presentation is 2005 2007 Citect Pty Ltd
Assign text description to numeric Tag
STRING sRecipeArray[5] = Full Cream", Lite", Sport", Skim", High protein";
STRING FUNCTIONRecipeSelection()END
This Presentation is 2005 2007 Citect Pty Ltd
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 4RETURN sRecipeArray[iRecipe];CASE ELSEMessage("Error","Not a valid number",64);END SELECTEND
This Presentation is 2005 2007 Citect Pty Ltd
CommentsComment ,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
This Presentation is 2005 2007 Citect Pty Ltd
Chapter 7 - Summary QuestionsWhat does a return function do?
What is an Array?
Why should comments be included in all Cicode files?
This Presentation is 2005 2007 Citect Pty Ltd
More Cicode FunctionsChapter SummaryReturn functionsDebugging codeArraysComments
This Presentation is 2005 2007 Citect Pty Ltd
Cicode Debugger Chapter 8
This Presentation is 2005 2007 Citect Pty Ltd
Cicode DebuggerChapter OverviewStarting the DebuggerDebug OptionsDebug your Code
This Presentation is 2005 2007 Citect Pty Ltd
Citect KernelCovered in Intermediate CourseCore of the Vijeo Citect systemLow-level diagnostic and debuggingUse with extreme careSecure access over-rides all other security measuresCommand Line interface
This Presentation is 2005 2007 Citect Pty Ltd
Cicode Editor in Debug ModeOpen Debug ToolbarRight-Click on blank area of toolbar
This Presentation is 2005 2007 Citect Pty Ltd
Open and test Pizza pageToggle Breakpoints
This Presentation is 2005 2007 Citect Pty Ltd
Find ErrorsFromDevFind(hDev,sPizzaNumber,NUMBER) ;ToDevFind(hDev,sPizzaNumber,NUM) ;
This Presentation is 2005 2007 Citect Pty Ltd
Advanced Stepping
This Presentation is 2005 2007 Citect Pty Ltd
Chapter 8 - Summary QuestionsExplain debug mode.
There are three tools to control stepping through functions. What are they?
This Presentation is 2005 2007 Citect Pty Ltd
Cicode DebuggerChapter SummaryCicode editor environmentAdvanced stepping
This Presentation is 2005 2007 Citect Pty Ltd
Did we Achieve the Objectives?Good Understanding & Competent in Use of CicodeBe Able to Use Cicode in Commands and ExpressionsApply Learning to Your Own Site or ProjectBe Able to Write Your Own Cicode FunctionsKnow How to Debug Your Own Cicode Functions
This Presentation is 2005 2007 Citect Pty Ltd
SCADA Training RoadmapUpgrade & New FeaturesNetworking & ArchitectureCustomisation & DesignCicode ProgrammingVijeo Citect Configuration
This Presentation is 2005 2007 Citect Pty Ltd
End of CourseQuestionsCertificatesCCSE CertificationCourse evaluationwww.citect.com/evaluation
This Presentation is 2005 2007 Citect Pty Ltd
This Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty LtdThis Presentation is 2005 2007 Citect Pty Ltd