|
1 <?xml version='1.0' encoding='utf-8'?> |
|
2 <PyFile xmlns:xhtml="http://www.w3.org/1999/xhtml"> |
|
3 <variables> |
|
4 <variable name="Test_Python_Var" type="INT" initial="4"/> |
|
5 <variable name="Second_Python_Var" type="INT" initial="5"/> |
|
6 </variables> |
|
7 <globals> |
|
8 <xhtml:p><![CDATA[ |
|
9 import time,sys,ctypes |
|
10 Python_to_C_Call = PLCBinary.Python_to_C_Call |
|
11 Python_to_C_Call.restype = ctypes.c_int |
|
12 Python_to_C_Call.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_int)] |
|
13 |
|
14 def MyPythonFunc(arg): |
|
15 i = ctypes.c_int() |
|
16 if(Python_to_C_Call(arg, i)): |
|
17 res = i.value |
|
18 print "toC:", arg, "from C:", res, "FBID:", FBID |
|
19 else: |
|
20 print "Failed Python_to_C_Call failed" |
|
21 res = None |
|
22 print "Python read PLC global :",PLCGlobals.Test_Python_Var |
|
23 print "Python read PLC global Grumpf :",PLCGlobals.Grumpf |
|
24 PLCGlobals.Second_Python_Var = 789 |
|
25 sys.stdout.flush() |
|
26 return res |
|
27 |
|
28 async_error_test_code = """ |
|
29 def badaboom(): |
|
30 tuple()[0] |
|
31 |
|
32 import wx |
|
33 def badaboomwx(): |
|
34 wx.CallAfter(badaboom) |
|
35 |
|
36 from threading import Timer |
|
37 a = Timer(3, badaboom) |
|
38 a.start() |
|
39 |
|
40 b = Timer(6, badaboomwx) |
|
41 b.start() |
|
42 """ |
|
43 ]]></xhtml:p> |
|
44 </globals> |
|
45 <init> |
|
46 <xhtml:p><![CDATA[ |
|
47 global x, y |
|
48 x = 2 |
|
49 y = 5 |
|
50 print "py_runtime init:", x, ",", y |
|
51 ]]></xhtml:p> |
|
52 </init> |
|
53 <cleanup> |
|
54 <xhtml:p><![CDATA[ |
|
55 print "py_runtime cleanup" |
|
56 ]]></xhtml:p> |
|
57 </cleanup> |
|
58 <start> |
|
59 <xhtml:p><![CDATA[ |
|
60 global x, y |
|
61 print "py_runtime start", x * x + y * y |
|
62 ]]></xhtml:p> |
|
63 </start> |
|
64 <stop> |
|
65 <xhtml:p><![CDATA[ |
|
66 print "py_runtime stop" |
|
67 ]]></xhtml:p> |
|
68 </stop> |
|
69 </PyFile> |