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