plcopen/structures.py
author lbessard
Mon, 28 Jan 2008 11:15:24 +0100
changeset 158 8a770e8d745a
parent 151 aaa80b48bead
child 170 5068ba721506
permissions -rw-r--r--
Adding support for Viewer font
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     3
14
cd0133ed377b Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents: 9
diff changeset
     4
import string, os, sys
cd0133ed377b Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents: 9
diff changeset
     5
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     6
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     7
#based on the plcopen standard. 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     8
#
58
39cd981ff242 Changing file headers
lbessard
parents: 57
diff changeset
     9
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    10
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    11
#See COPYING file for copyrights details.
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    12
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    13
#This library is free software; you can redistribute it and/or
5
f8652b073e84 GPL->LGPL
etisserant
parents: 0
diff changeset
    14
#modify it under the terms of the GNU General Public
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    15
#License as published by the Free Software Foundation; either
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    16
#version 2.1 of the License, or (at your option) any later version.
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    17
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    18
#This library is distributed in the hope that it will be useful,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    19
#but WITHOUT ANY WARRANTY; without even the implied warranty of
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    20
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
58
39cd981ff242 Changing file headers
lbessard
parents: 57
diff changeset
    21
#General Public License for more details.
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    22
#
5
f8652b073e84 GPL->LGPL
etisserant
parents: 0
diff changeset
    23
#You should have received a copy of the GNU General Public
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    24
#License along with this library; if not, write to the Free Software
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    25
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    26
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    27
9
b29105e29081 Adding test on step names in SFC Editor
lbessard
parents: 5
diff changeset
    28
LANGUAGES = ["IL","ST","FBD","LD","SFC"]
b29105e29081 Adding test on step names in SFC Editor
lbessard
parents: 5
diff changeset
    29
104
a9b8916d906d Adding support for generation of blocks in LD
lbessard
parents: 99
diff changeset
    30
LOCATIONDATATYPES = {"X" : ["BOOL"],
a9b8916d906d Adding support for generation of blocks in LD
lbessard
parents: 99
diff changeset
    31
                     "B" : ["SINT", "USINT", "BYTE", "STRING"],
a9b8916d906d Adding support for generation of blocks in LD
lbessard
parents: 99
diff changeset
    32
                     "W" : ["INT", "UINT", "WORD", "WSTRING"],
a9b8916d906d Adding support for generation of blocks in LD
lbessard
parents: 99
diff changeset
    33
                     "D" : ["DINT", "UDINT", "REAL", "DWORD"],
a9b8916d906d Adding support for generation of blocks in LD
lbessard
parents: 99
diff changeset
    34
                     "L" : ["LINT", "ULINT", "LREAL", "LWORD"]} 
a9b8916d906d Adding support for generation of blocks in LD
lbessard
parents: 99
diff changeset
    35
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    36
def generate_block(generator, block, body, link, order=False):
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    37
    body_type = body.getcontent()["name"]
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    38
    name = block.getinstanceName()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    39
    type = block.gettypeName()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    40
    executionOrderId = block.getexecutionOrderId()
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
    41
    block_infos = GetBlockType(type)
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    42
    if block_infos["type"] == "function":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    43
        output_variable = block.outputVariables.getvariable()[0]
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    44
        output_name = "%s%d_OUT"%(type, block.getlocalId())
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    45
        if not generator.ComputedBlocks.get(block, False) and not order:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    46
            if generator.Interface[-1][0] != "VAR" or generator.Interface[-1][1] or generator.Interface[-1][2] or generator.Interface[-1][3]:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    47
                generator.Interface.append(("VAR", False, False, False, []))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    48
            if output_variable.connectionPointOut in generator.ConnectionTypes:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    49
                generator.Interface[-1][4].append((generator.ConnectionTypes[output_variable.connectionPointOut], output_name, None, None))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    50
            else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    51
                generator.Interface[-1][4].append(("ANY", output_name, None, None))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    52
            vars = []
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    53
            for variable in block.inputVariables.getvariable():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    54
                connections = variable.connectionPointIn.getconnections()
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    55
                if connections and len(connections) == 1:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    56
                    if body_type == "FBD" or body_type == "SFC":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    57
                        value = generator.ComputeFBDExpression(body, connections[0], executionOrderId > 0)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    58
                    elif body_type == "LD":
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    59
                        paths = generator.GenerateLDPaths(variable.connectionPointIn.getConnections(), body)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    60
                        if len(paths) > 0:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    61
                            paths = tuple(paths)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    62
                        else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    63
                            paths = paths[0] 
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    64
                        value = generator.ComputeLDExpression(paths, True)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    65
                    vars.append(generator.ExtractModifier(variable, value))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    66
            generator.Program += "  %s := %s(%s);\n"%(output_name, type, ", ".join(vars))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    67
            generator.ComputedBlocks[block] = True
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    68
        return generator.ExtractModifier(output_variable, output_name)
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
    69
    elif block_infos["type"] == "functionBlock":
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    70
        if not generator.ComputedBlocks.get(block, False) and not order:
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
    71
            vars = []
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    72
            for variable in block.inputVariables.getvariable():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    73
                connections = variable.connectionPointIn.getconnections()
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
    74
                if connections and len(connections) == 1:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    75
                    parameter = variable.getformalParameter()
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 104
diff changeset
    76
                    if body_type == "FBD" or body_type == "SFC":
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    77
                        value = generator.ComputeFBDExpression(body, connections[0], executionOrderId > 0)
104
a9b8916d906d Adding support for generation of blocks in LD
lbessard
parents: 99
diff changeset
    78
                        vars.append("%s := %s"%(parameter, generator.ExtractModifier(variable, value)))
a9b8916d906d Adding support for generation of blocks in LD
lbessard
parents: 99
diff changeset
    79
                    elif body_type == "LD":
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    80
                        paths = generator.GenerateLDPaths(variable.connectionPointIn.getconnections(), body)
104
a9b8916d906d Adding support for generation of blocks in LD
lbessard
parents: 99
diff changeset
    81
                        if len(paths) > 0:
a9b8916d906d Adding support for generation of blocks in LD
lbessard
parents: 99
diff changeset
    82
                            paths = tuple(paths)
a9b8916d906d Adding support for generation of blocks in LD
lbessard
parents: 99
diff changeset
    83
                        else:
a9b8916d906d Adding support for generation of blocks in LD
lbessard
parents: 99
diff changeset
    84
                            paths = paths[0] 
a9b8916d906d Adding support for generation of blocks in LD
lbessard
parents: 99
diff changeset
    85
                        value = generator.ComputeLDExpression(paths, True)
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
    86
                    vars.append("%s := %s"%(parameter, generator.ExtractModifier(variable, value)))
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
    87
            generator.Program += "  %s(%s);\n"%(name, ", ".join(vars))
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
    88
            generator.ComputedBlocks[block] = True
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
    89
        if link:
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    90
            connectionPoint = link.getposition()[-1]
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
    91
        else:
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
    92
            connectionPoint = None
151
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    93
        for variable in block.outputVariables.getvariable():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    94
            blockPointx, blockPointy = variable.connectionPointOut.getrelPositionXY()
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    95
            if not connectionPoint or block.getx() + blockPointx == connectionPoint.getx() and block.gety() + blockPointy == connectionPoint.gety():
aaa80b48bead Adding support for the new version of xmlclass
lbessard
parents: 125
diff changeset
    96
                return generator.ExtractModifier(variable, "%s.%s"%(name, variable.getformalParameter()))
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
    97
        raise ValueError, "No output variable found"
21
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
    98
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
    99
def initialise_block(type, name):
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   100
    return [(type, name, None, None)]
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   101
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   102
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   103
#                        Function Block Types definitions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   104
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   105
21
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   106
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   107
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   108
Ordored list of common Function Blocks defined in the IEC 61131-3
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   109
Each block have this attributes:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   110
    - "name" : The block name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   111
    - "type" : The block type. It can be "function", "functionBlock" or "program"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   112
    - "extensible" : Boolean that define if the block is extensible
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   113
    - "inputs" : List of the block inputs
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   114
    - "outputs" : List of the block outputs
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   115
    - "comment" : Comment that will be displayed in the block popup
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   116
    - "generate" : Method that generator will call for generating ST block code
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   117
Inputs and outputs are a tuple of characteristics that are in order:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   118
    - The name
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   119
    - The data type
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   120
    - The default modifier which can be "none", "negated", "rising" or "falling"
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   121
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   122
14
cd0133ed377b Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents: 9
diff changeset
   123
BlockTypes = [{"name" : "Standard function blocks", "list":
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   124
               [{"name" : "SR", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   125
                    "inputs" : [("S1","BOOL","none"),("R","BOOL","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   126
                    "outputs" : [("Q1","BOOL","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   127
                    "comment" : "SR bistable\nThe SR bistable is a latch where the Set dominates.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   128
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   129
                {"name" : "RS", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   130
                    "inputs" : [("S","BOOL","none"),("R1","BOOL","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   131
                    "outputs" : [("Q1","BOOL","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   132
                    "comment" : "RS bistable\nThe RS bistable is a latch where the Reset dominates.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   133
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   134
                {"name" : "SEMA", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   135
                    "inputs" : [("CLAIM","BOOL","none"),("RELEASE","BOOL","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   136
                    "outputs" : [("BUSY","BOOL","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   137
                    "comment" : "Semaphore\nThe semaphore provides a mechanism to allow software elements mutually exclusive access to certain ressources.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   138
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   139
                {"name" : "R_TRIG", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   140
                    "inputs" : [("CLK","BOOL","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   141
                    "outputs" : [("Q","BOOL","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   142
                    "comment" : "Rising edge detector\nThe output produces a single pulse when a rising edge is detected.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   143
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   144
                {"name" : "F_TRIG", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   145
                    "inputs" : [("CLK","BOOL","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   146
                    "outputs" : [("Q","BOOL","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   147
                    "comment" : "Falling edge detector\nThe output produces a single pulse when a falling edge is detected.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   148
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   149
                {"name" : "CTU", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   150
                    "inputs" : [("CU","BOOL","rising"),("R","BOOL","none"),("PV","INT","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   151
                    "outputs" : [("Q","BOOL","none"),("CV","INT","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   152
                    "comment" : "Up-counter\nThe up-counter can be used to signal when a count has reached a maximum value.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   153
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   154
                {"name" : "CTD", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   155
                    "inputs" : [("CD","BOOL","rising"),("LD","BOOL","none"),("PV","INT","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   156
                    "outputs" : [("Q","BOOL","none"),("CV","INT","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   157
                    "comment" : "Down-counter\nThe down-counter can be used to signal when a count has reached zero, on counting down from a preset value.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   158
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   159
                {"name" : "CTUD", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   160
                    "inputs" : [("CU","BOOL","rising"),("CD","BOOL","rising"),("R","BOOL","none"),("LD","BOOL","none"),("PV","INT","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   161
                    "outputs" : [("QU","BOOL","none"),("QD","BOOL","none"),("CV","INT","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   162
                    "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 ans down on the other.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   163
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   164
                {"name" : "TP", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   165
                    "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   166
                    "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   167
                    "comment" : "Pulse timer\nThe pulse timer can be used to generate output pulses of a given time duration.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   168
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   169
                {"name" : "TOF", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   170
                    "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   171
                    "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   172
                    "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.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   173
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   174
                {"name" : "TON", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   175
                    "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   176
                    "outputs" : [("Q","BOOL","none"),("ET","TIME","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   177
                    "comment" : "Off-delay timer\nThe off-delay timer can be used to delay setting an output false, for fixed period after input goes false.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   178
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   179
                {"name" : "RTC", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   180
                    "inputs" : [("EN","BOOL","none"),("PDT","DATE_AND_TIME","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   181
                    "outputs" : [("Q","BOOL","none"),("CDT","DATE_AND_TIME","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   182
                    "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.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   183
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   184
                {"name" : "INTEGRAL", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   185
                    "inputs" : [("RUN","BOOL","none"),("R1","BOOL","none"),("XIN","REAL","none"),("X0","REAL","none"),("CYCLE","TIME","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   186
                    "outputs" : [("Q","BOOL","none"),("XOUT","REAL","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   187
                    "comment" : "Integral\nThe integral function block integrates the value of input XIN over time.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   188
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   189
                {"name" : "DERIVATIVE", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   190
                    "inputs" : [("RUN","BOOL","none"),("XIN","REAL","none"),("CYCLE","TIME","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   191
                    "outputs" : [("XOUT","REAL","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   192
                    "comment" : "Derivative\nThe derivative function block produces an output XOUT proportional to the rate of change of the input XIN.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   193
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   194
                {"name" : "PID", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   195
                    "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")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   196
                    "outputs" : [("XOUT","REAL","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   197
                    "comment" : "PID\nThe PID (proportional, Integral, Derivative) function block provides the classical three term controller for closed loop control.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   198
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   199
                {"name" : "RAMP", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   200
                    "inputs" : [("RUN","BOOL","none"),("X0","REAL","none"),("X1","REAL","none"),("TR","TIME","none"),("CYCLE","TIME","none"),("HOLDBACK","BOOL","none"),("ERROR","REAL","none"),("PV","REAL","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   201
                    "outputs" : [("RAMP","BOOL","none"),("XOUT","REAL","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   202
                    "comment" : "Ramp\nThe RAMP function block is modelled on example given in the standard but with the addition of a 'Holdback' feature.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   203
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   204
                {"name" : "HYSTERESIS", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   205
                    "inputs" : [("XIN1","REAL","none"),("XIN2","REAL","none"),("EPS","REAL","none")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   206
                    "outputs" : [("Q","BOOL","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   207
                    "comment" : "Hysteresis\nThe hysteresis function block provides a hysteresis boolean output driven by the difference of two floating point (REAL) inputs XIN1 and XIN2.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   208
                    "generate" : generate_block, "initialise" : initialise_block},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   209
                {"name" : "RATIO_MONITOR", "type" : "functionBlock", "extensible" : False, 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   210
                    "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")], 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   211
                    "outputs" : [("ALARM","BOOL","none"),("TOTAL_ERR","BOOL","none")],
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   212
                    "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.",
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   213
                    "generate" : generate_block, "initialise" : initialise_block}
57
9bf197698af0 SVGUI Functions Blocks added
jon
parents: 47
diff changeset
   214
                ]},
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   215
             ]
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   216
             
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   217
PluginTypes = []
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   218
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   219
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   220
Function that returns the block definition associated to the block type given
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   221
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   222
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   223
def GetBlockType(type, inputs = None):
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   224
    for category in BlockTypes + PluginTypes:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   225
        for blocktype in category["list"]:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   226
            if inputs:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   227
                block_inputs = tuple([var_type for name, var_type, modifier in blocktype["inputs"]])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   228
                same_inputs = inputs == block_inputs
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   229
            else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   230
                same_inputs = True
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
   231
            if blocktype["name"] == type and same_inputs:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   232
                return blocktype
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   233
    return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   234
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   235
"""
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   236
Function that add a new plugin to the plugin list
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   237
"""
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   238
92
76d5001393df Adding support for refreshing PLCOpenEditor block list
lbessard
parents: 78
diff changeset
   239
def AddPluginBlockList(blocklist):
76d5001393df Adding support for refreshing PLCOpenEditor block list
lbessard
parents: 78
diff changeset
   240
    PluginTypes.extend(blocklist)
76d5001393df Adding support for refreshing PLCOpenEditor block list
lbessard
parents: 78
diff changeset
   241
    
76d5001393df Adding support for refreshing PLCOpenEditor block list
lbessard
parents: 78
diff changeset
   242
def ClearPluginTypes():
76d5001393df Adding support for refreshing PLCOpenEditor block list
lbessard
parents: 78
diff changeset
   243
    for i in xrange(len(PluginTypes)):
76d5001393df Adding support for refreshing PLCOpenEditor block list
lbessard
parents: 78
diff changeset
   244
        PluginTypes.pop(0)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   245
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   246
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   247
#                           Data Types definitions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   248
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   249
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   250
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   251
Ordored list of common data types defined in the IEC 61131-3
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   252
Each type is associated to his direct parent type. It defines then a hierarchy
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   253
between type that permits to make a comparison of two types
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   254
"""
18
ee18a387e80a Enhanced standard funcrtion declaration from .csv file.
etisserant
parents: 15
diff changeset
   255
TypeHierarchy_list = [
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   256
    ("ANY", None),
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   257
    ("ANY_DERIVED", "ANY"),
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   258
    ("ANY_ELEMENTARY", "ANY"),
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   259
    ("ANY_MAGNITUDE", "ANY_ELEMENTARY"),
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   260
    ("ANY_BIT", "ANY_ELEMENTARY"),
25
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   261
    ("ANY_NBIT", "ANY_BIT"),
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   262
    ("ANY_STRING", "ANY_ELEMENTARY"),
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   263
    ("ANY_DATE", "ANY_ELEMENTARY"),
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   264
    ("ANY_NUM", "ANY_MAGNITUDE"),
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   265
    ("ANY_REAL", "ANY_NUM"),
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   266
    ("ANY_INT", "ANY_NUM"),
25
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   267
    ("ANY_SINT", "ANY_INT"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   268
    ("ANY_UINT", "ANY_INT"),
27
dae55dd9ee14 Current developping version
lbessard
parents: 25
diff changeset
   269
	("BOOL", "ANY_BIT"),
25
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   270
    ("SINT", "ANY_SINT"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   271
    ("INT", "ANY_SINT"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   272
    ("DINT", "ANY_SINT"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   273
    ("LINT", "ANY_SINT"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   274
    ("USINT", "ANY_UINT"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   275
    ("UINT", "ANY_UINT"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   276
    ("UDINT", "ANY_UINT"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   277
    ("ULINT", "ANY_UINT"),
27
dae55dd9ee14 Current developping version
lbessard
parents: 25
diff changeset
   278
    ("REAL", "ANY_REAL"),
dae55dd9ee14 Current developping version
lbessard
parents: 25
diff changeset
   279
    ("LREAL", "ANY_REAL"),
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   280
    ("TIME", "ANY_MAGNITUDE"),
27
dae55dd9ee14 Current developping version
lbessard
parents: 25
diff changeset
   281
    ("DATE", "ANY_DATE"),
dae55dd9ee14 Current developping version
lbessard
parents: 25
diff changeset
   282
    ("TOD", "ANY_DATE"),
dae55dd9ee14 Current developping version
lbessard
parents: 25
diff changeset
   283
    ("DT", "ANY_DATE"),
dae55dd9ee14 Current developping version
lbessard
parents: 25
diff changeset
   284
    ("STRING", "ANY_STRING"),
25
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   285
    ("BYTE", "ANY_NBIT"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   286
    ("WORD", "ANY_NBIT"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   287
    ("DWORD", "ANY_NBIT"),
27
dae55dd9ee14 Current developping version
lbessard
parents: 25
diff changeset
   288
    ("LWORD", "ANY_NBIT")
dae55dd9ee14 Current developping version
lbessard
parents: 25
diff changeset
   289
    #("WSTRING", "ANY_STRING") # TODO
dae55dd9ee14 Current developping version
lbessard
parents: 25
diff changeset
   290
]
18
ee18a387e80a Enhanced standard funcrtion declaration from .csv file.
etisserant
parents: 15
diff changeset
   291
ee18a387e80a Enhanced standard funcrtion declaration from .csv file.
etisserant
parents: 15
diff changeset
   292
TypeHierarchy = dict(TypeHierarchy_list)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   293
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   294
def ResetTypeHierarchy():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   295
    TypeHierarchy = dict(TypeHierarchy_list)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   296
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   297
def AddDataTypeHierarchy(name, reference):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   298
    TypeHierarchy[name] = reference
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   299
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   300
DataTypeRange_list = [
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   301
    ("SINT", (-2**7, 2**7 - 1)),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   302
    ("INT", (-2**15, 2**15 - 1)),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   303
    ("DINT", (-2**31, 2**31 - 1)),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   304
    ("LINT", (-2**31, 2**31 - 1)),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   305
    ("USINT", (0, 2**8 - 1)),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   306
    ("UINT", (0, 2**16 - 1)),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   307
    ("UDINT", (0, 2**31 - 1)),
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   308
    ("ULINT", (0, 2**31 - 1))
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   309
]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   310
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   311
DataTypeRange = dict(DataTypeRange_list)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   312
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   313
def ResetDataTypeRange():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   314
    DataTypeRange = dict(DataTypeRange_list)
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   315
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   316
def AddDataTypeRange(name, range):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   317
    DataTypeRange[name] = range
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   318
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   319
"""
15
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   320
returns true if the given data type is the same that "reference" meta-type or one of its types.
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   321
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   322
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   323
def IsOfType(test, reference):
98
ec5d7af033d8 Added support for wire type compatibility check
lbessard
parents: 93
diff changeset
   324
    if reference is None:
ec5d7af033d8 Added support for wire type compatibility check
lbessard
parents: 93
diff changeset
   325
        return True
ec5d7af033d8 Added support for wire type compatibility check
lbessard
parents: 93
diff changeset
   326
    while test is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   327
        if test == reference:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   328
            return True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   329
        test = TypeHierarchy[test]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   330
    return False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   331
99
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 98
diff changeset
   332
def IsEndType(reference):
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 98
diff changeset
   333
    if reference is not None:
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   334
        return not reference.startswith("ANY")
99
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 98
diff changeset
   335
    else:
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 98
diff changeset
   336
        return True
2b18a72dcaf0 Added support for standard functions type compatibility check
lbessard
parents: 98
diff changeset
   337
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   338
def GetDataTypeRange(reference):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   339
    while reference is not None:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   340
        if reference in DataTypeRange:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   341
            return DataTypeRange[reference]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   342
        else:
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   343
            reference = TypeHierarchy[reference]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   344
    return None
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   345
15
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   346
"""
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   347
returns list of all types that correspont to the ANY* meta type
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   348
"""
14
cd0133ed377b Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents: 9
diff changeset
   349
def GetSubTypes(reference):
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   350
    return [typename for typename, parenttype in TypeHierarchy.items() if not typename.startswith("ANY") and IsOfType(typename, reference)]
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   351
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   352
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   353
EnumeratedDataValues = []
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   354
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   355
def ResetEnumeratedDataValues():
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   356
    EnumeratedDataValues = []
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   357
    
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   358
def AddEnumeratedDataValues(values):
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   359
    EnumeratedDataValues.extend(values)
18
ee18a387e80a Enhanced standard funcrtion declaration from .csv file.
etisserant
parents: 15
diff changeset
   360
21
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   361
#-------------------------------------------------------------------------------
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   362
#                             Test identifier
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   363
#-------------------------------------------------------------------------------
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   364
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   365
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   366
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   367
# Test if identifier is valid
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   368
def TestIdentifier(identifier):
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   369
     if identifier[0].isdigit():
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   370
        return False
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   371
     words = identifier.split('_')
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   372
     for i, word in enumerate(words):
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   373
         if len(word) == 0 and i != 0:
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   374
             return False
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   375
         if len(word) != 0 and not word.isalnum():
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   376
             return False
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   377
     return True
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   378
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   379
e619d7bea692 Add support for AND, OR, XOR for booleans
lbessard
parents: 19
diff changeset
   380
#-------------------------------------------------------------------------------
109
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   381
#                        Standard functions list generation
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   382
#-------------------------------------------------------------------------------
18
ee18a387e80a Enhanced standard funcrtion declaration from .csv file.
etisserant
parents: 15
diff changeset
   383
ee18a387e80a Enhanced standard funcrtion declaration from .csv file.
etisserant
parents: 15
diff changeset
   384
15
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   385
"""
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   386
take a .csv file and translate it it a "csv_table"
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   387
"""            
14
cd0133ed377b Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents: 9
diff changeset
   388
def csv_file_to_table(file):
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   389
    return [ map(string.strip,line.split(';')) for line in file.xreadlines()]
14
cd0133ed377b Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents: 9
diff changeset
   390
15
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   391
"""
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   392
seek into the csv table to a section ( section_name match 1st field )
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   393
return the matching row without first field
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   394
"""
14
cd0133ed377b Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents: 9
diff changeset
   395
def find_section(section_name, table):
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   396
    fields = [None]
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   397
    while(fields[0] != section_name):
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   398
        fields = table.pop(0)
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   399
    return fields[1:]
14
cd0133ed377b Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents: 9
diff changeset
   400
15
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   401
"""
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   402
extract the standard functions standard parameter names and types...
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   403
return a { ParameterName: Type, ...}
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   404
"""
14
cd0133ed377b Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents: 9
diff changeset
   405
def get_standard_funtions_input_variables(table):
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   406
    variables = find_section("Standard_functions_variables_types", table)
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   407
    standard_funtions_input_variables = {}
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   408
    fields = [True,True]
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   409
    while(fields[1]):
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   410
        fields = table.pop(0)
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   411
        variable_from_csv = dict([(champ, val) for champ, val in zip(variables, fields[1:]) if champ!=''])
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   412
        standard_funtions_input_variables[variable_from_csv['name']] = variable_from_csv['type']
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   413
    return standard_funtions_input_variables
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   414
    
15
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   415
"""
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   416
translate .csv file input declaration into PLCOpenEditor interessting values
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   417
in : "(ANY_NUM, ANY_NUM)" and { ParameterName: Type, ...}
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   418
return [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")] 
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   419
"""
14
cd0133ed377b Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents: 9
diff changeset
   420
def csv_input_translate(str_decl, variables, base):
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   421
    decl = str_decl.replace('(','').replace(')','').replace(' ','').split(',')
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   422
    params = []
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   423
    
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   424
    len_of_not_predifined_variable = len([True for param_type in decl if param_type not in variables])
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   425
    
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   426
    for param_type in decl:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   427
        if param_type in variables.keys():
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   428
            param_name = param_type
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   429
            param_type = variables[param_type]
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   430
        elif len_of_not_predifined_variable > 1:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   431
            param_name = "IN%d"%base
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   432
            base += 1
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   433
        else:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   434
            param_name = "IN"
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   435
        params.append((param_name, param_type, "none"))
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   436
    return params
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   437
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   438
25
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   439
ANY_TO_ANY_LIST=[
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   440
        # simple type conv are let as C cast
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   441
        (("ANY_NUM","ANY_BIT"),("ANY_NUM","ANY_BIT"), "(%(return_type)s)%(IN_value)s"),
25
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   442
        # TO_TIME
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   443
        (("ANY_INT","ANY_BIT"),("ANY_DATE","TIME"), "(%(return_type)s)__int_to_time(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   444
        (("ANY_REAL",),("ANY_DATE","TIME"), "(%(return_type)s)__real_to_time(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   445
        (("ANY_STRING",), ("ANY_DATE","TIME"), "(%(return_type)s)__string_to_time(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   446
        # FROM_TIME
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   447
        (("ANY_DATE","TIME"), ("ANY_REAL",), "(%(return_type)s)__time_to_real(%(IN_value)s)"),
40
49c8ebc1ee25 Cleanup in generated C code for STD lib
etisserant
parents: 28
diff changeset
   448
        (("ANY_DATE","TIME"), ("ANY_INT","ANY_NBIT"), "(%(return_type)s)__time_to_int(%(IN_value)s)"),
25
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   449
        (("TIME",), ("ANY_STRING",), "(%(return_type)s)__time_to_string(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   450
        (("DATE",), ("ANY_STRING",), "(%(return_type)s)__date_to_string(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   451
        (("TOD",), ("ANY_STRING",), "(%(return_type)s)__tod_to_string(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   452
        (("DT",), ("ANY_STRING",), "(%(return_type)s)__dt_to_string(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   453
        # TO_STRING
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   454
        (("BOOL",), ("ANY_STRING",), "(%(return_type)s)__bool_to_string(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   455
        (("ANY_BIT",), ("ANY_STRING",), "(%(return_type)s)__bit_to_string(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   456
        (("ANY_REAL",), ("ANY_STRING",), "(%(return_type)s)__real_to_string(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   457
        (("ANY_SINT",), ("ANY_STRING",), "(%(return_type)s)__sint_to_string(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   458
        (("ANY_UINT",), ("ANY_STRING",), "(%(return_type)s)__uint_to_string(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   459
        # FROM_STRING
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   460
        (("ANY_STRING",), ("BOOL",), "(%(return_type)s)__string_to_bool(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   461
        (("ANY_STRING",), ("ANY_BIT",), "(%(return_type)s)__string_to_bit(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   462
        (("ANY_STRING",), ("ANY_SINT",), "(%(return_type)s)__string_to_sint(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   463
        (("ANY_STRING",), ("ANY_UINT",), "(%(return_type)s)__string_to_uint(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   464
        (("ANY_STRING",), ("ANY_REAL",), "(%(return_type)s)__string_to_real(%(IN_value)s)")]
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   465
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   466
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   467
BCD_TO_ANY_LIST=[
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   468
        (("BYTE",),("USINT",), "(%(return_type)s)__bcd_to_uint(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   469
        (("WORD",),("UINT",), "(%(return_type)s)__bcd_to_uint(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   470
        (("DWORD",),("UDINT",), "(%(return_type)s)__bcd_to_uint(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   471
        (("LWORD",),("ULINT",), "(%(return_type)s)__bcd_to_uint(%(IN_value)s)")]
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   472
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   473
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   474
ANY_TO_BCD_LIST=[
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   475
        (("USINT",),("BYTE",), "(%(return_type)s)__uint_to_bcd(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   476
        (("UINT",),("WORD",), "(%(return_type)s)__uint_to_bcd(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   477
        (("UDINT",),("DWORD",), "(%(return_type)s)__uint_to_bcd(%(IN_value)s)"),
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   478
        (("ULINT",),("LWORD",), "(%(return_type)s)__uint_to_bcd(%(IN_value)s)")]
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   479
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   480
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   481
def ANY_TO_ANY_FORMAT_GEN(any_to_any_list, fdecl):
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   482
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   483
    for (InTypes, OutTypes, Format) in any_to_any_list:
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   484
        outs = reduce(lambda a,b: a or b, map(lambda testtype : IsOfType(fdecl["outputs"][0][1],testtype), OutTypes))
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   485
        inps = reduce(lambda a,b: a or b, map(lambda testtype : IsOfType(fdecl["inputs"][0][1],testtype), InTypes))
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   486
        if inps and outs and fdecl["outputs"][0][1] != fdecl["inputs"][0][1]:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   487
             return Format
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   488
    
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   489
    return None
18
ee18a387e80a Enhanced standard funcrtion declaration from .csv file.
etisserant
parents: 15
diff changeset
   490
ee18a387e80a Enhanced standard funcrtion declaration from .csv file.
etisserant
parents: 15
diff changeset
   491
15
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   492
"""
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   493
Returns this kind of declaration for all standard functions
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   494
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   495
            [{"name" : "Numerical", 'list': [   {   
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   496
                'baseinputnumber': 1,
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   497
                'comment': 'Addition',
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   498
                'extensible': True,
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   499
                'inputs': [   ('IN1', 'ANY_NUM', 'none'),
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   500
                              ('IN2', 'ANY_NUM', 'none')],
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   501
                'name': 'ADD',
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   502
                'outputs': [('OUT', 'ANY_NUM', 'none')],
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   503
                'type': 'function'}, ...... ] },.....]
fc897b7bfa7b Enhanced standard function decalration fr cvs
etisserant
parents: 14
diff changeset
   504
"""
14
cd0133ed377b Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents: 9
diff changeset
   505
def get_standard_funtions(table):
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   506
    
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   507
    variables = get_standard_funtions_input_variables(table)
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   508
    
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   509
    fonctions = find_section("Standard_functions_type",table)
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   510
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   511
    Standard_Functions_Decl = []
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   512
    Current_section = None
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   513
    
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   514
    translate = {
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   515
            "extensible" : lambda x: {"yes":True, "no":False}[x],
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   516
            "inputs" : lambda x:csv_input_translate(x,variables,baseinputnumber),
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   517
            "outputs":lambda x:[("OUT",x,"none")]}
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   518
    
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   519
    for fields in table:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   520
        if fields[1]:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   521
            # If function section name given
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   522
            if fields[0]:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   523
                Current_section = {"name" : fields[0], "list" : []}
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   524
                Standard_Functions_Decl.append(Current_section)
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   525
                Function_decl_list = []
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   526
            if Current_section:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   527
                Function_decl = dict([(champ, val) for champ, val in zip(fonctions, fields[1:]) if champ])
78
049f2e7090a2 Adding support for adding block types with particular behaviour
lbessard
parents: 58
diff changeset
   528
                Function_decl["generate"] = generate_block
93
c3c24b979a4d Add support for custom block declaration
lbessard
parents: 92
diff changeset
   529
                Function_decl["initialise"] = lambda x,y:[]
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   530
                baseinputnumber = int(Function_decl.get("baseinputnumber",1))
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   531
                Function_decl["baseinputnumber"] = baseinputnumber
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   532
                for param, value in Function_decl.iteritems():
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   533
                    if param in translate:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   534
                        Function_decl[param] = translate[param](value)
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   535
                Function_decl["type"] = "function"
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   536
                
25
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   537
                if Function_decl["name"].startswith('*') or Function_decl["name"].endswith('*') :
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   538
                    input_ovrloading_types = GetSubTypes(Function_decl["inputs"][0][1])
25
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   539
                    output_types = GetSubTypes(Function_decl["outputs"][0][1])
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   540
                else:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   541
                    input_ovrloading_types = [None]
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   542
                    output_types = [None]
125
394d9f168258 Adding support for execution order in PLCGenerator
lbessard
parents: 109
diff changeset
   543
                
22
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   544
                funcdeclname_orig = Function_decl["name"]
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   545
                funcdeclname = Function_decl["name"].strip('*_')
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   546
                fdc = Function_decl["inputs"][:]
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   547
                for intype in input_ovrloading_types:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   548
                    if intype != None:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   549
                        Function_decl["inputs"] = []
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   550
                        for decl_tpl in fdc:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   551
                            if IsOfType(intype, decl_tpl[1]):
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   552
                                Function_decl["inputs"] += [(decl_tpl[0], intype, decl_tpl[2])]
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   553
                            else:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   554
                                Function_decl["inputs"] += [(decl_tpl)]
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   555
                            
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   556
                            if funcdeclname_orig.startswith('*'):
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   557
                                funcdeclin = intype + '_' + funcdeclname 
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   558
                            else:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   559
                                funcdeclin = funcdeclname
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   560
                    else:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   561
                        funcdeclin = funcdeclname
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   562
                        
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   563
                    for outype in output_types:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   564
                        if outype != None:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   565
                            decl_tpl = Function_decl["outputs"][0]
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   566
                            Function_decl["outputs"] = [ (decl_tpl[0] , outype,  decl_tpl[2])]
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   567
                            if funcdeclname_orig.endswith('*'):
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   568
                                funcdeclout =  funcdeclin + '_' + outype
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   569
                            else:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   570
                                funcdeclout =  funcdeclin
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   571
                        else:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   572
                            funcdeclout =  funcdeclin
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   573
                        Function_decl["name"] = funcdeclout
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   574
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   575
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   576
                        fdecl = Function_decl
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   577
                        res = eval(Function_decl["python_eval_c_code_format"])
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   578
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   579
                        if res != None :
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   580
                            # create the copy of decl dict to be appended to section
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   581
                            Function_decl_copy = Function_decl.copy()
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   582
                            # Have to generate type description in comment with freshly redefined types
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   583
                            Function_decl_copy["comment"] += (
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   584
                                "\n (" +
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   585
                                str([ " " + fctdecl[1]+":"+fctdecl[0] for fctdecl in Function_decl["inputs"]]).strip("[]").replace("'",'') +
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   586
                                " ) => (" +
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   587
                                str([ " " + fctdecl[1]+":"+fctdecl[0] for fctdecl in Function_decl["outputs"]]).strip("[]").replace("'",'') +
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   588
                                " )")
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   589
                            Current_section["list"].append(Function_decl_copy)
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   590
                            #pp.pprint(Function_decl_copy)
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   591
            else:
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   592
                raise "First function must be in a category"
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   593
    
a765fae3b361 Modifications on structure.py
lbessard
parents: 21
diff changeset
   594
    return Standard_Functions_Decl
14
cd0133ed377b Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents: 9
diff changeset
   595
25
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   596
std_decl = get_standard_funtions(csv_file_to_table(open(os.path.join(os.path.split(__file__)[0],"iec_std.csv"))))#, True)
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   597
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   598
BlockTypes.extend(std_decl)
8dc68e669d99 Early implementation of STD library.
etisserant
parents: 23
diff changeset
   599
109
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   600
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   601
#-------------------------------------------------------------------------------
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   602
#                            Languages Keywords
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   603
#-------------------------------------------------------------------------------
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   604
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   605
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   606
# Keywords for Pou Declaration
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   607
POU_KEYWORDS = ["FUNCTION", "END_FUNCTION", "FUNCTION_BLOCK", "END_FUNCTION_BLOCK",
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   608
 "PROGRAM", "END_PROGRAM", "EN", "ENO", "F_EDGE", "R_EDGE"]
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   609
for category in BlockTypes:
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   610
    for block in category["list"]:
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   611
        if block["name"] not in POU_KEYWORDS:
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   612
            POU_KEYWORDS.append(block["name"])
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   613
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   614
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   615
# Keywords for Type Declaration
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   616
TYPE_KEYWORDS = ["TYPE", "END_TYPE", "STRUCT", "END_STRUCT", "ARRAY", "OF", "T",
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   617
 "D", "TIME_OF_DAY", "DATE_AND_TIME"]
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   618
TYPE_KEYWORDS.extend([keyword for keyword in TypeHierarchy.keys() if keyword not in TYPE_KEYWORDS])
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   619
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   620
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   621
# Keywords for Variable Declaration
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   622
VAR_KEYWORDS = ["VAR", "VAR_INPUT", "VAR_OUTPUT", "VAR_IN_OUT", "VAR_TEMP", 
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   623
 "VAR_EXTERNAL", "END_VAR", "AT", "CONSTANT", "RETAIN", "NON_RETAIN"]
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   624
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   625
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   626
# Keywords for Configuration Declaration
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   627
CONFIG_KEYWORDS = ["CONFIGURATION", "END_CONFIGURATION", "RESOURCE", "ON", "END_RESOURCE",
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   628
 "PROGRAM", "WITH", "READ_ONLY", "READ_WRITE", "TASK", "VAR_ACCESS", "VAR_CONFIG", 
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   629
 "VAR_GLOBAL", "END_VAR"]
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   630
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   631
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   632
# Keywords for Structured Function Chart
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   633
SFC_KEYWORDS = ["ACTION", "END_ACTION", "INITIAL_STEP", "STEP", "END_STEP", "TRANSITION",
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   634
 "FROM", "TO", "END_TRANSITION"]
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   635
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   636
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   637
# Keywords for Instruction List
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   638
IL_KEYWORDS = ["TRUE", "FALSE", "LD", "LDN", "ST", "STN", "S", "R", "AND", "ANDN", "OR", "ORN",
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   639
 "XOR", "XORN", "NOT", "ADD", "SUB", "MUL", "DIV", "MOD", "GT", "GE", "EQ", "NE",
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   640
 "LE", "LT", "JMP", "JMPC", "JMPNC", "CAL", "CALC", "CALNC", "RET", "RETC", "RETNC"]
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   641
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   642
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   643
# Keywords for Structured Text
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   644
ST_KEYWORDS = ["TRUE", "FALSE", "IF", "THEN", "ELSIF", "ELSE", "END_IF", "CASE", "OF", "END_CASE", 
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   645
 "FOR", "TO", "BY", "DO", "END_FOR", "WHILE", "DO", "END_WHILE", "REPEAT", "UNTIL", 
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   646
 "END_REPEAT", "EXIT", "RETURN", "NOT", "MOD", "AND", "XOR", "OR"]
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   647
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   648
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   649
# All the keywords of IEC
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   650
IEC_KEYWORDS = ["E", "TRUE", "FALSE"]
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   651
IEC_KEYWORDS.extend([keyword for keyword in POU_KEYWORDS if keyword not in IEC_KEYWORDS])
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   652
IEC_KEYWORDS.extend([keyword for keyword in TYPE_KEYWORDS if keyword not in IEC_KEYWORDS])
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   653
IEC_KEYWORDS.extend([keyword for keyword in VAR_KEYWORDS if keyword not in IEC_KEYWORDS])
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   654
IEC_KEYWORDS.extend([keyword for keyword in CONFIG_KEYWORDS if keyword not in IEC_KEYWORDS])
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   655
IEC_KEYWORDS.extend([keyword for keyword in SFC_KEYWORDS if keyword not in IEC_KEYWORDS])
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   656
IEC_KEYWORDS.extend([keyword for keyword in IL_KEYWORDS if keyword not in IEC_KEYWORDS])
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   657
IEC_KEYWORDS.extend([keyword for keyword in ST_KEYWORDS if keyword not in IEC_KEYWORDS])
734e02ab4018 Bug that didn't affect standard function names as keywords fixed
lbessard
parents: 108
diff changeset
   658