1390
|
1 |
from os.path import join, split, realpath
|
|
2 |
sd = split(realpath(__file__))[0]
|
|
3 |
|
|
4 |
# Override gettext _ in this module
|
|
5 |
# since we just want string to be added to dictionnary
|
|
6 |
# but translation should happen here
|
|
7 |
_ = lambda x:x
|
|
8 |
|
|
9 |
LANGUAGES = ["IL","ST","FBD","LD","SFC"]
|
|
10 |
|
|
11 |
LOCATIONDATATYPES = {"X" : ["BOOL"],
|
|
12 |
"B" : ["SINT", "USINT", "BYTE", "STRING"],
|
|
13 |
"W" : ["INT", "UINT", "WORD", "WSTRING"],
|
|
14 |
"D" : ["DINT", "UDINT", "REAL", "DWORD"],
|
|
15 |
"L" : ["LINT", "ULINT", "LREAL", "LWORD"]}
|
|
16 |
|
|
17 |
#-------------------------------------------------------------------------------
|
|
18 |
# Function Block Types definitions
|
|
19 |
#-------------------------------------------------------------------------------
|
|
20 |
|
|
21 |
StdTC6Libs = [(_("Standard function blocks"), join(sd, "Standard_Function_Blocks.xml")),
|
|
22 |
(_("Additional function blocks"),join(sd, "Additional_Function_Blocks.xml"))]
|
|
23 |
|
|
24 |
StdFuncsCSV = join(sd,"iec_std.csv")
|
|
25 |
|
|
26 |
# FIXME : since std fb now loaded from TC6 file, is that still necessary ?
|
|
27 |
StdBlockComments = {
|
|
28 |
"SR": _("SR bistable\nThe SR bistable is a latch where the Set dominates."),
|
|
29 |
"RS": _("RS bistable\nThe RS bistable is a latch where the Reset dominates."),
|
|
30 |
"SEMA": _("Semaphore\nThe semaphore provides a mechanism to allow software elements mutually exclusive access to certain ressources."),
|
|
31 |
"R_TRIG": _("Rising edge detector\nThe output produces a single pulse when a rising edge is detected."),
|
|
32 |
"F_TRIG": _("Falling edge detector\nThe output produces a single pulse when a falling edge is detected."),
|
|
33 |
"CTU": _("Up-counter\nThe up-counter can be used to signal when a count has reached a maximum value."),
|
|
34 |
"CTD": _("Down-counter\nThe down-counter can be used to signal when a count has reached zero, on counting down from a preset value."),
|
|
35 |
"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."),
|
|
36 |
"TP": _("Pulse timer\nThe pulse timer can be used to generate output pulses of a given time duration."),
|
|
37 |
"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."),
|
|
38 |
"TOF": _("Off-delay timer\nThe off-delay timer can be used to delay setting an output false, for fixed period after input goes false."),
|
|
39 |
"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."),
|
|
40 |
"INTEGRAL": _("Integral\nThe integral function block integrates the value of input XIN over time."),
|
|
41 |
"DERIVATIVE": _("Derivative\nThe derivative function block produces an output XOUT proportional to the rate of change of the input XIN."),
|
|
42 |
"PID": _("PID\nThe PID (proportional, Integral, Derivative) function block provides the classical three term controller for closed loop control."),
|
|
43 |
"RAMP": _("Ramp\nThe RAMP function block is modelled on example given in the standard."),
|
|
44 |
"HYSTERESIS": _("Hysteresis\nThe hysteresis function block provides a hysteresis boolean output driven by the difference of two floating point (REAL) inputs XIN1 and XIN2."),
|
|
45 |
}
|
|
46 |
|
|
47 |
for block_type in ["CTU", "CTD", "CTUD"]:
|
|
48 |
for return_type in ["DINT", "LINT", "UDINT", "ULINT"]:
|
|
49 |
StdBlockComments["%s_%s" % (block_type, return_type)] = StdBlockComments[block_type]
|
|
50 |
|
|
51 |
def GetBlockInfos(pou):
|
|
52 |
infos = pou.getblockInfos()
|
|
53 |
# FIXME : as well
|
|
54 |
infos["comment"] = StdBlockComments[infos["name"]]
|
|
55 |
infos["inputs"] = [
|
|
56 |
(var_name, var_type, "rising")
|
|
57 |
if var_name in ["CU", "CD"]
|
|
58 |
else (var_name, var_type, var_modifier)
|
|
59 |
for var_name, var_type, var_modifier in infos["inputs"]]
|
|
60 |
return infos
|
|
61 |
|
|
62 |
#-------------------------------------------------------------------------------
|
|
63 |
# Data Types definitions
|
|
64 |
#-------------------------------------------------------------------------------
|
|
65 |
|
|
66 |
"""
|
|
67 |
Ordored list of common data types defined in the IEC 61131-3
|
|
68 |
Each type is associated to his direct parent type. It defines then a hierarchy
|
|
69 |
between type that permits to make a comparison of two types
|
|
70 |
"""
|
|
71 |
TypeHierarchy_list = [
|
|
72 |
("ANY", None),
|
|
73 |
("ANY_DERIVED", "ANY"),
|
|
74 |
("ANY_ELEMENTARY", "ANY"),
|
|
75 |
("ANY_MAGNITUDE", "ANY_ELEMENTARY"),
|
|
76 |
("ANY_BIT", "ANY_ELEMENTARY"),
|
|
77 |
("ANY_NBIT", "ANY_BIT"),
|
|
78 |
("ANY_STRING", "ANY_ELEMENTARY"),
|
|
79 |
("ANY_DATE", "ANY_ELEMENTARY"),
|
|
80 |
("ANY_NUM", "ANY_MAGNITUDE"),
|
|
81 |
("ANY_REAL", "ANY_NUM"),
|
|
82 |
("ANY_INT", "ANY_NUM"),
|
|
83 |
("ANY_SINT", "ANY_INT"),
|
|
84 |
("ANY_UINT", "ANY_INT"),
|
|
85 |
("BOOL", "ANY_BIT"),
|
|
86 |
("SINT", "ANY_SINT"),
|
|
87 |
("INT", "ANY_SINT"),
|
|
88 |
("DINT", "ANY_SINT"),
|
|
89 |
("LINT", "ANY_SINT"),
|
|
90 |
("USINT", "ANY_UINT"),
|
|
91 |
("UINT", "ANY_UINT"),
|
|
92 |
("UDINT", "ANY_UINT"),
|
|
93 |
("ULINT", "ANY_UINT"),
|
|
94 |
("REAL", "ANY_REAL"),
|
|
95 |
("LREAL", "ANY_REAL"),
|
|
96 |
("TIME", "ANY_MAGNITUDE"),
|
|
97 |
("DATE", "ANY_DATE"),
|
|
98 |
("TOD", "ANY_DATE"),
|
|
99 |
("DT", "ANY_DATE"),
|
|
100 |
("STRING", "ANY_STRING"),
|
|
101 |
("BYTE", "ANY_NBIT"),
|
|
102 |
("WORD", "ANY_NBIT"),
|
|
103 |
("DWORD", "ANY_NBIT"),
|
|
104 |
("LWORD", "ANY_NBIT")
|
|
105 |
#("WSTRING", "ANY_STRING") # TODO
|
|
106 |
]
|
|
107 |
|
|
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 _
|