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