plcopen/structures.py
author Paul Beltyukov
Thu, 18 Aug 2016 14:35:03 +0500
changeset 1517 30692ab8b5c7
parent 1390 0f4d32a033e0
child 1571 486f94a8032c
permissions -rw-r--r--
This fixes issue #5
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
1390
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    25
import string, re
1313
85c167bfff93 Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents: 1310
diff changeset
    26
from plcopen import LoadProject
1320
bb04c41cbee9 Used OrderedDict for keeping of standard function blocks library defined
Laurent Bessard
parents: 1313
diff changeset
    27
from collections import OrderedDict
1390
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    28
from definitions import *
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    29
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    30
TypeHierarchy = dict(TypeHierarchy_list)
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    31
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    32
"""
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    33
returns true if the given data type is the same that "reference" meta-type or one of its types.
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    34
"""
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    35
def IsOfType(type, reference):
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    36
    if reference is None:
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    37
        return True
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    38
    elif type == reference:
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    39
        return True
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    40
    else:
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    41
        parent_type = TypeHierarchy[type]
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    42
        if parent_type is not None:
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    43
            return IsOfType(parent_type, reference)
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    44
    return False
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    45
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    46
"""
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    47
returns list of all types that correspont to the ANY* meta type
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    48
"""
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    49
def GetSubTypes(type):
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    50
    return [typename for typename, parenttype in TypeHierarchy.items() if not typename.startswith("ANY") and IsOfType(typename, type)]
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    51
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    52
DataTypeRange = dict(DataTypeRange_list)
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    53
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    54
"""
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    55
Ordered list of common Function Blocks defined in the IEC 61131-3
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
Each block have this attributes:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
    - "name" : The block name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
    - "type" : The block type. It can be "function", "functionBlock" or "program"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
    - "extensible" : Boolean that define if the block is extensible
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
    - "inputs" : List of the block inputs
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
    - "outputs" : List of the block outputs
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
    - "comment" : Comment that will be displayed in the block popup
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
    - "generate" : Method that generator will call for generating ST block code
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
Inputs and outputs are a tuple of characteristics that are in order:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
    - The name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
    - The data type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
    - The default modifier which can be "none", "negated", "rising" or "falling"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
1390
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    70
StdBlckLibs = {libname : LoadProject(tc6fname)[0]
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    71
             for libname, tc6fname in StdTC6Libs}
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    72
StdBlckLst = [{"name" : libname, "list":
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    73
               [GetBlockInfos(pous) for pous in lib.getpous()]}
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
    74
             for libname, lib in StdBlckLibs.iteritems()]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
#                             Test identifier
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    78
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    79
965
308e51832711 Fixed test identifier function
Laurent Bessard
parents: 949
diff changeset
    80
IDENTIFIER_MODEL = re.compile(
308e51832711 Fixed test identifier function
Laurent Bessard
parents: 949
diff changeset
    81
    "(?:%(letter)s|_(?:%(letter)s|%(digit)s))(?:_?(?:%(letter)s|%(digit)s))*$" %
308e51832711 Fixed test identifier function
Laurent Bessard
parents: 949
diff changeset
    82
    {"letter": "[a-zA-Z]", "digit": "[0-9]"})
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
# Test if identifier is valid
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
def TestIdentifier(identifier):
965
308e51832711 Fixed test identifier function
Laurent Bessard
parents: 949
diff changeset
    86
     return IDENTIFIER_MODEL.match(identifier) is not None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    87
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
#                        Standard functions list generation
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    90
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
take a .csv file and translate it it a "csv_table"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
"""            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
def csv_file_to_table(file):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
    return [ map(string.strip,line.split(';')) for line in file.xreadlines()]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
seek into the csv table to a section ( section_name match 1st field )
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
return the matching row without first field
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
def find_section(section_name, table):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   104
    fields = [None]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   105
    while(fields[0] != section_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
        fields = table.pop(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
    return fields[1:]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   110
extract the standard functions standard parameter names and types...
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
return a { ParameterName: Type, ...}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
def get_standard_funtions_input_variables(table):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
    variables = find_section("Standard_functions_variables_types", table)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
    standard_funtions_input_variables = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   116
    fields = [True,True]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
    while(fields[1]):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
        fields = table.pop(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   119
        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
   120
        standard_funtions_input_variables[variable_from_csv['name']] = variable_from_csv['type']
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
    return standard_funtions_input_variables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   124
translate .csv file input declaration into PLCOpenEditor interessting values
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
in : "(ANY_NUM, ANY_NUM)" and { ParameterName: Type, ...}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
return [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")] 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   128
def csv_input_translate(str_decl, variables, base):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   129
    decl = str_decl.replace('(','').replace(')','').replace(' ','').split(',')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   130
    params = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   132
    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
   133
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
    for param_type in decl:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
        if param_type in variables.keys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
            param_name = param_type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
            param_type = variables[param_type]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
        elif len_of_not_predifined_variable > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   139
            param_name = "IN%d"%base
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   140
            base += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
            param_name = "IN"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   143
        params.append((param_name, param_type, "none"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   144
    return params
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   145
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
Returns this kind of declaration for all standard functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
            [{"name" : "Numerical", 'list': [   {   
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   151
                'baseinputnumber': 1,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
                'comment': 'Addition',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
                'extensible': True,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
                'inputs': [   ('IN1', 'ANY_NUM', 'none'),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
                              ('IN2', 'ANY_NUM', 'none')],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
                'name': 'ADD',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
                'outputs': [('OUT', 'ANY_NUM', 'none')],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
                'type': 'function'}, ...... ] },.....]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
def get_standard_funtions(table):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   162
    variables = get_standard_funtions_input_variables(table)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
    fonctions = find_section("Standard_functions_type",table)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
    Standard_Functions_Decl = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
    Current_section = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
    translate = {
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
            "extensible" : lambda x: {"yes":True, "no":False}[x],
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
            "inputs" : lambda x:csv_input_translate(x,variables,baseinputnumber),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   172
            "outputs":lambda x:[("OUT",x,"none")]}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   174
    for fields in table:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   175
        if fields[1]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   176
            # If function section name given
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   177
            if fields[0]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
                words = fields[0].split('"')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
                if len(words) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
                    section_name = words[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
                    section_name = fields[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
                Current_section = {"name" : section_name, "list" : []}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   184
                Standard_Functions_Decl.append(Current_section)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
                Function_decl_list = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
            if Current_section:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
                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
   188
                baseinputnumber = int(Function_decl.get("baseinputnumber",1))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   189
                Function_decl["baseinputnumber"] = baseinputnumber
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
                for param, value in Function_decl.iteritems():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
                    if param in translate:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
                        Function_decl[param] = translate[param](value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
                Function_decl["type"] = "function"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   194
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   195
                if Function_decl["name"].startswith('*') or Function_decl["name"].endswith('*') :
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   196
                    input_ovrloading_types = GetSubTypes(Function_decl["inputs"][0][1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
                    output_types = GetSubTypes(Function_decl["outputs"][0][1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   198
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
                    input_ovrloading_types = [None]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
                    output_types = [None]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
                
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
                funcdeclname_orig = Function_decl["name"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
                funcdeclname = Function_decl["name"].strip('*_')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
                fdc = Function_decl["inputs"][:]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
                for intype in input_ovrloading_types:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
                    if intype != None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
                        Function_decl["inputs"] = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
                        for decl_tpl in fdc:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
                            if IsOfType(intype, decl_tpl[1]):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   210
                                Function_decl["inputs"] += [(decl_tpl[0], intype, decl_tpl[2])]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   211
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   212
                                Function_decl["inputs"] += [(decl_tpl)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
                            
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   214
                            if funcdeclname_orig.startswith('*'):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
                                funcdeclin = intype + '_' + funcdeclname 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   216
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   217
                                funcdeclin = funcdeclname
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
                        funcdeclin = funcdeclname
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
                        
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
                    for outype in output_types:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   222
                        if outype != None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   223
                            decl_tpl = Function_decl["outputs"][0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   224
                            Function_decl["outputs"] = [ (decl_tpl[0] , outype,  decl_tpl[2])]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   225
                            if funcdeclname_orig.endswith('*'):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   226
                                funcdeclout =  funcdeclin + '_' + outype
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   227
                            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
                                funcdeclout =  funcdeclin
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   229
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   230
                            funcdeclout =  funcdeclin
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
                        Function_decl["name"] = funcdeclout
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
1390
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   233
                        # apply filter given in "filter" column
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   234
                        filter_name = Function_decl["filter"]
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   235
                        store = True
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   236
                        for (InTypes, OutTypes) in ANY_TO_ANY_FILTERS.get(filter_name,[]):
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   237
                            outs = reduce(lambda a,b: a or b, 
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   238
                                       map(lambda testtype : IsOfType(
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   239
                                           Function_decl["outputs"][0][1],
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   240
                                           testtype), OutTypes))
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   241
                            inps = reduce(lambda a,b: a or b,
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   242
                                       map(lambda testtype : IsOfType(
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   243
                                           Function_decl["inputs"][0][1],
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   244
                                           testtype), InTypes))
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   245
                            if inps and outs and Function_decl["outputs"][0][1] != Function_decl["inputs"][0][1]:
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   246
                                store = True
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   247
                                break
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   248
                            else:
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   249
                                store = False
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   250
                        if store :
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
                            # create the copy of decl dict to be appended to section
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   252
                            Function_decl_copy = Function_decl.copy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
                            Current_section["list"].append(Function_decl_copy)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   255
                raise "First function must be in a category"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
    return Standard_Functions_Decl
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
1390
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   259
StdBlckLst.extend(get_standard_funtions(csv_file_to_table(open(StdFuncsCSV))))
1283
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   260
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   261
# Dictionary to speedup block type fetching by name
1320
bb04c41cbee9 Used OrderedDict for keeping of standard function blocks library defined
Laurent Bessard
parents: 1313
diff changeset
   262
StdBlckDct = OrderedDict()
1283
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   263
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   264
for section in StdBlckLst:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   265
    for desc in section["list"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   266
        words = desc["comment"].split('"')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   267
        if len(words) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   268
            desc["comment"] = words[1]
1313
85c167bfff93 Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents: 1310
diff changeset
   269
        desc["usage"] = ("\n (%s) => (%s)" % 
85c167bfff93 Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents: 1310
diff changeset
   270
            (", ".join(["%s:%s" % (input[1], input[0]) 
85c167bfff93 Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents: 1310
diff changeset
   271
                        for input in desc["inputs"]]),
85c167bfff93 Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents: 1310
diff changeset
   272
             ", ".join(["%s:%s" % (output[1], output[0]) 
85c167bfff93 Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents: 1310
diff changeset
   273
                        for output in desc["outputs"]])))
1283
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   274
        BlkLst = StdBlckDct.setdefault(desc["name"],[])
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1239
diff changeset
   275
        BlkLst.append((section["name"], desc))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   276
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   277
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   278
#                            Languages Keywords
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   279
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   280
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   281
# Keywords for Pou Declaration
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   282
POU_BLOCK_START_KEYWORDS = ["FUNCTION", "FUNCTION_BLOCK", "PROGRAM"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   283
POU_BLOCK_END_KEYWORDS = ["END_FUNCTION", "END_FUNCTION_BLOCK", "END_PROGRAM"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   284
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
   285
for category in StdBlckLst:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   286
    for block in category["list"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   287
        if block["name"] not in POU_KEYWORDS:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   288
            POU_KEYWORDS.append(block["name"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   289
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
# Keywords for Type Declaration
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   292
TYPE_BLOCK_START_KEYWORDS = ["TYPE", "STRUCT"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
TYPE_BLOCK_END_KEYWORDS = ["END_TYPE", "END_STRUCT"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
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
   295
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
   296
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   297
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
# Keywords for Variable Declaration
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
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
   300
VAR_BLOCK_END_KEYWORDS = ["END_VAR"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   301
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
   302
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   303
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   304
# Keywords for Configuration Declaration
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   305
CONFIG_BLOCK_START_KEYWORDS = ["CONFIGURATION", "RESOURCE", "VAR_ACCESS", "VAR_CONFIG", "VAR_GLOBAL"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   306
CONFIG_BLOCK_END_KEYWORDS = ["END_CONFIGURATION", "END_RESOURCE", "END_VAR"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   307
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
   308
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   309
# Keywords for Structured Function Chart
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   310
SFC_BLOCK_START_KEYWORDS = ["ACTION", "INITIAL_STEP", "STEP", "TRANSITION"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
SFC_BLOCK_END_KEYWORDS = ["END_ACTION", "END_STEP", "END_TRANSITION"]
949
aa24cf3b7009 Fixed SFC keyword definition
Laurent Bessard
parents: 814
diff changeset
   312
SFC_KEYWORDS = ["FROM", "TO"] + SFC_BLOCK_START_KEYWORDS + SFC_BLOCK_END_KEYWORDS
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
# Keywords for Instruction List
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
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
   317
 "XOR", "XORN", "NOT", "ADD", "SUB", "MUL", "DIV", "MOD", "GT", "GE", "EQ", "NE",
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
 "LE", "LT", "JMP", "JMPC", "JMPCN", "CAL", "CALC", "CALCN", "RET", "RETC", "RETCN"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   320
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   321
# Keywords for Structured Text
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   322
ST_BLOCK_START_KEYWORDS = ["IF", "ELSIF", "ELSE", "CASE", "FOR", "WHILE", "REPEAT"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   323
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
   324
ST_KEYWORDS = ["TRUE", "FALSE", "THEN", "OF", "TO", "BY", "DO", "DO", "UNTIL", "EXIT", 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   325
 "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
   326
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   327
# All the keywords of IEC
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   328
IEC_BLOCK_START_KEYWORDS = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   329
IEC_BLOCK_END_KEYWORDS = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   330
IEC_KEYWORDS = ["E", "TRUE", "FALSE"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   331
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
   332
                                                                VAR_BLOCK_START_KEYWORDS, CONFIG_BLOCK_START_KEYWORDS,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   333
                                                                SFC_BLOCK_START_KEYWORDS, ST_BLOCK_START_KEYWORDS]),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   334
                                    (IEC_BLOCK_END_KEYWORDS, [POU_BLOCK_END_KEYWORDS, TYPE_BLOCK_END_KEYWORDS,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   335
                                                              VAR_BLOCK_END_KEYWORDS, CONFIG_BLOCK_END_KEYWORDS,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
                                                              SFC_BLOCK_END_KEYWORDS, ST_BLOCK_END_KEYWORDS]),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   337
                                    (IEC_KEYWORDS, [POU_KEYWORDS, TYPE_KEYWORDS, VAR_KEYWORDS, CONFIG_KEYWORDS,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   338
                                                    SFC_KEYWORDS, IL_KEYWORDS, ST_KEYWORDS])]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   339
    for keywords in keywords_list:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   340
        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
   341
1390
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1330
diff changeset
   342