Scripts & Data Enrich(Tutorial) teaches you to:
- Create alarm groups and items
- Configure alarm conditions
- Set up notifications
- Enable audit trail for FDA 21 CFR Part 11 compliance
Prerequisites:
In this page:
Simple Tag Expressions
- Navigate to Scripts → Expressions
- Add calculated tag:
Temperature Conversion:
- Create TagName:
Tank1_TempF (use New Tag on top toolbar to create the Tag, type: double)
- Expression:
@Tag.Tank1_TempC * 9/5 + 32
Conditional Logic:
- Create TagName:
System_Status (type: Text)
- Expression:
@Tag.Motor1_Running AND @Tag.Pump1_Running ? "Running" : "Stopped"
Create Script Task
- Go to Scripts → Tasks
- Add new task:
Production Counter:
csharp
// Reset counter at shift change
DateTime now = DateTime.Now;
if (now.Hour == 6 || now.Hour == 14 || now.Hour == 22)
{
if (@Tag.ShiftReset == false)
{
@Tag.Units_Previous = @Tag.Units_Produced;
@Tag.Units_Produced = 0;
@Tag.ShiftReset = true;
}
}
else
{
@Tag.ShiftReset = false;
}
Configure:
- Trigger: Timer
- Rate: 60000ms (1 minute)
- Domain: Server
Build Script Class
- Navigate to Scripts → Classes
- Create class:
TankCalculations:
csharp
public static double CalculateVolume(double level, double diameter)
{
double radius = diameter / 2;
return Math.PI * radius * radius * level;
}
public static double FlowRate(double volumeStart, double volumeEnd, int minutes)
{
return (volumeEnd - volumeStart) / minutes;
}
public static string GetAlarmText(double value, double limit)
{
if (value > limit)
return $"High: {value:F2} (Limit: {limit:F2})";
else
return "Normal";
}
Use Class in Expressions
In tag expressions:
csharp
@Script.Class.TankCalculations.CalculateVolume(@Tag.Tank1_Level, 10.5)
Python Integration
- Scripts → Settings
- Enable Python
- Create Python script:
python
import numpy as np
from datetime import datetime
def calculate_statistics(values):
"""Calculate statistical values"""
arr = np.array(values)
return {
'mean': np.mean(arr),
'std': np.std(arr),
'max': np.max(arr),
'min': np.min(arr)
}
def predict_value(history, hours_ahead):
"""Simple linear prediction"""
# Implementation here
return predicted_value
# Set tag values
tags['Stats_Mean'] = calculate_statistics(history)['mean']
Event-Driven Scripts
Create event handler:
csharp
// On tag change event
public void OnTemperatureChange()
{
if (@Tag.Tank1_Temperature > @Tag.HighLimit)
{
@Tag.Alarm_Active = true;
@Script.Class.Notifications.SendEmail(
"operator@company.com",
"High Temperature Alert",
$"Tank 1: {@Tag.Tank1_Temperature}°C"
);
}
}
Bind to tag:
- Tag: Tank1_Temperature
- Event: OnValueChange
- Script: OnTemperatureChange
Test Scripts
- Start Runtime with debugger
- Set breakpoints in scripts
- Monitor script execution:
- Scripts → Monitor
- Check execution time
- View error messages
Next Steps
- [SQL Database Query] - Database integration
- [Reports Module] - Automated reporting
- [Create Dashboards] - Display calculations