|
1 #!/usr/bin/env python |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor |
|
5 #based on the plcopen standard. |
|
6 # |
|
7 #Copyright (C): Edouard TISSERANT and Laurent BESSARD |
|
8 # |
|
9 #See COPYING file for copyrights details. |
|
10 # |
|
11 #This library is free software; you can redistribute it and/or |
|
12 #modify it under the terms of the GNU Lesser General Public |
|
13 #License as published by the Free Software Foundation; either |
|
14 #version 2.1 of the License, or (at your option) any later version. |
|
15 # |
|
16 #This library is distributed in the hope that it will be useful, |
|
17 #but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 #Lesser General Public License for more details. |
|
20 # |
|
21 #You should have received a copy of the GNU Lesser General Public |
|
22 #License along with this library; if not, write to the Free Software |
|
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
|
25 |
|
26 #------------------------------------------------------------------------------- |
|
27 # Function Block Types definitions |
|
28 #------------------------------------------------------------------------------- |
|
29 |
|
30 """ |
|
31 Ordored list of common Function Blocks defined in the IEC 61131-3 |
|
32 Each block have this attributes: |
|
33 - "name" : The block name |
|
34 - "type" : The block type. It can be "function", "functionBlock" or "program" |
|
35 - "extensible" : Boolean that define if the block is extensible |
|
36 - "inputs" : List of the block inputs |
|
37 - "outputs" : List of the block outputs |
|
38 - "comment" : Comment that will be displayed in the block popup |
|
39 Inputs and outputs are a tuple of characteristics that are in order: |
|
40 - The name |
|
41 - The data type |
|
42 - The default modifier which can be "none", "negated", "rising" or "falling" |
|
43 """ |
|
44 |
|
45 BlockTypes = [{"name" : "Numerical functions", "list": |
|
46 [{"name" : "ADD", "type" : "function", "extensible" : True, |
|
47 "inputs" : [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")], |
|
48 "outputs" : [("OUT","ANY_NUM","none")], |
|
49 "comment" : "Addition,\nresult := I1 + I2 + ..."}, |
|
50 {"name" : "MUL", "type" : "function", "extensible" : True, |
|
51 "inputs" : [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")], |
|
52 "outputs" : [("OUT","ANY_NUM","none")], |
|
53 "comment" : "Multiplication,\nresult := I1 * I2 * ..."}, |
|
54 {"name" : "SUB", "type" : "function", "extensible" : False, |
|
55 "inputs" : [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")], |
|
56 "outputs" : [("OUT","ANY_NUM","none")], |
|
57 "comment" : "Substration,\nresult := I1 - I2"}, |
|
58 {"name" : "DIV", "type" : "function", "extensible" : False, |
|
59 "inputs" : [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")], |
|
60 "outputs" : [("OUT","ANY_NUM","none")], |
|
61 "comment" : "Division,\nresult := I1 / I2\n(with integer division, any fractional remainder is truncated)"}, |
|
62 {"name" : "MOD", "type" : "function", "extensible" : False, |
|
63 "inputs" : [("IN1","ANY_INT","none"),("IN2","ANY_INT","none")], |
|
64 "outputs" : [("OUT","ANY_INT","none")], |
|
65 "comment" : "Modulus,\nresult := I1 MOD I2\n(only valid with integer values)"}, |
|
66 {"name" : "EXPT", "type" : "function", "extensible" : False, |
|
67 "inputs" : [("IN1","ANY_REAL","none"),("IN2","ANY_INT","none")], |
|
68 "outputs" : [("OUT","ANY_REAL","none")], |
|
69 "comment" : "Exponential,\nresult := I1 ^ I2\n(can only take integer exponents)"}, |
|
70 {"name" : "ABS", "type" : "function", "extensible" : False, |
|
71 "inputs" : [("IN","ANY_NUM","none")], |
|
72 "outputs" : [("OUT","ANY_NUM","none")], |
|
73 "comment" : "Absolute value (negative values become positive)"}, |
|
74 {"name" : "SQRT", "type" : "function", "extensible" : False, |
|
75 "inputs" : [("IN","ANY_REAL","none")], |
|
76 "outputs" : [("OUT","ANY_REAL","none")], |
|
77 "comment" : "Square root"}, |
|
78 {"name" : "LOG", "type" : "function", "extensible" : False, |
|
79 "inputs" : [("IN","ANY_REAL","none")], |
|
80 "outputs" : [("OUT","ANY_REAL","none")], |
|
81 "comment" : "Logarithm"}, |
|
82 {"name" : "LN", "type" : "function", "extensible" : False, |
|
83 "inputs" : [("IN","ANY_REAL","none")], |
|
84 "outputs" : [("OUT","ANY_REAL","none")], |
|
85 "comment" : "Natural logarithm"}, |
|
86 {"name" : "EXP", "type" : "function", "extensible" : False, |
|
87 "inputs" : [("IN","ANY_REAL","none")], |
|
88 "outputs" : [("OUT","ANY_REAL","none")], |
|
89 "comment" : "Natural exponential"}, |
|
90 {"name" : "SIN", "type" : "function", "extensible" : False, |
|
91 "inputs" : [("IN","ANY_REAL","none")], |
|
92 "outputs" : [("OUT","ANY_REAL","none")], |
|
93 "comment" : "Sine of input as radians"}, |
|
94 {"name" : "COS", "type" : "function", "extensible" : False, |
|
95 "inputs" : [("IN","ANY_REAL","none")], |
|
96 "outputs" : [("OUT","ANY_REAL","none")], |
|
97 "comment" : "Cosine of input as radians"}, |
|
98 {"name" : "TAN", "type" : "function", "extensible" : False, |
|
99 "inputs" : [("IN","ANY_REAL","none")], |
|
100 "outputs" : [("OUT","ANY_REAL","none")], |
|
101 "comment" : "Tangent of input as radians"}, |
|
102 {"name" : "ASIN", "type" : "function", "extensible" : False, |
|
103 "inputs" : [("IN","ANY_REAL","none")], |
|
104 "outputs" : [("OUT","ANY_REAL","none")], |
|
105 "comment" : "Principal arc-sine, result in radians"}, |
|
106 {"name" : "ACOS", "type" : "function", "extensible" : False, |
|
107 "inputs" : [("IN","ANY_REAL","none")], |
|
108 "outputs" : [("OUT","ANY_REAL","none")], |
|
109 "comment" : "Principal arc-cosine, result in radians"}, |
|
110 {"name" : "ATAN", "type" : "function", "extensible" : False, |
|
111 "inputs" : [("IN","ANY_REAL","none")], |
|
112 "outputs" : [("OUT","ANY_REAL","none")], |
|
113 "comment" : "Principal arc-tangent, result in radians"} |
|
114 ]}, |
|
115 {"name" : "Boolean and bit functions", "list": |
|
116 [{"name" : "AND", "type" : "function", "extensible" : True, |
|
117 "inputs" : [("IN1","ANY_BIT","none"),("IN2","ANY_BIT","none")], |
|
118 "outputs" : [("OUT","ANY_BIT","none")], |
|
119 "comment" : "Result := I1 & I2 & ..."}, |
|
120 {"name" : "OR", "type" : "function", "extensible" : True, |
|
121 "inputs" : [("IN1","ANY_BIT","none"),("IN2","ANY_BIT","none")], |
|
122 "outputs" : [("OUT","ANY_BIT","none")], |
|
123 "comment" : "Result := I1 OR I2 OR ..."}, |
|
124 {"name" : "XOR", "type" : "function", "extensible" : True, |
|
125 "inputs" : [("IN1","ANY_BIT","none"),("IN2","ANY_BIT","none")], |
|
126 "outputs" : [("OUT","ANY_BIT","none")], |
|
127 "comment" : "Result := I1 XOR I2 XOR ..."}, |
|
128 {"name" : "NOT", "type" : "function", "extensible" : False, |
|
129 "inputs" : [("IN","BIT","none")], |
|
130 "outputs" : [("OUT","BIT","none")], |
|
131 "comment" : "Result := NOT I1"}, |
|
132 {"name" : "SHL", "type" : "function", "extensible" : False, |
|
133 "inputs" : [("IN","ANY_BIT","none"),("N","ANY_INT","none")], |
|
134 "outputs" : [("OUT","ANY_BIT","none")], |
|
135 "comment" : "Shift bit-string n bit positions left, zero fill on the right."}, |
|
136 {"name" : "SHR", "type" : "function", "extensible" : False, |
|
137 "inputs" : [("IN","ANY_BIT","none"),("N","ANY_INT","none")], |
|
138 "outputs" : [("OUT","ANY_BIT")], |
|
139 "comment" : "Shift bit-string right n bit positions, zero fill on the left."}, |
|
140 {"name" : "ROR", "type" : "function", "extensible" : False, |
|
141 "inputs" : [("IN","ANY_BIT","none"),("N","ANY_INT","none")], |
|
142 "outputs" : [("OUT","ANY_BIT","none")], |
|
143 "comment" : "Shift bit-string right, rotate by n bit positions."}, |
|
144 {"name" : "ROL", "type" : "function", "extensible" : False, |
|
145 "inputs" : [("IN","ANY_BIT","none"),("N","ANY_INT","none")], |
|
146 "outputs" : [("OUT","ANY_BIT","none")], |
|
147 "comment" : "Shift bit-string left, rotate by n bit positions."} |
|
148 ]}, |
|
149 {"name" : "Selection functions", "list": |
|
150 [{"name" : "SEL", "type" : "function", "extensible" : False, |
|
151 "inputs" : [("G","BOOL","none"),("IN0","ANY","none"),("IN1","ANY","none")], |
|
152 "outputs" : [("OUT","ANY","none")], |
|
153 "comment" : "Selection\nIf G = TRUE then\nResult := IN1 else\nResult := IN2"}, |
|
154 {"name" : "MAX", "type" : "function", "extensible" : True, |
|
155 "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], |
|
156 "outputs" : [("OUT","ANY","none")], |
|
157 "comment" : "Maximum\nResult := maximum value of all inputs"}, |
|
158 {"name" : "MIN", "type" : "function", "extensible" : True, |
|
159 "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], |
|
160 "outputs" : [("","ANY","none")], |
|
161 "comment" : "Minimum\nResult := minimum value of all inputs"}, |
|
162 {"name" : "LIMIT", "type" : "function", "extensible" : False, |
|
163 "inputs" : [("MN","ANY","none"),("IN","ANY","none"),("MX","ANY","none")], |
|
164 "outputs" : [("OUT","ANY","none")], |
|
165 "comment" : "Limit\nResult is the value of IN limited between a minimum value of MN and a maximum value of MX."}, |
|
166 {"name" : "MUX", "type" : "function", "extensible" : True, |
|
167 "inputs" : [("K","ANY_INT","none"),("IN1","ANY","none"),("IN2","ANY","none")], |
|
168 "outputs" : [("OUT","ANY","none")], |
|
169 "comment" : "Multiplexer\nResult is the value of the input selected by the value of K."} |
|
170 ]}, |
|
171 {"name" : "Comparison functions", "list": |
|
172 [{"name" : "GT", "type" : "function", "extensible" : True, |
|
173 "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], |
|
174 "outputs" : [("OUT","ANY","none")], |
|
175 "comment" : "Greater than\nResult := IN1 > IN2"}, |
|
176 {"name" : "GE", "type" : "function", "extensible" : True, |
|
177 "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], |
|
178 "outputs" : [("OUT","ANY","none")], |
|
179 "comment" : "Greater than or equal\nResult := IN1 >= IN2"}, |
|
180 {"name" : "EQ", "type" : "function", "extensible" : True, |
|
181 "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], |
|
182 "outputs" : [("OUT","ANY","none")], |
|
183 "comment" : "Equality\nResult := IN1 = IN2"}, |
|
184 {"name" : "LE", "type" : "function", "extensible" : True, |
|
185 "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], |
|
186 "outputs" : [("OUT","ANY","none")], |
|
187 "comment" : "Lesser than or equal\nResult := IN1 <= IN2"}, |
|
188 {"name" : "LT", "type" : "function", "extensible" : True, |
|
189 "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], |
|
190 "outputs" : [("OUT","ANY","none")], |
|
191 "comment" : "Lesser than\nResult := IN1 < IN2"}, |
|
192 {"name" : "NE", "type" : "function", "extensible" : False, |
|
193 "inputs" : [("IN1","ANY","none"),("IN2","ANY","none")], |
|
194 "outputs" : [("OUT","ANY","none")], |
|
195 "comment" : "Not equal\nResult := IN1 <> IN2"} |
|
196 ]}, |
|
197 {"name" : "Character string functions", "list": |
|
198 [{"name" : "LEFT", "type" : "function", "extensible" : False, |
|
199 "inputs" : [("IN","STRING","none"),("L","ANY_INT","none")], |
|
200 "outputs" : [("OUT","STRING","none")], |
|
201 "comment" : "Extract left string\nResult is the string formed from L characters from the leftmost character of string IN."}, |
|
202 {"name" : "RIGHT", "type" : "function", "extensible" : False, |
|
203 "inputs" : [("IN","STRING","none"),("L","ANY_INT","none")], |
|
204 "outputs" : [("OUT","STRING","none")], |
|
205 "comment" : "Extract right string\nResult is the string formed from L characters from the rightmost part of string IN."}, |
|
206 {"name" : "MID", "type" : "function", "extensible" : False, |
|
207 "inputs" : [("IN","ANY","none"),("L","ANY_INT","none"),("P","ANY_INT","none")], |
|
208 "outputs" : [("OUT","STRING","none")], |
|
209 "comment" : "Extract mid string\nResult is a string extracted from the input string IN starting at character position P, and L characters long."}, |
|
210 {"name" : "CONCAT", "type" : "function", "extensible" : True, |
|
211 "inputs" : [("IN1","STRING","none"),("IN2","STRING","none")], |
|
212 "outputs" : [("OUT","STRING","none")], |
|
213 "comment" : "Concatenate strings\nResult is a string formed by joining the input strings together. This is an extensible function that can take two or more input strings."}, |
|
214 {"name" : "INSERT", "type" : "function", "extensible" : False, |
|
215 "inputs" : [("IN1","STRING","none"),("IN2","STRING","none"),("P","ANY_INT","none")], |
|
216 "outputs" : [("OUT","STRING","none")], |
|
217 "comment" : "Insert string\nThe result is formed by the string IN2 being inserted into string IN1, P character positions from the start of IN1."}, |
|
218 {"name" : "DELETE", "type" : "function", "extensible" : False, |
|
219 "inputs" : [("IN","STRING","none"),("L","ANY_INT","none"),("P","ANY_INT","none")], |
|
220 "outputs" : [("OUT","STRING","none")], |
|
221 "comment" : "Delete string\nThe result is formed by a string of characters L in length, being deleted from the input string IN, starting from character position P."}, |
|
222 {"name" : "REPLACE", "type" : "function", "extensible" : False, |
|
223 "inputs" : [("IN1","STRING","none"),("IN2","STRING","none"),("L","ANY_INT","none"),("P","ANY_INT","none")], |
|
224 "outputs" : [("OUT","STRING","none")], |
|
225 "comment" : "Replace string\nThe result is formed by replacing L characters in string IN1, starting at position P, with character string in IN2."}, |
|
226 {"name" : "LEN", "type" : "function", "extensible" : False, |
|
227 "inputs" : [("IN","STRING","none")], |
|
228 "outputs" : [("OUT","INT","none")], |
|
229 "comment" : "Length\nResult is length of the input string."}, |
|
230 {"name" : "FIND", "type" : "function", "extensible" : False, |
|
231 "inputs" : [("IN1","STRING","none"),("IN2","STRING","none")], |
|
232 "outputs" : [("OUT","INT","none")], |
|
233 "comment" : "Find string\nResult is the position where string IN2 is first found in string IN1.\nIf string IN2 is not found in IN1, the result is 0."}, |
|
234 ]}, |
|
235 {"name" : "Standard function blocks", "list": |
|
236 [{"name" : "SR", "type" : "functionBlock", "extensible" : False, |
|
237 "inputs" : [("S1","BOOL","none"),("R","BOOL","none")], |
|
238 "outputs" : [("Q1","BOOL","none")], |
|
239 "comment" : "SR bistable\nThe SR bistable is a latch where the Set dominates."}, |
|
240 {"name" : "RS", "type" : "functionBlock", "extensible" : False, |
|
241 "inputs" : [("S","BOOL","none"),("R1","BOOL","none")], |
|
242 "outputs" : [("Q1","BOOL","none")], |
|
243 "comment" : "RS bistable\nThe RS bistable is a latch where the Reset dominates."}, |
|
244 {"name" : "SEMA", "type" : "functionBlock", "extensible" : False, |
|
245 "inputs" : [("CLAIM","BOOL","none"),("RELEASE","BOOL","none")], |
|
246 "outputs" : [("BUSY","BOOL","none")], |
|
247 "comment" : "Semaphore\nThe semaphore provides a mechanism to allow software elements mutually exclusive access to certain ressources."}, |
|
248 {"name" : "R_TRIG", "type" : "functionBlock", "extensible" : False, |
|
249 "inputs" : [("CLK","BOOL","none")], |
|
250 "outputs" : [("Q","BOOL","none")], |
|
251 "comment" : "Rising edge detector\nThe output produces a single pulse when a rising edge is detected."}, |
|
252 {"name" : "F_TRIG", "type" : "functionBlock", "extensible" : False, |
|
253 "inputs" : [("CLK","BOOL","none")], |
|
254 "outputs" : [("Q","BOOL","none")], |
|
255 "comment" : "Falling edge detector\nThe output produces a single pulse when a falling edge is detected."}, |
|
256 {"name" : "CTU", "type" : "functionBlock", "extensible" : False, |
|
257 "inputs" : [("CU","BOOL","rising"),("R","BOOL","none"),("PV","INT","none")], |
|
258 "outputs" : [("Q","BOOL","none"),("CV","INT","none")], |
|
259 "comment" : "Up-counter\nThe up-counter can be used to signal when a count has reached a maximum value."}, |
|
260 {"name" : "CTD", "type" : "functionBlock", "extensible" : False, |
|
261 "inputs" : [("CD","BOOL","rising"),("LD","BOOL","none"),("PV","INT","none")], |
|
262 "outputs" : [("Q","BOOL","none"),("CV","INT","none")], |
|
263 "comment" : "Down-counter\nThe down-counter can be used to signal when a count has reached zero, on counting down from a preset value."}, |
|
264 {"name" : "CTUD", "type" : "functionBlock", "extensible" : False, |
|
265 "inputs" : [("CU","BOOL","rising"),("CD","BOOL","rising"),("R","BOOL","none"),("LD","BOOL","none"),("PV","INT","none")], |
|
266 "outputs" : [("QU","BOOL","none"),("QD","BOOL","none"),("CV","INT","none")], |
|
267 "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."}, |
|
268 {"name" : "TP", "type" : "functionBlock", "extensible" : False, |
|
269 "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], |
|
270 "outputs" : [("Q","BOOL","none"),("ET","TIME","none")], |
|
271 "comment" : "Pulse timer\nThe pulse timer can be used to generate output pulses of a given time duration."}, |
|
272 {"name" : "TOF", "type" : "functionBlock", "extensible" : False, |
|
273 "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], |
|
274 "outputs" : [("Q","BOOL","none"),("ET","TIME","none")], |
|
275 "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."}, |
|
276 {"name" : "TON", "type" : "functionBlock", "extensible" : False, |
|
277 "inputs" : [("IN","BOOL","none"),("PT","TIME","none")], |
|
278 "outputs" : [("Q","BOOL","none"),("ET","TIME","none")], |
|
279 "comment" : "Off-delay timer\nThe off-delay timer can be used to delay setting an output false, for fixed period after input goes false."}, |
|
280 {"name" : "RTC", "type" : "functionBlock", "extensible" : False, |
|
281 "inputs" : [("EN","BOOL","none"),("PDT","DATE_AND_TIME","none")], |
|
282 "outputs" : [("Q","BOOL","none"),("CDT","DATE_AND_TIME","none")], |
|
283 "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."}, |
|
284 {"name" : "INTEGRAL", "type" : "functionBlock", "extensible" : False, |
|
285 "inputs" : [("RUN","BOOL","none"),("R1","BOOL","none"),("XIN","REAL","none"),("X0","REAL","none"),("CYCLE","TIME","none")], |
|
286 "outputs" : [("Q","BOOL","none"),("XOUT","REAL","none")], |
|
287 "comment" : "Integral\nThe integral function block integrates the value of input XIN over time."}, |
|
288 {"name" : "DERIVATIVE", "type" : "functionBlock", "extensible" : False, |
|
289 "inputs" : [("RUN","BOOL","none"),("XIN","REAL","none"),("CYCLE","TIME","none")], |
|
290 "outputs" : [("XOUT","REAL","none")], |
|
291 "comment" : "Derivative\nThe derivative function block produces an output XOUT proportional to the rate of change of the input XIN."}, |
|
292 {"name" : "PID", "type" : "functionBlock", "extensible" : False, |
|
293 "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")], |
|
294 "outputs" : [("XOUT","REAL","none")], |
|
295 "comment" : "PID\nThe PID (proportional, Integral, Derivative) function block provides the classical three term controller for closed loop control."}, |
|
296 {"name" : "RAMP", "type" : "functionBlock", "extensible" : False, |
|
297 "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")], |
|
298 "outputs" : [("RAMP","BOOL","none"),("XOUT","REAL","none")], |
|
299 "comment" : "Ramp\nThe RAMP function block is modelled on example given in the standard but with the addition of a 'Holdback' feature."}, |
|
300 {"name" : "HYSTERESIS", "type" : "functionBlock", "extensible" : False, |
|
301 "inputs" : [("XIN1","REAL","none"),("XIN2","REAL","none"),("EPS","REAL","none")], |
|
302 "outputs" : [("Q","BOOL","none")], |
|
303 "comment" : "Hysteresis\nThe hysteresis function block provides a hysteresis boolean output driven by the difference of two floating point (REAL) inputs XIN1 and XIN2."}, |
|
304 {"name" : "RATIO_MONITOR", "type" : "functionBlock", "extensible" : False, |
|
305 "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")], |
|
306 "outputs" : [("ALARM","BOOL","none"),("TOTAL_ERR","BOOL","none")], |
|
307 "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."}, |
|
308 ]} |
|
309 ] |
|
310 |
|
311 """ |
|
312 Function that returns the block definition associated to the block type given |
|
313 """ |
|
314 |
|
315 def GetBlockType(type): |
|
316 for category in BlockTypes: |
|
317 for blocktype in category["list"]: |
|
318 if blocktype["name"] == type: |
|
319 return blocktype |
|
320 return None |
|
321 |
|
322 |
|
323 #------------------------------------------------------------------------------- |
|
324 # Data Types definitions |
|
325 #------------------------------------------------------------------------------- |
|
326 |
|
327 """ |
|
328 Ordored list of common data types defined in the IEC 61131-3 |
|
329 Each type is associated to his direct parent type. It defines then a hierarchy |
|
330 between type that permits to make a comparison of two types |
|
331 """ |
|
332 |
|
333 TypeHierarchy = {"ANY" : None, |
|
334 "ANY_DERIVED" : "ANY", |
|
335 "ANY_ELEMENTARY" : "ANY", |
|
336 "ANY_MAGNITUDE": "ANY_ELEMENTARY", |
|
337 "ANY_BIT" : "ANY_ELEMENTARY", |
|
338 "ANY_STRING" : "ANY_ELEMENTARY", |
|
339 "ANY_DATE" : "ANY_ELEMENTARY", |
|
340 "ANY_NUM" : "ANY_MAGNITUDE", |
|
341 "ANY_REAL" : "ANY_NUM", |
|
342 "ANY_INT" : "ANY_NUM", |
|
343 "REAL" : "ANY_REAL", |
|
344 "LREAL" : "ANY_REAL", |
|
345 "SINT" : "ANY_INT", |
|
346 "INT" : "ANY_INT", |
|
347 "DINT" : "ANY_INT", |
|
348 "LINT" : "ANY_INT", |
|
349 "USINT" : "ANY_INT", |
|
350 "UINT" : "ANY_INT", |
|
351 "UDINT" : "ANY_INT", |
|
352 "ULINT" : "ANY_INT", |
|
353 "TIME" : "ANY_MAGNITUDE", |
|
354 "BOOL" : "ANY_BIT", |
|
355 "BYTE" : "ANY_BIT", |
|
356 "WORD" : "ANY_BIT", |
|
357 "DWORD" : "ANY_BIT", |
|
358 "LWORD" : "ANY_BIT", |
|
359 "STRING" : "ANY_STRING", |
|
360 "WSTRING" : "ANY_STRING", |
|
361 "DATE" : "ANY_DATE", |
|
362 "TOD" : "ANY_DATE", |
|
363 "DT" : "ANY_DATE" |
|
364 } |
|
365 |
|
366 """ |
|
367 Function that returns if the given data type is the same that "reference" or one |
|
368 of its children types |
|
369 """ |
|
370 |
|
371 def IsOfType(test, reference): |
|
372 while test != None: |
|
373 if test == reference: |
|
374 return True |
|
375 test = TypeHierarchy[test] |
|
376 return False |
|
377 |
|
378 |
|
379 #------------------------------------------------------------------------------- |
|
380 # Languages Keywords |
|
381 #------------------------------------------------------------------------------- |
|
382 |
|
383 |
|
384 |
|
385 # Keywords for Pou Declaration |
|
386 POU_KEYWORDS = ["FUNCTION", "END_FUNCTION", "FUNCTION_BLOCK", "END_FUNCTION_BLOCK", |
|
387 "PROGRAM", "END_PROGRAM", "EN", "ENO", "F_EDGE", "R_EDGE"] |
|
388 for category in BlockTypes: |
|
389 for block in category["list"]: |
|
390 if block["name"] not in POU_KEYWORDS: |
|
391 POU_KEYWORDS.append(block["name"]) |
|
392 |
|
393 |
|
394 # Keywords for Type Declaration |
|
395 TYPE_KEYWORDS = ["TYPE", "END_TYPE", "STRUCT", "END_STRUCT", "ARRAY", "OF", "T", |
|
396 "D", "TIME_OF_DAY", "DATE_AND_TIME"] |
|
397 TYPE_KEYWORDS.extend([keyword for keyword in TypeHierarchy.keys() if keyword not in TYPE_KEYWORDS]) |
|
398 |
|
399 |
|
400 # Keywords for Variable Declaration |
|
401 VAR_KEYWORDS = ["VAR", "VAR_INPUT", "VAR_OUTPUT", "VAR_IN_OUT", "VAR_TEMP", |
|
402 "VAR_EXTERNAL", "END_VAR", "AT", "CONSTANT", "RETAIN", "NON_RETAIN"] |
|
403 |
|
404 |
|
405 # Keywords for Configuration Declaration |
|
406 CONFIG_KEYWORDS = ["CONFIGURATION", "END_CONFIGURATION", "RESOURCE", "ON", "END_RESOURCE", |
|
407 "PROGRAM", "WITH", "READ_ONLY", "READ_WRITE", "TASK", "VAR_ACCESS", "VAR_CONFIG", |
|
408 "VAR_GLOBAL", "END_VAR"] |
|
409 |
|
410 |
|
411 # Keywords for Structured Function Chart |
|
412 SFC_KEYWORDS = ["ACTION", "END_ACTION", "INITIAL_STEP", "STEP", "END_STEP", "TRANSITION", |
|
413 "FROM", "TO", "END_TRANSITION"] |
|
414 |
|
415 |
|
416 # Keywords for Instruction List |
|
417 IL_KEYWORDS = ["LD", "LDN", "ST", "STN", "S", "R", "AND", "ANDN", "OR", "ORN", |
|
418 "XOR", "XORN", "NOT", "ADD", "SUB", "MUL", "DIV", "MOD", "GT", "GE", "EQ", "NE", |
|
419 "LE", "LT", "JMP", "JMPC", "JMPNC", "CAL", "CALC", "CALNC", "RET", "RETC", "RETNC"] |
|
420 |
|
421 |
|
422 # Keywords for Instruction List and Structured Text |
|
423 ST_KEYWORDS = ["IF", "THEN", "ELSIF", "ELSE", "END_IF", "CASE", "OF", "END_CASE", |
|
424 "FOR", "TO", "BY", "DO", "END_FOR", "WHILE", "DO", "END_WHILE", "REPEAT", "UNTIL", |
|
425 "END_REPEAT", "EXIT", "RETURN", "NOT", "MOD", "AND", "XOR", "OR"] |
|
426 |
|
427 |
|
428 # All the keywords of IEC |
|
429 IEC_KEYWORDS = ["E", "TRUE", "FALSE"] |
|
430 IEC_KEYWORDS.extend([keyword for keyword in POU_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
431 IEC_KEYWORDS.extend([keyword for keyword in TYPE_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
432 IEC_KEYWORDS.extend([keyword for keyword in VAR_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
433 IEC_KEYWORDS.extend([keyword for keyword in CONFIG_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
434 IEC_KEYWORDS.extend([keyword for keyword in SFC_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
435 IEC_KEYWORDS.extend([keyword for keyword in IL_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
436 IEC_KEYWORDS.extend([keyword for keyword in ST_KEYWORDS if keyword not in IEC_KEYWORDS]) |
|
437 |