author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 11 Jan 2017 12:57:40 +0300 | |
changeset 1624 | bc84d659894f |
parent 1511 | 91538d0c242c |
child 1625 | be3f68731798 |
permissions | -rw-r--r-- |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
1 |
#!/usr/bin/env python |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
3 |
|
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
6 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
8 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
10 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
15 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
19 |
# GNU General Public License for more details. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
20 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
24 |
|
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1412
diff
changeset
|
25 |
|
1390 | 26 |
from os.path import join, split, realpath |
27 |
sd = split(realpath(__file__))[0] |
|
28 |
||
29 |
# Override gettext _ in this module |
|
30 |
# since we just want string to be added to dictionnary |
|
31 |
# but translation should happen here |
|
32 |
_ = lambda x:x |
|
33 |
||
34 |
LANGUAGES = ["IL","ST","FBD","LD","SFC"] |
|
35 |
||
36 |
LOCATIONDATATYPES = {"X" : ["BOOL"], |
|
37 |
"B" : ["SINT", "USINT", "BYTE", "STRING"], |
|
38 |
"W" : ["INT", "UINT", "WORD", "WSTRING"], |
|
39 |
"D" : ["DINT", "UDINT", "REAL", "DWORD"], |
|
1411 | 40 |
"L" : ["LINT", "ULINT", "LREAL", "LWORD"]} |
1390 | 41 |
|
42 |
#------------------------------------------------------------------------------- |
|
43 |
# Function Block Types definitions |
|
44 |
#------------------------------------------------------------------------------- |
|
45 |
||
46 |
StdTC6Libs = [(_("Standard function blocks"), join(sd, "Standard_Function_Blocks.xml")), |
|
47 |
(_("Additional function blocks"),join(sd, "Additional_Function_Blocks.xml"))] |
|
48 |
||
49 |
StdFuncsCSV = join(sd,"iec_std.csv") |
|
50 |
||
51 |
# FIXME : since std fb now loaded from TC6 file, is that still necessary ? |
|
52 |
StdBlockComments = { |
|
53 |
"SR": _("SR bistable\nThe SR bistable is a latch where the Set dominates."), |
|
54 |
"RS": _("RS bistable\nThe RS bistable is a latch where the Reset dominates."), |
|
55 |
"SEMA": _("Semaphore\nThe semaphore provides a mechanism to allow software elements mutually exclusive access to certain ressources."), |
|
56 |
"R_TRIG": _("Rising edge detector\nThe output produces a single pulse when a rising edge is detected."), |
|
57 |
"F_TRIG": _("Falling edge detector\nThe output produces a single pulse when a falling edge is detected."), |
|
58 |
"CTU": _("Up-counter\nThe up-counter can be used to signal when a count has reached a maximum value."), |
|
59 |
"CTD": _("Down-counter\nThe down-counter can be used to signal when a count has reached zero, on counting down from a preset value."), |
|
60 |
"CTUD": _("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."), |
|
61 |
"TP": _("Pulse timer\nThe pulse timer can be used to generate output pulses of a given time duration."), |
|
62 |
"TON": _("On-delay timer\nThe on-delay timer can be used to delay setting an output true, for fixed period after an input becomes true."), |
|
63 |
"TOF": _("Off-delay timer\nThe off-delay timer can be used to delay setting an output false, for fixed period after input goes false."), |
|
64 |
"RTC": _("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."), |
|
65 |
"INTEGRAL": _("Integral\nThe integral function block integrates the value of input XIN over time."), |
|
66 |
"DERIVATIVE": _("Derivative\nThe derivative function block produces an output XOUT proportional to the rate of change of the input XIN."), |
|
67 |
"PID": _("PID\nThe PID (proportional, Integral, Derivative) function block provides the classical three term controller for closed loop control."), |
|
68 |
"RAMP": _("Ramp\nThe RAMP function block is modelled on example given in the standard."), |
|
69 |
"HYSTERESIS": _("Hysteresis\nThe hysteresis function block provides a hysteresis boolean output driven by the difference of two floating point (REAL) inputs XIN1 and XIN2."), |
|
70 |
} |
|
71 |
||
72 |
for block_type in ["CTU", "CTD", "CTUD"]: |
|
73 |
for return_type in ["DINT", "LINT", "UDINT", "ULINT"]: |
|
74 |
StdBlockComments["%s_%s" % (block_type, return_type)] = StdBlockComments[block_type] |
|
75 |
||
76 |
def GetBlockInfos(pou): |
|
77 |
infos = pou.getblockInfos() |
|
78 |
# FIXME : as well |
|
79 |
infos["comment"] = StdBlockComments[infos["name"]] |
|
80 |
infos["inputs"] = [ |
|
81 |
(var_name, var_type, "rising") |
|
82 |
if var_name in ["CU", "CD"] |
|
83 |
else (var_name, var_type, var_modifier) |
|
84 |
for var_name, var_type, var_modifier in infos["inputs"]] |
|
85 |
return infos |
|
86 |
||
87 |
#------------------------------------------------------------------------------- |
|
88 |
# Data Types definitions |
|
89 |
#------------------------------------------------------------------------------- |
|
90 |
||
91 |
""" |
|
92 |
Ordored list of common data types defined in the IEC 61131-3 |
|
93 |
Each type is associated to his direct parent type. It defines then a hierarchy |
|
94 |
between type that permits to make a comparison of two types |
|
95 |
""" |
|
96 |
TypeHierarchy_list = [ |
|
97 |
("ANY", None), |
|
98 |
("ANY_DERIVED", "ANY"), |
|
99 |
("ANY_ELEMENTARY", "ANY"), |
|
100 |
("ANY_MAGNITUDE", "ANY_ELEMENTARY"), |
|
101 |
("ANY_BIT", "ANY_ELEMENTARY"), |
|
102 |
("ANY_NBIT", "ANY_BIT"), |
|
103 |
("ANY_STRING", "ANY_ELEMENTARY"), |
|
104 |
("ANY_DATE", "ANY_ELEMENTARY"), |
|
105 |
("ANY_NUM", "ANY_MAGNITUDE"), |
|
106 |
("ANY_REAL", "ANY_NUM"), |
|
107 |
("ANY_INT", "ANY_NUM"), |
|
108 |
("ANY_SINT", "ANY_INT"), |
|
109 |
("ANY_UINT", "ANY_INT"), |
|
110 |
("BOOL", "ANY_BIT"), |
|
111 |
("SINT", "ANY_SINT"), |
|
112 |
("INT", "ANY_SINT"), |
|
113 |
("DINT", "ANY_SINT"), |
|
114 |
("LINT", "ANY_SINT"), |
|
115 |
("USINT", "ANY_UINT"), |
|
116 |
("UINT", "ANY_UINT"), |
|
117 |
("UDINT", "ANY_UINT"), |
|
118 |
("ULINT", "ANY_UINT"), |
|
119 |
("REAL", "ANY_REAL"), |
|
120 |
("LREAL", "ANY_REAL"), |
|
121 |
("TIME", "ANY_MAGNITUDE"), |
|
122 |
("DATE", "ANY_DATE"), |
|
123 |
("TOD", "ANY_DATE"), |
|
124 |
("DT", "ANY_DATE"), |
|
125 |
("STRING", "ANY_STRING"), |
|
126 |
("BYTE", "ANY_NBIT"), |
|
127 |
("WORD", "ANY_NBIT"), |
|
128 |
("DWORD", "ANY_NBIT"), |
|
129 |
("LWORD", "ANY_NBIT") |
|
130 |
#("WSTRING", "ANY_STRING") # TODO |
|
131 |
] |
|
132 |
||
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
1411
diff
changeset
|
133 |
DefaultType = "DINT" |
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
1411
diff
changeset
|
134 |
|
1390 | 135 |
DataTypeRange_list = [ |
136 |
("SINT", (-2**7, 2**7 - 1)), |
|
137 |
("INT", (-2**15, 2**15 - 1)), |
|
138 |
("DINT", (-2**31, 2**31 - 1)), |
|
139 |
("LINT", (-2**31, 2**31 - 1)), |
|
140 |
("USINT", (0, 2**8 - 1)), |
|
141 |
("UINT", (0, 2**16 - 1)), |
|
142 |
("UDINT", (0, 2**31 - 1)), |
|
143 |
("ULINT", (0, 2**31 - 1)) |
|
144 |
] |
|
145 |
||
146 |
ANY_TO_ANY_FILTERS = { |
|
147 |
"ANY_TO_ANY":[ |
|
148 |
# simple type conv are let as C cast |
|
149 |
(("ANY_INT","ANY_BIT"),("ANY_NUM","ANY_BIT")), |
|
150 |
(("ANY_REAL",),("ANY_REAL",)), |
|
151 |
# REAL_TO_INT |
|
152 |
(("ANY_REAL",),("ANY_SINT",)), |
|
153 |
(("ANY_REAL",),("ANY_UINT",)), |
|
154 |
(("ANY_REAL",),("ANY_BIT",)), |
|
155 |
# TO_TIME |
|
156 |
(("ANY_INT","ANY_BIT"),("ANY_DATE","TIME")), |
|
157 |
(("ANY_REAL",),("ANY_DATE","TIME")), |
|
158 |
(("ANY_STRING",), ("ANY_DATE","TIME")), |
|
159 |
# FROM_TIME |
|
160 |
(("ANY_DATE","TIME"), ("ANY_REAL",)), |
|
161 |
(("ANY_DATE","TIME"), ("ANY_INT","ANY_NBIT")), |
|
162 |
(("TIME",), ("ANY_STRING",)), |
|
163 |
(("DATE",), ("ANY_STRING",)), |
|
164 |
(("TOD",), ("ANY_STRING",)), |
|
165 |
(("DT",), ("ANY_STRING",)), |
|
166 |
# TO_STRING |
|
167 |
(("BOOL",), ("ANY_STRING",)), |
|
168 |
(("ANY_BIT",), ("ANY_STRING",)), |
|
169 |
(("ANY_REAL",), ("ANY_STRING",)), |
|
170 |
(("ANY_SINT",), ("ANY_STRING",)), |
|
171 |
(("ANY_UINT",), ("ANY_STRING",)), |
|
172 |
# FROM_STRING |
|
173 |
(("ANY_STRING",), ("BOOL",)), |
|
174 |
(("ANY_STRING",), ("ANY_BIT",)), |
|
175 |
(("ANY_STRING",), ("ANY_SINT",)), |
|
176 |
(("ANY_STRING",), ("ANY_UINT",)), |
|
177 |
(("ANY_STRING",), ("ANY_REAL",))], |
|
178 |
"BCD_TO_ANY":[ |
|
179 |
(("BYTE",),("USINT",)), |
|
180 |
(("WORD",),("UINT",)), |
|
181 |
(("DWORD",),("UDINT",)), |
|
182 |
(("LWORD",),("ULINT",))], |
|
183 |
"ANY_TO_BCD":[ |
|
184 |
(("USINT",),("BYTE",)), |
|
185 |
(("UINT",),("WORD",)), |
|
186 |
(("UDINT",),("DWORD",)), |
|
187 |
(("ULINT",),("LWORD",))] |
|
188 |
} |
|
189 |
||
190 |
# remove gettext override |
|
191 |
del _ |