# HG changeset patch # User Laurent Bessard # Date 1368448614 -7200 # Node ID 1b1472e76f076e5e6d27137825649db8068227df # Parent b1705000eba193365b39d45a86c029d8c0caa90c Updated python example diff -r b1705000eba1 -r 1b1472e76f07 tests/python/c_code@c_ext/cfile.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> diff -r b1705000eba1 -r 1b1472e76f07 tests/python/python@py_ext/pyfile.xml --- 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>