tests/python/python@py_ext/pyfile.xml
author Laurent Bessard
Tue, 14 May 2013 11:23:43 +0200
changeset 1135 519a21ddbc40
parent 1125 1b1472e76f07
child 1145 203f4eff3313
permissions -rw-r--r--
Added support for updating model when broken connection is detected in Viewer
1099
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
     1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
     2
<PyFile>
1099
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
     3
  <variables>
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
     4
    <variable name="Test_Python_Var" type="INT" initial="0"/>
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
     5
  </variables>
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
     6
  <globals>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
     7
<![CDATA[
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
     8
import time,sys,ctypes
1099
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
     9
Python_to_C_Call = PLCBinary.Python_to_C_Call
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    10
Python_to_C_Call.restype = ctypes.c_int
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    11
Python_to_C_Call.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_int)]
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    12
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    13
def MyPythonFunc(arg):
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    14
    i = ctypes.c_int()
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    15
    if(Python_to_C_Call(arg, i)):
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    16
        res = i.value
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    17
        print "toC:", arg, "from C:", res, "FBID:", FBID
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    18
    else:
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    19
        print "Failed Python_to_C_Call failed"
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    20
        res = None
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    21
    sys.stdout.flush()
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    22
    return res
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    23
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    24
async_error_test_code = """
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    25
def badaboom():
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    26
    tuple()[0]
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    27
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    28
import wx
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    29
def badaboomwx():
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    30
    wx.CallAfter(badaboom)
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    31
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    32
from threading import Timer
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    33
a = Timer(3, badaboom)
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    34
a.start()
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    35
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    36
b = Timer(6, badaboomwx)
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    37
b.start()
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    38
"""
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    39
]]>
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    40
  </globals>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    41
  <init>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    42
<![CDATA[
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    43
global x, y
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    44
x = 2
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    45
y = 5
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    46
print "py_runtime init:", x, ",", y
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    47
]]>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    48
  </init>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    49
  <cleanup>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    50
<![CDATA[
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    51
print "py_runtime cleanup"
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    52
]]>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    53
  </cleanup>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    54
  <start>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    55
<![CDATA[
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    56
global x, y
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    57
print "py_runtime start", x * x + y * y
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    58
]]>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    59
  </start>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    60
  <stop>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    61
<![CDATA[
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    62
print "py_runtime stop"
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    63
]]>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    64
  </stop>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    65
</PyFile>