Using SCADA Functions Within Scripts
SCADA functions available in the function window in Wise SCADA can also be executed within C# and VB scripts.
When calling a SCADA function within a script, the function type and its parameters must be defined in the same order as they appear in the function window.
The parameter structures of the functions and the available options can be reviewed in the function window.
Basic Usage
C#
In C# scripts, SCADA functions are called using the SCADAFunctionRun method.
BOOL result = SCADAFunctionRun(“FonksiyonTipi”, Param0, Param1, Param2, Param3, Param4);
Example:
public class MainClass
{
public void Main()
{
BOOL result = SCADAFunctionRun("Tag", "_Tag", "=", "\"true\"", null, null);
}
}
VB
In VB scripts, SCADA functions are called using the SCADAFunction.Run method.
When using VB, the SCADAFunction object must be defined within MainClass.
Example:
Public Class MainClass
Public SCADAFunction As Object
Public Sub Main
Dim result As BOOL = SCADAFunction.Run("Tag", "_Tag", "=", """true""", Nothing, Nothing)
End Sub
End Class
Unused Parameters
Parameter positions that are not used by a SCADA function must be written as:
- null for C#
- Nothing for VB
C#
BOOL result = SCADAFunctionRun("Script", "Script (1)", null, null, null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Script", "Script (1)", Nothing, Nothing, Nothing, Nothing)
Note: null / Nothing and an empty string (“”) are not the same. In some SCADA functions, the relevant parameter may need to be passed specifically as an empty string. The parameter structure defined in the Alarm function window must be preserved.
Using Values in SCADA Function Parameters
Some SCADA function parameters can accept:
- A SCADA tag name
- A constant value
- A variable value created or modified within the script
Therefore, the SCADA function must be able to distinguish whether the supplied parameter is a SCADA tag reference or a value to be used directly.
This distinction is one of the most important rules when using SCADA functions within scripts.
1. Using a SCADA Tag Value
If a SCADA tag name is written directly as a parameter, the current value of that tag in SCADA is used when the function is executed.
C#
BOOL result = SCADAFunctionRun("Tag", "BooleanTag_0", "=", "BooleanTag_1", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Tag", "BooleanTag_0", "=", "BooleanTag_1", Nothing, Nothing)
2. Using a Constant Value
If a constant value is to be passed directly to a parameter, the value must be sent to the SCADA function together with quotation mark characters.
A constant value written as “true” in the function window must be written as:
- C# script: “\”true\””
- VB script: “””true”””
This usage is not limited to Boolean values.
The same method can also be used for parameters that accept constant values such as numbers, text, recipe names, email addresses, or Notification targets.
Constant BOOL Value
C#
BOOL result = SCADAFunctionRun("Tag", "BooleanTag_0", "=", "\"true\"", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Tag", "BooleanTag_0", "=", """true""", Nothing, Nothing)
Constant Numeric Value
C#
BOOL result = SCADAFunctionRun("Tag", "_Tag", "=", "\"15\"", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Tag", "_Tag", "=", """15""", Nothing, Nothing)
Important: The purpose of using quotation marks is not to specify the data type. Quotation marks are used to indicate that the parameter should be treated as a direct value rather than as a SCADA tag reference.
3. Using the Value of a Variable Within the Script
If the current value of a variable created, calculated, or modified within the script is to be passed to a SCADA function, it must also be sent in constant value format.
In other words, the result of the variable must be enclosed in quotation marks.
C#
public class MainClass
{
public void Main()
{
UINT Value = (UINT)TagRead("BooleanTag_0");
Value++;
BOOL result = SCADAFunctionRun("Tag", "BooleanTag_0", "=", $"\"{Value}\"", null, null);
}
}
VB
Public Class MainClass
Public SCADAFunction As Object
Public Tag As Object
Public Sub Main()
Dim Value As Integer = CInt(Tag.Read("_Tag"))
Value += 1
Dim Result As Boolean = SCADAFunction.Run("Tag", "_Tag", "=", """" & Value.ToString() & """", Nothing, Nothing)
End Sub
End Class
Here, the current value of the Value variable within the script is passed to the SCADA function.
The same method can also be used for local variables created within the script.
C#
INT NewValue = 25;
BOOL result = SCADAFunctionRun("Tag", "_Tag", "=", $"\"{NewValue}\"", null, null);
VB
Dim NewValue As INT = 25
Dim result As BOOL = SCADAFunction.Run("Tag", "_Tag", "=", """" & NewValue.ToString() & """", Nothing, Nothing)
Difference Between a SCADA Tag Value and a Value Within the Script
The following two usages are not the same.
Using the Tag Value in SCADA
C#
BOOL result = SCADAFunctionRun("Tag", "BooleanTag_0", "=", "BooleanTag_1", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Tag", "BooleanTag_0", "=", "BooleanTag_1", Nothing, Nothing)
Here, BooleanTag_1 is treated as a SCADA tag reference. When the function is executed, the current value of the tag in SCADA is used.
Using the Value Within the Script
C#
BOOL result = SCADAFunctionRun("Tag", "BooleanTag_0", "=", $"\"{BooleanTag_1}\"", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Tag", "BooleanTag_0", "=", """" & BooleanTag_1.ToString() & """", Nothing, Nothing)
In this usage, BooleanTag_1 is a variable within the script, and its current value in the script is used.
This difference is especially important when the value is modified within the script.
For example, a tag value may be read at the beginning of the script and then modified in a local variable.
In this case:
“BooleanTag_1” uses the tag value on the SCADA side, while $"\"{BooleanTag_1}\"" uses the current value of the variable within the script.
Quick Usage Summary
|
Usage |
C# |
VB |
|---|---|---|
|
SCADA Tag Value |
“_Tag_1” |
“_Tag_1” |
|
Constant BOOL |
“\”true\”” |
“””true””” |
|
Constant Number |
“\”15\”” |
“””15″”” |
|
Script Variable |
$”\”{Value}\”” |
“””” & Value.ToString() & “””” |
Examples of Using SCADA Functions Within Scripts
1. Tag
The Tag function can be used to change the value of a SCADA tag.
Writing a Constant BOOL Value
C#
BOOL result = SCADAFunctionRun("Tag", "BooleanTag_0", "=", "\"true\"", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Tag", "BooleanTag_0", "=", """true""", Nothing, Nothing)
Writing a Constant INT Value
C#
BOOL result = SCADAFunctionRun("Tag", "_Tag", "=", "\"15\"", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Tag", "_Tag", "=", """15""", Nothing, Nothing)
Writing the Value of a Variable Within the Script
C#
INT Value = (INT)TagRead("_Tag");
Value++;
BOOL result = SCADAFunctionRun("Tag", "_Tag", "=", $"\"{Value}\"", null, null);
VB
Dim Value As Integer = CInt(Tag.Read("_Tag"))
Value += 1
Dim Result As BOOL = SCADAFunction.Run("Tag", "_Tag", "=", """" & Value.ToString() & """", Nothing, Nothing)
Writing the Value of One Tag to Another Tag
C#
BOOL result = SCADAFunctionRun("Tag", "_Tag", "=", "_Tag_1", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Tag", "_Tag", "=", "_Tag_1", Nothing, Nothing)
2. Screen
The Screen function can be used to open a screen, replace the current screen, open a Dialog, or close a screen.
Replacing the Current Screen
C#
BOOL result = SCADAFunctionRun("Screen", "Screen (1)", "", "Replace Existing", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Screen", "Screen (1)", "", "Replace Existing", Nothing, Nothing)
Opening a Screen in a New Window
C#
BOOL result = SCADAFunctionRun("Screen", "Screen (1)", "", "New Window", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Screen", "Screen (1)", "", "New Window", Nothing, Nothing)
Opening a Screen as a Dialog
C#
BOOL result = SCADAFunctionRun("Screen", "Screen (1)", "", "Dialog", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Screen", "Screen (1)", "", "Dialog", Nothing, Nothing)
Closing a Screen
C#
BOOL result = SCADAFunctionRun("Screen", "Screen", "", "Close", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Screen", "Screen", "", "Close", Nothing, Nothing)
Using a Screen Name from a Script Variable
The screen name can be obtained from a variable within the script.
C#
string Name = "Screen (1)";
BOOL result = SCADAFunctionRun("Screen", $"{Name}", "", "New Window", null, null);
VB
Dim Name As String = "Screen (1)"
Dim result As BOOL = SCADAFunction.Run("Screen", Name, "", "New Window", Nothing, Nothing)
Since the screen name is used directly in this parameter, it does not need to be converted to constant value format.
Getting the Screen Name from a Tag Value
C#
BOOL result = SCADAFunctionRun("Screen", "", "_Tag_3", "New Window", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Screen", "", "_Tag_3", "New Window", Nothing, Nothing)
In this usage, the value of the _Tag_3 tag determines the name of the screen to be opened.
Opening a Screen with Tag Binding
C#
BOOL result = SCADAFunctionRun("Screen", "Screen (1)", "", "New Window", "\"Tag_1,Tag_2,Tag_3\"", null);
VB
Dim result As BOOL = SCADAFunction.Run("Screen", "Screen (1)", "", "New Window", """Tag_1,Tag_2,Tag_3""", Nothing)
3. Script
The Script function is used to run another SCADA script.
Running with a Constant Script Name
C#
BOOL result = SCADAFunctionRun("Script", "Script (1)", null, null, null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Script", "Script (1)", Nothing, Nothing, Nothing, Nothing)
Getting the Script Name from a Tag Value
C#
BOOL result = SCADAFunctionRun("Script", null, "_Tag_3", null, null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Script", Nothing, "_Tag_3", Nothing, Nothing, Nothing)
In this usage, the value of the _Tag_3 tag determines the name of the script to be executed.
4. Email
The Email function can be used to send an email using an Email configuration defined in Wise SCADA.
The following are specified through the function parameters:
- Recipient address
- Subject content
- Body content
The subject and body contents are prepared in JSON format and passed to the Email function.
Using JSON in C#
The following namespace must be added at the top of the C# script:
using Newtonsoft.Json;
Preparing the Subject Content
var SubjectContents = new[]
{
new
{
Header = "Email_Title",
Tag = "",
Information = "d1"
}
};
Preparing the Body Content
var BodyContents = new[]
{
new
{
Header = "Header123",
Tag = "_Tag",
Information = "Text123"
},
new
{
Header = "Header456",
Tag = "_Tag_1",
Information = "Text456"
}
};
When a SCADA tag name is entered in the Tag field, the value of the corresponding tag can be used in the email content.
The Header and Information fields can be used to define constant text to be included in the email content.
Each { ... } block inside BodyContents represents a separate line in the email body. If multiple lines are defined, a comma (,) must be placed between each line block. If only one line is defined, no comma is used.
Creating the JSON Data
The prepared subject and body contents are converted to JSON format:
string SubjectJson = JsonConvert.SerializeObject(SubjectContents);
string BodyJson = JsonConvert.SerializeObject(BodyContents);
The generated SubjectJson and BodyJson values are then passed to the Email function as parameters.
Sending an Email to a Constant Recipient Address
If the recipient address is entered as a constant value, the address must be passed to the SCADA function together with quotation mark characters.
C#
BOOL result = SCADAFunctionRun("Email", "Email_1", "\"xxx@gmail.com\"", SubjectJson, BodyJson, null);
VB
Dim result As BOOL = SCADAFunction.Run("Email", "Email_1", """xxx@gmail.com""", SubjectJson, BodyJson, Nothing)
Here:
- “Email_1” specifies the name of the Email configuration to be used,
- “\”xxx@gmail.com\”” specifies the constant recipient address,
- SubjectJson specifies the email subject,
- BodyJson specifies the email body.
Getting the Recipient Address from a Tag Value
If the recipient email address is stored in a SCADA tag, the corresponding tag name can be used directly as the parameter.
C#
BOOL result = SCADAFunctionRun("Email", "Email", "\"xxx@gmail.com\"", SubjectJson, BodyJson, null);
VB
Dim result As BOOL = SCADAFunction.Run("Email", "Email", """xxx@gmail.com""", SubjectJson, BodyJson, Nothing)
In this usage, _Tag_3 is treated as a SCADA tag reference, and the current value of the tag is used as the recipient email address.
5. Notification
The Notification function can be used to send notifications using Notification configurations defined in Wise SCADA.
The message body is prepared in JSON format:
C#
var BodyContents = new[]
{
new
{
Header = "Header123",
Tag = "_Tag",
Information = "Text123"
},
new
{
Header = "Header456",
Tag = "_Tag_1",
Information = "Text456"
}
};
string BodyJson = Newtonsoft.Json.JsonConvert.SerializeObject(BodyContents);
VB
Dim BodyContents = New Object() {
New With {
.Header = "Header123",
.Tag = "_Tag",
.Information = "Text123"
},
New With {
.Header = "Header456",
.Tag = "_Tag_1",
.Information = "Text456"
}
}
Dim BodyJson As String = Newtonsoft.Json.JsonConvert.SerializeObject(BodyContents)
Telegram
Sending a Telegram Notification to a Constant Target
C#
BOOL result = SCADAFunctionRun("Notification", "Telegram", "\"180****581\"", BodyJson, null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Notification", "Telegram", """180****581""", BodyJson, Nothing, Nothing)
Here:
- “Telegram” specifies the Notification configuration to be used,
- “\”180****581\”” specifies the constant target information (Group ID or Chat ID),
- BodyJson specifies the message content to be sent.
Getting the Target Information from a Tag Value
C#
BOOL result = SCADAFunctionRun("Notification", "Telegram", "_Tag_3", BodyJson, null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Notification", "Telegram", "_Tag_3", BodyJson, Nothing, Nothing)
SMS
Sending an SMS Notification to a Constant Target
C#
BOOL result = SCADAFunctionRun("Notification", "SMS", "\"YourPhoneNumber\"", BodyJson, null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Notification", "SMS", """YourPhoneNumber""", BodyJson, Nothing, Nothing)
Here:
- “SMS” specifies the Notification configuration to be used,
"\"YourPhoneNumber\""specifies the constant phone number,- BodyJson specifies the message content to be sent.
Getting the Target Information from a Tag Value
C#
BOOL result = SCADAFunctionRun("Notification", "SMS", "_Tag_3", BodyJson, null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Notification", "SMS", "_Tag_3", BodyJson, Nothing, Nothing)
6. Report
The Report function can be used to generate a defined report and, when required, send it by email.
Generating a Report
C#
BOOL result = SCADAFunctionRun("Report", "Report", null, null, null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Report", "Report", Nothing, Nothing, Nothing, Nothing)
Sending the Report to a Constant Email Address
C#
BOOL result = SCADAFunctionRun("Report", "Report", "Email", "\"xxx@gmail.com\"", -1, null);
VB
Dim result As BOOL = SCADAFunction.Run("Report", "Report", "Email", """xxx@gmail.com""", -1, Nothing)
Getting the Recipient Address from a Tag Value
C#
BOOL result = SCADAFunctionRun("Report", "Report", "Email", "_Tag_3", -1, null);
VB
Dim result As BOOL = SCADAFunction.Run("Report", "Report", "Email", "_Tag_3", -1, Nothing)
In this usage, the value of the _Tag_3 tag is used as the email address to which the report will be sent.
7. Print
The Print function can be used to print an entire screen or a specific control on the screen.
Printing a Specific Control
C#
BOOL result = SCADAFunctionRun("Print", "Default", "Portrait", "96", "Screen", "Button_0");
VB
Dim result As BOOL = SCADAFunction.Run("Print", "Default", "Portrait", "96", "Screen", "Button_0")
In this example, the Button_0 control on the Screen screen is printed.
Printing the Entire Screen
C#
BOOL result = SCADAFunctionRun("Print", "Default", "Portrait", "96", "Screen", null);
VB
Dim result As BOOL = SCADAFunction.Run("Print", "Default", "Portrait", "96", "Screen", Nothing)
Since the last parameter is not used, the entire specified screen is printed.
8. Recipe
The Recipe function can be used to load, save, or delete recipe records.
The record name can be specified as a constant value or obtained from the value of a SCADA tag.
Getting the Record Name from a Tag Value
Load
C#
BOOL result = SCADAFunctionRun("Recipe", "Symbol", "_Tag", "Load", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Recipe", "Symbol", "_Tag", "Load", Nothing, Nothing)
Delete
C#
BOOL result = SCADAFunctionRun("Recipe", "Symbol", "_Tag", "Delete", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Recipe", "Symbol", "_Tag", "Delete", Nothing, Nothing)
Save
C#
BOOL result = SCADAFunctionRun("Recipe", "Symbol", "_Tag", "Save", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Recipe", "Symbol", "_Tag", "Save", Nothing, Nothing)
Using a Constant Record Name
The constant record name is passed to the SCADA function together with quotation mark characters.
Load
C#
BOOL result = SCADAFunctionRun("Recipe", "Symbol", ""name"", "Load", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Recipe", "Symbol", """name""", "Load", Nothing, Nothing)
Delete
C#
BOOL result = SCADAFunctionRun("Recipe", "Symbol", ""name"", "Delete", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Recipe", "Symbol", """name""", "Delete", Nothing, Nothing)
Save
C#
BOOL result = SCADAFunctionRun("Recipe", "Symbol", ""name"", "Save", null, null);
VB
Dim result As BOOL = SCADAFunction.Run("Recipe", "Symbol", """name""", "Save", Nothing, Nothing)
