runtime/xenomai.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 13 Aug 2018 18:29:07 +0300
changeset 2284 64bb520009f3
parent 2015 4eeefc6a13fd
child 3750 f62625418bff
permissions -rw-r--r--
Fix wxHMI example after upgrading wxGlade

Newer wxGlade generates code to initialize GridSizer's with empty
elements.

...
grid_sizer_1.Add(self.window_1, 1, wx.ALIGN_CENTER, 0)
sizer_2.Add((0, 0), 0, 0, 0)
sizer_2.Add((0, 0), 0, 0, 0)
sizer_2.Add((0, 0), 0, 0, 0)
sizer_2.Add((0, 0), 0, 0, 0)
...

That causes following traceback, if new buttons are added
to already full sizer.

PLCobject : Traceback (most recent call last):

File "./Beremiz_service.py", line 389, in default_evaluator
res = (tocall(*args, **kwargs), None)

File "/tmp/tmpQS8ct2/runtime_0.py", line 540, in _runtime_0_start
wx.MessageBox(_("Please stop PLC to close"))

File "/tmp/tmpQS8ct2/runtime_0.py", line 504, in Init
lambda axis:( MakeButtonFunc(self, sizer, axis+"axisMinus"),

File "/tmp/tmpQS8ct2/runtime_0.py", line 502, in <lambda>
lambda btname: MakeButtonFunc(self, sizer, btname), ActionButtons)

File "/tmp/tmpQS8ct2/runtime_0.py", line 461, in MakeButtonFunc
print sizer, btname

File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk3/wx/_core.py", line 14453, in Add
return _core_.Sizer_Add(*args, **kwargs)

PyAssertionError: C++ assertion "Assert failure" failed at
../src/common/sizer.cpp(1401) in DoInsert(): too many items (11 > 2*5)
in grid sizer (maybe you should omit the number of either rows or
columns?)


Tested with wxGlade version 0.8.3
Closes #41
2015
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     1
#!/usr/bin/env python
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     2
# -*- coding: utf-8 -*-
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     3
#
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     4
# See COPYING.Runtime file for copyrights details.
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     5
#
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     6
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     7
from __future__ import absolute_import
2000
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
     8
from ctypes import CDLL, RTLD_GLOBAL, pointer, c_int, POINTER, c_char, create_string_buffer
2015
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     9
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
    10
2000
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    11
def TryPreloadXenomai():
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    12
    """
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    13
    Xenomai 3 (at least for version <= 3.0.6) do not handle properly dlclose
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    14
    of shared objects whose dlopen did trigger xenomai_init.
2015
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
    15
    As a workaround, this pre-loads xenomai libraries that need to be
2000
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    16
    initialized and call xenomai_init once for all.
2015
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
    17
2000
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    18
    Xenomai auto init of libs MUST be disabled (see --auto-init-solib in xeno-config)
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    19
    """
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    20
    try:
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    21
        for name in ["cobalt", "modechk", "copperplate", "alchemy"]:
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    22
            globals()[name] = CDLL("lib"+name+".so", mode=RTLD_GLOBAL)
2015
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
    23
        cobalt.xenomai_init(pointer(c_int(0)), pointer((POINTER(c_char)*2)(create_string_buffer("prog_name"), None)))
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
    24
    except Exception:
2000
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    25
        pass