Common Cicode Errors and How to Fix Them in AVEVA™ Plant SCADA
Avoid downtime with this complete guide to common Cicode errors in AVEVA™ Plant SCADA. Learn causes, solutions, and debugging tips with real examples.
Cicode is the scripting language that powers advanced automation and custom logic in AVEVA™ Plant SCADA (formerly CitectSCADA).
While Plant SCADA provides a graphical configuration environment, Cicode is essential for:
- Event-driven logic (e.g., start/stop sequences)
- Advanced calculations
- Custom alarm handling
- Integrations with external systems
However, even experienced engineers make mistakes in Cicode that can cause runtime errors, unexpected behavior, or degraded performance. In this guide, we’ll cover the most common Cicode errors, how to fix them, and best practices to avoid them in future — complete with real-world examples.
1. Syntax Errors
What it looks like: “Syntax Error” or red highlight in the editor.
Common causes:
- Missing semicolons
- Mismatched brackets
- Misspelled keywords
Faulty Code:
INT iCount
iCount = 10
IF iCount > 5 THEN
Message("Info", "Count is greater than 5")
END
Corrected Code:
INT iCount;
iCount = 10;
IF iCount > 5 THEN
Message("Info", "Count is greater than 5");
END
2. Undefined Variables
Error: Variable ‘PumpStatus’ is undefined
Cause: Used without declaration or declared in a wrong scope.
Faulty Code:
IF PumpStatus = 1 THEN
StartPump();
END
Corrected Code:
INT PumpStatus;
PumpStatus = TagRead("Plant1.Pump101.Status");
IF PumpStatus = 1 THEN
StartPump();
END
3. Incorrect Tag References
Issue: TagRead() returns zero or wrong value.
Faulty Code:
Level = TagRead("Tank1_Lvl");
Corrected Code:
Level = TagRead("Plant1.Tank1.Level");
4. Infinite Loops
Symptom: System freezes, CPU 100%
Faulty Code:
WHILE TRUE DO
TagWrite("Pump101.Status", 1);
END
Corrected Code:
WHILE TagRead("Pump101.Enable") = 1 DO
TagWrite("Pump101.Status", 1);
SleepMS(1000);
END
5. Overusing Sleep/Delay
Impact: Laggy system response
Sleep(10);
Tip: Replace with event-driven methods like EventSet()
6. Runtime Null Errors
Example: Reading from offline device
IF TagRead("Plant1.FlowSensor1.Status") = 1 THEN
FlowRate = TagRead("Plant1.FlowSensor1.Rate");
ELSE
FlowRate = 0;
END
7. Not Freeing Resources
Cause: Opened files not closed
Corrected Code:
INT hFile = FileOpen("log.txt", "a");
FileWrite(hFile, "Data line");
FileClose(hFile);
Best Practices to Avoid Errors
- Use modular functions
- Stick to tag naming standards
- Comment code often
- Test in simulation before going live
- Reuse common code blocks from a library
Debugging Tips
- Use
Message()
andTrace()
for diagnostics - Check the Kernel window for logs
- Use breakpoints for line-by-line debugging
Need help with Cicode optimization or advanced AVEVA™ Plant SCADA training?
Contact our team for expert assistance.