runtime/xenomai.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 29 Dec 2020 15:35:39 +0100
branchsvghmi
changeset 3099 c7d14130401f
parent 2015 4eeefc6a13fd
child 3750 f62625418bff
permissions -rw-r--r--
SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
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