tests/python/python@py_ext/pyfile.xml
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 05 Mar 2019 11:19:36 +0300
changeset 2519 27955f010b23
parent 1401 611fded24ce4
child 2680 6bfed6757495
permissions -rw-r--r--
Fix crash if LD input contact isn't connected

Traceback (most recent call last):
File "/home/developer/WorkData/PLC/beremiz/beremiz/BeremizIDE.py", line 339, in OnMethod
obj.CTR.CallMethod('_'+meth)
File "/home/developer/WorkData/PLC/beremiz/beremiz/ProjectController.py", line 1996, in CallMethod
getattr(self, method)()
File "/home/developer/WorkData/PLC/beremiz/beremiz/ProjectController.py", line 1134, in _Build
IECGenRes = self._Generate_SoftPLC()
File "/home/developer/WorkData/PLC/beremiz/beremiz/ProjectController.py", line 746, in _Generate_SoftPLC
if self._Generate_PLC_ST():
File "/home/developer/WorkData/PLC/beremiz/beremiz/ProjectController.py", line 763, in _Generate_PLC_ST
self._getIECgeneratedcodepath())
File "/home/developer/WorkData/PLC/beremiz/beremiz/PLCControler.py", line 456, in GenerateProgram
self.ProgramChunks = GenerateCurrentProgram(self, self.Project, errors, warnings)
File "/home/developer/WorkData/PLC/beremiz/beremiz/PLCGenerator.py", line 1762, in GenerateCurrentProgram
generator.GenerateProgram()
File "/home/developer/WorkData/PLC/beremiz/beremiz/PLCGenerator.py", line 478, in GenerateProgram
self.GeneratePouProgram(pou_name)
File "/home/developer/WorkData/PLC/beremiz/beremiz/PLCGenerator.py", line 260, in GeneratePouProgram
program = pou_program.GenerateProgram(pou)
File "/home/developer/WorkData/PLC/beremiz/beremiz/PLCGenerator.py", line 1718, in GenerateProgram
self.ComputeProgram(pou)
File "/home/developer/WorkData/PLC/beremiz/beremiz/PLCGenerator.py", line 1028, in ComputeProgram
self.GenerateBlock(instance, block_infos, body, None)
File "/home/developer/WorkData/PLC/beremiz/beremiz/PLCGenerator.py", line 1144, in GenerateBlock
expression = self.ComputeExpression(body, connections, executionOrderId > 0)
File "/home/developer/WorkData/PLC/beremiz/beremiz/PLCGenerator.py", line 1373, in ComputeExpression
paths = self.GeneratePaths(connections, body, order, to_inout)
File "/home/developer/WorkData/PLC/beremiz/beremiz/PLCGenerator.py", line 1344, in GeneratePaths
elif isinstance(result[0], list):
IndexError: list index out of range


Close #70
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1145
diff changeset
     1
<?xml version='1.0' encoding='utf-8'?>
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1145
diff changeset
     2
<PyFile xmlns:xhtml="http://www.w3.org/1999/xhtml">
1099
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
     3
  <variables>
1145
203f4eff3313 Fixed PLC global var access from python. Added test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
     4
    <variable name="Test_Python_Var" type="INT" initial="4"/>
203f4eff3313 Fixed PLC global var access from python. Added test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
     5
    <variable name="Second_Python_Var" type="INT" initial="5"/>
1099
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
     6
  </variables>
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
     7
  <globals>
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1145
diff changeset
     8
    <xhtml:p><![CDATA[
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
     9
import time,sys,ctypes
1099
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    10
Python_to_C_Call = PLCBinary.Python_to_C_Call
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    11
Python_to_C_Call.restype = ctypes.c_int
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    12
Python_to_C_Call.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_int)]
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    13
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    14
def MyPythonFunc(arg):
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    15
    i = ctypes.c_int()
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    16
    if(Python_to_C_Call(arg, i)):
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    17
        res = i.value
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    18
        print "toC:", arg, "from C:", res, "FBID:", FBID
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    19
    else:
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    20
        print "Failed Python_to_C_Call failed"
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    21
        res = None
1145
203f4eff3313 Fixed PLC global var access from python. Added test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
    22
    print "Python read PLC global :",PLCGlobals.Test_Python_Var
203f4eff3313 Fixed PLC global var access from python. Added test in tests/python
Edouard Tisserant
parents: 1125
diff changeset
    23
    PLCGlobals.Second_Python_Var = 789
1099
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    24
    sys.stdout.flush()
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    25
    return res
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    26
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    27
async_error_test_code = """
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    28
def badaboom():
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    29
    tuple()[0]
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    30
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    31
import wx
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    32
def badaboomwx():
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    33
    wx.CallAfter(badaboom)
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    34
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    35
from threading import Timer
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    36
a = Timer(3, badaboom)
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    37
a.start()
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    38
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    39
b = Timer(6, badaboomwx)
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    40
b.start()
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    41
"""
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1145
diff changeset
    42
]]></xhtml:p>
1099
d9c28879e55b Updated python test
Laurent Bessard
parents:
diff changeset
    43
  </globals>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    44
  <init>
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1145
diff changeset
    45
    <xhtml:p><![CDATA[
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    46
global x, y
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    47
x = 2
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    48
y = 5
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    49
print "py_runtime init:", x, ",", y
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1145
diff changeset
    50
]]></xhtml:p>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    51
  </init>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    52
  <cleanup>
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1145
diff changeset
    53
    <xhtml:p><![CDATA[
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    54
print "py_runtime cleanup"
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1145
diff changeset
    55
]]></xhtml:p>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    56
  </cleanup>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    57
  <start>
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1145
diff changeset
    58
    <xhtml:p><![CDATA[
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    59
global x, y
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    60
print "py_runtime start", x * x + y * y
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1145
diff changeset
    61
]]></xhtml:p>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    62
  </start>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    63
  <stop>
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1145
diff changeset
    64
    <xhtml:p><![CDATA[
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    65
print "py_runtime stop"
1401
611fded24ce4 Pair with matiec a51a3bb4d613. Re-enable resource add/remove, updated CFLAGS, disabled broken global FG test in tests/python
Edouard Tisserant
parents: 1145
diff changeset
    66
]]></xhtml:p>
1125
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    67
  </stop>
1b1472e76f07 Updated python example
Laurent Bessard
parents: 1099
diff changeset
    68
</PyFile>