Updated python example
authorLaurent Bessard
Mon, 13 May 2013 14:36:54 +0200
changeset 1125 1b1472e76f07
parent 1124 b1705000eba1
child 1126 26baa0ae9fd7
Updated python example
tests/python/c_code@c_ext/cfile.xml
tests/python/python@py_ext/pyfile.xml
--- a/tests/python/c_code@c_ext/cfile.xml	Mon May 13 14:31:23 2013 +0200
+++ b/tests/python/c_code@c_ext/cfile.xml	Mon May 13 14:36:54 2013 +0200
@@ -1,14 +1,16 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<CodeFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="codefile.xsd">
+<CFile>
   <includes>
-<![CDATA[#include "stdio.h"]]>
+<![CDATA[
+]]>
   </includes>
   <variables>
     <variable name="TestInput" type="SINT" initial="0"/>
     <variable name="TestOutput" type="SINT"/>
   </variables>
   <globals>
-<![CDATA[volatile long Lock=0;
+<![CDATA[
+volatile long Lock=0;
 volatile char PtoC=1,CtoP=2;
 
 extern long AtomicCompareExchange(long*,long, long);
@@ -45,21 +47,27 @@
       return 1;
   }
   return 0;
-}]]>
+}
+]]>
   </globals>
   <initFunction>
-<![CDATA[]]>
+<![CDATA[
+]]>
   </initFunction>
   <cleanUpFunction>
-<![CDATA[]]>
+<![CDATA[
+]]>
   </cleanUpFunction>
   <retrieveFunction>
-<![CDATA[]]>
+<![CDATA[
+]]>
   </retrieveFunction>
   <publishFunction>
-<![CDATA[if(!AtomicCompareExchange((long*)&Lock, 0, 1)){
+<![CDATA[
+if(!AtomicCompareExchange((long*)&Lock, 0, 1)){
     TestInput = CtoP + PtoC + TestOutput;
     AtomicCompareExchange((long*)&Lock, 1, 0);
-}]]>
+}
+]]>
   </publishFunction>
-</CodeFile>
+</CFile>
--- a/tests/python/python@py_ext/pyfile.xml	Mon May 13 14:31:23 2013 +0200
+++ b/tests/python/python@py_ext/pyfile.xml	Mon May 13 14:36:54 2013 +0200
@@ -1,13 +1,11 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<CodeFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="codefile.xsd">
-  <includes>
-<![CDATA[]]>
-  </includes>
+<PyFile>
   <variables>
     <variable name="Test_Python_Var" type="INT" initial="0"/>
   </variables>
   <globals>
-<![CDATA[import time,sys,ctypes
+<![CDATA[
+import time,sys,ctypes
 Python_to_C_Call = PLCBinary.Python_to_C_Call
 Python_to_C_Call.restype = ctypes.c_int
 Python_to_C_Call.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_int)]
@@ -40,16 +38,28 @@
 """
 ]]>
   </globals>
-  <initFunction>
-<![CDATA[]]>
-  </initFunction>
-  <cleanUpFunction>
-<![CDATA[]]>
-  </cleanUpFunction>
-  <retrieveFunction>
-<![CDATA[]]>
-  </retrieveFunction>
-  <publishFunction>
-<![CDATA[]]>
-  </publishFunction>
-</CodeFile>
+  <init>
+<![CDATA[
+global x, y
+x = 2
+y = 5
+print "py_runtime init:", x, ",", y
+]]>
+  </init>
+  <cleanup>
+<![CDATA[
+print "py_runtime cleanup"
+]]>
+  </cleanup>
+  <start>
+<![CDATA[
+global x, y
+print "py_runtime start", x * x + y * y
+]]>
+  </start>
+  <stop>
+<![CDATA[
+print "py_runtime stop"
+]]>
+  </stop>
+</PyFile>