You can use C# code in a project to test the code and integrate third-party .NET libraries.
A NetLogic object contains C# code to execute at runtime or design time.
You can use the following NetLogic templates:
- Runtime NetLogic
- Develop runtime logic linked to the lifecycle of the node that contains it.TIP: The lifecycle of a runtime NetLogic (or its existence at runtime) is equivalent to the lifecycle of the node that contains it. It exists from the time the parent node is created (for example, a Panel object) to the time when the same node is removed. TheStart()andStop()methods represent node creation and removal in the C# code of a NetLogic. In these methods, you can define the logics to be executed at runtime when the parent node is created and removed.
- Define new OPC UA methods. SeeMethods and events in C# .TIP: The OPC UA methods are exposed by NetLogic and can be referenced at any point of the project at design time. The OPC UA methods can then be invoked at runtime according to the project logic or by an OPC UA client.
- Design-time NetLogic
- Enables you to develop scripts to execute at design time to automate specific operations. For example, you can implement a script that reads a CSV file that contains 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 at design time. When a NetLogic object is renamed, the corresponding contained C# class is renamed.
IMPORTANT: To change the name of the class, rename the NetLogic in
FactoryTalk Optix Studio. Do
notchange the name of the class in the code as this would compromise its operation.
For example, a
PanelLogicNetLogic contains this declaration that defines the
public class PanelLogic : BaseNetLogic
TIP: The class in a NetLogic is always derived from the
BaseNetLogicclass. The base class supplies the most of the methods to NetLogic, including the
All C# classes are grouped in a .NET project created and automatically updated.
You can create NetLogic objects in any node of the information model, inside or outside a type.
- In a type
- At runtime, the NetLogic exists in each instance of the type (for example, in aMotorType) until the instance is removed.
- Outside a type
- At runtime, the NetLogic is created at project start and deleted at project closure. For example, inside a folder, inside other instances, or inside the root node of the project.
FactoryTalk Optix Studiofollows the object-oriented programming principles. This means that context and Session are important when creating and accessing objects. To interact with graphic objects, you can add custom NetLogics as children of these objects.
NetLogic security warning
The NetLogic security warning displays if the project NetLogics reference .NET assemblies that may be critical for the project security when you deploy the project, run the project, or execute design-time NetLogics.
The .NET assemblies that are critical for the project security belong to these categories:
- I/O operations on the filesystem
- Execution of external processes and tracing
- Network communication
- C# reflection
- Invocation of external default libraries
- Security and cryptography
The NetLogic security warning also includes information about any NuGet packages and third-party .NET assemblies used and referenced by the C# code in the project.
TIP: If you are familiar with the C# code in the project, you can select
Do not show this warning againto prevent the NetLogic security warning from displaying when you deploy the project, run the project, or execute design-time NetLogics.
Have questions or feedback about this documentation? Please submit your feedback here.