author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 05 Apr 2017 14:24:52 +0300 | |
changeset 1673 | fab1b8da6eba |
parent 1625 | be3f68731798 |
child 1680 | 6db967480b7d |
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 |
def GetBlockInfos(pou): |
|
52 |
infos = pou.getblockInfos() |
|
53 |
infos["inputs"] = [ |
|
54 |
(var_name, var_type, "rising") |
|
55 |
if var_name in ["CU", "CD"] |
|
56 |
else (var_name, var_type, var_modifier) |
|
57 |
for var_name, var_type, var_modifier in infos["inputs"]] |
|
58 |
return infos |
|
59 |
||
60 |
#------------------------------------------------------------------------------- |
|
61 |
# Data Types definitions |
|
62 |
#------------------------------------------------------------------------------- |
|
63 |
||
64 |
""" |
|
65 |
Ordored list of common data types defined in the IEC 61131-3 |
|
66 |
Each type is associated to his direct parent type. It defines then a hierarchy |
|
67 |
between type that permits to make a comparison of two types |
|
68 |
""" |
|
69 |
TypeHierarchy_list = [ |
|
70 |
("ANY", None), |
|
71 |
("ANY_DERIVED", "ANY"), |
|
72 |
("ANY_ELEMENTARY", "ANY"), |
|
73 |
("ANY_MAGNITUDE", "ANY_ELEMENTARY"), |
|
74 |
("ANY_BIT", "ANY_ELEMENTARY"), |
|
75 |
("ANY_NBIT", "ANY_BIT"), |
|
76 |
("ANY_STRING", "ANY_ELEMENTARY"), |
|
77 |
("ANY_DATE", "ANY_ELEMENTARY"), |
|
78 |
("ANY_NUM", "ANY_MAGNITUDE"), |
|
79 |
("ANY_REAL", "ANY_NUM"), |
|
80 |
("ANY_INT", "ANY_NUM"), |
|
81 |
("ANY_SINT", "ANY_INT"), |
|
82 |
("ANY_UINT", "ANY_INT"), |
|
83 |
("BOOL", "ANY_BIT"), |
|
84 |
("SINT", "ANY_SINT"), |
|
85 |
("INT", "ANY_SINT"), |
|
86 |
("DINT", "ANY_SINT"), |
|
87 |
("LINT", "ANY_SINT"), |
|
88 |
("USINT", "ANY_UINT"), |
|
89 |
("UINT", "ANY_UINT"), |
|
90 |
("UDINT", "ANY_UINT"), |
|
91 |
("ULINT", "ANY_UINT"), |
|
92 |
("REAL", "ANY_REAL"), |
|
93 |
("LREAL", "ANY_REAL"), |
|
94 |
("TIME", "ANY_MAGNITUDE"), |
|
95 |
("DATE", "ANY_DATE"), |
|
96 |
("TOD", "ANY_DATE"), |
|
97 |
("DT", "ANY_DATE"), |
|
98 |
("STRING", "ANY_STRING"), |
|
99 |
("BYTE", "ANY_NBIT"), |
|
100 |
("WORD", "ANY_NBIT"), |
|
101 |
("DWORD", "ANY_NBIT"), |
|
102 |
("LWORD", "ANY_NBIT") |
|
103 |
#("WSTRING", "ANY_STRING") # TODO |
|
104 |
] |
|
105 |
||
1412
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
1411
diff
changeset
|
106 |
DefaultType = "DINT" |
50192dd2f5ff
Added plcopen.definitions.DefaultType, set to INT.
Edouard Tisserant
parents:
1411
diff
changeset
|
107 |
|
1390 | 108 |
DataTypeRange_list = [ |
109 |
("SINT", (-2**7, 2**7 - 1)), |
|
110 |
("INT", (-2**15, 2**15 - 1)), |
|
111 |
("DINT", (-2**31, 2**31 - 1)), |
|
112 |
("LINT", (-2**31, 2**31 - 1)), |
|
113 |
("USINT", (0, 2**8 - 1)), |
|
114 |
("UINT", (0, 2**16 - 1)), |
|
115 |
("UDINT", (0, 2**31 - 1)), |
|
116 |
("ULINT", (0, 2**31 - 1)) |
|
117 |
] |
|
118 |
||
119 |
ANY_TO_ANY_FILTERS = { |
|
120 |
"ANY_TO_ANY":[ |
|
121 |
# simple type conv are let as C cast |
|
122 |
(("ANY_INT","ANY_BIT"),("ANY_NUM","ANY_BIT")), |
|
123 |
(("ANY_REAL",),("ANY_REAL",)), |
|
124 |
# REAL_TO_INT |
|
125 |
(("ANY_REAL",),("ANY_SINT",)), |
|
126 |
(("ANY_REAL",),("ANY_UINT",)), |
|
127 |
(("ANY_REAL",),("ANY_BIT",)), |
|
128 |
# TO_TIME |
|
129 |
(("ANY_INT","ANY_BIT"),("ANY_DATE","TIME")), |
|
130 |
(("ANY_REAL",),("ANY_DATE","TIME")), |
|
131 |
(("ANY_STRING",), ("ANY_DATE","TIME")), |
|
132 |
# FROM_TIME |
|
133 |
(("ANY_DATE","TIME"), ("ANY_REAL",)), |
|
134 |
(("ANY_DATE","TIME"), ("ANY_INT","ANY_NBIT")), |
|
135 |
(("TIME",), ("ANY_STRING",)), |
|
136 |
(("DATE",), ("ANY_STRING",)), |
|
137 |
(("TOD",), ("ANY_STRING",)), |
|
138 |
(("DT",), ("ANY_STRING",)), |
|
139 |
# TO_STRING |
|
140 |
(("BOOL",), ("ANY_STRING",)), |
|
141 |
(("ANY_BIT",), ("ANY_STRING",)), |
|
142 |
(("ANY_REAL",), ("ANY_STRING",)), |
|
143 |
(("ANY_SINT",), ("ANY_STRING",)), |
|
144 |
(("ANY_UINT",), ("ANY_STRING",)), |
|
145 |
# FROM_STRING |
|
146 |
(("ANY_STRING",), ("BOOL",)), |
|
147 |
(("ANY_STRING",), ("ANY_BIT",)), |
|
148 |
(("ANY_STRING",), ("ANY_SINT",)), |
|
149 |
(("ANY_STRING",), ("ANY_UINT",)), |
|
150 |
(("ANY_STRING",), ("ANY_REAL",))], |
|
151 |
"BCD_TO_ANY":[ |
|
152 |
(("BYTE",),("USINT",)), |
|
153 |
(("WORD",),("UINT",)), |
|
154 |
(("DWORD",),("UDINT",)), |
|
155 |
(("LWORD",),("ULINT",))], |
|
156 |
"ANY_TO_BCD":[ |
|
157 |
(("USINT",),("BYTE",)), |
|
158 |
(("UINT",),("WORD",)), |
|
159 |
(("UDINT",),("DWORD",)), |
|
160 |
(("ULINT",),("LWORD",))] |
|
161 |
} |
|
162 |
||
163 |
# remove gettext override |
|
164 |
del _ |