Hi, for some reason, we don't have the reporting module so we made a python script that makes a report, it works perfectly. I want to press a button to execute the script but, when I try to pass the script to igntion I realize that the script is in python 3, I try to download the python version but it does not work, can I execute the script outside of igntion? I saw that the system.util.execute
could work but I do not know if I can place it on a button in perspective. If it is impossible what other options would I have to make the reports without the module?
If you only need a single report, you can buy a 1-report version that's much cheaper than the full reporting module as listed on the pricing page. In fact, I believe you can license the reporting module just like the clients where you can buy anywhere from 1-5 reports or unlimited, but the pricing page only shows the unlimited reporting module price.
But, with that said, you'll have to send a message to the gateway so that the gateway can execute your script externally if you want to stick with the Python 3 implementation.
Perspective runs on the gateway, so you can execute scripts there. I prefer using subprocess
library. I like getting feedback that my script ran fully, and the .check_output
option redirects the console to your function. I am not calling python3 in my use-case but it should work fine assuming you have that installed in the OS. If you can run it from the command line then calling from Perspective should work fine. The following psuedo-code is what I current run:
import subprocess
def yourFunc():
yourCommand = "<scriptname> <arg1> <arg2> ..."
response = str(subprocess.check_output(yourCommand, shell=True))
then inspect the response string for errors, etc.
You should not use this. It will fail with internationalized strings in your pipes. Use Java's ProcessBuilder
instead. (Same basic functionality, without the broken [expletive].)
Hello, thank you for your reply
I have tried but I have not been able, I have not programmed with java in ignition and I do not know how it works, could you help me with the pseudo code to run the python file.
A variety of examples to study:
First thing that pops to mind is using some external reporting tools or implementing a custom module, but that relies on Java so I suppose it's not for you.
You could try what you already mentioned, which is using system.util.execute()
. I would structure it in the following way:
def scriptExec():
script_path = "[path_to_script]"
result = system.util.execute(["python3", script_path])
print(result)
Place an action handler on the click of a button with the above script.
There's no result returned from system.util.execute()
. Which is why there were suggestions to use jython's subprocess
(Eww!) and Java's ProcessBuilder
.
Java classes can be used directly in jython scripting with appropriate imports. No custom module required.