Create Script Expressions, Tasks and Classes.
Tutorials → Scripts| Tutorial | How-to Guide | Reference
Table of Contents maxLevel 2 minLevel 2 indent 10px exclude Tutorial style none
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 |
Add calculations, business logic, and data transformations using FrameworX's scripting capabilities. Create expressions, tasks, and classes for advanced functionality.
Temperature Conversion:
Tank1_TempF
@Tag.Tank1_TempC * 9/5 + 32
Conditional Logic:
System_Status
@Tag.Motor1_Running AND @Tag.Pump1_Running ? "Running" : "Stopped"
Production Counter:
csharp
ShiftCounter
Server.DateTimeInfo.Hour
as Trigger// Reset counter at shift change
DateTimeint nowhour = DateTime@Server.DateTimeInfo.NowHour;
if (now.Hourhour == 6 || now.Hourhour == 14 || now.Hourhour == 22)
{
if (@Tag.ShiftReset == false)
{
@Tag.Units_Previous = @Tag.Units_Produced;
@Tag.Units_Produced = 0;
@Tag.ShiftReset = true;
}
}
else
{
@Tag.ShiftReset = false;
}
Configure:
Trigger: TimerTankCalculations
csharp
public class TankCalculations
{
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";
}
}
Step In tag expressions:
csharp
@ScriptField | Value |
---|---|
Object | Tag.Tank1_Volume |
Expression | Script.Class.TankCalculations.CalculateVolume( |
Tag.Tank1_Level, |
10.5) |
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']
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:
Script for database logging:
csharp
public void LogProduction()
{
string query = @"
INSERT INTO ProductionLog
(Timestamp, Product, Quantity, Operator)
VALUES
(@time, @product, @qty, @user)";
@Dataset.DB.SqlExecuteCommand(query,
"@time", DateTime.Now,
"@product", @Tag.Current_Product,
"@qty", @Tag.Units_Produced,
"@user", @Client.UserName
);
}
Execution | OnChange |
Note: No @ symbol needed in expressions
Excerpt Include | ||||||
---|---|---|---|---|---|---|
|
Page Tree | ||||
---|---|---|---|---|
|