Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

The Scripting Reference provides comprehensive documentation for developing custom logic in FrameworX 10.1. With support for multiple programming languages including C#, VB.NET, Python, and JavaScript, you can implement complex calculations, automation logic, and integrations. This guide covers syntax, APIs, best practices, and practical examples for all scripting scenarios.

...

Supported Languages

Language Comparison

LanguageUse CasesPerformanceLearning CurveKey Features
C#Complex logic, performance-criticalExcellentModerateFull .NET access, strongly typed
VB.NETLegacy systems, simple logicExcellentEasyFamiliar syntax, .NET access
PythonData analysis, ML, scriptingGoodEasyLibraries, readable syntax
JavaScriptClient-side, expressions ,HTML5 (*1)GoodEasyWeb integration, JSON


Info
title(1) Use Portable pages instead of HTML

JavaScript is available only in HTML5-only, displays.  Prefer always to the Portable Pages, which allows the configuration on Desktop Rich Clients (.NET WPF) and Web/Mobile clients (WebAssembly).

Keep JavaScript and HTML5 only required for code compatibility  or use of external HTML5 controls.

Language Selection Guide

Decision Tree:
Need maximum performance? ??? => C#
Need higher level of runtime security & Reliably => C#
Legacy VB code? ???=> VB.NET Data science/ML? ???=> Python Client-side logic? ??? JavaScript => C# & Python server classes
Simple expressions? ??? Any language=> any language. Platform expression editor can parse different languages.

...

Script Types

Tasks (Scheduled Scripts)

Tasks execute on schedules or triggers:

csharp

// C# Task Example
public class ProductionTask : TaskScript
{
    public override void Execute()
    {
        // Read current values
        double production = @Tag.Production.Counter;
        DateTime shiftStart = @Tag.Shift.StartTime;
        
        // Calculate metrics
            double ratehours = CalculateRate(production,(DateTime.Now - shiftStart).TotalHours;

double rate = // Update tags
@Tag.KPI.ProductionRate = rate; count / hours;
@Tag.KPI.LastUpdate = DateTime.Now;
// Log to database // Update LogToDatabase(rate);tags } @Tag.KPI.ProductionRate = rate; private double CalculateRate(double count, DateTime start) @Tag.KPI.LastUpdate = DateTime.Now; { double hours = (DateTime.Now - start).TotalHours; // Log to database return count / hours @Script.Class.Util.LogToDatabase(rate);     } }

Classes (Reusable Libraries)

Classes provide reusable functions:

csharp

// C# Class Library
public static class : EngineeringCalcs
{
    // Flow calculation
    public static double CalculateFlow(double dp, double k)
    {
        return k * Math.Sqrt(dp);
    }
    
    // Temperature conversion
    public static double CelsiusToFahrenheit(double celsius)
    {
        return (celsius * 9.0 / 5.0) + 32;
    }
    
    // Pressure conversion
    public static double PSIToBar(double psi)
    {
        return psi * 0.0689476;
    }
    
    // Tank volume
    public static double CylindricalTankVolume(double diameter, double level)
    {
        double radius = diameter / 2;
        return Math.PI * radius * radius * level;
    }
}

Expressions (Inline Calculations)

Expressions are single-line calculations:

javascript

// JavaScript Expressions
// Conditional logic
@Tag.Pump.Status = @Tag.Pump.Running ? "Running" : "Stopped"

// Mathematical calculation
@Tag.Tank.Volume = Math.PI * Math.pow(@Tag.Tank.Radius, 2) * @Tag.Tank.Level

// String manipulation
@Tag.Display.Message = "Temperature: " + @Tag.Temp.Value.toFixed(1) + "°C"

// Date/time calculation
@Tag.Batch.Duration = (Date.now() - @Tag.Batch.StartTime) / 1000 / 60

Display Scripts (UI Event Handlers)

Scripts triggered by UI events:

csharp

// C# Display Script
public void OnButtonClick(object sender, EventArgs e)
{
    // Validate user input
    if (!ValidatePermissions())
    {
        ShowMessage("Access Denied");
        return;
    }
    
    // Execute command
    @Tag.Equipment.StartCommand = true;
    
    // Log action
    LogUserAction("Start button pressed");
    
    // Update display
    RefreshDisplay();
}

private bool ValidatePermissions()
{
    return @Tag.Security.UserLevel >= 2;
}

...