Integration Philosophy: FrameworX provides true bidirectional integration between Python and .NET, not just Python scripting capability. This design leverages Python's extensive data science libraries while maintaining .NET's performance and reliability for industrial control.
The platform requires Python 3.7 or later, delivering significant performance improvements over Python 2. According to Python.org benchmarks, Python 3 runs approximately 10-30% faster than Python 2 in most scenarios, with some operations seeing 5x improvements.
Table of Contents maxLevel 2 minLevel 2 indent 10px style none
Language | Best For | Performance | Key Features |
---|---|---|---|
C# | Complex logic, performance-critical operations | Excellent | Full .NET access, strongly typed, IntelliSense |
Python | Data analysis, ML integration | Good | Extensive libraries, NumPy/Pandas support |
Python code runs within FrameworX's Script Tasks and Classes, with full access to tags and namespaces:
# Python accessing FrameworX tags
@Tag.Temperature = @Tag.SetPoint + 5
result = ProcessData(@Tag.ProductionRate)
Execute external Python files while maintaining tag access:
result = TK.ExecutePythonShell("analytics.py", [@Tag.Input1, @Tag.Input2])
@Tag.Result = result
Info | ||
---|---|---|
| ||
When the editor is used to edit Script Tasks, you can test the scripts directly, using the Play button at the Task name line. The results of your code will show in the standard Designer output. |
3. Cross-Language Calls
C# calling Python:
// C# code calling Python class
var result = @Script.Class.PythonAnalytics.ProcessML(data);
Python calling C#:
# Python code calling C# method
result = @Script.Class.CSharpLogic.Calculate(param1, param2)
Python code accesses FrameworX objects directly through the same '@' notation used in C#:
No marshaling, conversion, or intermediate layers, Python operates on the same objects as .NET code.
Each solution specifies its Python interpreter, enabling:
# Use scikit-learn for anomaly detection
from sklearn.ensemble import IsolationForest
model = IsolationForest()
data = GetHistorianData(@Tag.Equipment)
anomalies = model.fit_predict(data)
# Pandas for production analytics
import pandas as pd
df = pd.DataFrame(@Dataset.Query("SELECT * FROM Production"))
daily_avg = df.groupby('Day')['Output'].mean()
@Tag.DailyAverage = daily_avg.iloc[-1]
# Implement proprietary protocol
import struct
packet = struct.pack('>HH', @Tag.DeviceID, @Tag.Command)
response = SendCustomProtocol(packet)
@Tag.Response = struct.unpack('>H', response)[0]
Operation Type | Recommended | Reason |
---|---|---|
Real-time control loops | C# | Deterministic execution, minimal latency |
Statistical analysis | Python | NumPy/Pandas optimized C libraries |
Tag calculations | C# | Direct memory access, no interpreter |
Machine learning inference | Python | Scikit-learn, TensorFlow ecosystems |
Database operations | Either | Both have excellent SQL support |
Excerpt |
---|
Python and .NET Integration LinksExplanation - to understand concepts→ Platform / Technology Foundation / Python and .NET Integration Tutorials - to learn by doing→ Tutorials / Technology Learning / Python and .NET Integration Reference - technical details→ Technical Reference / Programming and APIs Reference / Python and .NET Integration |
Page Tree | ||||
---|---|---|---|---|
|
The platform includes a unique set of features for Python integration:
On this page:
Table of Contents | ||||
---|---|---|---|---|
|
The Python Shell integration requires Python releases 3.7 onwards and the installation of Python.NET.
Setup Steps:
1. Install Python and Python.NET in the machines where you run the application and on those using the Solution Designer.
2. Configure the Solution Settings to select the appropriate Python shell folder.
Each solution can specify its own Python interpreter, facilitating the development and maintenance of different solutions that may require different Python versions.
title | Click here to expand on how to Install Python |
---|
You can download Python here.
Check the Use admin privileges checkbox, and select Customize installation.
During the installation of the Python Engine,select the option to “Install for all users”.
If You install Python under your local user, you may have issues when running the solution as a service, or when deploying the solution for production.
Tip |
---|
This image may be slightly different for your Python version, but always enable the options equivalent to:
Especially in the production server.
|
Once you've downloaded, open the command prompt as an ADMINISTRATOR and type “pip install pythonnet”. For this work, you'll need internet access. If internet is not available, download and install manually.
Once Python.NET has been installed, you can start using Python in your solution.
Note |
---|
Note: For Python versions above 3.12, Pythonnet is not available. For more information, visit their documentation. |
title | Click here to expand on how the setup the Python location in the Designer |
---|
Python Interpreter | |
---|---|
Local | Defines the path of the Python installation folder on the local machine. |
Server | Defines the path of the Python installation folder on the remote server. |
Once you've installed Python, you can take a look at our Python demo with code examples.
→ Learn more at Python Example.
The Python Example illustrates how to use the Python and .NET languages for the Scripts.
This section presents a summary of that information, listing the modules in the solution where Python code can be used.
The Code Behind for the displays can be written in C#, VB.NET or JavaScript, not Python directly. But from the CodeBehind you can call tasks and methods, which can be written in Python.
This integration allows you to execute Python code from external files. Just create a Script Task with the following code:
Code Block | ||||
---|---|---|---|---|
| ||||
# This code call the execution of the external file using Python Shell
# with the optional args defined in this initial section
#
# The macro _ExecutionPath_ is replaced by the path where the solution is set to execute
# Replace that macro by a specific path, or user other built-in macros as nedded
#
arg1 = @Tag.Tag1
arg2 = @Tag.Tag2
result = TK.ExecutePythonShell("_ExecutionPath_ExternalSum.py", [arg1, arg2])
@Tag.Result = result |
Tip | ||
---|---|---|
| ||
Any Python scripts you create in Scripts / Tasks can be edited and tested in Scripts / Code Editor. To test your script, click on [Monitor Icon] in the top toolbar. This will run your code and display messages in the Output Window, under the script editor. This integration will work if your Python version is 3.7 or newer, with Python.NET installed, and the executable is correctly mapped in Solution / Settings. |
The code editor can be accessed through Scripts / Code Editor.
When the editor is used to edit Script Tasks, you can test the scripts directly, using the Play button at the Task name line. The results of your code will show in the standard Designer output.
The access to tags and other properties for other models is exactly the same as C# or VB.NET; just use the '@' symbol to access the properties directly, as shown in the image: '@Tag.Tag1'.
In the Script, or in any place in your solution where Expressions are allowed, you can use the following syntax to call classes.
Code Block | ||
---|---|---|
| ||
@Script.Class.TestClass.ExempleMethod(param1, param2) |
This activation is independent of the language the class was created in.
This means C# and VB.NET can call Python classes, and Python code can call .NET classes.
In this section:
Page Tree | ||
---|---|---|
|