plcopen/InstanceTagnameCollector.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 05 Mar 2019 11:19:36 +0300
changeset 2519 27955f010b23
parent 1953 5736d25bb393
child 3750 f62625418bff
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
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     3
# This file is part of Beremiz.
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     4
# See COPYING file for copyrights details.
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     5
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     6
from __future__ import absolute_import
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
     7
from plcopen.XSLTModelQuery import XSLTModelQuery
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     8
from plcopen.types_enums import *
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     9
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    10
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    11
class InstanceTagName(object):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    12
    """Helpers object for generating instance tagname"""
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    13
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    14
    def __init__(self):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    15
        self.TagName = None
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    16
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    17
    def GetTagName(self):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    18
        return self.TagName
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    19
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    20
    def ConfigTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    21
        self.TagName = ComputeConfigurationName(args[0][0])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    22
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    23
    def ResourceTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    24
        self.TagName = ComputeConfigurationResourceName(args[0][0], args[1][0])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    25
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    26
    def PouTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    27
        self.TagName = ComputePouName(args[0][0])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    28
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    29
    def ActionTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    30
        self.TagName = ComputePouActionName(args[0][0], args[0][1])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    31
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    32
    def TransitionTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    33
        self.TagName = ComputePouTransitionName(args[0][0], args[0][1])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    34
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    35
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    36
class InstanceTagnameCollector(XSLTModelQuery):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    37
    """ object for collecting instances path list"""
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    38
    def __init__(self, controller):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    39
        XSLTModelQuery.__init__(self,
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    40
                                controller,
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    41
                                "instance_tagname.xslt",
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    42
                                [(name, self.FactoryCaller(name))
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    43
                                 for name in ["ConfigTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    44
                                              "ResourceTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    45
                                              "PouTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    46
                                              "ActionTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    47
                                              "TransitionTagName"]])
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    48
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    49
    def FactoryCaller(self, funcname):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    50
        def CallFactory(*args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    51
            return getattr(self.factory, funcname)(*args)
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    52
        return CallFactory
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    53
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    54
    def Collect(self, root, debug, instance_path):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    55
        self.factory = InstanceTagName()
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    56
        self._process_xslt(root, debug, instance_path=instance_path)
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    57
        res = self.factory.GetTagName()
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    58
        self.factory = None
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    59
        return res