1. Create Tag Expressions
- Navigate to Scripts → Expressions
- Add temperature conversion:
Field | Value |
---|
Object | Tag.Tank1_TempF (create as Double) |
Expression | Tag.Tank1_Temp * 1.8 + 32 |
Execution | OnChange |
Domain | Server |
Add status logic:
Field | Value |
---|
Object | Tag.System_Status (create as String) |
Expression | TIF(Tag.Tank1_Status = 2, "Running", "Stopped") |
Execution | OnChange |
Domain | Server |
2. Create Script Task
- Go to Scripts → Tasks
- Click plus icon, name:
ShiftCounter
- Choose language CSharp
- Press OK
- Use
Server.DateTimeInfo.Hour
as Trigger - Double-click to open Code Editor
- Enter code (no method wrapper):
// Reset counter at shift change
int hour = @Server.DateTimeInfo.Hour;
if (hour == 6 || hour == 14 || hour == 22)
{
@Tag.Units_Previous = @Tag.Units_Produced;
@Tag.Units_Produced = 0;
}
3. Build Script Class
- Navigate to Scripts → Classes
- Create class:
TankCalculations
- Enter methods (no class declaration):
public double CalculateVolume(double level, double diameter)
{
double radius = diameter / 2;
return Math.PI * radius * radius * level;
}
public double CalculateFlowRate(double volumeStart, double volumeEnd, int minutes)
{
if (minutes == 0) return 0;
return (volumeEnd - volumeStart) / minutes;
}
public string GetStatusText(double value, double limit)
{
if (value > limit)
return $"High: {value:F2} (Limit: {limit:F2})";
else
return "Normal";
}
4. Use Class in Expression
- Go to Scripts → Expressions
- Create volume calculation:
Field | Value |
---|
Object | Tag.Tank1_Volume |
Expression | Script.Class.TankCalculations.CalculateVolume(Tag.Tank1_Level, 10.5) |
Execution | OnChange |
Note: No @ symbol needed in expressions
Test and Debug
- Build verification:
- Check green checkmark in BuildStatus
- Review BuildErrors if red X
- Runtime monitoring:
- Go to Scripts → Scripts Monitor
- Check Counter
- Review LastRun
- Debug with breakpoints:
Excerpt Include |
---|
| Scripts Module |
---|
| Scripts Module |
---|
nopanel | true |
---|
|