plcopen/structures.py
author Laurent Bessard
Fri, 30 Aug 2013 10:59:06 +0200
changeset 1298 f034fb2b1aab
parent 1297 cd639725fba5
child 1310 3d7fa2257b24
permissions -rw-r--r--
Fixed SFC block edition and SFC to SFC_textual code generating
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
965
308e51832711 Fixed test identifier function
Laurent Bessard
parents: 949
diff changeset
    25
import string, os, sys, re
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
LANGUAGES = ["IL","ST","FBD","LD","SFC"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
LOCATIONDATATYPES = {"X" : ["BOOL"],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
                     "B" : ["SINT", "USINT", "BYTE", "STRING"],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
                     "W" : ["INT", "UINT", "WORD", "WSTRING"],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
                     "D" : ["DINT", "UDINT", "REAL", "DWORD"],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
                     "L" : ["LINT", "ULINT", "LREAL", "LWORD"]} 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
_ = lambda x:x
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
# Helper for emulate join on element list
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    38
def JoinList(separator, mylist):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
    if len(mylist) > 0 :
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
        return reduce(lambda x, y: x + separator + y, mylist)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
    else :
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
        return mylist
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
def generate_block(generator, block, block_infos, body, link, order=False, to_inout=False):
1297
cd639725fba5 Fixed ST program generating module
Laurent Bessard
parents: 1283
diff changeset
    45
    body_type = body.getcontent().getLocalTag()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
    name = block.getinstanceName()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
    type = block.gettypeName()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
    executionOrderId = block.getexecutionOrderId()
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    49
    input_variables = block.inputVariables.getvariable()
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    50
    output_variables = block.outputVariables.getvariable()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
    inout_variables = {}
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    52
    for input_variable in input_variables:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    53
        for output_variable in output_variables:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
            if input_variable.getformalParameter() == output_variable.getformalParameter():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
                inout_variables[input_variable.getformalParameter()] = ""
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    56
    input_names = [input[0] for input in block_infos["inputs"]]
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    57
    output_names = [output[0] for output in block_infos["outputs"]]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
    if block_infos["type"] == "function":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
        if not generator.ComputedBlocks.get(block, False) and not order:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
            generator.ComputedBlocks[block] = True
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    61
            connected_vars = []
1149
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    62
            if not block_infos["extensible"]:
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    63
                input_connected = dict([("EN", None)] + 
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    64
                                       [(input_name, None) for input_name in input_names])
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    65
                for variable in input_variables:
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    66
                    parameter = variable.getformalParameter()
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    67
                    if input_connected.has_key(parameter):
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    68
                        input_connected[parameter] = variable
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    69
                if input_connected["EN"] is None:
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    70
                    input_connected.pop("EN")
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    71
                    input_parameters = input_names
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    72
                else:
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    73
                    input_parameters = ["EN"] + input_names
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    74
            else:
1149
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    75
                input_connected = dict([(variable.getformalParameter(), variable)
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    76
                                        for variable in input_variables])
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    77
                input_parameters = [variable.getformalParameter()
67df52302ea6 Fixed bug in ST code generator with extensible standard functions
Laurent Bessard
parents: 1143
diff changeset
    78
                                    for variable in input_variables]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
            one_input_connected = False
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    80
            all_input_connected = True
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    81
            for i, parameter in enumerate(input_parameters):
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    82
                variable = input_connected.get(parameter)
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    83
                if variable is not None:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    84
                    input_info = (generator.TagName, "block", block.getlocalId(), "input", i)
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    85
                    connections = variable.connectionPointIn.getconnections()
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    86
                    if connections is not None:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    87
                        if parameter != "EN":
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    88
                            one_input_connected = True
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    89
                        if inout_variables.has_key(parameter):
1239
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1149
diff changeset
    90
                            expression = generator.ComputeExpression(body, connections, executionOrderId > 0, True)
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1149
diff changeset
    91
                            if expression is not None:
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1149
diff changeset
    92
                                inout_variables[parameter] = value
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    93
                        else:
1239
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1149
diff changeset
    94
                            expression = generator.ComputeExpression(body, connections, executionOrderId > 0)
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1149
diff changeset
    95
                        if expression is not None:
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1149
diff changeset
    96
                            connected_vars.append(([(parameter, input_info), (" := ", ())],
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1149
diff changeset
    97
                                                   generator.ExtractModifier(variable, expression, input_info)))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
                    else:
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
    99
                        all_input_connected = False
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   100
                else:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   101
                    all_input_connected = False
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   102
            if len(output_variables) > 1 or not all_input_connected:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   103
                vars = [name + value for name, value in connected_vars]
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   104
            else:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   105
                vars = [value for name, value in connected_vars]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
            if one_input_connected:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
                for i, variable in enumerate(output_variables):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
                    parameter = variable.getformalParameter()
1143
59818c488ead Fixed bug in ST code generator when function output variable has no name
Laurent Bessard
parents: 1134
diff changeset
   109
                    if not inout_variables.has_key(parameter) and parameter in output_names + ["", "ENO"]:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
                        if variable.getformalParameter() == "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
                            variable_name = "%s%d"%(type, block.getlocalId())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
                            variable_name = "%s%d_%s"%(type, block.getlocalId(), parameter)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
                        if generator.Interface[-1][0] != "VAR" or generator.Interface[-1][1] is not None or generator.Interface[-1][2]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
                            generator.Interface.append(("VAR", None, False, []))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   116
                        if variable.connectionPointOut in generator.ConnectionTypes:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
                            generator.Interface[-1][3].append((generator.ConnectionTypes[variable.connectionPointOut], variable_name, None, None))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
                            generator.Interface[-1][3].append(("ANY", variable_name, None, None))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
                        if len(output_variables) > 1 and parameter not in ["", "OUT"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
                            vars.append([(parameter, (generator.TagName, "block", block.getlocalId(), "output", i)), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
                                         (" => %s"%variable_name, ())])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   124
                            output_info = (generator.TagName, "block", block.getlocalId(), "output", i)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
                            output_name = variable_name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
                generator.Program += [(generator.CurrentIndent, ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
                                      (output_name, output_info),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
                                      (" := ", ()),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
                                      (type, (generator.TagName, "block", block.getlocalId(), "type")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
                                      ("(", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
                generator.Program += JoinList([(", ", ())], vars)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   132
                generator.Program += [(");\n", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
                generator.Warnings.append(_("\"%s\" function cancelled in \"%s\" POU: No input connected")%(type, generator.TagName.split("::")[-1]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
    elif block_infos["type"] == "functionBlock":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
        if not generator.ComputedBlocks.get(block, False) and not order:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
            generator.ComputedBlocks[block] = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
            vars = []
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   139
            offset_idx = 0
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   140
            for variable in input_variables:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   141
                parameter = variable.getformalParameter()
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   142
                if parameter in input_names or parameter == "EN":
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   143
                    if parameter == "EN":
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   144
                        input_idx = 0
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   145
                        offset_idx = 1
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   146
                    else:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   147
                        input_idx = offset_idx + input_names.index(parameter)
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   148
                    input_info = (generator.TagName, "block", block.getlocalId(), "input", input_idx)
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   149
                    connections = variable.connectionPointIn.getconnections()
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   150
                    if connections is not None:
1239
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1149
diff changeset
   151
                        expression = generator.ComputeExpression(body, connections, executionOrderId > 0, inout_variables.has_key(parameter))
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1149
diff changeset
   152
                        if expression is not None:
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1149
diff changeset
   153
                            vars.append([(parameter, input_info),
d1f6ea56555d Fixed bug when generating ST code and connection is broken in POU using graphical language
Laurent Bessard
parents: 1149
diff changeset
   154
                                         (" := ", ())] + generator.ExtractModifier(variable, expression, input_info))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
            generator.Program += [(generator.CurrentIndent, ()), 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
                                  (name, (generator.TagName, "block", block.getlocalId(), "name")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
                                  ("(", ())]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
            generator.Program += JoinList([(", ", ())], vars)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
            generator.Program += [(");\n", ())]
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   160
    
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   161
    if link is not None:
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   162
        connectionPoint = link.getposition()[-1]
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   163
        output_parameter = link.getformalParameter()
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   164
    else:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   165
        connectionPoint = None
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   166
        output_parameter = None
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   167
    
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   168
    output_variable = None
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   169
    output_idx = 0
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   170
    if output_parameter is not None:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   171
        if output_parameter in output_names or output_parameter == "ENO":
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   172
            for variable in output_variables:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   173
                if variable.getformalParameter() == output_parameter:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   174
                    output_variable = variable
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   175
                    if output_parameter != "ENO":
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   176
                        output_idx = output_names.index(output_parameter)
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   177
    else:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   178
        for i, variable in enumerate(output_variables):
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   179
            blockPointx, blockPointy = variable.connectionPointOut.getrelPositionXY()
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   180
            if (connectionPoint is None or 
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   181
                block.getx() + blockPointx == connectionPoint.getx() and 
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   182
                block.gety() + blockPointy == connectionPoint.gety()):
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   183
                output_variable = variable
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   184
                output_parameter = variable.getformalParameter()
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   185
                output_idx = i
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   186
    
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   187
    if output_variable is not None:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   188
        if block_infos["type"] == "function":
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   189
            output_info = (generator.TagName, "block", block.getlocalId(), "output", output_idx)
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   190
            if inout_variables.has_key(output_parameter):
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   191
                output_value = inout_variables[output_parameter]
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   192
            else:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   193
                if output_parameter == "":
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   194
                    output_name = "%s%d"%(type, block.getlocalId())
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   195
                else:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   196
                    output_name = "%s%d_%s"%(type, block.getlocalId(), output_parameter)
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   197
                output_value = [(output_name, output_info)]
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   198
            return generator.ExtractModifier(output_variable, output_value, output_info)
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   199
        
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   200
        if block_infos["type"] == "functionBlock":
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   201
            output_info = (generator.TagName, "block", block.getlocalId(), "output", output_idx)
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   202
            output_name = generator.ExtractModifier(output_variable, [("%s.%s"%(name, output_parameter), output_info)], output_info)
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   203
            if to_inout:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   204
                variable_name = "%s_%s"%(name, output_parameter)
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   205
                if not generator.IsAlreadyDefined(variable_name):
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   206
                    if generator.Interface[-1][0] != "VAR" or generator.Interface[-1][1] is not None or generator.Interface[-1][2]:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   207
                        generator.Interface.append(("VAR", None, False, []))
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   208
                    if variable.connectionPointOut in generator.ConnectionTypes:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   209
                        generator.Interface[-1][3].append(
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   210
                            (generator.ConnectionTypes[output_variable.connectionPointOut], variable_name, None, None))
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   211
                    else:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   212
                        generator.Interface[-1][3].append(("ANY", variable_name, None, None))
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   213
                    generator.Program += [(generator.CurrentIndent, ()),
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   214
                                          ("%s := "%variable_name, ())]
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   215
                    generator.Program += output_name
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   216
                    generator.Program += [(";\n", ())]
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   217
                return [(variable_name, ())]
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   218
            return output_name 
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   219
    if link is not None:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   220
        if output_parameter is None:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   221
            output_parameter = ""
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   222
        if name:
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   223
            blockname = "%s(%s)" % (name, type)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   224
        else:
1134
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   225
            blockname = type
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   226
        raise ValueError, _("No output %s variable found in block %s in POU %s. Connection must be broken")  % \
1c7a4ad86aa1 Fixed PLC code generator when interface of an already used POU has changed
Laurent Bessard
parents: 965
diff changeset
   227
                          (output_parameter, blockname, generator.Name)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   229
def initialise_block(type, name, block = None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   230
    return [(type, name, None, None)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
#                        Function Block Types definitions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   235
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   236
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
Ordored list of common Function Blocks defined in the IEC 61131-3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
Each block have this attributes:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
    - "name" : The block name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
    - "type" : The block type. It can be "function", "functionBlock" or "program"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
    - "extensible" : Boolean that define if the block is extensible
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
    - "inputs" : List of the block inputs
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
    - "outputs" : List of the block outputs
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
    - "comment" : Comment that will be displayed in the block popup
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
    - "generate" : Method that generator will call for generating ST block code
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
Inputs and outputs are a tuple of characteristics that are in order:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
    - The name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
    - The data type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
    - The default modifier which can be "none", "negated", "rising" or "falling"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   252
1283
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   253
StdBlckLst = [{"name" : _("Standard function blocks"), "list":
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
               [{"name" : "SR", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   255
                    "inputs" : [("S1","BOOL","none"),("R","BOOL","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
                    "outputs" : [("Q1","BOOL","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
                    "comment" : _("SR bistable\nThe SR bistable is a latch where the Set dominates."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   259
                {"name" : "RS", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   260
                    "inputs" : [("S","BOOL","none"),("R1","BOOL","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
                    "outputs" : [("Q1","BOOL","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   262
                    "comment" : _("RS bistable\nThe RS bistable is a latch where the Reset dominates."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   263
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   264
                {"name" : "SEMA", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   265
                    "inputs" : [("CLAIM","BOOL","none"),("RELEASE","BOOL","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   266
                    "outputs" : [("BUSY","BOOL","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   267
                    "comment" : _("Semaphore\nThe semaphore provides a mechanism to allow software elements mutually exclusive access to certain ressources."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   268
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   269
                {"name" : "R_TRIG", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   270
                    "inputs" : [("CLK","BOOL","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   271
                    "outputs" : [("Q","BOOL","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   272
                    "comment" : _("Rising edge detector\nThe output produces a single pulse when a rising edge is detected."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   273
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   274
                {"name" : "F_TRIG", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   275
                    "inputs" : [("CLK","BOOL","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   276
                    "outputs" : [("Q","BOOL","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   277
                    "comment" : _("Falling edge detector\nThe output produces a single pulse when a falling edge is detected."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   278
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   279
                {"name" : "CTU", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   280
                    "inputs" : [("CU","BOOL","rising"),("R","BOOL","none"),("PV","INT","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   281
                    "outputs" : [("Q","BOOL","none"),("CV","INT","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   282
                    "comment" : _("Up-counter\nThe up-counter can be used to signal when a count has reached a maximum value."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   283
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
                {"name" : "CTD", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   285
                    "inputs" : [("CD","BOOL","rising"),("LD","BOOL","none"),("PV","INT","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   286
                    "outputs" : [("Q","BOOL","none"),("CV","INT","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   287
                    "comment" : _("Down-counter\nThe down-counter can be used to signal when a count has reached zero, on counting down from a preset value."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   288
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   289
                {"name" : "CTUD", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
                    "inputs" : [("CU","BOOL","rising"),("CD","BOOL","rising"),("R","BOOL","none"),("LD","BOOL","none"),("PV","INT","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
                    "outputs" : [("QU","BOOL","none"),("QD","BOOL","none"),("CV","INT","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   292
                    "comment" : _("Up-down counter\nThe up-down counter has two inputs CU and CD. It can be used to both count up on one input and down on the other."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
                {"name" : "TP", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
                    "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
                    "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   297
                    "comment" : _("Pulse timer\nThe pulse timer can be used to generate output pulses of a given time duration."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
                {"name" : "TON", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
                    "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   301
                    "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   302
                    "comment" : _("On-delay timer\nThe on-delay timer can be used to delay setting an output true, for fixed period after an input becomes true."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   303
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
                {"name" : "TOF", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
                    "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
                    "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   307
                    "comment" : _("Off-delay timer\nThe off-delay timer can be used to delay setting an output false, for fixed period after input goes false."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   308
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
                ]},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
              {"name" : _("Additional function blocks"), "list":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
               [{"name" : "RTC", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   312
                    "inputs" : [("IN","BOOL","none"),("PDT","DATE_AND_TIME","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
                    "outputs" : [("Q","BOOL","none"),("CDT","DATE_AND_TIME","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
                    "comment" : _("Real time clock\nThe real time clock has many uses including time stamping, setting dates and times of day in batch reports, in alarm messages and so on."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
                {"name" : "INTEGRAL", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   317
                    "inputs" : [("RUN","BOOL","none"),("R1","BOOL","none"),("XIN","REAL","none"),("X0","REAL","none"),("CYCLE","TIME","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
                    "outputs" : [("Q","BOOL","none"),("XOUT","REAL","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
                    "comment" : _("Integral\nThe integral function block integrates the value of input XIN over time."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   320
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   321
                {"name" : "DERIVATIVE", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   322
                    "inputs" : [("RUN","BOOL","none"),("XIN","REAL","none"),("CYCLE","TIME","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   323
                    "outputs" : [("XOUT","REAL","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   324
                    "comment" : _("Derivative\nThe derivative function block produces an output XOUT proportional to the rate of change of the input XIN."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   325
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   326
                {"name" : "PID", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
                    "inputs" : [("AUTO","BOOL","none"),("PV","REAL","none"),("SP","REAL","none"),("X0","REAL","none"),("KP","REAL","none"),("TR","REAL","none"),("TD","REAL","none"),("CYCLE","TIME","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
                    "outputs" : [("XOUT","REAL","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
                    "comment" : _("PID\nThe PID (proportional, Integral, Derivative) function block provides the classical three term controller for closed loop control."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   331
                {"name" : "RAMP", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   332
                    "inputs" : [("RUN","BOOL","none"),("X0","REAL","none"),("X1","REAL","none"),("TR","TIME","none"),("CYCLE","TIME","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   333
                    "outputs" : [("BUSY","BOOL","none"),("XOUT","REAL","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   334
                    "comment" : _("Ramp\nThe RAMP function block is modelled on example given in the standard."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   335
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
                {"name" : "HYSTERESIS", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   337
                    "inputs" : [("XIN1","REAL","none"),("XIN2","REAL","none"),("EPS","REAL","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   338
                    "outputs" : [("Q","BOOL","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   339
                    "comment" : _("Hysteresis\nThe hysteresis function block provides a hysteresis boolean output driven by the difference of two floating point (REAL) inputs XIN1 and XIN2."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   340
                    "generate" : generate_block, "initialise" : initialise_block},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   341
##                {"name" : "RATIO_MONITOR", "type" : "functionBlock", "extensible" : False, 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   342
##                    "inputs" : [("PV1","REAL","none"),("PV2","REAL","none"),("RATIO","REAL","none"),("TIMON","TIME","none"),("TIMOFF","TIME","none"),("TOLERANCE","BOOL","none"),("RESET","BOOL","none"),("CYCLE","TIME","none")], 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   343
##                    "outputs" : [("ALARM","BOOL","none"),("TOTAL_ERR","BOOL","none")],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   344
##                    "comment" : _("Ratio monitor\nThe ratio_monitor function block checks that one process value PV1 is always a given ratio (defined by input RATIO) of a second process value PV2."),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   345
##                    "generate" : generate_block, "initialise" : initialise_block}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   346
                ]},
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   347
             ]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   348
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   349
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   350
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   351
#                           Data Types definitions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   352
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   353
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   354
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   355
Ordored list of common data types defined in the IEC 61131-3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   356
Each type is associated to his direct parent type. It defines then a hierarchy
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   357
between type that permits to make a comparison of two types
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   358
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   359
TypeHierarchy_list = [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   360
    ("ANY", None),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   361
    ("ANY_DERIVED", "ANY"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   362
    ("ANY_ELEMENTARY", "ANY"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   363
    ("ANY_MAGNITUDE", "ANY_ELEMENTARY"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   364
    ("ANY_BIT", "ANY_ELEMENTARY"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   365
    ("ANY_NBIT", "ANY_BIT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   366
    ("ANY_STRING", "ANY_ELEMENTARY"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   367
    ("ANY_DATE", "ANY_ELEMENTARY"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   368
    ("ANY_NUM", "ANY_MAGNITUDE"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   369
    ("ANY_REAL", "ANY_NUM"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   370
    ("ANY_INT", "ANY_NUM"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   371
    ("ANY_SINT", "ANY_INT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   372
    ("ANY_UINT", "ANY_INT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   373
    ("BOOL", "ANY_BIT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   374
    ("SINT", "ANY_SINT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   375
    ("INT", "ANY_SINT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   376
    ("DINT", "ANY_SINT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   377
    ("LINT", "ANY_SINT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   378
    ("USINT", "ANY_UINT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   379
    ("UINT", "ANY_UINT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   380
    ("UDINT", "ANY_UINT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   381
    ("ULINT", "ANY_UINT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   382
    ("REAL", "ANY_REAL"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   383
    ("LREAL", "ANY_REAL"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   384
    ("TIME", "ANY_MAGNITUDE"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   385
    ("DATE", "ANY_DATE"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   386
    ("TOD", "ANY_DATE"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   387
    ("DT", "ANY_DATE"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   388
    ("STRING", "ANY_STRING"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   389
    ("BYTE", "ANY_NBIT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   390
    ("WORD", "ANY_NBIT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   391
    ("DWORD", "ANY_NBIT"),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   392
    ("LWORD", "ANY_NBIT")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   393
    #("WSTRING", "ANY_STRING") # TODO
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   395
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   396
TypeHierarchy = dict(TypeHierarchy_list)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   397
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   398
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   399
returns true if the given data type is the same that "reference" meta-type or one of its types.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   400
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   401
def IsOfType(type, reference):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   402
    if reference is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   403
        return True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   404
    elif type == reference:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   405
        return True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   406
    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   407
        parent_type = TypeHierarchy[type]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   408
        if parent_type is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   409
            return IsOfType(parent_type, reference)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   410
    return False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   411
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   412
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   413
returns list of all types that correspont to the ANY* meta type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   414
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   415
def GetSubTypes(type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   416
    return [typename for typename, parenttype in TypeHierarchy.items() if not typename.startswith("ANY") and IsOfType(typename, type)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   417
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   418
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   419
DataTypeRange_list = [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   420
    ("SINT", (-2**7, 2**7 - 1)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   421
    ("INT", (-2**15, 2**15 - 1)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   422
    ("DINT", (-2**31, 2**31 - 1)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   423
    ("LINT", (-2**31, 2**31 - 1)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   424
    ("USINT", (0, 2**8 - 1)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   425
    ("UINT", (0, 2**16 - 1)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   426
    ("UDINT", (0, 2**31 - 1)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   427
    ("ULINT", (0, 2**31 - 1))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   428
]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   429
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   430
DataTypeRange = dict(DataTypeRange_list)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   431
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   432
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   433
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   434
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   435
#                             Test identifier
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   436
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   437
965
308e51832711 Fixed test identifier function
Laurent Bessard
parents: 949
diff changeset
   438
IDENTIFIER_MODEL = re.compile(
308e51832711 Fixed test identifier function
Laurent Bessard
parents: 949
diff changeset
   439
    "(?:%(letter)s|_(?:%(letter)s|%(digit)s))(?:_?(?:%(letter)s|%(digit)s))*$" %
308e51832711 Fixed test identifier function
Laurent Bessard
parents: 949
diff changeset
   440
    {"letter": "[a-zA-Z]", "digit": "[0-9]"})
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   441
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   442
# Test if identifier is valid
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   443
def TestIdentifier(identifier):
965
308e51832711 Fixed test identifier function
Laurent Bessard
parents: 949
diff changeset
   444
     return IDENTIFIER_MODEL.match(identifier) is not None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   445
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   446
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   447
#                        Standard functions list generation
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   448
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   449
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   450
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   451
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   452
take a .csv file and translate it it a "csv_table"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   453
"""            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   454
def csv_file_to_table(file):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   455
    return [ map(string.strip,line.split(';')) for line in file.xreadlines()]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   456
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   457
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   458
seek into the csv table to a section ( section_name match 1st field )
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   459
return the matching row without first field
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   460
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   461
def find_section(section_name, table):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   462
    fields = [None]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   463
    while(fields[0] != section_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   464
        fields = table.pop(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   465
    return fields[1:]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   466
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   467
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   468
extract the standard functions standard parameter names and types...
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   469
return a { ParameterName: Type, ...}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   470
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   471
def get_standard_funtions_input_variables(table):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   472
    variables = find_section("Standard_functions_variables_types", table)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   473
    standard_funtions_input_variables = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   474
    fields = [True,True]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   475
    while(fields[1]):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   476
        fields = table.pop(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   477
        variable_from_csv = dict([(champ, val) for champ, val in zip(variables, fields[1:]) if champ!=''])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   478
        standard_funtions_input_variables[variable_from_csv['name']] = variable_from_csv['type']
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   479
    return standard_funtions_input_variables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   480
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   481
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   482
translate .csv file input declaration into PLCOpenEditor interessting values
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   483
in : "(ANY_NUM, ANY_NUM)" and { ParameterName: Type, ...}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   484
return [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")] 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   485
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   486
def csv_input_translate(str_decl, variables, base):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   487
    decl = str_decl.replace('(','').replace(')','').replace(' ','').split(',')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   488
    params = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   489
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   490
    len_of_not_predifined_variable = len([True for param_type in decl if param_type not in variables])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   491
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   492
    for param_type in decl:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   493
        if param_type in variables.keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   494
            param_name = param_type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   495
            param_type = variables[param_type]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   496
        elif len_of_not_predifined_variable > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   497
            param_name = "IN%d"%base
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   498
            base += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   499
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   500
            param_name = "IN"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   501
        params.append((param_name, param_type, "none"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   502
    return params
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   503
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   504
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   505
ANY_TO_ANY_LIST=[
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   506
        # simple type conv are let as C cast
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   507
        (("ANY_INT","ANY_BIT"),("ANY_NUM","ANY_BIT"), ("return_type", "__move_", "IN_type")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   508
        (("ANY_REAL",),("ANY_REAL",), ("return_type", "__move_", "IN_type")),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   509
        # REAL_TO_INT
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   510
        (("ANY_REAL",),("ANY_SINT",), ("return_type", "__real_to_sint", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   511
        (("ANY_REAL",),("ANY_UINT",), ("return_type", "__real_to_uint", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   512
        (("ANY_REAL",),("ANY_BIT",), ("return_type", "__real_to_bit", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   513
        # TO_TIME
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   514
        (("ANY_INT","ANY_BIT"),("ANY_DATE","TIME"), ("return_type", "__int_to_time", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   515
        (("ANY_REAL",),("ANY_DATE","TIME"), ("return_type", "__real_to_time", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   516
        (("ANY_STRING",), ("ANY_DATE","TIME"), ("return_type", "__string_to_time", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   517
        # FROM_TIME
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   518
        (("ANY_DATE","TIME"), ("ANY_REAL",), ("return_type", "__time_to_real", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   519
        (("ANY_DATE","TIME"), ("ANY_INT","ANY_NBIT"), ("return_type", "__time_to_int", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   520
        (("TIME",), ("ANY_STRING",), ("return_type", "__time_to_string", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   521
        (("DATE",), ("ANY_STRING",), ("return_type", "__date_to_string", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   522
        (("TOD",), ("ANY_STRING",), ("return_type", "__tod_to_string", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   523
        (("DT",), ("ANY_STRING",), ("return_type", "__dt_to_string", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   524
        # TO_STRING
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   525
        (("BOOL",), ("ANY_STRING",), ("return_type", "__bool_to_string", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   526
        (("ANY_BIT",), ("ANY_STRING",), ("return_type", "__bit_to_string", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   527
        (("ANY_REAL",), ("ANY_STRING",), ("return_type", "__real_to_string", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   528
        (("ANY_SINT",), ("ANY_STRING",), ("return_type", "__sint_to_string", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   529
        (("ANY_UINT",), ("ANY_STRING",), ("return_type", "__uint_to_string", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   530
        # FROM_STRING
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   531
        (("ANY_STRING",), ("BOOL",), ("return_type", "__string_to_bool", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   532
        (("ANY_STRING",), ("ANY_BIT",), ("return_type", "__string_to_bit", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   533
        (("ANY_STRING",), ("ANY_SINT",), ("return_type", "__string_to_sint", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   534
        (("ANY_STRING",), ("ANY_UINT",), ("return_type", "__string_to_uint", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   535
        (("ANY_STRING",), ("ANY_REAL",), ("return_type", "__string_to_real", None))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   536
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   537
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   538
BCD_TO_ANY_LIST=[
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   539
        (("BYTE",),("USINT",), ("return_type", "__bcd_to_uint", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   540
        (("WORD",),("UINT",), ("return_type", "__bcd_to_uint", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   541
        (("DWORD",),("UDINT",), ("return_type", "__bcd_to_uint", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   542
        (("LWORD",),("ULINT",), ("return_type", "__bcd_to_uint", None))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   543
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   544
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   545
ANY_TO_BCD_LIST=[
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   546
        (("USINT",),("BYTE",), ("return_type", "__uint_to_bcd", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   547
        (("UINT",),("WORD",), ("return_type", "__uint_to_bcd", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   548
        (("UDINT",),("DWORD",), ("return_type", "__uint_to_bcd", None)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   549
        (("ULINT",),("LWORD",), ("return_type", "__uint_to_bcd", None))]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   550
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   551
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   552
def ANY_TO_ANY_FORMAT_GEN(any_to_any_list, fdecl):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   553
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   554
    for (InTypes, OutTypes, Format) in any_to_any_list:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   555
        outs = reduce(lambda a,b: a or b, map(lambda testtype : IsOfType(fdecl["outputs"][0][1],testtype), OutTypes))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   556
        inps = reduce(lambda a,b: a or b, map(lambda testtype : IsOfType(fdecl["inputs"][0][1],testtype), InTypes))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   557
        if inps and outs and fdecl["outputs"][0][1] != fdecl["inputs"][0][1]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   558
             return Format
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   559
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   560
    return None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   561
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   562
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   563
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   564
Returns this kind of declaration for all standard functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   565
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   566
            [{"name" : "Numerical", 'list': [   {   
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   567
                'baseinputnumber': 1,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   568
                'comment': 'Addition',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   569
                'extensible': True,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   570
                'inputs': [   ('IN1', 'ANY_NUM', 'none'),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   571
                              ('IN2', 'ANY_NUM', 'none')],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   572
                'name': 'ADD',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   573
                'outputs': [('OUT', 'ANY_NUM', 'none')],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   574
                'type': 'function'}, ...... ] },.....]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   575
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   576
def get_standard_funtions(table):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   577
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   578
    variables = get_standard_funtions_input_variables(table)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   579
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   580
    fonctions = find_section("Standard_functions_type",table)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   581
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   582
    Standard_Functions_Decl = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   583
    Current_section = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   584
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   585
    translate = {
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   586
            "extensible" : lambda x: {"yes":True, "no":False}[x],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   587
            "inputs" : lambda x:csv_input_translate(x,variables,baseinputnumber),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   588
            "outputs":lambda x:[("OUT",x,"none")]}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   589
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   590
    for fields in table:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   591
        if fields[1]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   592
            # If function section name given
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   593
            if fields[0]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   594
                words = fields[0].split('"')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   595
                if len(words) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   596
                    section_name = words[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   597
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   598
                    section_name = fields[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   599
                Current_section = {"name" : section_name, "list" : []}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   600
                Standard_Functions_Decl.append(Current_section)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   601
                Function_decl_list = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   602
            if Current_section:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   603
                Function_decl = dict([(champ, val) for champ, val in zip(fonctions, fields[1:]) if champ])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   604
                Function_decl["generate"] = generate_block
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   605
                Function_decl["initialise"] = lambda x,y:[]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   606
                baseinputnumber = int(Function_decl.get("baseinputnumber",1))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   607
                Function_decl["baseinputnumber"] = baseinputnumber
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   608
                for param, value in Function_decl.iteritems():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   609
                    if param in translate:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   610
                        Function_decl[param] = translate[param](value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   611
                Function_decl["type"] = "function"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   612
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   613
                if Function_decl["name"].startswith('*') or Function_decl["name"].endswith('*') :
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   614
                    input_ovrloading_types = GetSubTypes(Function_decl["inputs"][0][1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   615
                    output_types = GetSubTypes(Function_decl["outputs"][0][1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   616
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   617
                    input_ovrloading_types = [None]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   618
                    output_types = [None]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   619
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   620
                funcdeclname_orig = Function_decl["name"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   621
                funcdeclname = Function_decl["name"].strip('*_')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   622
                fdc = Function_decl["inputs"][:]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   623
                for intype in input_ovrloading_types:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   624
                    if intype != None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   625
                        Function_decl["inputs"] = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   626
                        for decl_tpl in fdc:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   627
                            if IsOfType(intype, decl_tpl[1]):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   628
                                Function_decl["inputs"] += [(decl_tpl[0], intype, decl_tpl[2])]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   629
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   630
                                Function_decl["inputs"] += [(decl_tpl)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   631
                            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   632
                            if funcdeclname_orig.startswith('*'):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   633
                                funcdeclin = intype + '_' + funcdeclname 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   634
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   635
                                funcdeclin = funcdeclname
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   636
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   637
                        funcdeclin = funcdeclname
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   638
                        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   639
                    for outype in output_types:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   640
                        if outype != None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   641
                            decl_tpl = Function_decl["outputs"][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   642
                            Function_decl["outputs"] = [ (decl_tpl[0] , outype,  decl_tpl[2])]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   643
                            if funcdeclname_orig.endswith('*'):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   644
                                funcdeclout =  funcdeclin + '_' + outype
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   645
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   646
                                funcdeclout =  funcdeclin
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   647
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   648
                            funcdeclout =  funcdeclin
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   649
                        Function_decl["name"] = funcdeclout
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   650
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   651
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   652
                        fdecl = Function_decl
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   653
                        res = eval(Function_decl["python_eval_c_code_format"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   654
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   655
                        if res != None :
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   656
                            # create the copy of decl dict to be appended to section
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   657
                            Function_decl_copy = Function_decl.copy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   658
                            Current_section["list"].append(Function_decl_copy)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   659
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   660
                raise "First function must be in a category"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   661
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   662
    return Standard_Functions_Decl
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   663
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   664
std_decl = get_standard_funtions(csv_file_to_table(open(os.path.join(os.path.split(__file__)[0],"iec_std.csv"))))#, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   665
1283
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   666
StdBlckLst.extend(std_decl)
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   667
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   668
# Dictionary to speedup block type fetching by name
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   669
StdBlckDct = {}
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   670
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   671
for section in StdBlckLst:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   672
    for desc in section["list"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   673
        words = desc["comment"].split('"')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   674
        if len(words) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   675
            desc["comment"] = words[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   676
        desc["usage"] = (
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   677
            "\n (" +
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   678
            str([ " " + fctdecl[1]+":"+fctdecl[0] for fctdecl in desc["inputs"]]).strip("[]").replace("'",'') +
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   679
            " ) => (" +
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   680
            str([ " " + fctdecl[1]+":"+fctdecl[0] for fctdecl in desc["outputs"]]).strip("[]").replace("'",'') +
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   681
            " )")
1283
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   682
        BlkLst = StdBlckDct.setdefault(desc["name"],[])
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   683
        BlkLst.append((section["name"], desc))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   684
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   685
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   686
#                            Languages Keywords
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   687
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   688
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   689
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   690
# Keywords for Pou Declaration
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   691
POU_BLOCK_START_KEYWORDS = ["FUNCTION", "FUNCTION_BLOCK", "PROGRAM"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   692
POU_BLOCK_END_KEYWORDS = ["END_FUNCTION", "END_FUNCTION_BLOCK", "END_PROGRAM"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   693
POU_KEYWORDS = ["EN", "ENO", "F_EDGE", "R_EDGE"] + POU_BLOCK_START_KEYWORDS + POU_BLOCK_END_KEYWORDS
1283
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   694
for category in StdBlckLst:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   695
    for block in category["list"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   696
        if block["name"] not in POU_KEYWORDS:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   697
            POU_KEYWORDS.append(block["name"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   698
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   699
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   700
# Keywords for Type Declaration
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   701
TYPE_BLOCK_START_KEYWORDS = ["TYPE", "STRUCT"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   702
TYPE_BLOCK_END_KEYWORDS = ["END_TYPE", "END_STRUCT"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   703
TYPE_KEYWORDS = ["ARRAY", "OF", "T", "D", "TIME_OF_DAY", "DATE_AND_TIME"] + TYPE_BLOCK_START_KEYWORDS + TYPE_BLOCK_END_KEYWORDS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   704
TYPE_KEYWORDS.extend([keyword for keyword in TypeHierarchy.keys() if keyword not in TYPE_KEYWORDS])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   705
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   706
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   707
# Keywords for Variable Declaration
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   708
VAR_BLOCK_START_KEYWORDS = ["VAR", "VAR_INPUT", "VAR_OUTPUT", "VAR_IN_OUT", "VAR_TEMP", "VAR_EXTERNAL"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   709
VAR_BLOCK_END_KEYWORDS = ["END_VAR"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   710
VAR_KEYWORDS = ["AT", "CONSTANT", "RETAIN", "NON_RETAIN"] + VAR_BLOCK_START_KEYWORDS + VAR_BLOCK_END_KEYWORDS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   711
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   712
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   713
# Keywords for Configuration Declaration
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   714
CONFIG_BLOCK_START_KEYWORDS = ["CONFIGURATION", "RESOURCE", "VAR_ACCESS", "VAR_CONFIG", "VAR_GLOBAL"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   715
CONFIG_BLOCK_END_KEYWORDS = ["END_CONFIGURATION", "END_RESOURCE", "END_VAR"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   716
CONFIG_KEYWORDS = ["ON", "PROGRAM", "WITH", "READ_ONLY", "READ_WRITE", "TASK"] + CONFIG_BLOCK_START_KEYWORDS + CONFIG_BLOCK_END_KEYWORDS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   717
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   718
# Keywords for Structured Function Chart
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   719
SFC_BLOCK_START_KEYWORDS = ["ACTION", "INITIAL_STEP", "STEP", "TRANSITION"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   720
SFC_BLOCK_END_KEYWORDS = ["END_ACTION", "END_STEP", "END_TRANSITION"]
949
aa24cf3b7009 Fixed SFC keyword definition
Laurent Bessard
parents: 814
diff changeset
   721
SFC_KEYWORDS = ["FROM", "TO"] + SFC_BLOCK_START_KEYWORDS + SFC_BLOCK_END_KEYWORDS
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   722
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   723
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   724
# Keywords for Instruction List
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   725
IL_KEYWORDS = ["TRUE", "FALSE", "LD", "LDN", "ST", "STN", "S", "R", "AND", "ANDN", "OR", "ORN",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   726
 "XOR", "XORN", "NOT", "ADD", "SUB", "MUL", "DIV", "MOD", "GT", "GE", "EQ", "NE",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   727
 "LE", "LT", "JMP", "JMPC", "JMPCN", "CAL", "CALC", "CALCN", "RET", "RETC", "RETCN"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   728
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   729
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   730
# Keywords for Structured Text
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   731
ST_BLOCK_START_KEYWORDS = ["IF", "ELSIF", "ELSE", "CASE", "FOR", "WHILE", "REPEAT"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   732
ST_BLOCK_END_KEYWORDS = ["END_IF", "END_CASE", "END_FOR", "END_WHILE", "END_REPEAT"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   733
ST_KEYWORDS = ["TRUE", "FALSE", "THEN", "OF", "TO", "BY", "DO", "DO", "UNTIL", "EXIT", 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   734
 "RETURN", "NOT", "MOD", "AND", "XOR", "OR"] + ST_BLOCK_START_KEYWORDS + ST_BLOCK_END_KEYWORDS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   735
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   736
# All the keywords of IEC
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   737
IEC_BLOCK_START_KEYWORDS = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   738
IEC_BLOCK_END_KEYWORDS = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   739
IEC_KEYWORDS = ["E", "TRUE", "FALSE"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   740
for all_keywords, keywords_list in [(IEC_BLOCK_START_KEYWORDS, [POU_BLOCK_START_KEYWORDS, TYPE_BLOCK_START_KEYWORDS,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   741
                                                                VAR_BLOCK_START_KEYWORDS, CONFIG_BLOCK_START_KEYWORDS,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   742
                                                                SFC_BLOCK_START_KEYWORDS, ST_BLOCK_START_KEYWORDS]),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   743
                                    (IEC_BLOCK_END_KEYWORDS, [POU_BLOCK_END_KEYWORDS, TYPE_BLOCK_END_KEYWORDS,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   744
                                                              VAR_BLOCK_END_KEYWORDS, CONFIG_BLOCK_END_KEYWORDS,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   745
                                                              SFC_BLOCK_END_KEYWORDS, ST_BLOCK_END_KEYWORDS]),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   746
                                    (IEC_KEYWORDS, [POU_KEYWORDS, TYPE_KEYWORDS, VAR_KEYWORDS, CONFIG_KEYWORDS,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   747
                                                    SFC_KEYWORDS, IL_KEYWORDS, ST_KEYWORDS])]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   748
    for keywords in keywords_list:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   749
        all_keywords.extend([keyword for keyword in keywords if keyword not in all_keywords])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   750