Skip to main content
Version: 5.3

.NET C# Script Editor

In addition to standard operating functions (copy, paste, cut, undo, save), the editor offers some special functions:

  • "File - Save externally" Menu: Saves the script as an XML file with header data, code and parameter definitions. It is also possible to open such XML files and thus import scripts.
  • "Settings - Edit parameters" Menu: This is where you create the required parameters and variables (see Transfer object scripts and trigger scripts).
  • "Settings - Edit comment" Menu: The comment is displayed in the script list of the plug-in.
  • "F6" Key: Compiles and tests the programme for errors.

On the right-hand side of the window you will find a graphical programming aid for OPC accesses, variables, from the OPC Router configuration, log messages and parameters.

  • Double-click on an entry and the corresponding prepared line of code will be inserted. Entries can be written as string (in inverted commas) or as a pre-assigned variable.

Indications on OPC zero values

If you have ticked "Transfer OPC zero values" in the OPC UA plug-in, the corresponding values of the data points are always transferred if they are zero.

If the box is not ticked and the "Quality" of the data point is not "Good", the value is not transferred again and the connection runs on error.

If the tick is not set and the "Quality" of the data point is "Good" and the value is zero, then zero is transferred.

OpcAccess.Read

Reads out the value of an OPC item.

Object <myValue\> = OpcAccess.Read("<ItemPath\>", "<OPCServerName\>")
  • Return: Object
  • ItemPath: Access path and name of the item.
  • OPCServerName: Name of the OPC connection in the router project.

OpcAccess.ReadMultiple

Reads out the value of multiple OPC items.

List<string> <lItemNames\> = new List<string> ();

<lItemNames\>.Add ("<ItemPath.ItemName1\>");
<lItemNames\>.Add ("<ItemPath.ItemName2\>");
...

Dictionary<string,object> <MyValues\> = OpcAccess.ReadMultiple(<lItemNames\>, "<OPCServerName\>");
  • Return: Dictionnary <string>
  • ItemPath: Access paths and item names as a list.
  • OPCServerName: Name of the OPC connection in the router project.

OpcAccess.Write

Writes a value to an OPC item.

OpcAccess.Write ("<ItemPath\>", <objValue\>, "<OPCServerName\>")
  • Return: None
  • ItemPath: Access path and name of the item.
  • objValue: Value to write.
  • OPCServerName: Name of the OPC connection in the router project.

OpcAccess.WriteMultiple

Writes multiple values to multiple OPC items.

Dictionary<string,object> <dicItemsToWrite\> = new Dictionary<string,object> ();
<dicItemsToWrite\>.Add("<ItemPath.ItemName1\>", <Value1\>);
<dicItemsToWrite\>.Add("<ItemPath.ItemName2\>", <Value2\>);
...
OpcAccess.WriteMultiple(<dicItemsToWrite\>, "<OPCServerName\>")
  • Return: None.
  • dicItemsToWrite: Dictionnary with items and values.
  • OPCServerName: Name of the OPC connection in the router project.

OpcAccess.Browse

Provides the option of performing a browse (object search) for OPC DA and UA connections.

ItemPath: Access path and name of the item.

OPCServerName: Name of the OPC connection in the router project.

Various queries are available to you :

OpcAccess.Browse(ItemPath, ServerName).Select(e => e.DisplayName).ToArray()
  • Return: Specifies the names of the tags from this OPC path.
OpcAccess.Browse(ItemPath, ServerName).Select(e => e.NodeKind.ToString()).ToArray()
  • Return: Returns the type of tags from this OPC path.
OpcAccess.Browse(ItemPath, ServerName).Select(e => e.Identifier).ToArray()
  • Return: Returns the name of the tags with full path.
OpcAccess.Browse(ItemPath, ServerName).Select(e => e.HasChildren).ToArray()
  • Return: Returns wether the tags still have sub-objects (childs).
warning

Important: To search for OPC objects, the usings "Using System.Linq;" and the assembly reference "System.Core.dll" must be specified.

VariableAccess.Read

Reads the value of a variable from the OPC Router project. This only refers to variables that were created via the variable plug-in, that means no placeholders in templates, mail objects or similar. If the variable does not exist, NULL is returned.

Object <myValue\> = VariablesAccess.Read("<VariableName\>")
  • Return: Object.
  • VariableName: Variable name in the OPC Router project.

VariableAccess.Write

Assigns a value to a variable of the OPC Router project. This only refers to variables that have been created via the variable plug-in, that means no placeholders in templates, mail objects or similar. If the variable does not exist it is created again.

VariablesAccess.Write("<VariableName\>", Value)
  • Return: None.
  • VariableName: Variable name in the OPC Router project.
  • Value: Value that is assigned, Object.

Log

Write a message in the log file.

Log("<strMessage\>", MessageType.<LogLevel\>)
  • Return: None.
  • strMessage: Message to write.
  • LogLevel: Log level to write. If the corresponding log level is deactivated, no logging takes place. MessageType.All logs in any case, regardless of the router configuration.