Scripts & Data EnrichEnrichment (Tutorial) teaches you to:
Prerequisites:
Prerequisites:
Table of Contents maxLevel 2 minLevel 2 indent 10px exclude Steps style none
Temperature Conversion:
Create TagName:Field | Value |
---|---|
Object | Tag.Tank1_TempF ( |
create as Double) |
Expression |
Tag.Tank1_ |
Temp * 1.8 + 32 | |
Execution | OnChange |
Domain | Server |
Field | Value |
---|---|
Object | Tag. |
Conditional Logic:
Create TagName:System_Status ( |
create as String) |
Expression |
TIF(Tag.Tank1_Status = 2, "Running" |
, "Stopped") | |
Execution | OnChange |
Domain | Server |
ShiftCounter
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:
TankCalculations
csharp
public static double CalculateVolume(double level, double diameter)
{
double radius = diameter / 2;
return Math.PI * radius * radius * level;
}
public static double FlowRateCalculateFlowRate(double volumeStart, double volumeEnd, int minutes)
{
if {
(minutes == 0) return 0;
return (volumeEnd - volumeStart) / minutes;
}
public static string GetAlarmTextGetStatusText(double value, double limit)
{
if (value > limit)
return $"High: {value:F2} (Limit: {limit:F2})";
else
return "Normal";
}
In tag expressions:
csharp
@ScriptField | Value |
---|---|
Object | Tag.Tank1_Volume |
Expression | Script.Class.TankCalculations.CalculateVolume( |
Tag.Tank1_Level, |
10.5) |
python
Execution | OnChange |
Note: No @ symbol needed in expressions
TemperatureMonitor
csharp
import numpy as np from datetime import datetime def calculate_statistics(values): """Calculate statistical values""" arr = np.array(values) returnif (@Tag.Tank1_Temp > @Tag.HighLimit)
{
'mean': np.mean(arr), 'std': np.std(arr),@Tag.Alarm_Active = true;
'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']
Create event handler:
csharp
// On tag change event
public void OnTemperatureChange()
{
if (@Tag.Tank1_Temperature > @Tag.HighLimit)
{
@Tag.Alarm_Active = true;
@Tag.Alarm_Message = $"High Temperature: {@Tag.Tank1_Temp:F1}°C";
@Tag.Alarm_Time = DateTime.Now;
// Log to historian
@Script.Class.NotificationsServerMain.SendEmail(
"operator@company.com",
LogEvent(
"High Temperature AlertAlarm",
$"Tank 1: {@Tag.Tank1_Temperature}°C"
Temp
);
}
}
Bind to tagConfigure:
Step-by-step guide to add calculations, automation, and data enrichment to your TankFarm solution using Scripts module capabilities.
[Create Dashboards] - Display calculationsPage Tree | ||||
---|---|---|---|---|
|