NetLogic¶
Introduction
Q Studio enables development of customized runtime and design time logics written in C# language. At runtime, using these logics, it is possible to run operations in the information model (for example change the value of a variable when another variable changes status) or outside the information model (for example send an e-mail when a specific variable changes status).
To develop these logics, special objects called NetLogic are used.
What is a NetLogic
A NetLogic is an object that contains C# code to execute at runtime or design time. The following templates are available:
Runtime NetLogic, to create runtime logics linked to the life cycle of the node that contains it (see Logics related to the life cycle of a node) or to define new OPC UA methods (see Define an OPC UA method in C#).
Note
the OPC UA methods, unlike C# methods, are exposed by NetLogic and can be referenced in any point of the Q Studio project at design time. They can then be invoked at runtime according to the project logics or by a OPC UA client.
Design time NetLogic, to create scripts to execute at design time to automate specific operations (for example read a CSV file containing alarm descriptions to write automatically in the project).
NetLogic and C# classes
A NetLogic contains a C# class with the same name in its code, automatically created by Q Studio at design time. When a NetLogic object is renamed, Q Studio also automatically renames the corresponding contained C# class.
Warning
To change the name of this class, rename the NetLogic in Q Studio. Do not change the name of the class in the code as this would compromise its operation.
For example, a NetLogic called PanelLogic contains the following declaration which defines the PanelLogic
class:
public class PanelLogic : BaseNetLogic
Note
the class in a NetLogic is always derived from the Q Platform BaseNetLogic
class, i.e. the base class that supplies most of the methods to NetLogic, including the Start
and Stop
methods (see Runtime NetLogic structure).
All C# classes are grouped in a .NET project created and automatically updated by Q Studio (see Projects on the File System).
Logics related to the life cycle of a node
The life cycle of a runtime NetLogic, i.e. its existence at runtime, is equivalent to the life cycle of the node that contains it. Therefore, it exists from the time the parent node is created (for example a Panel object) to the time when the same node is removed. These two moments are represented in the C# code of a NetLogic by the Start()
and Stop()
methods. In these methods it is therefore possible to define the logics to be executed at runtime when the parent node is created and deleted.
Where to create a NetLogic
NetLogics can be created in any node of the information model. In general, there are two possible positions with different effects at runtime:
In a type (for example in a
MotorType
). In this case, at runtime the NetLogic exists in each instance of the type until the same instance is deleted.Outside a type (for example, inside a folder, inside other instances, inside the root node of the project). In this case, at runtime the NetLogic is created at project start and deleted at project closure.