How to Use python script in WinCC OA as a extended library

Discussion about recent product features & solutions!
8 posts • Page 1 of 1
saurabhltts
Posts:12
Joined: Fri Nov 11, 2016 11:25 am

How to Use python script in WinCC OA as a extended library

Post by saurabhltts »

I want to integrate python script in WinCC OA as a extended library.
The main objective that I want to run python functionality in WinCC OA as a extended library. I am sure WinCC OA 3.15 version can do that. I have WinCC OA 3.15 version.

kindly provide me possible ways to do that.

Your timely feedback highly appreciated.

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: How to Use python script in WinCC OA as a extended library

Post by mkoller »

You need to create a CTRL extension. Check the install/api directory and the README file.
There is a script called newWCCILCtrlExt.sh you can use to create
a template/example extension.

saurabhltts
Posts:12
Joined: Fri Nov 11, 2016 11:25 am

Re: How to Use python script in WinCC OA as a extended library

Post by saurabhltts »

Do I need to create every function of python or is the file readily available?

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: How to Use python script in WinCC OA as a extended library

Post by mkoller »

Nothing regarding python is available.
Whatever you need from python must be implemented by you.

vogler
Posts:122
Joined: Thu Oct 28, 2010 8:32 am

Re: How to Use python script in WinCC OA as a extended library

Post by vogler »

Hi,
what is your primary use case?
*) Do you have a Pyhton program which needs to have access to OA? (dpGet,dpSet,dpConnect,...)
*) Or is your main program OA (ctrl or ui) and you want to call some python code? (and pass data in/out)
regards,
Andreas

saurabhltts
Posts:12
Joined: Fri Nov 11, 2016 11:25 am

Re: How to Use python script in WinCC OA as a extended library

Post by saurabhltts »

my primary use case would be,

main program OA (ctrl or ui) and i want to call some python code? (and pass data in/out)

vogler
Posts:122
Joined: Thu Oct 28, 2010 8:32 am

Re: How to Use python script in WinCC OA as a extended library

Post by vogler »

I found "Jython", so i gave it a try to use this in a JavaManager... a bit strange solution, but it works.

maybe same can be done with the WinCC OA C# Manager and Python for .NET (http://pythonnet.sourceforge.net/readme.html)

a dpConnect to two datapoints, the summary is calculated with a python script which is executed by Jython in Java.

Code: Select all

public void run() {
        PythonInterpreter python = new PythonInterpreter();

        JDebug.out.info("dpConnect...");
        JDpConnect conn = JClient.dpConnect() // dpConnect in Java
                .add("ExampleDP_Arg1.")
                .add("ExampleDP_Arg2.")
                .action((JDpHLGroup hotlink)->{
                        JDebug.out.info("--- HOTLINK BEG ---");
                        JDebug.out.info(hotlink.toString());

                        Double n1 = hotlink.getItem(0).getVariable().getFloatVar().getValue();
                        Double n2 = hotlink.getItem(1).getVariable().getFloatVar().getValue();

                        JDebug.out.info("n1="+n1+" n2="+n2);

                        python.set("number1", new PyFloat(n1));
                        python.set("number2", new PyFloat(n2));
                        python.exec("number3 = number1+number2"); // this is the very simple python script
                        PyObject n3 = python.get("number3");

                        JDebug.out.info("result from python n3="+n3);
                        JDebug.out.info("--- HOTLINK END ---");
                })
                .connect();

WCCOAjava1:2017.06.06 13:01:52.616 Main.lambda$run$0 INFO : --- HOTLINK BEG ---
WCCOAjava1:2017.06.06 13:01:52.617 Main.lambda$run$0 INFO : DpIdValueList: 2
WCCOAjava1:System1:ExampleDP_Arg1.:_online.._value: 1.0 [FloatVar]
WCCOAjava1:System1:ExampleDP_Arg2.:_online.._value: 2.0 [FloatVar]
WCCOAjava1:2017.06.06 13:01:52.617 Main.lambda$run$0 INFO : n1=1.0 n2=2.0
WCCOAjava1:2017.06.06 13:01:52.621 Main.lambda$run$0 INFO : result from python n3=3.0
WCCOAjava1:2017.06.06 13:01:52.622 Main.lambda$run$0 INFO : --- HOTLINK END ---

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: How to Use python script in WinCC OA as a extended library

Post by mkoller »

I'd be keen to know what python code you'd like to execute and why you do not use CTRL directly.
Are you using any special python libraries ?
Can you give an example, please ?

8 posts • Page 1 of 1