author | Minyoung Sung |
Mon, 27 Aug 2012 17:41:35 +0200 | |
changeset 749 | 7b17f3c5cf21 |
parent 649 | ea237e1431ec |
child 754 | 48966b6ceedc |
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 |
||
391 | 36 |
_ = lambda x:x |
37 |
||
230
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
38 |
# Helper for emulate join on element list |
305
0ed2b61de43e
Fixed bug structures.py crashing with non-connected blocks.
etisserant
parents:
284
diff
changeset
|
39 |
def JoinList(separator, mylist): |
0ed2b61de43e
Fixed bug structures.py crashing with non-connected blocks.
etisserant
parents:
284
diff
changeset
|
40 |
if len(mylist) > 0 : |
0ed2b61de43e
Fixed bug structures.py crashing with non-connected blocks.
etisserant
parents:
284
diff
changeset
|
41 |
return reduce(lambda x, y: x + separator + y, mylist) |
0ed2b61de43e
Fixed bug structures.py crashing with non-connected blocks.
etisserant
parents:
284
diff
changeset
|
42 |
else : |
0ed2b61de43e
Fixed bug structures.py crashing with non-connected blocks.
etisserant
parents:
284
diff
changeset
|
43 |
return mylist |
230
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
44 |
|
526
79900abdfa3c
Bug when using arithmetic functions (ADD, SUB, MUL, DIV) for TIME datatypes fixed.
laurent
parents:
517
diff
changeset
|
45 |
def generate_block(generator, block, block_infos, body, link, order=False): |
151 | 46 |
body_type = body.getcontent()["name"] |
47 |
name = block.getinstanceName() |
|
48 |
type = block.gettypeName() |
|
49 |
executionOrderId = block.getexecutionOrderId() |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
50 |
if block_infos["type"] == "function": |
270
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
51 |
output_variables = block.outputVariables.getvariable() |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
52 |
if not generator.ComputedBlocks.get(block, False) and not order: |
208
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
194
diff
changeset
|
53 |
generator.ComputedBlocks[block] = True |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
54 |
vars = [] |
307
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
55 |
one_input_connected = False |
230
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
56 |
for i, variable in enumerate(block.inputVariables.getvariable()): |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
57 |
input_info = (generator.TagName, "block", block.getlocalId(), "input", i) |
151 | 58 |
connections = variable.connectionPointIn.getconnections() |
250 | 59 |
if connections is not None: |
307
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
60 |
parameter = variable.getformalParameter() |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
61 |
if parameter != "EN": |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
62 |
one_input_connected = True |
250 | 63 |
value = generator.ComputeExpression(body, connections, executionOrderId > 0) |
270
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
64 |
if len(output_variables) > 1: |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
65 |
vars.append([(parameter, input_info), |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
66 |
(" := ", ())] + generator.ExtractModifier(variable, value, input_info)) |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
67 |
else: |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
68 |
vars.append(generator.ExtractModifier(variable, value, input_info)) |
307
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
69 |
if one_input_connected: |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
70 |
for i, variable in enumerate(output_variables): |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
71 |
parameter = variable.getformalParameter() |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
72 |
if variable.getformalParameter() == "": |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
73 |
variable_name = "%s%d"%(type, block.getlocalId()) |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
74 |
else: |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
75 |
variable_name = "%s%d_%s"%(type, block.getlocalId(), parameter) |
483
779a519f78f2
Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents:
431
diff
changeset
|
76 |
if generator.Interface[-1][0] != "VAR" or generator.Interface[-1][1] is not None or generator.Interface[-1][2]: |
779a519f78f2
Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents:
431
diff
changeset
|
77 |
generator.Interface.append(("VAR", None, False, [])) |
307
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
78 |
if variable.connectionPointOut in generator.ConnectionTypes: |
483
779a519f78f2
Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents:
431
diff
changeset
|
79 |
generator.Interface[-1][3].append((generator.ConnectionTypes[variable.connectionPointOut], variable_name, None, None)) |
307
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
80 |
else: |
483
779a519f78f2
Replace Retain and Constant column in VariablePanel by Option and add the option Non-Retain
laurent
parents:
431
diff
changeset
|
81 |
generator.Interface[-1][3].append(("ANY", variable_name, None, None)) |
307
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
82 |
if len(output_variables) > 1 and parameter not in ["", "OUT"]: |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
83 |
vars.append([(parameter, (generator.TagName, "block", block.getlocalId(), "output", i)), |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
84 |
(" => %s"%variable_name, ())]) |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
85 |
else: |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
86 |
output_info = (generator.TagName, "block", block.getlocalId(), "output", i) |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
87 |
output_name = variable_name |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
88 |
generator.Program += [(generator.CurrentIndent, ()), |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
89 |
(output_name, output_info), |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
90 |
(" := ", ()), |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
91 |
(type, (generator.TagName, "block", block.getlocalId(), "type")), |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
92 |
("(", ())] |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
93 |
generator.Program += JoinList([(", ", ())], vars) |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
94 |
generator.Program += [(");\n", ())] |
fd1f6ae26d4f
Adding support for cancelling code generation of function with no input connected
lbessard
parents:
305
diff
changeset
|
95 |
else: |
391 | 96 |
generator.Warnings.append(_("\"%s\" function cancelled in \"%s\" POU: No input connected")%(type, generator.TagName.split("::")[-1])) |
270
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
97 |
if link: |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
98 |
connectionPoint = link.getposition()[-1] |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
99 |
else: |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
100 |
connectionPoint = None |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
101 |
for i, variable in enumerate(output_variables): |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
102 |
blockPointx, blockPointy = variable.connectionPointOut.getrelPositionXY() |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
103 |
if not connectionPoint or block.getx() + blockPointx == connectionPoint.getx() and block.gety() + blockPointy == connectionPoint.gety(): |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
104 |
output_info = (generator.TagName, "block", block.getlocalId(), "output", i) |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
105 |
output_name = variable.getformalParameter() |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
106 |
if variable.getformalParameter() == "": |
279
2ad276084038
Bug involving possible name conflict between return value and ouputs fixed
lbessard
parents:
270
diff
changeset
|
107 |
output_name = "%s%d"%(type, block.getlocalId()) |
270
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
108 |
else: |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
109 |
output_name = "%s%d_%s"%(type, block.getlocalId(), variable.getformalParameter()) |
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
110 |
return generator.ExtractModifier(variable, [(output_name, output_info)], output_info) |
78
049f2e7090a2
Adding support for adding block types with particular behaviour
lbessard
parents:
58
diff
changeset
|
111 |
elif block_infos["type"] == "functionBlock": |
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
112 |
if not generator.ComputedBlocks.get(block, False) and not order: |
208
c70aefcadf66
Bugs with feedback path in View, Controler and Generator fixed
lbessard
parents:
194
diff
changeset
|
113 |
generator.ComputedBlocks[block] = True |
78
049f2e7090a2
Adding support for adding block types with particular behaviour
lbessard
parents:
58
diff
changeset
|
114 |
vars = [] |
230
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
115 |
for i, variable in enumerate(block.inputVariables.getvariable()): |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
116 |
input_info = (generator.TagName, "block", block.getlocalId(), "input", i) |
151 | 117 |
connections = variable.connectionPointIn.getconnections() |
250 | 118 |
if connections is not None: |
151 | 119 |
parameter = variable.getformalParameter() |
250 | 120 |
value = generator.ComputeExpression(body, connections, executionOrderId > 0) |
230
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
121 |
vars.append([(parameter, input_info), |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
122 |
(" := ", ())] + generator.ExtractModifier(variable, value, input_info)) |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
123 |
generator.Program += [(generator.CurrentIndent, ()), |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
124 |
(name, (generator.TagName, "block", block.getlocalId(), "name")), |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
125 |
("(", ())] |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
126 |
generator.Program += JoinList([(", ", ())], vars) |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
127 |
generator.Program += [(");\n", ())] |
78
049f2e7090a2
Adding support for adding block types with particular behaviour
lbessard
parents:
58
diff
changeset
|
128 |
if link: |
151 | 129 |
connectionPoint = link.getposition()[-1] |
78
049f2e7090a2
Adding support for adding block types with particular behaviour
lbessard
parents:
58
diff
changeset
|
130 |
else: |
049f2e7090a2
Adding support for adding block types with particular behaviour
lbessard
parents:
58
diff
changeset
|
131 |
connectionPoint = None |
230
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
132 |
for i, variable in enumerate(block.outputVariables.getvariable()): |
151 | 133 |
blockPointx, blockPointy = variable.connectionPointOut.getrelPositionXY() |
134 |
if not connectionPoint or block.getx() + blockPointx == connectionPoint.getx() and block.gety() + blockPointy == connectionPoint.gety(): |
|
270
351d134babd7
Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents:
250
diff
changeset
|
135 |
output_info = (generator.TagName, "block", block.getlocalId(), "output", i) |
230
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
136 |
return generator.ExtractModifier(variable, [("%s.%s"%(name, variable.getformalParameter()), output_info)], output_info) |
354 | 137 |
if link is not None: |
391 | 138 |
raise ValueError, _("No output variable found") |
21 | 139 |
|
194
1b3f8b4f8e04
Adding support for Beremiz svgui plugin variable declaration
lbessard
parents:
170
diff
changeset
|
140 |
def initialise_block(type, name, block = None): |
93 | 141 |
return [(type, name, None, None)] |
142 |
||
0 | 143 |
#------------------------------------------------------------------------------- |
144 |
# Function Block Types definitions |
|
145 |
#------------------------------------------------------------------------------- |
|
146 |
||
21 | 147 |
|
0 | 148 |
""" |
149 |
Ordored list of common Function Blocks defined in the IEC 61131-3 |
|
150 |
Each block have this attributes: |
|
151 |
- "name" : The block name |
|
152 |
- "type" : The block type. It can be "function", "functionBlock" or "program" |
|
153 |
- "extensible" : Boolean that define if the block is extensible |
|
154 |
- "inputs" : List of the block inputs |
|
155 |
- "outputs" : List of the block outputs |
|
156 |
- "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
|
157 |
- "generate" : Method that generator will call for generating ST block code |
0 | 158 |
Inputs and outputs are a tuple of characteristics that are in order: |
159 |
- The name |
|
160 |
- The data type |
|
161 |
- The default modifier which can be "none", "negated", "rising" or "falling" |
|
162 |
""" |
|
163 |
||
391 | 164 |
BlockTypes = [{"name" : _("Standard function blocks"), "list": |
0 | 165 |
[{"name" : "SR", "type" : "functionBlock", "extensible" : False, |
166 |
"inputs" : [("S1","BOOL","none"),("R","BOOL","none")], |
|
167 |
"outputs" : [("Q1","BOOL","none")], |
|
391 | 168 |
"comment" : _("SR bistable\nThe SR bistable is a latch where the Set dominates."), |
93 | 169 |
"generate" : generate_block, "initialise" : initialise_block}, |
0 | 170 |
{"name" : "RS", "type" : "functionBlock", "extensible" : False, |
171 |
"inputs" : [("S","BOOL","none"),("R1","BOOL","none")], |
|
172 |
"outputs" : [("Q1","BOOL","none")], |
|
391 | 173 |
"comment" : _("RS bistable\nThe RS bistable is a latch where the Reset dominates."), |
93 | 174 |
"generate" : generate_block, "initialise" : initialise_block}, |
0 | 175 |
{"name" : "SEMA", "type" : "functionBlock", "extensible" : False, |
176 |
"inputs" : [("CLAIM","BOOL","none"),("RELEASE","BOOL","none")], |
|
177 |
"outputs" : [("BUSY","BOOL","none")], |
|
391 | 178 |
"comment" : _("Semaphore\nThe semaphore provides a mechanism to allow software elements mutually exclusive access to certain ressources."), |
93 | 179 |
"generate" : generate_block, "initialise" : initialise_block}, |
0 | 180 |
{"name" : "R_TRIG", "type" : "functionBlock", "extensible" : False, |
181 |
"inputs" : [("CLK","BOOL","none")], |
|
182 |
"outputs" : [("Q","BOOL","none")], |
|
391 | 183 |
"comment" : _("Rising edge detector\nThe output produces a single pulse when a rising edge is detected."), |
93 | 184 |
"generate" : generate_block, "initialise" : initialise_block}, |
0 | 185 |
{"name" : "F_TRIG", "type" : "functionBlock", "extensible" : False, |
186 |
"inputs" : [("CLK","BOOL","none")], |
|
187 |
"outputs" : [("Q","BOOL","none")], |
|
391 | 188 |
"comment" : _("Falling edge detector\nThe output produces a single pulse when a falling edge is detected."), |
93 | 189 |
"generate" : generate_block, "initialise" : initialise_block}, |
0 | 190 |
{"name" : "CTU", "type" : "functionBlock", "extensible" : False, |
191 |
"inputs" : [("CU","BOOL","rising"),("R","BOOL","none"),("PV","INT","none")], |
|
192 |
"outputs" : [("Q","BOOL","none"),("CV","INT","none")], |
|
391 | 193 |
"comment" : _("Up-counter\nThe up-counter can be used to signal when a count has reached a maximum value."), |
93 | 194 |
"generate" : generate_block, "initialise" : initialise_block}, |
0 | 195 |
{"name" : "CTD", "type" : "functionBlock", "extensible" : False, |
196 |
"inputs" : [("CD","BOOL","rising"),("LD","BOOL","none"),("PV","INT","none")], |
|
197 |
"outputs" : [("Q","BOOL","none"),("CV","INT","none")], |
|
391 | 198 |
"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 | 199 |
"generate" : generate_block, "initialise" : initialise_block}, |
0 | 200 |
{"name" : "CTUD", "type" : "functionBlock", "extensible" : False, |
201 |
"inputs" : [("CU","BOOL","rising"),("CD","BOOL","rising"),("R","BOOL","none"),("LD","BOOL","none"),("PV","INT","none")], |
|
202 |
"outputs" : [("QU","BOOL","none"),("QD","BOOL","none"),("CV","INT","none")], |
|
391 | 203 |
"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 and down on the other."), |
93 | 204 |
"generate" : generate_block, "initialise" : initialise_block}, |
0 | 205 |
{"name" : "TP", "type" : "functionBlock", "extensible" : False, |
206 |
"inputs" : [("IN","BOOL","none"),("PT","TIME","none")], |
|
207 |
"outputs" : [("Q","BOOL","none"),("ET","TIME","none")], |
|
391 | 208 |
"comment" : _("Pulse timer\nThe pulse timer can be used to generate output pulses of a given time duration."), |
93 | 209 |
"generate" : generate_block, "initialise" : initialise_block}, |
247
4a47ccafbef7
Inversion between TON and TOF comments and errors in IL keywords fixed
lbessard
parents:
242
diff
changeset
|
210 |
{"name" : "TON", "type" : "functionBlock", "extensible" : False, |
0 | 211 |
"inputs" : [("IN","BOOL","none"),("PT","TIME","none")], |
212 |
"outputs" : [("Q","BOOL","none"),("ET","TIME","none")], |
|
391 | 213 |
"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 | 214 |
"generate" : generate_block, "initialise" : initialise_block}, |
247
4a47ccafbef7
Inversion between TON and TOF comments and errors in IL keywords fixed
lbessard
parents:
242
diff
changeset
|
215 |
{"name" : "TOF", "type" : "functionBlock", "extensible" : False, |
0 | 216 |
"inputs" : [("IN","BOOL","none"),("PT","TIME","none")], |
217 |
"outputs" : [("Q","BOOL","none"),("ET","TIME","none")], |
|
391 | 218 |
"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 | 219 |
"generate" : generate_block, "initialise" : initialise_block}, |
373 | 220 |
]}, |
427 | 221 |
{"name" : _("Additional function blocks"), "list": |
649 | 222 |
[{"name" : "RTC", "type" : "functionBlock", "extensible" : False, |
223 |
"inputs" : [("IN","BOOL","none"),("PDT","DATE_AND_TIME","none")], |
|
224 |
"outputs" : [("Q","BOOL","none"),("CDT","DATE_AND_TIME","none")], |
|
225 |
"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."), |
|
226 |
"generate" : generate_block, "initialise" : initialise_block}, |
|
227 |
{"name" : "INTEGRAL", "type" : "functionBlock", "extensible" : False, |
|
0 | 228 |
"inputs" : [("RUN","BOOL","none"),("R1","BOOL","none"),("XIN","REAL","none"),("X0","REAL","none"),("CYCLE","TIME","none")], |
229 |
"outputs" : [("Q","BOOL","none"),("XOUT","REAL","none")], |
|
391 | 230 |
"comment" : _("Integral\nThe integral function block integrates the value of input XIN over time."), |
93 | 231 |
"generate" : generate_block, "initialise" : initialise_block}, |
0 | 232 |
{"name" : "DERIVATIVE", "type" : "functionBlock", "extensible" : False, |
233 |
"inputs" : [("RUN","BOOL","none"),("XIN","REAL","none"),("CYCLE","TIME","none")], |
|
234 |
"outputs" : [("XOUT","REAL","none")], |
|
391 | 235 |
"comment" : _("Derivative\nThe derivative function block produces an output XOUT proportional to the rate of change of the input XIN."), |
93 | 236 |
"generate" : generate_block, "initialise" : initialise_block}, |
0 | 237 |
{"name" : "PID", "type" : "functionBlock", "extensible" : False, |
238 |
"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")], |
|
239 |
"outputs" : [("XOUT","REAL","none")], |
|
391 | 240 |
"comment" : _("PID\nThe PID (proportional, Integral, Derivative) function block provides the classical three term controller for closed loop control."), |
93 | 241 |
"generate" : generate_block, "initialise" : initialise_block}, |
0 | 242 |
{"name" : "RAMP", "type" : "functionBlock", "extensible" : False, |
638 | 243 |
"inputs" : [("RUN","BOOL","none"),("X0","REAL","none"),("X1","REAL","none"),("TR","TIME","none"),("CYCLE","TIME","none")], |
244 |
"outputs" : [("BUSY","BOOL","none"),("XOUT","REAL","none")], |
|
245 |
"comment" : _("Ramp\nThe RAMP function block is modelled on example given in the standard."), |
|
93 | 246 |
"generate" : generate_block, "initialise" : initialise_block}, |
0 | 247 |
{"name" : "HYSTERESIS", "type" : "functionBlock", "extensible" : False, |
248 |
"inputs" : [("XIN1","REAL","none"),("XIN2","REAL","none"),("EPS","REAL","none")], |
|
249 |
"outputs" : [("Q","BOOL","none")], |
|
391 | 250 |
"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 | 251 |
"generate" : generate_block, "initialise" : initialise_block}, |
371 | 252 |
## {"name" : "RATIO_MONITOR", "type" : "functionBlock", "extensible" : False, |
253 |
## "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")], |
|
254 |
## "outputs" : [("ALARM","BOOL","none"),("TOTAL_ERR","BOOL","none")], |
|
391 | 255 |
## "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."), |
371 | 256 |
## "generate" : generate_block, "initialise" : initialise_block} |
57 | 257 |
]}, |
0 | 258 |
] |
230
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
259 |
|
0 | 260 |
|
261 |
#------------------------------------------------------------------------------- |
|
262 |
# Data Types definitions |
|
263 |
#------------------------------------------------------------------------------- |
|
264 |
||
265 |
""" |
|
266 |
Ordored list of common data types defined in the IEC 61131-3 |
|
267 |
Each type is associated to his direct parent type. It defines then a hierarchy |
|
268 |
between type that permits to make a comparison of two types |
|
269 |
""" |
|
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
270 |
TypeHierarchy_list = [ |
22 | 271 |
("ANY", None), |
272 |
("ANY_DERIVED", "ANY"), |
|
273 |
("ANY_ELEMENTARY", "ANY"), |
|
274 |
("ANY_MAGNITUDE", "ANY_ELEMENTARY"), |
|
275 |
("ANY_BIT", "ANY_ELEMENTARY"), |
|
25 | 276 |
("ANY_NBIT", "ANY_BIT"), |
22 | 277 |
("ANY_STRING", "ANY_ELEMENTARY"), |
278 |
("ANY_DATE", "ANY_ELEMENTARY"), |
|
279 |
("ANY_NUM", "ANY_MAGNITUDE"), |
|
280 |
("ANY_REAL", "ANY_NUM"), |
|
281 |
("ANY_INT", "ANY_NUM"), |
|
25 | 282 |
("ANY_SINT", "ANY_INT"), |
283 |
("ANY_UINT", "ANY_INT"), |
|
230
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
284 |
("BOOL", "ANY_BIT"), |
25 | 285 |
("SINT", "ANY_SINT"), |
286 |
("INT", "ANY_SINT"), |
|
287 |
("DINT", "ANY_SINT"), |
|
288 |
("LINT", "ANY_SINT"), |
|
289 |
("USINT", "ANY_UINT"), |
|
290 |
("UINT", "ANY_UINT"), |
|
291 |
("UDINT", "ANY_UINT"), |
|
292 |
("ULINT", "ANY_UINT"), |
|
27 | 293 |
("REAL", "ANY_REAL"), |
294 |
("LREAL", "ANY_REAL"), |
|
22 | 295 |
("TIME", "ANY_MAGNITUDE"), |
27 | 296 |
("DATE", "ANY_DATE"), |
297 |
("TOD", "ANY_DATE"), |
|
298 |
("DT", "ANY_DATE"), |
|
299 |
("STRING", "ANY_STRING"), |
|
25 | 300 |
("BYTE", "ANY_NBIT"), |
301 |
("WORD", "ANY_NBIT"), |
|
302 |
("DWORD", "ANY_NBIT"), |
|
27 | 303 |
("LWORD", "ANY_NBIT") |
304 |
#("WSTRING", "ANY_STRING") # TODO |
|
305 |
] |
|
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
306 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
307 |
TypeHierarchy = dict(TypeHierarchy_list) |
0 | 308 |
|
230
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
309 |
""" |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
310 |
returns true if the given data type is the same that "reference" meta-type or one of its types. |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
311 |
""" |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
312 |
def IsOfType(type, reference): |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
313 |
if reference is None: |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
314 |
return True |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
315 |
elif type == reference: |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
316 |
return True |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
317 |
else: |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
318 |
parent_type = TypeHierarchy[type] |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
319 |
if parent_type is not None: |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
320 |
return IsOfType(parent_type, reference) |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
321 |
return False |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
322 |
|
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
323 |
""" |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
324 |
returns list of all types that correspont to the ANY* meta type |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
325 |
""" |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
326 |
def GetSubTypes(type): |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
327 |
return [typename for typename, parenttype in TypeHierarchy.items() if not typename.startswith("ANY") and IsOfType(typename, type)] |
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
328 |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
329 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
330 |
DataTypeRange_list = [ |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
331 |
("SINT", (-2**7, 2**7 - 1)), |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
332 |
("INT", (-2**15, 2**15 - 1)), |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
333 |
("DINT", (-2**31, 2**31 - 1)), |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
334 |
("LINT", (-2**31, 2**31 - 1)), |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
335 |
("USINT", (0, 2**8 - 1)), |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
336 |
("UINT", (0, 2**16 - 1)), |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
337 |
("UDINT", (0, 2**31 - 1)), |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
338 |
("ULINT", (0, 2**31 - 1)) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
339 |
] |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
340 |
|
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
341 |
DataTypeRange = dict(DataTypeRange_list) |
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
342 |
|
230
45d70748e45a
Moving Data types and POU types informations into project model
lbessard
parents:
210
diff
changeset
|
343 |
|
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
344 |
|
21 | 345 |
#------------------------------------------------------------------------------- |
346 |
# Test identifier |
|
347 |
#------------------------------------------------------------------------------- |
|
348 |
||
349 |
||
350 |
||
351 |
# Test if identifier is valid |
|
352 |
def TestIdentifier(identifier): |
|
353 |
if identifier[0].isdigit(): |
|
354 |
return False |
|
355 |
words = identifier.split('_') |
|
356 |
for i, word in enumerate(words): |
|
357 |
if len(word) == 0 and i != 0: |
|
358 |
return False |
|
359 |
if len(word) != 0 and not word.isalnum(): |
|
360 |
return False |
|
361 |
return True |
|
362 |
||
363 |
||
364 |
#------------------------------------------------------------------------------- |
|
109
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
365 |
# Standard functions list generation |
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
366 |
#------------------------------------------------------------------------------- |
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
367 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
368 |
|
15 | 369 |
""" |
370 |
take a .csv file and translate it it a "csv_table" |
|
371 |
""" |
|
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
372 |
def csv_file_to_table(file): |
22 | 373 |
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
|
374 |
|
15 | 375 |
""" |
376 |
seek into the csv table to a section ( section_name match 1st field ) |
|
377 |
return the matching row without first field |
|
378 |
""" |
|
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
379 |
def find_section(section_name, table): |
22 | 380 |
fields = [None] |
381 |
while(fields[0] != section_name): |
|
382 |
fields = table.pop(0) |
|
383 |
return fields[1:] |
|
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
384 |
|
15 | 385 |
""" |
386 |
extract the standard functions standard parameter names and types... |
|
387 |
return a { ParameterName: Type, ...} |
|
388 |
""" |
|
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
389 |
def get_standard_funtions_input_variables(table): |
22 | 390 |
variables = find_section("Standard_functions_variables_types", table) |
391 |
standard_funtions_input_variables = {} |
|
392 |
fields = [True,True] |
|
393 |
while(fields[1]): |
|
394 |
fields = table.pop(0) |
|
395 |
variable_from_csv = dict([(champ, val) for champ, val in zip(variables, fields[1:]) if champ!='']) |
|
396 |
standard_funtions_input_variables[variable_from_csv['name']] = variable_from_csv['type'] |
|
397 |
return standard_funtions_input_variables |
|
398 |
||
15 | 399 |
""" |
400 |
translate .csv file input declaration into PLCOpenEditor interessting values |
|
401 |
in : "(ANY_NUM, ANY_NUM)" and { ParameterName: Type, ...} |
|
402 |
return [("IN1","ANY_NUM","none"),("IN2","ANY_NUM","none")] |
|
403 |
""" |
|
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
404 |
def csv_input_translate(str_decl, variables, base): |
22 | 405 |
decl = str_decl.replace('(','').replace(')','').replace(' ','').split(',') |
406 |
params = [] |
|
407 |
||
408 |
len_of_not_predifined_variable = len([True for param_type in decl if param_type not in variables]) |
|
409 |
||
410 |
for param_type in decl: |
|
411 |
if param_type in variables.keys(): |
|
412 |
param_name = param_type |
|
413 |
param_type = variables[param_type] |
|
414 |
elif len_of_not_predifined_variable > 1: |
|
415 |
param_name = "IN%d"%base |
|
416 |
base += 1 |
|
417 |
else: |
|
418 |
param_name = "IN" |
|
419 |
params.append((param_name, param_type, "none")) |
|
420 |
return params |
|
421 |
||
422 |
||
25 | 423 |
ANY_TO_ANY_LIST=[ |
424 |
# simple type conv are let as C cast |
|
541
24f111835805
Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents:
526
diff
changeset
|
425 |
(("ANY_INT","ANY_BIT"),("ANY_NUM","ANY_BIT"), ("return_type", "__move_", "IN_type")), |
24f111835805
Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents:
526
diff
changeset
|
426 |
(("ANY_REAL",),("ANY_REAL",), ("return_type", "__move_", "IN_type")), |
24f111835805
Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents:
526
diff
changeset
|
427 |
# REAL_TO_INT |
24f111835805
Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents:
526
diff
changeset
|
428 |
(("ANY_REAL",),("ANY_SINT",), ("return_type", "__real_to_sint", None)), |
24f111835805
Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents:
526
diff
changeset
|
429 |
(("ANY_REAL",),("ANY_UINT",), ("return_type", "__real_to_uint", None)), |
24f111835805
Fixing REAL_TO_INT conversion (behaved like a trunc and not like a round)
laurent
parents:
526
diff
changeset
|
430 |
(("ANY_REAL",),("ANY_BIT",), ("return_type", "__real_to_bit", None)), |
25 | 431 |
# TO_TIME |
284 | 432 |
(("ANY_INT","ANY_BIT"),("ANY_DATE","TIME"), ("return_type", "__int_to_time", None)), |
433 |
(("ANY_REAL",),("ANY_DATE","TIME"), ("return_type", "__real_to_time", None)), |
|
434 |
(("ANY_STRING",), ("ANY_DATE","TIME"), ("return_type", "__string_to_time", None)), |
|
25 | 435 |
# FROM_TIME |
284 | 436 |
(("ANY_DATE","TIME"), ("ANY_REAL",), ("return_type", "__time_to_real", None)), |
437 |
(("ANY_DATE","TIME"), ("ANY_INT","ANY_NBIT"), ("return_type", "__time_to_int", None)), |
|
438 |
(("TIME",), ("ANY_STRING",), ("return_type", "__time_to_string", None)), |
|
439 |
(("DATE",), ("ANY_STRING",), ("return_type", "__date_to_string", None)), |
|
440 |
(("TOD",), ("ANY_STRING",), ("return_type", "__tod_to_string", None)), |
|
441 |
(("DT",), ("ANY_STRING",), ("return_type", "__dt_to_string", None)), |
|
25 | 442 |
# TO_STRING |
284 | 443 |
(("BOOL",), ("ANY_STRING",), ("return_type", "__bool_to_string", None)), |
444 |
(("ANY_BIT",), ("ANY_STRING",), ("return_type", "__bit_to_string", None)), |
|
445 |
(("ANY_REAL",), ("ANY_STRING",), ("return_type", "__real_to_string", None)), |
|
446 |
(("ANY_SINT",), ("ANY_STRING",), ("return_type", "__sint_to_string", None)), |
|
447 |
(("ANY_UINT",), ("ANY_STRING",), ("return_type", "__uint_to_string", None)), |
|
25 | 448 |
# FROM_STRING |
284 | 449 |
(("ANY_STRING",), ("BOOL",), ("return_type", "__string_to_bool", None)), |
450 |
(("ANY_STRING",), ("ANY_BIT",), ("return_type", "__string_to_bit", None)), |
|
451 |
(("ANY_STRING",), ("ANY_SINT",), ("return_type", "__string_to_sint", None)), |
|
452 |
(("ANY_STRING",), ("ANY_UINT",), ("return_type", "__string_to_uint", None)), |
|
453 |
(("ANY_STRING",), ("ANY_REAL",), ("return_type", "__string_to_real", None))] |
|
25 | 454 |
|
455 |
||
456 |
BCD_TO_ANY_LIST=[ |
|
284 | 457 |
(("BYTE",),("USINT",), ("return_type", "__bcd_to_uint", None)), |
458 |
(("WORD",),("UINT",), ("return_type", "__bcd_to_uint", None)), |
|
459 |
(("DWORD",),("UDINT",), ("return_type", "__bcd_to_uint", None)), |
|
460 |
(("LWORD",),("ULINT",), ("return_type", "__bcd_to_uint", None))] |
|
25 | 461 |
|
462 |
||
463 |
ANY_TO_BCD_LIST=[ |
|
284 | 464 |
(("USINT",),("BYTE",), ("return_type", "__uint_to_bcd", None)), |
465 |
(("UINT",),("WORD",), ("return_type", "__uint_to_bcd", None)), |
|
466 |
(("UDINT",),("DWORD",), ("return_type", "__uint_to_bcd", None)), |
|
467 |
(("ULINT",),("LWORD",), ("return_type", "__uint_to_bcd", None))] |
|
25 | 468 |
|
469 |
||
470 |
def ANY_TO_ANY_FORMAT_GEN(any_to_any_list, fdecl): |
|
471 |
||
472 |
for (InTypes, OutTypes, Format) in any_to_any_list: |
|
22 | 473 |
outs = reduce(lambda a,b: a or b, map(lambda testtype : IsOfType(fdecl["outputs"][0][1],testtype), OutTypes)) |
474 |
inps = reduce(lambda a,b: a or b, map(lambda testtype : IsOfType(fdecl["inputs"][0][1],testtype), InTypes)) |
|
475 |
if inps and outs and fdecl["outputs"][0][1] != fdecl["inputs"][0][1]: |
|
476 |
return Format |
|
477 |
||
478 |
return None |
|
18
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
479 |
|
ee18a387e80a
Enhanced standard funcrtion declaration from .csv file.
etisserant
parents:
15
diff
changeset
|
480 |
|
15 | 481 |
""" |
482 |
Returns this kind of declaration for all standard functions |
|
483 |
||
484 |
[{"name" : "Numerical", 'list': [ { |
|
485 |
'baseinputnumber': 1, |
|
486 |
'comment': 'Addition', |
|
487 |
'extensible': True, |
|
488 |
'inputs': [ ('IN1', 'ANY_NUM', 'none'), |
|
489 |
('IN2', 'ANY_NUM', 'none')], |
|
490 |
'name': 'ADD', |
|
491 |
'outputs': [('OUT', 'ANY_NUM', 'none')], |
|
492 |
'type': 'function'}, ...... ] },.....] |
|
493 |
""" |
|
14
cd0133ed377b
Standard IEC functions declaration now made from iec_std.csv file for easier maintainance.
etisserant
parents:
9
diff
changeset
|
494 |
def get_standard_funtions(table): |
22 | 495 |
|
496 |
variables = get_standard_funtions_input_variables(table) |
|
497 |
||
498 |
fonctions = find_section("Standard_functions_type",table) |
|
499 |
||
500 |
Standard_Functions_Decl = [] |
|
501 |
Current_section = None |
|
502 |
||
503 |
translate = { |
|
504 |
"extensible" : lambda x: {"yes":True, "no":False}[x], |
|
505 |
"inputs" : lambda x:csv_input_translate(x,variables,baseinputnumber), |
|
506 |
"outputs":lambda x:[("OUT",x,"none")]} |
|
507 |
||
508 |
for fields in table: |
|
509 |
if fields[1]: |
|
510 |
# If function section name given |
|
511 |
if fields[0]: |
|
391 | 512 |
words = fields[0].split('"') |
513 |
if len(words) > 1: |
|
514 |
section_name = words[1] |
|
515 |
else: |
|
516 |
section_name = fields[0] |
|
517 |
Current_section = {"name" : section_name, "list" : []} |
|
22 | 518 |
Standard_Functions_Decl.append(Current_section) |
519 |
Function_decl_list = [] |
|
520 |
if Current_section: |
|
521 |
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
|
522 |
Function_decl["generate"] = generate_block |
93 | 523 |
Function_decl["initialise"] = lambda x,y:[] |
22 | 524 |
baseinputnumber = int(Function_decl.get("baseinputnumber",1)) |
525 |
Function_decl["baseinputnumber"] = baseinputnumber |
|
526 |
for param, value in Function_decl.iteritems(): |
|
527 |
if param in translate: |
|
528 |
Function_decl[param] = translate[param](value) |
|
529 |
Function_decl["type"] = "function" |
|
530 |
||
25 | 531 |
if Function_decl["name"].startswith('*') or Function_decl["name"].endswith('*') : |
22 | 532 |
input_ovrloading_types = GetSubTypes(Function_decl["inputs"][0][1]) |
25 | 533 |
output_types = GetSubTypes(Function_decl["outputs"][0][1]) |
22 | 534 |
else: |
535 |
input_ovrloading_types = [None] |
|
536 |
output_types = [None] |
|
125
394d9f168258
Adding support for execution order in PLCGenerator
lbessard
parents:
109
diff
changeset
|
537 |
|
22 | 538 |
funcdeclname_orig = Function_decl["name"] |
539 |
funcdeclname = Function_decl["name"].strip('*_') |
|
540 |
fdc = Function_decl["inputs"][:] |
|
541 |
for intype in input_ovrloading_types: |
|
542 |
if intype != None: |
|
543 |
Function_decl["inputs"] = [] |
|
544 |
for decl_tpl in fdc: |
|
545 |
if IsOfType(intype, decl_tpl[1]): |
|
546 |
Function_decl["inputs"] += [(decl_tpl[0], intype, decl_tpl[2])] |
|
547 |
else: |
|
548 |
Function_decl["inputs"] += [(decl_tpl)] |
|
549 |
||
550 |
if funcdeclname_orig.startswith('*'): |
|
551 |
funcdeclin = intype + '_' + funcdeclname |
|
552 |
else: |
|
553 |
funcdeclin = funcdeclname |
|
554 |
else: |
|
555 |
funcdeclin = funcdeclname |
|
556 |
||
557 |
for outype in output_types: |
|
558 |
if outype != None: |
|
559 |
decl_tpl = Function_decl["outputs"][0] |
|
560 |
Function_decl["outputs"] = [ (decl_tpl[0] , outype, decl_tpl[2])] |
|
561 |
if funcdeclname_orig.endswith('*'): |
|
562 |
funcdeclout = funcdeclin + '_' + outype |
|
563 |
else: |
|
564 |
funcdeclout = funcdeclin |
|
565 |
else: |
|
566 |
funcdeclout = funcdeclin |
|
567 |
Function_decl["name"] = funcdeclout |
|
568 |
||
569 |
||
570 |
fdecl = Function_decl |
|
571 |
res = eval(Function_decl["python_eval_c_code_format"]) |
|
572 |
||
573 |
if res != None : |
|
574 |
# create the copy of decl dict to be appended to section |
|
575 |
Function_decl_copy = Function_decl.copy() |
|
576 |
Current_section["list"].append(Function_decl_copy) |
|
577 |
else: |
|
578 |
raise "First function must be in a category" |
|
579 |
||
580 |
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
|
581 |
|
25 | 582 |
std_decl = get_standard_funtions(csv_file_to_table(open(os.path.join(os.path.split(__file__)[0],"iec_std.csv"))))#, True) |
583 |
||
584 |
BlockTypes.extend(std_decl) |
|
585 |
||
517
026ef159e8a2
Added POU interface description in library help text for standard function blocks too, not only in standard functions
Edouard Tisserant
parents:
483
diff
changeset
|
586 |
for section in BlockTypes: |
026ef159e8a2
Added POU interface description in library help text for standard function blocks too, not only in standard functions
Edouard Tisserant
parents:
483
diff
changeset
|
587 |
for desc in section["list"]: |
026ef159e8a2
Added POU interface description in library help text for standard function blocks too, not only in standard functions
Edouard Tisserant
parents:
483
diff
changeset
|
588 |
words = desc["comment"].split('"') |
026ef159e8a2
Added POU interface description in library help text for standard function blocks too, not only in standard functions
Edouard Tisserant
parents:
483
diff
changeset
|
589 |
if len(words) > 1: |
026ef159e8a2
Added POU interface description in library help text for standard function blocks too, not only in standard functions
Edouard Tisserant
parents:
483
diff
changeset
|
590 |
desc["comment"] = words[1] |
026ef159e8a2
Added POU interface description in library help text for standard function blocks too, not only in standard functions
Edouard Tisserant
parents:
483
diff
changeset
|
591 |
desc["usage"] = ( |
026ef159e8a2
Added POU interface description in library help text for standard function blocks too, not only in standard functions
Edouard Tisserant
parents:
483
diff
changeset
|
592 |
"\n (" + |
026ef159e8a2
Added POU interface description in library help text for standard function blocks too, not only in standard functions
Edouard Tisserant
parents:
483
diff
changeset
|
593 |
str([ " " + fctdecl[1]+":"+fctdecl[0] for fctdecl in desc["inputs"]]).strip("[]").replace("'",'') + |
026ef159e8a2
Added POU interface description in library help text for standard function blocks too, not only in standard functions
Edouard Tisserant
parents:
483
diff
changeset
|
594 |
" ) => (" + |
026ef159e8a2
Added POU interface description in library help text for standard function blocks too, not only in standard functions
Edouard Tisserant
parents:
483
diff
changeset
|
595 |
str([ " " + fctdecl[1]+":"+fctdecl[0] for fctdecl in desc["outputs"]]).strip("[]").replace("'",'') + |
026ef159e8a2
Added POU interface description in library help text for standard function blocks too, not only in standard functions
Edouard Tisserant
parents:
483
diff
changeset
|
596 |
" )") |
026ef159e8a2
Added POU interface description in library help text for standard function blocks too, not only in standard functions
Edouard Tisserant
parents:
483
diff
changeset
|
597 |
|
109
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
598 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
599 |
#------------------------------------------------------------------------------- |
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
600 |
# Languages Keywords |
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
601 |
#------------------------------------------------------------------------------- |
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
602 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
603 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
604 |
# Keywords for Pou Declaration |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
605 |
POU_BLOCK_START_KEYWORDS = ["FUNCTION", "FUNCTION_BLOCK", "PROGRAM"] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
606 |
POU_BLOCK_END_KEYWORDS = ["END_FUNCTION", "END_FUNCTION_BLOCK", "END_PROGRAM"] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
607 |
POU_KEYWORDS = ["EN", "ENO", "F_EDGE", "R_EDGE"] + POU_BLOCK_START_KEYWORDS + POU_BLOCK_END_KEYWORDS |
109
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
608 |
for category in BlockTypes: |
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
609 |
for block in category["list"]: |
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
610 |
if block["name"] not in POU_KEYWORDS: |
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
611 |
POU_KEYWORDS.append(block["name"]) |
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
612 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
613 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
614 |
# Keywords for Type Declaration |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
615 |
TYPE_BLOCK_START_KEYWORDS = ["TYPE", "STRUCT"] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
616 |
TYPE_BLOCK_END_KEYWORDS = ["END_TYPE", "END_STRUCT"] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
617 |
TYPE_KEYWORDS = ["ARRAY", "OF", "T", "D", "TIME_OF_DAY", "DATE_AND_TIME"] + TYPE_BLOCK_START_KEYWORDS + TYPE_BLOCK_END_KEYWORDS |
109
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
618 |
TYPE_KEYWORDS.extend([keyword for keyword in TypeHierarchy.keys() if keyword not in TYPE_KEYWORDS]) |
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
619 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
620 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
621 |
# Keywords for Variable Declaration |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
622 |
VAR_BLOCK_START_KEYWORDS = ["VAR", "VAR_INPUT", "VAR_OUTPUT", "VAR_IN_OUT", "VAR_TEMP", "VAR_EXTERNAL"] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
623 |
VAR_BLOCK_END_KEYWORDS = ["END_VAR"] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
624 |
VAR_KEYWORDS = ["AT", "CONSTANT", "RETAIN", "NON_RETAIN"] + VAR_BLOCK_START_KEYWORDS + VAR_BLOCK_END_KEYWORDS |
109
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
625 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
626 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
627 |
# Keywords for Configuration Declaration |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
628 |
CONFIG_BLOCK_START_KEYWORDS = ["CONFIGURATION", "RESOURCE", "VAR_ACCESS", "VAR_CONFIG", "VAR_GLOBAL"] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
629 |
CONFIG_BLOCK_END_KEYWORDS = ["END_CONFIGURATION", "END_RESOURCE", "END_VAR"] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
630 |
CONFIG_KEYWORDS = ["ON", "PROGRAM", "WITH", "READ_ONLY", "READ_WRITE", "TASK"] + CONFIG_BLOCK_START_KEYWORDS + CONFIG_BLOCK_END_KEYWORDS |
109
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
631 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
632 |
# Keywords for Structured Function Chart |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
633 |
SFC_BLOCK_START_KEYWORDS = ["ACTION", "INITIAL_STEP", "STEP", "TRANSITION"] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
634 |
SFC_BLOCK_END_KEYWORDS = ["END_ACTION", "END_STEP", "END_TRANSITION"] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
635 |
SFC_KEYWORDS = ["FROM", "TO"] + SFC_BLOCK_START_KEYWORDS + SFC_BLOCK_START_KEYWORDS |
109
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
636 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
637 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
638 |
# Keywords for Instruction List |
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
639 |
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
|
640 |
"XOR", "XORN", "NOT", "ADD", "SUB", "MUL", "DIV", "MOD", "GT", "GE", "EQ", "NE", |
247
4a47ccafbef7
Inversion between TON and TOF comments and errors in IL keywords fixed
lbessard
parents:
242
diff
changeset
|
641 |
"LE", "LT", "JMP", "JMPC", "JMPCN", "CAL", "CALC", "CALCN", "RET", "RETC", "RETCN"] |
109
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
642 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
643 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
644 |
# Keywords for Structured Text |
582
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
541
diff
changeset
|
645 |
ST_BLOCK_START_KEYWORDS = ["IF", "ELSIF", "ELSE", "CASE", "FOR", "WHILE", "REPEAT"] |
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
541
diff
changeset
|
646 |
ST_BLOCK_END_KEYWORDS = ["END_IF", "END_CASE", "END_FOR", "END_WHILE", "END_REPEAT"] |
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
541
diff
changeset
|
647 |
ST_KEYWORDS = ["TRUE", "FALSE", "THEN", "OF", "TO", "BY", "DO", "DO", "UNTIL", "EXIT", |
aa41547baa2a
Adding support for folding/unfolding and auto-indentation in ST code editor
laurent
parents:
541
diff
changeset
|
648 |
"RETURN", "NOT", "MOD", "AND", "XOR", "OR"] + ST_BLOCK_START_KEYWORDS + ST_BLOCK_END_KEYWORDS |
109
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
649 |
|
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
650 |
# All the keywords of IEC |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
651 |
IEC_BLOCK_START_KEYWORDS = [] |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
652 |
IEC_BLOCK_END_KEYWORDS = [] |
109
734e02ab4018
Bug that didn't affect standard function names as keywords fixed
lbessard
parents:
108
diff
changeset
|
653 |
IEC_KEYWORDS = ["E", "TRUE", "FALSE"] |
586
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
654 |
for all_keywords, keywords_list in [(IEC_BLOCK_START_KEYWORDS, [POU_BLOCK_START_KEYWORDS, TYPE_BLOCK_START_KEYWORDS, |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
655 |
VAR_BLOCK_START_KEYWORDS, CONFIG_BLOCK_START_KEYWORDS, |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
656 |
SFC_BLOCK_START_KEYWORDS, ST_BLOCK_START_KEYWORDS]), |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
657 |
(IEC_BLOCK_END_KEYWORDS, [POU_BLOCK_END_KEYWORDS, TYPE_BLOCK_END_KEYWORDS, |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
658 |
VAR_BLOCK_END_KEYWORDS, CONFIG_BLOCK_END_KEYWORDS, |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
659 |
SFC_BLOCK_END_KEYWORDS, ST_BLOCK_END_KEYWORDS]), |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
660 |
(IEC_KEYWORDS, [POU_KEYWORDS, TYPE_KEYWORDS, VAR_KEYWORDS, CONFIG_KEYWORDS, |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
661 |
SFC_KEYWORDS, IL_KEYWORDS, ST_KEYWORDS])]: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
662 |
for keywords in keywords_list: |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
663 |
all_keywords.extend([keyword for keyword in keywords if keyword not in all_keywords]) |
9aa96a36cf33
Moving variable panel from bottom notebook panel to POU editor panel
laurent
parents:
582
diff
changeset
|
664 |