Step 1
. Create a Simple Text ReportWe'll create a shift report showing tank status.
- Navigate to Reports → Forms
- Click first row to add new form
- Configure:
- Name:
ShiftReport
- SaveFormat:
Text
- SaveFileName:
C:/Reports/Shift.txt
- Press Enter
2. Design Report Content
- Go to Reports → Forms Editor
- Double click
ShiftReport
- Enter the report template below, then Save the report:
================================
TANK FARM SHIFT REPORT
Date: {Server.DateTimeInfo.Date}
Time: {Server.DateTimeInfo.Time}
================================
TANK STATUS SUMMARY
-------------------
Tank 1:
Level: {Tag.TankFarm/Tank1/Level} ft
Temperature: {Tag.TankFarm/Tank1/Temp} °F
Pressure: {Tag.TankFarm/Tank1/Pressure} PSI
Status: {Tag.TankFarm/Tank1/Status}
Tank 2:
Level: {Tag.TankFarm/Tank2/Level} ft
Temperature: {Tag.TankFarm/Tank2/Temp} °F
Pressure: {Tag.TankFarm/Tank2/Pressure} PSI
Status: {Tag.TankFarm/Tank2/Status}
PRODUCTION METRICS
------------------
Total Volume: {Tag.TankFarm/Metrics/TotalVolume} gal
Flow Rate: {Tag.TankFarm/Metrics/FlowRate} gpm
Daily Production: {Tag.TankFarm/Metrics/DailyProduction} gal
================================
End of Report
3. Test Report Generation
- Start runtime
- Open PropertyWatch
- Go to List2 and type: Report.Form.ShiftReport.Save
- Change the value from 0 to 1
- Check the folder to see generated report
4. Schedule Automatic Reports
Create scheduled task for shift reports:
- Go to Reports → Forms
- Change the SaveTrigger to: Server.Hour
- The report will be generated every hour once the solution is running.
5. Monitor Report Status
: Installation and Setup
The Python Shell integration requires Python releases 3.7 onwards and the installation of Python.NET.
- You can download Python here.
- Check the User admin privileges checkbox, and select Customize installation.
Image Added
- During the installation of the Python Engine,select the option to “Install for all users”.
Image Added
- 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. - Install with admin rights to all users,
- Customize the installation to installation in the Program Files, instead of Users folder
|
- 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.
Image Added
- Go to Solution / Settingsand locate the Python Interpreter box. Click the "..." button, navigate to find the installed Python Engine, and select the python.exe file.
Image Added
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. |
Step 2: Using Python in the Solution
Scripts Tasks and Classes
- Scripts / Tasks: Event driven or periodical tasks, running on the server computer. They can be written in Python, C# or VB.NET.
- Scripts / Classes: library of methods and functions that can be used on both server and client machines. They can be written in Python, C# or VB.NET.
Displays CodeBehind and Graphical Elements
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.
2.1 Shell Integration
- Shell Integration allows you to execute Python code from external files.
In order to achieve that, follow the steps below:
- Go to your solution folder (the folder where your solution is located) and add a script with the name "ExternalSum.py"
- In this file, add the following code:
Code Block |
---|
language | py |
---|
firstline | 1 |
---|
title | ExternalSum |
---|
linenumbers | true |
---|
|
import sys
value1 = float(sys.argv[1])
value2 = float(sys.argv[2])
result = value1 + value2
print(result) |
- Create a Script → Task and choose Python as the language
- Add a trigger task into the Trigger column
- Create the following tags:
- Tag1 - Integer
- Tag2 - Integer
- TagResult - Integer
- In your task, use the following script:
Code Block |
---|
language | py |
---|
firstline | 1 |
---|
title | ExternalSum |
---|
linenumbers | true |
---|
|
arg1 = @Tag.Tag1(0)
arg2 = @Tag.Tag2(0)
result = TK.ExecutePythonShell("_ExecutionPath_ExternalSum.py", [arg1, arg2])
@Tag.Result(0) = result |
- Run your solution and use Property Watch to change the values and see the results (don't forget to run the task trigger)
2.2 Standard Integration
- Standard Integration allows you to execute Python code in FrameworX script task.
In order to achieve that, follow the steps below:
- Create a Script → Task and choose Python as the language
- Add a trigger task into the Trigger column
- Create the following tags:
- Tag1 - Integer
- Tag2 - Integer
- TagResult - Integer
- In your task, use the following script:
Code Block |
---|
language | py |
---|
firstline | 1 |
---|
title | Internal Sum |
---|
linenumbers | true |
---|
|
def add(val1, val2):
return val1 + val2 |
- Run your solution and use Property Watch to change the values and see the results (don't forget to run the task trigger)
2.3 Python and .NET Integration
- Python and .NET Integration allows a Python function directly from Python Class on the code editor.
In order to achieve that, follow the steps below:
- Create a Script → Task and choose CSharp as the language
- Add a trigger task into the Trigger column
- Create the following tags:
- Tag1 - Integer
- Tag2 - Integer
- TagResult - Integer
- In your task, use the following script:
Code Block |
---|
language | c# |
---|
firstline | 1 |
---|
title | Python and .NET |
---|
linenumbers | true |
---|
|
@Tag.Result = TK.ToInt( @Script.Class.ClassPython.sum(@Tag.Tag1, @Tag.Tag2) ); |
- Run your solution and use Property Watch to change the values and see the results (don't forget to run the task trigger)
Excerpt Include |
---|
| Python and .NET Integration |
---|
| Python and .NET Integration |
---|
nopanel | true |
---|
|
During runtime, open Reports → Reports MonitorVerify report status:- Name: ShiftReport
- LastStatus: 0
- SavedFileName: Shows generated file path
Check for any errors in LastStatusMessage