runtime/__init__.py
author Edouard Tisserant
Tue, 11 Sep 2018 16:08:21 +0200
changeset 2272 28b0a783975e
parent 2270 d9175daf6522
child 2307 c44692b53736
permissions -rw-r--r--
Change behaviour of python_eval function block : if TRIG is false, then ACK is also false except a pulse precisely when receiving answer from interpreter
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import traceback

from runtime.Worker import worker
MainWorker = worker()

from runtime.PLCObject import PLCObject

_PLCObjectSingleton = None

def GetPLCObjectSingleton():
    global _PLCObjectSingleton
    assert(_PLCObjectSingleton is not None)
    return _PLCObjectSingleton


def LogMessageAndException(msg, exp=None):
    global _PLCObjectSingleton
    if exp is None:
        exp = sys.exc_info()
    if _PLCObjectSingleton is not None:
        _PLCObjectSingleton.LogMessage(0, msg + '\n'.join(traceback.format_exception(*exp)))
    else:
        print(msg)
        traceback.print_exception(*exp)

def CreatePLCObjectSingleton(*args):
    global _PLCObjectSingleton
    _PLCObjectSingleton = PLCObject(*args)