author | Edouard Tisserant |
Tue, 27 Sep 2011 18:27:14 +0200 | |
changeset 618 | c6b1a22aa614 |
parent 599 | c7be4d09c5f4 |
child 625 | 08d4cc1ceb9b |
permissions | -rw-r--r-- |
442 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
503 | 3 |
import shutil |
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
4 |
import socket |
442 | 5 |
|
6 |
__version__ = "$Revision$" |
|
7 |
||
8 |
import os, sys, getopt, wx, tempfile |
|
9 |
from types import TupleType, StringType, UnicodeType |
|
10 |
||
11 |
CWD = os.path.split(os.path.realpath(__file__))[0] |
|
12 |
||
13 |
def Bpath(*args): |
|
14 |
return os.path.join(CWD,*args) |
|
15 |
||
16 |
if __name__ == '__main__': |
|
17 |
def usage(): |
|
18 |
print "\nUsage of LPCBeremiz.py :" |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
19 |
print "\n %s Projectpath Buildpath port\n"%sys.argv[0] |
442 | 20 |
|
21 |
try: |
|
22 |
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) |
|
23 |
except getopt.GetoptError: |
|
24 |
# print help information and exit: |
|
25 |
usage() |
|
26 |
sys.exit(2) |
|
27 |
||
28 |
for o, a in opts: |
|
29 |
if o in ("-h", "--help"): |
|
30 |
usage() |
|
31 |
sys.exit() |
|
32 |
||
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
33 |
if len(args) != 3: |
442 | 34 |
usage() |
35 |
sys.exit() |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
36 |
else: |
442 | 37 |
projectOpen = args[0] |
38 |
buildpath = args[1] |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
39 |
try: |
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
40 |
port = int(args[2]) |
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
41 |
except: |
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
42 |
usage() |
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
43 |
sys.exit() |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
44 |
|
571
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
45 |
if os.path.exists("LPC_DEBUG"): |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
46 |
__builtins__.BMZ_DBG = True |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
47 |
else : |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
48 |
__builtins__.BMZ_DBG = False |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
49 |
|
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
50 |
app = wx.PySimpleApp(redirect=BMZ_DBG) |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
51 |
app.SetAppName('beremiz') |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
52 |
wx.InitAllImageHandlers() |
442 | 53 |
|
54 |
# Import module for internationalization |
|
55 |
import gettext |
|
56 |
import __builtin__ |
|
57 |
||
58 |
if __name__ == '__main__': |
|
59 |
__builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
|
60 |
||
61 |
from Beremiz import * |
|
492 | 62 |
from plugger import PluginsRoot, PlugTemplate, opjimg, connectors |
442 | 63 |
from plcopen.structures import LOCATIONDATATYPES |
64 |
from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\ |
|
65 |
LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
|
500
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
66 |
from PLCOpenEditor import IDEFrame, ProjectDialog |
442 | 67 |
|
68 |
#------------------------------------------------------------------------------- |
|
512
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
510
diff
changeset
|
69 |
# CANFESTIVAL PLUGIN HACK |
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
510
diff
changeset
|
70 |
#------------------------------------------------------------------------------- |
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
510
diff
changeset
|
71 |
from plugins.canfestival import canfestival |
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
510
diff
changeset
|
72 |
class LPC_canfestival_config: |
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
510
diff
changeset
|
73 |
def getCFLAGS(self, *args): |
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
510
diff
changeset
|
74 |
return "" |
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
510
diff
changeset
|
75 |
|
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
510
diff
changeset
|
76 |
def getLDFLAGS(self, *args): |
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
510
diff
changeset
|
77 |
return "" |
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
510
diff
changeset
|
78 |
|
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
510
diff
changeset
|
79 |
canfestival.local_canfestival_config = LPC_canfestival_config() |
36aeab46f27d
Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents:
510
diff
changeset
|
80 |
#------------------------------------------------------------------------------- |
442 | 81 |
# LPCModule Class |
82 |
#------------------------------------------------------------------------------- |
|
83 |
||
472
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
84 |
LOCATION_TYPES = {"I": LOCATION_VAR_INPUT, |
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
85 |
"Q": LOCATION_VAR_OUTPUT, |
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
86 |
"M": LOCATION_VAR_MEMORY} |
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
87 |
|
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
88 |
LOCATION_DIRS = dict([(dir, size) for size, dir in LOCATION_TYPES.iteritems()]) |
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
89 |
|
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
90 |
LOCATION_SIZES = {} |
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
91 |
for size, types in LOCATIONDATATYPES.iteritems(): |
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
92 |
for type in types: |
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
93 |
LOCATION_SIZES[type] = size |
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
94 |
|
442 | 95 |
def _GetModuleChildren(module): |
96 |
children = [] |
|
97 |
for child in module["children"]: |
|
98 |
if child["type"] == LOCATION_GROUP: |
|
99 |
children.extend(child["children"]) |
|
100 |
else: |
|
101 |
children.append(child) |
|
102 |
return children |
|
103 |
||
550
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
104 |
def _GetVariables(module): |
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
105 |
variables = [] |
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
106 |
for child in module["children"]: |
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
107 |
if child["type"] in [LOCATION_GROUP, LOCATION_MODULE]: |
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
108 |
variables.extend(_GetVariables(child)) |
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
109 |
else: |
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
110 |
variables.append(child) |
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
111 |
return variables |
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
112 |
|
442 | 113 |
def _GetLastModuleGroup(module): |
114 |
group = module |
|
115 |
for child in module["children"]: |
|
116 |
if child["type"] == LOCATION_GROUP: |
|
117 |
group = child |
|
118 |
return group["children"] |
|
119 |
||
120 |
def _GetModuleBySomething(module, something, toks): |
|
121 |
for child in _GetModuleChildren(module): |
|
122 |
if child.get(something) == toks[0]: |
|
123 |
if len(toks) > 1: |
|
124 |
return _GetModuleBySomething(child, something, toks[1:]) |
|
125 |
return child |
|
126 |
return None |
|
127 |
||
472
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
128 |
def _GetModuleVariable(module, location, direction): |
442 | 129 |
for child in _GetModuleChildren(module): |
472
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
130 |
if child["location"] == location and child["type"] == LOCATION_TYPES[direction]: |
442 | 131 |
return child |
132 |
return None |
|
133 |
||
134 |
def _RemoveModuleChild(module, child): |
|
135 |
if child in module["children"]: |
|
136 |
module["children"].remove(child) |
|
137 |
else: |
|
138 |
for group in module["children"]: |
|
139 |
if group["type"] == LOCATION_GROUP and child in group["children"]: |
|
140 |
group["children"].remove(child) |
|
141 |
||
142 |
BUS_TEXT = """/* Code generated by LPCBus plugin */ |
|
143 |
||
144 |
/* LPCBus plugin includes */ |
|
145 |
#include "app_glue.h" |
|
146 |
#ifdef _WINDOWS_H |
|
147 |
#include "iec_types.h" |
|
148 |
#else |
|
149 |
#include "iec_std_lib.h" |
|
150 |
#endif |
|
151 |
||
553 | 152 |
%(declare_code)s |
153 |
||
442 | 154 |
/* LPCBus plugin user variables definition */ |
155 |
%(var_decl)s |
|
156 |
||
157 |
/* LPCBus plugin functions */ |
|
158 |
int __init_%(location_str)s(int argc,char **argv) |
|
159 |
{ |
|
553 | 160 |
%(init_code)s |
442 | 161 |
return 0; |
162 |
} |
|
163 |
||
164 |
void __cleanup_%(location_str)s(void) |
|
165 |
{ |
|
166 |
} |
|
167 |
||
168 |
void __retrieve_%(location_str)s(void) |
|
169 |
{ |
|
550
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
170 |
%(retrieve_code)s |
442 | 171 |
} |
172 |
||
173 |
void __publish_%(location_str)s(void) |
|
174 |
{ |
|
550
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
175 |
%(publish_code)s |
442 | 176 |
} |
177 |
""" |
|
178 |
||
179 |
class LPCBus(object): |
|
180 |
||
181 |
def __init__(self): |
|
182 |
self.VariableLocationTree = [] |
|
183 |
self.ResetUsedLocations() |
|
184 |
self.Icon = None |
|
185 |
||
186 |
def __getitem__(self, key): |
|
187 |
if key == "children": |
|
188 |
return self.VariableLocationTree |
|
189 |
raise KeyError, "Only 'children' key is available" |
|
190 |
||
191 |
def SetIcon(self, icon): |
|
192 |
self.Icon = icon |
|
193 |
||
194 |
def _GetChildBySomething(self, something, toks): |
|
195 |
return _GetModuleBySomething({"children" : self.VariableLocationTree}, something, toks) |
|
196 |
||
197 |
def GetBaseTypes(self): |
|
198 |
return self.GetPlugRoot().GetBaseTypes() |
|
199 |
||
200 |
def GetSizeOfType(self, type): |
|
201 |
return LOCATION_SIZES[self.GetPlugRoot().GetBaseType(type)] |
|
202 |
||
203 |
def _GetVariableLocationTree(self, current_location, infos): |
|
204 |
if infos["type"] == LOCATION_MODULE: |
|
205 |
location = current_location + (infos["IEC_Channel"],) |
|
206 |
return {"name": infos["name"], |
|
207 |
"type": infos["type"], |
|
208 |
"location": ".".join(map(str, location + ("x",))), |
|
209 |
"icon": infos["icon"], |
|
210 |
"children": [self._GetVariableLocationTree(location, child) for child in infos["children"]]} |
|
211 |
elif infos["type"] == LOCATION_GROUP: |
|
212 |
return {"name": infos["name"], |
|
213 |
"type": infos["type"], |
|
214 |
"location": "", |
|
215 |
"icon": infos["icon"], |
|
216 |
"children": [self._GetVariableLocationTree(current_location, child) for child in infos["children"]]} |
|
217 |
else: |
|
218 |
size = self.GetSizeOfType(infos["IEC_type"]) |
|
219 |
location = "%" + LOCATION_DIRS[infos["type"]] + size + ".".join(map(str, current_location + infos["location"])) |
|
220 |
return {"name": infos["name"], |
|
221 |
"type": infos["type"], |
|
222 |
"size": size, |
|
223 |
"IEC_type": infos["IEC_type"], |
|
224 |
"location": location, |
|
225 |
"description": infos["description"], |
|
226 |
"children": []} |
|
227 |
||
228 |
def GetVariableLocationTree(self): |
|
229 |
return {"name": self.BaseParams.getName(), |
|
230 |
"type": LOCATION_PLUGIN, |
|
231 |
"location": self.GetFullIEC_Channel(), |
|
232 |
"icon": self.Icon, |
|
233 |
"children": [self._GetVariableLocationTree(self.GetCurrentLocation(), child) |
|
234 |
for child in self.VariableLocationTree]} |
|
235 |
||
236 |
def PlugTestModified(self): |
|
237 |
return False |
|
238 |
||
239 |
def PlugMakeDir(self): |
|
240 |
pass |
|
241 |
||
242 |
def PlugRequestSave(self): |
|
243 |
return None |
|
244 |
||
245 |
def ResetUsedLocations(self): |
|
246 |
self.UsedLocations = {} |
|
247 |
||
248 |
def _AddUsedLocation(self, parent, location): |
|
249 |
num = location.pop(0) |
|
250 |
if not parent.has_key(num): |
|
251 |
parent[num] = {"used": False, "children": {}} |
|
252 |
if len(location) > 0: |
|
253 |
self._AddUsedLocation(parent[num]["children"], location) |
|
254 |
else: |
|
255 |
parent[num]["used"] = True |
|
256 |
||
257 |
def AddUsedLocation(self, location): |
|
258 |
if len(location) > 0: |
|
259 |
self._AddUsedLocation(self.UsedLocations, list(location)) |
|
260 |
||
261 |
def _CheckLocationConflicts(self, parent, location): |
|
262 |
num = location.pop(0) |
|
263 |
if not parent.has_key(num): |
|
264 |
return False |
|
265 |
if len(location) > 0: |
|
266 |
if parent[num]["used"]: |
|
267 |
return True |
|
268 |
return self._CheckLocationConflicts(parent[num]["children"], location) |
|
269 |
elif len(parent[num]["children"]) > 0: |
|
270 |
return True |
|
271 |
return False |
|
272 |
||
273 |
def CheckLocationConflicts(self, location): |
|
274 |
if len(location) > 0: |
|
275 |
return self._CheckLocationConflicts(self.UsedLocations, list(location)) |
|
276 |
return False |
|
277 |
||
278 |
def PlugGenerate_C(self, buildpath, locations): |
|
279 |
""" |
|
280 |
Generate C code |
|
281 |
@param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
|
282 |
@param locations: List of complete variables locations \ |
|
283 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
|
284 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
|
285 |
"DIR" : direction "Q","I" or "M" |
|
286 |
"SIZE" : size "X", "B", "W", "D", "L" |
|
287 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
|
288 |
}, ...] |
|
289 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
|
290 |
""" |
|
291 |
current_location = self.GetCurrentLocation() |
|
292 |
# define a unique name for the generated C file |
|
293 |
location_str = "_".join(map(str, current_location)) |
|
294 |
||
295 |
code_str = {"location_str": location_str, |
|
296 |
"var_decl": "", |
|
297 |
"declare_code": "", |
|
553 | 298 |
"init_code": "", |
442 | 299 |
"retrieve_code": "", |
300 |
"publish_code": "", |
|
301 |
} |
|
302 |
||
553 | 303 |
for module in _GetModuleChildren(self): |
304 |
if module["init"] != "": |
|
305 |
code_str["init_code"] += " %s\n" % module["init"] |
|
550
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
306 |
|
442 | 307 |
# Adding variables |
308 |
vars = [] |
|
309 |
self.ResetUsedLocations() |
|
310 |
for location in locations: |
|
311 |
loc = location["LOC"][len(current_location):] |
|
312 |
group = next = self |
|
313 |
i = 0 |
|
314 |
while next is not None and i < len(loc): |
|
315 |
next = self._GetChildBySomething("IEC_Channel", loc[:i + 1]) |
|
316 |
if next is not None: |
|
317 |
i += 1 |
|
318 |
group = next |
|
319 |
var_loc = loc[i:] |
|
530 | 320 |
for variable in _GetModuleChildren(group): |
566
657900299557
Fix bug in LPCBeremiz that use input retrieve and publish code for ouput with the same location
laurent
parents:
561
diff
changeset
|
321 |
if variable["location"] == var_loc and location["DIR"] == LOCATION_DIRS[variable["type"]]: |
543
3dec6ff88620
Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents:
541
diff
changeset
|
322 |
# if location["DIR"] != LOCATION_DIRS[variable["type"]]: |
3dec6ff88620
Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents:
541
diff
changeset
|
323 |
# raise Exception, "Direction conflict in variable definition" |
3dec6ff88620
Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents:
541
diff
changeset
|
324 |
# if location["IEC_TYPE"] != variable["IEC_type"]: |
3dec6ff88620
Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents:
541
diff
changeset
|
325 |
# raise Exception, "Type conflict in variable definition" |
442 | 326 |
if location["DIR"] == "Q": |
327 |
if self.CheckLocationConflicts(location["LOC"]): |
|
328 |
raise Exception, "BYTE and BIT from the same BYTE can't be used together" |
|
329 |
self.AddUsedLocation(location["LOC"]) |
|
330 |
vars.append({"location": location["NAME"], |
|
331 |
"Type": variable["IEC_type"], |
|
332 |
"Retrieve": variable["retrieve"], |
|
333 |
"Publish": variable["publish"], |
|
334 |
}) |
|
335 |
break |
|
336 |
base_types = self.GetPlugRoot().GetBaseTypes() |
|
337 |
for var in vars: |
|
338 |
prefix = "" |
|
339 |
if var["Type"] in base_types: |
|
340 |
prefix = "IEC_" |
|
341 |
code_str["var_decl"] += "%s%s beremiz%s;\n"%(prefix, var["Type"], var["location"]) |
|
342 |
code_str["var_decl"] += "%s%s *%s = &beremiz%s;\n"%(prefix, var["Type"], var["location"], var["location"]) |
|
343 |
if var["Retrieve"] != "": |
|
550
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
344 |
code_str["retrieve_code"] += " " + var["Retrieve"] % ("*" + var["location"]) + "\n" |
442 | 345 |
if var["Publish"] != "": |
550
b03f586547c9
Adding support for initialize all LPC module variables even if not used
laurent
parents:
549
diff
changeset
|
346 |
code_str["publish_code"] += " " + var["Publish"] % ("*" + var["location"]) + "\n" |
442 | 347 |
|
553 | 348 |
Gen_Module_path = os.path.join(buildpath, "Bus_%s.c"%location_str) |
442 | 349 |
module = open(Gen_Module_path,'w') |
350 |
module.write(BUS_TEXT % code_str) |
|
351 |
module.close() |
|
352 |
||
353 |
matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath()) |
|
354 |
return [(Gen_Module_path, matiec_flags)],"",True |
|
355 |
||
356 |
#------------------------------------------------------------------------------- |
|
357 |
# LPCPluginsRoot Class |
|
358 |
#------------------------------------------------------------------------------- |
|
359 |
||
360 |
def mycopytree(src, dst): |
|
361 |
""" |
|
362 |
Copy content of a directory to an other, omit hidden files |
|
363 |
@param src: source directory |
|
364 |
@param dst: destination directory |
|
365 |
""" |
|
366 |
for i in os.listdir(src): |
|
367 |
if not i.startswith('.'): |
|
368 |
srcpath = os.path.join(src,i) |
|
369 |
dstpath = os.path.join(dst,i) |
|
370 |
if os.path.isdir(srcpath): |
|
503 | 371 |
if os.path.exists(dstpath): |
372 |
shutil.rmtree(dstpath) |
|
373 |
os.makedirs(dstpath) |
|
442 | 374 |
mycopytree(srcpath, dstpath) |
375 |
elif os.path.isfile(srcpath): |
|
376 |
shutil.copy2(srcpath, dstpath) |
|
377 |
||
572
c965548cb6f7
Fixed MD5 computation for makefile based toolchain, helps avoiding unnecessary builds
edouard
parents:
571
diff
changeset
|
378 |
[SIMULATION_MODE, TRANSFER_MODE] = range(2) |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
379 |
|
442 | 380 |
class LPCPluginsRoot(PluginsRoot): |
381 |
||
382 |
PluginMethods = [ |
|
492 | 383 |
{"bitmap" : opjimg("Debug"), |
384 |
"name" : _("Simulate"), |
|
385 |
"tooltip" : _("Simulate PLC"), |
|
386 |
"method" : "_Simulate"}, |
|
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
387 |
{"bitmap" : opjimg("Run"), |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
388 |
"name" : _("Run"), |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
389 |
"shown" : False, |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
390 |
"tooltip" : _("Start PLC"), |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
391 |
"method" : "_Run"}, |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
392 |
{"bitmap" : opjimg("Stop"), |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
393 |
"name" : _("Stop"), |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
394 |
"shown" : False, |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
395 |
"tooltip" : _("Stop Running PLC"), |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
396 |
"method" : "_Stop"}, |
541 | 397 |
{"bitmap" : opjimg("Build"), |
398 |
"name" : _("Build"), |
|
399 |
"tooltip" : _("Build project into build folder"), |
|
400 |
"method" : "_build"}, |
|
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
401 |
{"bitmap" : opjimg("Transfer"), |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
402 |
"name" : _("Transfer"), |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
403 |
"shown" : False, |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
404 |
"tooltip" : _("Transfer PLC"), |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
405 |
"method" : "_Transfer"}, |
442 | 406 |
] |
407 |
||
478 | 408 |
def __init__(self, frame, logger): |
409 |
PluginsRoot.__init__(self, frame, logger) |
|
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
410 |
|
478 | 411 |
self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus")] |
412 |
||
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
413 |
self.OnlineMode = "OFF" |
561 | 414 |
self.LPCConnector = None |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
415 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
416 |
self.CurrentMode = None |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
417 |
self.previous_mode = None |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
418 |
|
492 | 419 |
self.SimulationBuildPath = None |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
420 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
421 |
self.AbortTransferTimer = None |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
422 |
|
442 | 423 |
def GetProjectName(self): |
424 |
return self.Project.getname() |
|
425 |
||
510
8038c08b9874
Getting default target when no target defined fixed
laurent
parents:
503
diff
changeset
|
426 |
def GetDefaultTargetName(self): |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
427 |
if self.CurrentMode == SIMULATION_MODE: |
510
8038c08b9874
Getting default target when no target defined fixed
laurent
parents:
503
diff
changeset
|
428 |
return PluginsRoot.GetDefaultTargetName(self) |
492 | 429 |
else: |
510
8038c08b9874
Getting default target when no target defined fixed
laurent
parents:
503
diff
changeset
|
430 |
return "LPC" |
8038c08b9874
Getting default target when no target defined fixed
laurent
parents:
503
diff
changeset
|
431 |
|
8038c08b9874
Getting default target when no target defined fixed
laurent
parents:
503
diff
changeset
|
432 |
def GetTarget(self): |
8038c08b9874
Getting default target when no target defined fixed
laurent
parents:
503
diff
changeset
|
433 |
target = PluginsRoot.GetTarget(self) |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
434 |
if self.CurrentMode != SIMULATION_MODE: |
510
8038c08b9874
Getting default target when no target defined fixed
laurent
parents:
503
diff
changeset
|
435 |
target.getcontent()["value"].setBuildPath(self.BuildPath) |
442 | 436 |
return target |
492 | 437 |
|
438 |
def _getBuildPath(self): |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
439 |
if self.CurrentMode == SIMULATION_MODE: |
492 | 440 |
if self.SimulationBuildPath is None: |
441 |
self.SimulationBuildPath = os.path.join(tempfile.mkdtemp(), os.path.basename(self.ProjectPath), "build") |
|
442 |
return self.SimulationBuildPath |
|
443 |
else: |
|
494
9e4263099427
Bug when opening with not empty buildpath parameter fixed
laurent
parents:
492
diff
changeset
|
444 |
return PluginsRoot._getBuildPath(self) |
503 | 445 |
|
446 |
def _build(self): |
|
599 | 447 |
save = self.ProjectTestModified() |
448 |
if save: |
|
449 |
self.SaveProject() |
|
450 |
self.AppFrame._Refresh(TITLE, FILEMENU) |
|
503 | 451 |
if self.BuildPath is not None: |
452 |
mycopytree(self.OrigBuildPath, self.BuildPath) |
|
453 |
PluginsRoot._build(self) |
|
599 | 454 |
if save: |
455 |
wx.CallAfter(self.AppFrame.RefreshAll) |
|
492 | 456 |
|
442 | 457 |
def SetProjectName(self, name): |
458 |
return self.Project.setname(name) |
|
459 |
||
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
460 |
def SetOnlineMode(self, mode, path=None): |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
461 |
if self.OnlineMode != mode.upper(): |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
462 |
self.OnlineMode = mode.upper() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
463 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
464 |
if self.OnlineMode != "OFF": |
543
3dec6ff88620
Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents:
541
diff
changeset
|
465 |
uri = "LPC://%s/%s" % (self.OnlineMode,path) |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
466 |
try: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
467 |
self.LPCConnector = connectors.ConnectorFactory(uri, self) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
468 |
except Exception, msg: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
469 |
self.logger.write_error(_("Exception while connecting %s!\n")%uri) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
470 |
self.logger.write_error(traceback.format_exc()) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
471 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
472 |
# Did connection success ? |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
473 |
if self.LPCConnector is None: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
474 |
# Oups. |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
475 |
self.logger.write_error(_("Connection failed to %s!\n")%uri) |
492 | 476 |
|
477 |
else: |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
478 |
self.LPCConnector = None |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
479 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
480 |
self.ApplyOnlineMode() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
481 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
482 |
def ApplyOnlineMode(self): |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
483 |
if self.CurrentMode != SIMULATION_MODE: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
484 |
self.KillDebugThread() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
485 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
486 |
self._connector = self.LPCConnector |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
487 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
488 |
# Init with actual PLC status and print it |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
489 |
self.UpdateMethodsFromPLCStatus() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
490 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
491 |
if self.LPCConnector is not None and self.OnlineMode == "APPLICATION": |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
492 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
493 |
self.CompareLocalAndRemotePLC() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
494 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
495 |
if self.previous_plcstate is not None: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
496 |
status = _(self.previous_plcstate) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
497 |
else: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
498 |
status = "" |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
499 |
self.logger.write(_("PLC is %s\n")%status) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
500 |
|
575
6765adf58711
Removed status polling for LPC, as status cannot change by itself, fixed MD5 comparison in app mode
edouard
parents:
574
diff
changeset
|
501 |
#if self.StatusTimer and not self.StatusTimer.IsRunning(): |
6765adf58711
Removed status polling for LPC, as status cannot change by itself, fixed MD5 comparison in app mode
edouard
parents:
574
diff
changeset
|
502 |
# # Start the status Timer |
6765adf58711
Removed status polling for LPC, as status cannot change by itself, fixed MD5 comparison in app mode
edouard
parents:
574
diff
changeset
|
503 |
# self.StatusTimer.Start(milliseconds=2000, oneShot=False) |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
504 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
505 |
if self.previous_plcstate=="Started": |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
506 |
if self.DebugAvailable() and self.GetIECProgramsAndVariables(): |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
507 |
self.logger.write(_("Debug connect matching running PLC\n")) |
576
7fcdc0d3d8d9
Some typo fixes to make debug related methods in LPCAppOject stop throwing exceptions, less agressive error message when unplugging LPC
edouard
parents:
575
diff
changeset
|
508 |
self._connect_debug() |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
509 |
else: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
510 |
self.logger.write_warning(_("Debug do not match PLC - stop/transfert/start to re-enable\n")) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
511 |
|
543
3dec6ff88620
Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents:
541
diff
changeset
|
512 |
elif self.StatusTimer and self.StatusTimer.IsRunning(): |
492 | 513 |
self.StatusTimer.Stop() |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
514 |
|
572
c965548cb6f7
Fixed MD5 computation for makefile based toolchain, helps avoiding unnecessary builds
edouard
parents:
571
diff
changeset
|
515 |
if self.CurrentMode == TRANSFER_MODE: |
492 | 516 |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
517 |
if self.OnlineMode == "BOOTLOADER": |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
518 |
self.BeginTransfer() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
519 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
520 |
elif self.OnlineMode == "APPLICATION": |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
521 |
self.CurrentMode = None |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
522 |
self.AbortTransferTimer.Stop() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
523 |
self.AbortTransferTimer = None |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
524 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
525 |
self.logger.write(_("PLC transferred successfully\n")) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
526 |
|
444
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
527 |
# Update a PLCOpenEditor Pou variable name |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
528 |
def UpdateProjectVariableName(self, old_name, new_name): |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
529 |
self.Project.updateElementName(old_name, new_name) |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
530 |
self.BufferProject() |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
531 |
|
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
532 |
def RemoveProjectVariableByAddress(self, address): |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
533 |
self.Project.removeVariableByAddress(address) |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
534 |
self.BufferProject() |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
535 |
|
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
536 |
def RemoveProjectVariableByFilter(self, leading): |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
537 |
self.Project.removeVariableByFilter(leading) |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
538 |
self.BufferProject() |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
539 |
|
442 | 540 |
def LoadProject(self, ProjectPath, BuildPath=None): |
541 |
""" |
|
478 | 542 |
Load a project contained in a folder |
543 |
@param ProjectPath: path of the project folder |
|
442 | 544 |
""" |
478 | 545 |
if os.path.basename(ProjectPath) == "": |
546 |
ProjectPath = os.path.dirname(ProjectPath) |
|
500
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
547 |
|
478 | 548 |
# Verify that project contains a PLCOpen program |
549 |
plc_file = os.path.join(ProjectPath, "plc.xml") |
|
500
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
550 |
if os.path.isfile(plc_file): |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
551 |
# Load PLCOpen file |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
552 |
result = self.OpenXMLFile(plc_file) |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
553 |
if result: |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
554 |
return result |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
555 |
else: |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
556 |
self.CreateNewProject({"companyName": "", |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
557 |
"productName": "", |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
558 |
"productVersion": "", |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
559 |
"projectName": "", |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
560 |
"pageSize": (0, 0), |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
561 |
"scaling": {}}) |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
562 |
|
442 | 563 |
# Change XSD into class members |
564 |
self._AddParamsMembers() |
|
565 |
self.PluggedChilds = {} |
|
500
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
566 |
|
442 | 567 |
# Keep track of the root plugin (i.e. project path) |
568 |
self.ProjectPath = ProjectPath |
|
500
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
569 |
|
478 | 570 |
self.BuildPath = self._getBuildPath() |
503 | 571 |
self.OrigBuildPath = BuildPath |
442 | 572 |
if BuildPath is not None: |
573 |
mycopytree(BuildPath, self.BuildPath) |
|
574 |
||
478 | 575 |
# If dir have already be made, and file exist |
576 |
if os.path.isdir(self.PlugPath()) and os.path.isfile(self.PluginXmlFilePath()): |
|
577 |
#Load the plugin.xml file into parameters members |
|
578 |
result = self.LoadXMLParams() |
|
579 |
if result: |
|
580 |
return result |
|
581 |
#Load and init all the childs |
|
582 |
self.LoadChilds() |
|
500
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
583 |
|
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
584 |
if self.PlugTestModified(): |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
585 |
self.SaveProject() |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
586 |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
587 |
if wx.GetApp() is None: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
588 |
self.RefreshPluginsBlockLists() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
589 |
else: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
590 |
wx.CallAfter(self.RefreshPluginsBlockLists) |
478 | 591 |
|
592 |
return None |
|
442 | 593 |
|
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
594 |
############# Real PLC object access ############# |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
595 |
def UpdateMethodsFromPLCStatus(self): |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
596 |
# Get PLC state : Running or Stopped |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
597 |
# TODO : use explicit status instead of boolean |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
598 |
if self.OnlineMode == "OFF": |
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
599 |
status = "Disconnected" |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
600 |
elif self.OnlineMode == "BOOTLOADER": |
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
601 |
status = "Connected" |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
602 |
else: |
492 | 603 |
if self._connector is not None: |
604 |
status = self._connector.GetPLCstatus() |
|
605 |
else: |
|
606 |
status = "Disconnected" |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
607 |
if self.previous_plcstate != status or self.previous_mode != self.CurrentMode: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
608 |
simulating = self.CurrentMode == SIMULATION_MODE |
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
609 |
for args in { |
492 | 610 |
"Started" : [("_Simulate", False), |
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
611 |
("_Run", False), |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
612 |
("_Stop", True), |
560
681fe60443fc
Fix transfer button enable state and build button state
laurent
parents:
559
diff
changeset
|
613 |
("_build", True), |
559 | 614 |
("_Transfer", True)], |
615 |
"Stopped" : [("_Simulate", False), |
|
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
616 |
("_Run", True), |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
617 |
("_Stop", False), |
560
681fe60443fc
Fix transfer button enable state and build button state
laurent
parents:
559
diff
changeset
|
618 |
("_build", True), |
559 | 619 |
("_Transfer", True)], |
492 | 620 |
"Connected" : [("_Simulate", not simulating), |
571
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
621 |
("_Run", True), |
492 | 622 |
("_Stop", simulating), |
560
681fe60443fc
Fix transfer button enable state and build button state
laurent
parents:
559
diff
changeset
|
623 |
("_build", True), |
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
624 |
("_Transfer", True)], |
492 | 625 |
"Disconnected" :[("_Simulate", not simulating), |
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
626 |
("_Run", False), |
492 | 627 |
("_Stop", simulating), |
541 | 628 |
("_build", True), |
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
629 |
("_Transfer", False)], |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
630 |
}.get(status,[]): |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
631 |
self.ShowMethod(*args) |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
632 |
self.previous_plcstate = status |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
633 |
self.previous_mode = self.CurrentMode |
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
634 |
return True |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
635 |
return False |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
636 |
|
492 | 637 |
def Generate_plc_declare_locations(self): |
638 |
""" |
|
639 |
Declare used locations in order to simulatePLC in a black box |
|
640 |
""" |
|
641 |
return """#include "iec_types_all.h" |
|
642 |
||
643 |
#define __LOCATED_VAR(type, name, ...) \ |
|
644 |
type beremiz_##name;\ |
|
645 |
type *name = &beremiz_##name; |
|
646 |
||
647 |
#include "LOCATED_VARIABLES.h" |
|
648 |
||
649 |
#undef __LOCATED_VAR |
|
650 |
||
651 |
""" |
|
652 |
||
653 |
def _Simulate(self): |
|
654 |
""" |
|
655 |
Method called by user to Simulate PLC |
|
656 |
""" |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
657 |
self.CurrentMode = SIMULATION_MODE |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
658 |
|
492 | 659 |
uri = "LOCAL://" |
660 |
try: |
|
661 |
self._connector = connectors.ConnectorFactory(uri, self) |
|
662 |
except Exception, msg: |
|
663 |
self.logger.write_error(_("Exception while connecting %s!\n")%uri) |
|
664 |
self.logger.write_error(traceback.format_exc()) |
|
665 |
||
666 |
# Did connection success ? |
|
667 |
if self._connector is None: |
|
668 |
# Oups. |
|
669 |
self.logger.write_error(_("Connection failed to %s!\n")%uri) |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
670 |
self.StopSimulation() |
492 | 671 |
return False |
672 |
||
673 |
buildpath = self._getBuildPath() |
|
674 |
||
675 |
# Eventually create build dir |
|
676 |
if not os.path.exists(buildpath): |
|
677 |
os.makedirs(buildpath) |
|
678 |
||
679 |
# Generate SoftPLC IEC code |
|
680 |
IECGenRes = self._Generate_SoftPLC() |
|
681 |
||
682 |
# If IEC code gen fail, bail out. |
|
683 |
if not IECGenRes: |
|
684 |
self.logger.write_error(_("IEC-61131-3 code generation failed !\n")) |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
685 |
self.StopSimulation() |
492 | 686 |
return False |
687 |
||
688 |
# Reset variable and program list that are parsed from |
|
689 |
# CSV file generated by IEC2C compiler. |
|
690 |
self.ResetIECProgramsAndVariables() |
|
691 |
||
692 |
gen_result = self.PlugGenerate_C(buildpath, self.PLCGeneratedLocatedVars) |
|
693 |
PlugCFilesAndCFLAGS, PlugLDFLAGS, DoCalls = gen_result[:3] |
|
694 |
# if some files have been generated put them in the list with their location |
|
695 |
if PlugCFilesAndCFLAGS: |
|
696 |
self.LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), PlugCFilesAndCFLAGS, DoCalls)] |
|
697 |
else: |
|
698 |
self.LocationCFilesAndCFLAGS = [] |
|
699 |
||
700 |
# plugin asks for some LDFLAGS |
|
701 |
if PlugLDFLAGS: |
|
702 |
# LDFLAGS can be either string |
|
703 |
if type(PlugLDFLAGS)==type(str()): |
|
704 |
self.LDFLAGS=[PlugLDFLAGS] |
|
705 |
#or list of strings |
|
706 |
elif type(PlugLDFLAGS)==type(list()): |
|
707 |
self.LDFLAGS=PlugLDFLAGS[:] |
|
708 |
else: |
|
709 |
self.LDFLAGS=[] |
|
710 |
||
711 |
# Template based part of C code generation |
|
712 |
# files are stacked at the beginning, as files of plugin tree root |
|
713 |
for generator, filename, name in [ |
|
714 |
# debugger code |
|
715 |
(self.Generate_plc_debugger, "plc_debugger.c", "Debugger"), |
|
716 |
# init/cleanup/retrieve/publish, run and align code |
|
717 |
(self.Generate_plc_common_main,"plc_common_main.c","Common runtime"), |
|
718 |
# declare located variables for simulate in a black box |
|
719 |
(self.Generate_plc_declare_locations,"plc_declare_locations.c","Declare Locations")]: |
|
720 |
try: |
|
721 |
# Do generate |
|
722 |
code = generator() |
|
723 |
if code is None: |
|
724 |
raise |
|
725 |
code_path = os.path.join(buildpath,filename) |
|
726 |
open(code_path, "w").write(code) |
|
727 |
# Insert this file as first file to be compiled at root plugin |
|
728 |
self.LocationCFilesAndCFLAGS[0][1].insert(0,(code_path, self.plcCFLAGS)) |
|
729 |
except Exception, exc: |
|
730 |
self.logger.write_error(name+_(" generation failed !\n")) |
|
731 |
self.logger.write_error(traceback.format_exc()) |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
732 |
self.StopSimulation() |
492 | 733 |
return False |
734 |
||
735 |
# Get simulation builder |
|
736 |
builder = self.GetBuilder() |
|
737 |
if builder is None: |
|
738 |
self.logger.write_error(_("Fatal : cannot get builder.\n")) |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
739 |
self.StopSimulation() |
492 | 740 |
return False |
741 |
||
742 |
# Build |
|
743 |
try: |
|
744 |
if not builder.build() : |
|
745 |
self.logger.write_error(_("C Build failed.\n")) |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
746 |
self.StopSimulation() |
492 | 747 |
return False |
748 |
except Exception, exc: |
|
749 |
self.logger.write_error(_("C Build crashed !\n")) |
|
750 |
self.logger.write_error(traceback.format_exc()) |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
751 |
self.StopSimulation() |
492 | 752 |
return False |
753 |
||
754 |
data = builder.GetBinaryCode() |
|
755 |
if data is not None : |
|
756 |
if self._connector.NewPLC(builder.GetBinaryCodeMD5(), data, []): |
|
757 |
if self.AppFrame is not None: |
|
758 |
self.AppFrame.CloseDebugTabs() |
|
759 |
self.AppFrame.RefreshInstancesTree() |
|
760 |
self.UnsubscribeAllDebugIECVariable() |
|
761 |
self.ProgramTransferred() |
|
762 |
self.logger.write(_("Transfer completed successfully.\n")) |
|
763 |
else: |
|
764 |
self.logger.write_error(_("Transfer failed\n")) |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
765 |
self.StopSimulation() |
492 | 766 |
return False |
767 |
||
768 |
self._Run() |
|
769 |
||
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
770 |
if not self.StatusTimer.IsRunning(): |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
771 |
# Start the status Timer |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
772 |
self.StatusTimer.Start(milliseconds=500, oneShot=False) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
773 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
774 |
def StopSimulation(self): |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
775 |
self.CurrentMode = None |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
776 |
self.ApplyOnlineMode() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
777 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
778 |
def _Stop(self): |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
779 |
PluginsRoot._Stop(self) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
780 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
781 |
if self.CurrentMode == SIMULATION_MODE: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
782 |
self.StopSimulation() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
783 |
|
560
681fe60443fc
Fix transfer button enable state and build button state
laurent
parents:
559
diff
changeset
|
784 |
def CompareLocalAndRemotePLC(self): |
681fe60443fc
Fix transfer button enable state and build button state
laurent
parents:
559
diff
changeset
|
785 |
if self.LPCConnector is None: |
681fe60443fc
Fix transfer button enable state and build button state
laurent
parents:
559
diff
changeset
|
786 |
return |
681fe60443fc
Fix transfer button enable state and build button state
laurent
parents:
559
diff
changeset
|
787 |
# We are now connected. Update button status |
681fe60443fc
Fix transfer button enable state and build button state
laurent
parents:
559
diff
changeset
|
788 |
MD5 = self.GetLastBuildMD5() |
681fe60443fc
Fix transfer button enable state and build button state
laurent
parents:
559
diff
changeset
|
789 |
# Check remote target PLC correspondance to that md5 |
681fe60443fc
Fix transfer button enable state and build button state
laurent
parents:
559
diff
changeset
|
790 |
if MD5 is not None and self.LPCConnector.MatchMD5(MD5): |
681fe60443fc
Fix transfer button enable state and build button state
laurent
parents:
559
diff
changeset
|
791 |
# warns controller that program match |
681fe60443fc
Fix transfer button enable state and build button state
laurent
parents:
559
diff
changeset
|
792 |
self.ProgramTransferred() |
681fe60443fc
Fix transfer button enable state and build button state
laurent
parents:
559
diff
changeset
|
793 |
|
571
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
794 |
def GetLastBuildMD5(self): |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
795 |
builder=self.GetBuilder() |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
796 |
if builder is not None: |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
797 |
return builder.GetBinaryCodeMD5(self.OnlineMode) |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
798 |
else: |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
799 |
return None |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
800 |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
801 |
def _Transfer(self): |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
802 |
if self.CurrentMode is None and self.OnlineMode != "OFF": |
572
c965548cb6f7
Fixed MD5 computation for makefile based toolchain, helps avoiding unnecessary builds
edouard
parents:
571
diff
changeset
|
803 |
self.CurrentMode = TRANSFER_MODE |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
804 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
805 |
PluginsRoot._build(self) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
806 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
807 |
ID_ABORTTRANSFERTIMER = wx.NewId() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
808 |
self.AbortTransferTimer = wx.Timer(self.AppFrame, ID_ABORTTRANSFERTIMER) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
809 |
self.AppFrame.Bind(wx.EVT_TIMER, self.AbortTransfer, self.AbortTransferTimer) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
810 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
811 |
if self.OnlineMode == "BOOTLOADER": |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
812 |
self.BeginTransfer() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
813 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
814 |
else: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
815 |
self.logger.write(_("Resetting PLC\n")) |
575
6765adf58711
Removed status polling for LPC, as status cannot change by itself, fixed MD5 comparison in app mode
edouard
parents:
574
diff
changeset
|
816 |
#self.StatusTimer.Stop() |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
817 |
self.LPCConnector.ResetPLC() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
818 |
self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
819 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
820 |
def BeginTransfer(self): |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
821 |
self.logger.write(_("Start PLC transfer\n")) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
822 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
823 |
self.AbortTransferTimer.Stop() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
824 |
PluginsRoot._Transfer(self) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
825 |
self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
826 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
827 |
def AbortTransfer(self, event): |
543
3dec6ff88620
Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents:
541
diff
changeset
|
828 |
self.logger.write_warning(_("Timeout waiting PLC to recover\n")) |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
829 |
|
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
830 |
self.CurrentMode = None |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
831 |
self.AbortTransferTimer.Stop() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
832 |
self.AbortTransferTimer = None |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
833 |
event.Skip() |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
834 |
|
571
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
835 |
def _Run(self): |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
836 |
""" |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
837 |
Start PLC |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
838 |
""" |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
839 |
if self.GetIECProgramsAndVariables(): |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
840 |
self._connector.StartPLC() |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
841 |
self.logger.write(_("Starting PLC\n")) |
576
7fcdc0d3d8d9
Some typo fixes to make debug related methods in LPCAppOject stop throwing exceptions, less agressive error message when unplugging LPC
edouard
parents:
575
diff
changeset
|
842 |
self._connect_debug() |
571
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
843 |
else: |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
844 |
self.logger.write_error(_("Couldn't start PLC !\n")) |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
845 |
self.UpdateMethodsFromPLCStatus() |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
846 |
|
442 | 847 |
#------------------------------------------------------------------------------- |
848 |
# LPCBeremiz Class |
|
849 |
#------------------------------------------------------------------------------- |
|
549 | 850 |
lpcberemiz_cmd=None |
442 | 851 |
|
852 |
class LPCBeremiz(Beremiz): |
|
853 |
||
854 |
def _init_coll_FileMenu_Items(self, parent): |
|
855 |
AppendMenu(parent, help='', id=wx.ID_SAVE, |
|
856 |
kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S')) |
|
857 |
AppendMenu(parent, help='', id=wx.ID_CLOSE, |
|
858 |
kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W')) |
|
859 |
parent.AppendSeparator() |
|
860 |
AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP, |
|
861 |
kind=wx.ITEM_NORMAL, text=_(u'Page Setup')) |
|
862 |
AppendMenu(parent, help='', id=wx.ID_PREVIEW, |
|
863 |
kind=wx.ITEM_NORMAL, text=_(u'Preview')) |
|
864 |
AppendMenu(parent, help='', id=wx.ID_PRINT, |
|
865 |
kind=wx.ITEM_NORMAL, text=_(u'Print')) |
|
866 |
parent.AppendSeparator() |
|
867 |
AppendMenu(parent, help='', id=wx.ID_PROPERTIES, |
|
868 |
kind=wx.ITEM_NORMAL, text=_(u'Properties')) |
|
869 |
parent.AppendSeparator() |
|
870 |
AppendMenu(parent, help='', id=wx.ID_EXIT, |
|
871 |
kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q')) |
|
872 |
||
873 |
self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE) |
|
874 |
self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE) |
|
875 |
self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP) |
|
876 |
self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW) |
|
877 |
self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT) |
|
878 |
self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES) |
|
879 |
self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT) |
|
880 |
||
881 |
def _init_ctrls(self, prnt): |
|
882 |
IDEFrame._init_ctrls(self, prnt) |
|
883 |
||
884 |
self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=ID_BEREMIZINSPECTOR) |
|
885 |
accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL|wx.ACCEL_ALT, ord('I'), ID_BEREMIZINSPECTOR)]) |
|
886 |
self.SetAcceleratorTable(accel) |
|
887 |
||
888 |
self.PLCConfig = wx.ScrolledWindow(id=ID_BEREMIZPLCCONFIG, |
|
889 |
name='PLCConfig', parent=self.LeftNoteBook, pos=wx.Point(0, 0), |
|
890 |
size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL) |
|
891 |
self.PLCConfig.SetBackgroundColour(wx.WHITE) |
|
892 |
self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) |
|
893 |
self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow) |
|
894 |
self.LeftNoteBook.InsertPage(0, self.PLCConfig, _("Topology"), True) |
|
895 |
||
896 |
self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='', |
|
897 |
name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0), |
|
898 |
size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2) |
|
899 |
self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick) |
|
900 |
self.BottomNoteBook.AddPage(self.LogConsole, _("Log Console")) |
|
901 |
||
902 |
self._init_beremiz_sizers() |
|
903 |
||
904 |
def OnCloseFrame(self, event): |
|
519
3a5faff52e5c
Adding message to standard output to signal when LPCBeremiz is closed
laurent
parents:
517
diff
changeset
|
905 |
global frame |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
906 |
|
596
b36422acae13
Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents:
578
diff
changeset
|
907 |
if self.CheckSaveBeforeClosing(_("Close Application")): |
b36422acae13
Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents:
578
diff
changeset
|
908 |
|
b36422acae13
Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents:
578
diff
changeset
|
909 |
frame.Hide() |
b36422acae13
Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents:
578
diff
changeset
|
910 |
|
b36422acae13
Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents:
578
diff
changeset
|
911 |
self.PluginRoot.ResetAppFrame(lpcberemiz_cmd.Log) |
b36422acae13
Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents:
578
diff
changeset
|
912 |
if self.PluginRoot.OnlineMode == 0: |
b36422acae13
Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents:
578
diff
changeset
|
913 |
self.PluginRoot._connector = None |
b36422acae13
Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents:
578
diff
changeset
|
914 |
|
b36422acae13
Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents:
578
diff
changeset
|
915 |
self.PluginRoot.KillDebugThread() |
b36422acae13
Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents:
578
diff
changeset
|
916 |
self.KillLocalRuntime() |
b36422acae13
Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents:
578
diff
changeset
|
917 |
|
598
6c919bc1551d
Adding support for saving frame size while closing and restore it at next launch
laurent
parents:
597
diff
changeset
|
918 |
self.SaveFrameSize() |
6c919bc1551d
Adding support for saving frame size while closing and restore it at next launch
laurent
parents:
597
diff
changeset
|
919 |
|
596
b36422acae13
Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents:
578
diff
changeset
|
920 |
lpcberemiz_cmd.Log.write("Closed\n") |
b36422acae13
Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents:
578
diff
changeset
|
921 |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
922 |
event.Veto() |
442 | 923 |
|
500
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
924 |
def ShowProperties(self): |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
925 |
old_values = self.Controler.GetProjectProperties() |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
926 |
dialog = ProjectDialog(self ,False) |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
927 |
dialog.SetValues(old_values) |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
928 |
if dialog.ShowModal() == wx.ID_OK: |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
929 |
new_values = dialog.GetValues() |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
930 |
new_values["creationDateTime"] = old_values["creationDateTime"] |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
931 |
if new_values != old_values: |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
932 |
self.Controler.SetProjectProperties(None, new_values) |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
933 |
self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
934 |
TYPESTREE, INSTANCESTREE, SCALING) |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
935 |
dialog.Destroy() |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
936 |
|
442 | 937 |
def RefreshFileMenu(self): |
938 |
if self.PluginRoot is not None: |
|
939 |
selected = self.TabsOpened.GetSelection() |
|
940 |
if selected >= 0: |
|
941 |
graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer) |
|
942 |
else: |
|
943 |
graphic_viewer = False |
|
944 |
if self.TabsOpened.GetPageCount() > 0: |
|
945 |
self.FileMenu.Enable(wx.ID_CLOSE, True) |
|
946 |
if graphic_viewer: |
|
947 |
self.FileMenu.Enable(wx.ID_PREVIEW, True) |
|
948 |
self.FileMenu.Enable(wx.ID_PRINT, True) |
|
949 |
else: |
|
950 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
951 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
952 |
else: |
|
953 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
954 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
955 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
956 |
self.FileMenu.Enable(wx.ID_PAGE_SETUP, True) |
|
500
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
957 |
self.FileMenu.Enable(wx.ID_SAVE, self.PluginRoot.PlugTestModified()) |
442 | 958 |
self.FileMenu.Enable(wx.ID_PROPERTIES, True) |
959 |
else: |
|
960 |
self.FileMenu.Enable(wx.ID_CLOSE, False) |
|
961 |
self.FileMenu.Enable(wx.ID_PAGE_SETUP, False) |
|
962 |
self.FileMenu.Enable(wx.ID_PREVIEW, False) |
|
963 |
self.FileMenu.Enable(wx.ID_PRINT, False) |
|
964 |
self.FileMenu.Enable(wx.ID_SAVE, False) |
|
965 |
self.FileMenu.Enable(wx.ID_PROPERTIES, False) |
|
966 |
||
967 |
def RefreshPLCParams(self): |
|
968 |
self.Freeze() |
|
969 |
self.ClearSizer(self.PLCParamsSizer) |
|
970 |
||
971 |
if self.PluginRoot is not None: |
|
972 |
plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
|
973 |
if self.PluginRoot.PlugTestModified(): |
|
974 |
bkgdclr = CHANGED_TITLE_COLOUR |
|
975 |
else: |
|
976 |
bkgdclr = TITLE_COLOUR |
|
977 |
||
978 |
if self.PluginRoot not in self.PluginInfos: |
|
979 |
self.PluginInfos[self.PluginRoot] = {"right_visible" : False} |
|
980 |
||
981 |
plcwindow.SetBackgroundColour(TITLE_COLOUR) |
|
982 |
plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) |
|
983 |
self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW) |
|
984 |
||
985 |
plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
|
986 |
plcwindow.SetSizer(plcwindowsizer) |
|
987 |
||
988 |
st = wx.StaticText(plcwindow, -1) |
|
989 |
st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
|
990 |
st.SetLabel(self.PluginRoot.GetProjectName()) |
|
991 |
plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER) |
|
992 |
||
993 |
plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL) |
|
994 |
plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL) |
|
995 |
||
996 |
plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL) |
|
997 |
plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER) |
|
998 |
||
999 |
msizer = self.GenerateMethodButtonSizer(self.PluginRoot, plcwindow, not self.PluginInfos[self.PluginRoot]["right_visible"]) |
|
1000 |
plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) |
|
1001 |
||
1002 |
self.PLCConfigMainSizer.Layout() |
|
1003 |
self.RefreshScrollBars() |
|
1004 |
self.Thaw() |
|
1005 |
||
1006 |
def GenerateTreeBranch(self, plugin): |
|
1007 |
leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
|
1008 |
if plugin.PlugTestModified(): |
|
1009 |
bkgdclr=CHANGED_WINDOW_COLOUR |
|
1010 |
else: |
|
1011 |
bkgdclr=WINDOW_COLOUR |
|
1012 |
||
1013 |
leftwindow.SetBackgroundColour(bkgdclr) |
|
1014 |
||
1015 |
if plugin not in self.PluginInfos: |
|
1016 |
self.PluginInfos[plugin] = {"expanded" : False, "left_visible" : False, "right_visible" : False} |
|
1017 |
||
1018 |
self.PluginInfos[plugin]["children"] = plugin.IECSortedChilds() |
|
1019 |
plugin_infos = plugin.GetVariableLocationTree() |
|
1020 |
plugin_locations = [] |
|
1021 |
if len(self.PluginInfos[plugin]["children"]) == 0: |
|
1022 |
plugin_locations = plugin_infos["children"] |
|
1023 |
if not self.PluginInfos[plugin].has_key("locations_infos"): |
|
1024 |
self.PluginInfos[plugin]["locations_infos"] = {"root": {"expanded" : False}} |
|
1025 |
||
1026 |
self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = [] |
|
1027 |
||
1028 |
self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW) |
|
1029 |
||
1030 |
leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
|
1031 |
leftwindow.SetSizer(leftwindowsizer) |
|
1032 |
||
1033 |
st = wx.StaticText(leftwindow, -1) |
|
1034 |
st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
|
1035 |
st.SetLabel(plugin.GetFullIEC_Channel()) |
|
1036 |
leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT) |
|
1037 |
||
1038 |
expandbutton_id = wx.NewId() |
|
1039 |
expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')), |
|
1040 |
name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0), |
|
1041 |
size=wx.Size(13, 13), style=wx.NO_BORDER) |
|
1042 |
expandbutton.labelDelta = 0 |
|
1043 |
expandbutton.SetBezelWidth(0) |
|
1044 |
expandbutton.SetUseFocusIndicator(False) |
|
1045 |
expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png'))) |
|
1046 |
||
1047 |
if len(self.PluginInfos[plugin]["children"]) > 0: |
|
1048 |
expandbutton.SetToggle(self.PluginInfos[plugin]["expanded"]) |
|
1049 |
def togglebutton(event): |
|
1050 |
if expandbutton.GetToggle(): |
|
1051 |
self.ExpandPlugin(plugin) |
|
1052 |
else: |
|
1053 |
self.CollapsePlugin(plugin) |
|
1054 |
self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle() |
|
1055 |
self.PLCConfigMainSizer.Layout() |
|
1056 |
self.RefreshScrollBars() |
|
1057 |
event.Skip() |
|
1058 |
expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id) |
|
1059 |
elif len(plugin_locations) > 0: |
|
1060 |
locations_infos = self.PluginInfos[plugin]["locations_infos"] |
|
1061 |
expandbutton.SetToggle(locations_infos["root"]["expanded"]) |
|
1062 |
def togglebutton(event): |
|
1063 |
if expandbutton.GetToggle(): |
|
1064 |
self.ExpandLocation(locations_infos, "root") |
|
1065 |
else: |
|
1066 |
self.CollapseLocation(locations_infos, "root") |
|
1067 |
self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle() |
|
1068 |
locations_infos["root"]["expanded"] = expandbutton.GetToggle() |
|
1069 |
self.PLCConfigMainSizer.Layout() |
|
1070 |
self.RefreshScrollBars() |
|
1071 |
event.Skip() |
|
1072 |
expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id) |
|
1073 |
else: |
|
1074 |
expandbutton.Enable(False) |
|
1075 |
leftwindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
|
1076 |
||
1077 |
sb = wx.StaticBitmap(leftwindow, -1) |
|
1078 |
icon = plugin_infos.get("icon", None) |
|
1079 |
if icon is None: |
|
1080 |
icon = os.path.join(base_folder, "plcopeneditor", 'Images', '%s.png' % self.LOCATION_BITMAP[plugin_infos["type"]]) |
|
1081 |
sb.SetBitmap(wx.Bitmap(icon)) |
|
1082 |
leftwindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
|
1083 |
||
1084 |
st_id = wx.NewId() |
|
1085 |
st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER) |
|
1086 |
st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
|
1087 |
st.SetLabel(plugin.MandatoryParams[1].getName()) |
|
1088 |
leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
|
1089 |
||
1090 |
rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
|
1091 |
rightwindow.SetBackgroundColour(bkgdclr) |
|
1092 |
||
1093 |
self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
|
1094 |
||
1095 |
self.PluginInfos[plugin]["left"] = leftwindow |
|
1096 |
self.PluginInfos[plugin]["right"] = rightwindow |
|
1097 |
for child in self.PluginInfos[plugin]["children"]: |
|
1098 |
self.GenerateTreeBranch(child) |
|
1099 |
if not self.PluginInfos[child]["expanded"]: |
|
1100 |
self.CollapsePlugin(child) |
|
1101 |
if len(plugin_locations) > 0: |
|
1102 |
locations_infos = self.PluginInfos[plugin]["locations_infos"] |
|
1103 |
for location in plugin_locations: |
|
1104 |
locations_infos["root"]["children"].append("root.%s" % location["name"]) |
|
1105 |
self.GenerateLocationTreeBranch(locations_infos, "root", location) |
|
1106 |
if not locations_infos["root"]["expanded"]: |
|
1107 |
self.CollapseLocation(locations_infos, "root") |
|
1108 |
||
1109 |
class StdoutPseudoFile: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1110 |
|
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1111 |
def __init__(self, port): |
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1112 |
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1113 |
self.socket.connect(('localhost', port)) |
552 | 1114 |
self.Buffer = "" |
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1115 |
|
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1116 |
def __del__(self): |
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1117 |
self.socket.close() |
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1118 |
|
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1119 |
def readline(self): |
552 | 1120 |
idx = self.Buffer.find("\n") |
1121 |
if idx == -1: |
|
1122 |
self.Buffer += self.socket.recv(2048) |
|
1123 |
idx = self.Buffer.find("\n") |
|
1124 |
if idx != -1: |
|
1125 |
line = self.Buffer[:idx+1] |
|
1126 |
self.Buffer = self.Buffer[idx+1:] |
|
571
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
1127 |
if BMZ_DBG: |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
1128 |
print "command >"+line |
552 | 1129 |
return line |
1130 |
return "" |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1131 |
|
442 | 1132 |
""" Base class for file like objects to facilitate StdOut for the Shell.""" |
1133 |
def write(self, s, style = None): |
|
1134 |
if s != '': |
|
578 | 1135 |
self.socket.send(s.encode('utf8')) |
1136 |
||
1137 |
def writeyield(self, s): |
|
1138 |
self.write(s) |
|
1139 |
||
442 | 1140 |
def write_warning(self, s): |
1141 |
self.write(s) |
|
1142 |
||
1143 |
def write_error(self, s): |
|
1144 |
self.write(s) |
|
1145 |
||
1146 |
def flush(self): |
|
1147 |
pass |
|
1148 |
||
1149 |
def isatty(self): |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1150 |
return False |
442 | 1151 |
|
1152 |
if __name__ == '__main__': |
|
1153 |
||
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1154 |
from threading import Thread, Timer, Semaphore |
442 | 1155 |
import cmd |
1156 |
||
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1157 |
wx_eval_lock = Semaphore(0) |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1158 |
eval_res = None |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1159 |
def wx_evaluator(callable, *args, **kwargs): |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1160 |
global eval_res |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1161 |
eval_res = None |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1162 |
try: |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1163 |
eval_res=callable(*args,**kwargs) |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1164 |
finally: |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1165 |
wx_eval_lock.release() |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1166 |
|
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1167 |
def evaluator(callable, *args, **kwargs): |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1168 |
global eval_res |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1169 |
wx.CallAfter(wx_evaluator,callable,*args,**kwargs) |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1170 |
wx_eval_lock.acquire() |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1171 |
return eval_res |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1172 |
|
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1173 |
# Command log for debug, for viewing from wxInspector |
571
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
1174 |
if BMZ_DBG: |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
1175 |
__builtins__.cmdlog = [] |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1176 |
|
442 | 1177 |
class LPCBeremiz_Cmd(cmd.Cmd): |
1178 |
||
1179 |
prompt = "" |
|
1180 |
RefreshTimer = None |
|
1181 |
||
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1182 |
def __init__(self, PluginRoot, Log): |
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1183 |
cmd.Cmd.__init__(self, stdin=Log, stdout=Log) |
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1184 |
self.use_rawinput = False |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1185 |
self.Log = Log |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1186 |
self.PluginRoot = PluginRoot |
442 | 1187 |
|
1188 |
def RestartTimer(self): |
|
1189 |
if self.RefreshTimer is not None: |
|
1190 |
self.RefreshTimer.cancel() |
|
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1191 |
self.RefreshTimer = Timer(0.1, wx.CallAfter, args = [self.Refresh]) |
442 | 1192 |
self.RefreshTimer.start() |
1193 |
||
1194 |
def Exit(self): |
|
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
1195 |
global frame, app |
442 | 1196 |
self.Close() |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
1197 |
app.ExitMainLoop() |
442 | 1198 |
return True |
1199 |
||
1200 |
def do_EOF(self, line): |
|
1201 |
return self.Exit() |
|
1202 |
||
1203 |
def Show(self): |
|
445 | 1204 |
global frame |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
1205 |
if frame is not None: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
1206 |
self.PluginRoot.SetAppFrame(frame, frame.Log) |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1207 |
frame.Show() |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1208 |
frame.Raise() |
442 | 1209 |
|
1210 |
def Refresh(self): |
|
1211 |
global frame |
|
1212 |
if frame is not None: |
|
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1213 |
frame._Refresh(TITLE, INSTANCESTREE, FILEMENU, EDITMENU) |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1214 |
frame.RefreshEditor() |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1215 |
frame.RefreshAll() |
442 | 1216 |
|
1217 |
def Close(self): |
|
1218 |
global frame |
|
1219 |
||
1220 |
self.PluginRoot.ResetAppFrame(self.Log) |
|
1221 |
if frame is not None: |
|
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1222 |
frame.Hide() |
442 | 1223 |
|
1224 |
def Compile(self): |
|
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1225 |
self.PluginRoot._build() |
442 | 1226 |
|
500
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
1227 |
def SetProjectProperties(self, projectname, productname, productversion, companyname): |
af7c28de4cc7
Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents:
494
diff
changeset
|
1228 |
properties = self.PluginRoot.GetProjectProperties() |
597
6fbfd3bf2927
Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents:
596
diff
changeset
|
1229 |
new_properties = properties.copy() |
6fbfd3bf2927
Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents:
596
diff
changeset
|
1230 |
new_properties["projectName"] = projectname |
6fbfd3bf2927
Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents:
596
diff
changeset
|
1231 |
new_properties["productName"] = productname |
6fbfd3bf2927
Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents:
596
diff
changeset
|
1232 |
new_properties["productVersion"] = productversion |
6fbfd3bf2927
Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents:
596
diff
changeset
|
1233 |
new_properties["companyName"] = companyname |
6fbfd3bf2927
Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents:
596
diff
changeset
|
1234 |
if new_properties != properties: |
6fbfd3bf2927
Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents:
596
diff
changeset
|
1235 |
self.PluginRoot.SetProjectProperties(properties=new_properties) |
6fbfd3bf2927
Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents:
596
diff
changeset
|
1236 |
self.RestartTimer() |
442 | 1237 |
|
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
1238 |
def SetOnlineMode(self, mode, path=None): |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1239 |
self.PluginRoot.SetOnlineMode(mode, path) |
487
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
1240 |
self.RestartTimer() |
1df4a28d3586
Adding support for receiving PLC state from LPCComposer
laurent
parents:
478
diff
changeset
|
1241 |
|
442 | 1242 |
def AddBus(self, iec_channel, name, icon=None): |
1243 |
for child in self.PluginRoot.IterChilds(): |
|
1244 |
if child.BaseParams.getName() == name: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1245 |
return "Error: A bus named %s already exists\n" % name |
442 | 1246 |
elif child.BaseParams.getIEC_Channel() == iec_channel: |
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1247 |
return "Error: A bus with IEC_channel %d already exists\n" % iec_channel |
442 | 1248 |
bus = self.PluginRoot.PlugAddChild(name, "LPCBus", iec_channel) |
1249 |
if bus is None: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1250 |
return "Error: Unable to create bus\n" |
442 | 1251 |
bus.SetIcon(icon) |
1252 |
self.RestartTimer() |
|
1253 |
||
1254 |
def RenameBus(self, iec_channel, name): |
|
1255 |
bus = self.PluginRoot.GetChildByIECLocation((iec_channel,)) |
|
1256 |
if bus is None: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1257 |
return "Error: No bus found\n" |
442 | 1258 |
for child in self.PluginRoot.IterChilds(): |
1259 |
if child != bus and child.BaseParams.getName() == name: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1260 |
return "Error: A bus named %s already exists\n" % name |
442 | 1261 |
bus.BaseParams.setName(name) |
1262 |
self.RestartTimer() |
|
1263 |
||
1264 |
def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel): |
|
1265 |
bus = self.PluginRoot.GetChildByIECLocation((old_iec_channel,)) |
|
1266 |
if bus is None: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1267 |
return "Error: No bus found\n" |
442 | 1268 |
for child in self.PluginRoot.IterChilds(): |
1269 |
if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1270 |
return "Error: A bus with IEC_channel %d already exists\n" % new_iec_channel |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
1271 |
if wx.GetApp() is None: |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
1272 |
self.PluginRoot.UpdateProjectVariableLocation(str(old_iec_channel), |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
1273 |
str(new_iec_channel)) |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
1274 |
else: |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1275 |
self.PluginRoot.UpdateProjectVariableLocation( |
539
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
1276 |
str(old_iec_channel), |
6ff2c1d34640
Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents:
530
diff
changeset
|
1277 |
str(new_iec_channel)) |
442 | 1278 |
bus.BaseParams.setIEC_Channel(new_iec_channel) |
1279 |
self.RestartTimer() |
|
1280 |
||
1281 |
def RemoveBus(self, iec_channel): |
|
1282 |
bus = self.PluginRoot.GetChildByIECLocation((iec_channel,)) |
|
1283 |
if bus is None: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1284 |
return "Error: No bus found\n" |
444
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
1285 |
self.PluginRoot.RemoveProjectVariableByFilter(str(iec_channel)) |
442 | 1286 |
self.PluginRoot.PluggedChilds["LPCBus"].remove(bus) |
1287 |
self.RestartTimer() |
|
1288 |
||
553 | 1289 |
def AddModule(self, parent, iec_channel, name, icode, icon=None): |
442 | 1290 |
module = self.PluginRoot.GetChildByIECLocation(parent) |
1291 |
if module is None: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1292 |
return "Error: No parent found\n" |
442 | 1293 |
for child in _GetModuleChildren(module): |
1294 |
if child["name"] == name: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1295 |
return "Error: A module named %s already exists\n" % name |
442 | 1296 |
elif child["IEC_Channel"] == iec_channel: |
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1297 |
return "Error: A module with IEC_channel %d already exists\n" % iec_channel |
442 | 1298 |
_GetLastModuleGroup(module).append({"name": name, |
1299 |
"type": LOCATION_MODULE, |
|
1300 |
"IEC_Channel": iec_channel, |
|
1301 |
"icon": icon, |
|
553 | 1302 |
"init": icode, |
442 | 1303 |
"children": []}) |
1304 |
self.RestartTimer() |
|
1305 |
||
1306 |
def RenameModule(self, iec_location, name): |
|
1307 |
module = self.PluginRoot.GetChildByIECLocation(iec_location) |
|
1308 |
if module is None: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1309 |
return "Error: No module found\n" |
442 | 1310 |
parent = self.PluginRoot.GetChildByIECLocation(iec_location[:-1]) |
1311 |
if parent is self.PluginRoot: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1312 |
return "Error: No module found\n" |
442 | 1313 |
if module["name"] != name: |
1314 |
for child in _GetModuleChildren(parent): |
|
1315 |
if child["name"] == name: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1316 |
return "Error: A module named %s already exists\n" % name |
442 | 1317 |
module["name"] = name |
1318 |
self.RestartTimer() |
|
1319 |
||
1320 |
def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel): |
|
1321 |
module = self.PluginRoot.GetChildByIECLocation(old_iec_location) |
|
1322 |
if module is None: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1323 |
return "Error: No module found\n" |
442 | 1324 |
parent = self.PluginRoot.GetChildByIECLocation(old_iec_location[:-1]) |
1325 |
if parent is self.PluginRoot: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1326 |
return "Error: No module found\n" |
442 | 1327 |
if module["IEC_Channel"] != new_iec_channel: |
1328 |
for child in _GetModuleChildren(parent): |
|
1329 |
if child["IEC_Channel"] == new_iec_channel: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1330 |
return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel |
444
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
1331 |
self.PluginRoot.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,)))) |
442 | 1332 |
module["IEC_Channel"] = new_iec_channel |
1333 |
self.RestartTimer() |
|
553 | 1334 |
|
1335 |
def ChangeModuleInitCode(self, iec_location, icode): |
|
1336 |
module = self.PluginRoot.GetChildByIECLocation(iec_location) |
|
1337 |
if module is None: |
|
1338 |
return "Error: No module found\n" |
|
1339 |
module["init"] = icode |
|
1340 |
||
442 | 1341 |
def RemoveModule(self, parent, iec_channel): |
1342 |
module = self.PluginRoot.GetChildByIECLocation(parent) |
|
1343 |
if module is None: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1344 |
return "Error: No parent found\n" |
442 | 1345 |
child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,)) |
1346 |
if child is None: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1347 |
return "Error: No module found\n" |
444
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
1348 |
self.PluginRoot.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,)))) |
442 | 1349 |
_RemoveModuleChild(module, child) |
1350 |
self.RestartTimer() |
|
1351 |
||
1352 |
def StartGroup(self, parent, name, icon=None): |
|
1353 |
module = self.PluginRoot.GetChildByIECLocation(parent) |
|
1354 |
if module is None: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1355 |
return "Error: No parent found\n" |
442 | 1356 |
for child in module["children"]: |
1357 |
if child["type"] == LOCATION_GROUP and child["name"] == name: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1358 |
return "Error: A group named %s already exists\n" % name |
442 | 1359 |
module["children"].append({"name": name, |
1360 |
"type": LOCATION_GROUP, |
|
1361 |
"icon": icon, |
|
1362 |
"children": []}) |
|
1363 |
self.RestartTimer() |
|
1364 |
||
553 | 1365 |
def AddVariable(self, parent, location, name, direction, type, rcode, pcode, description=""): |
442 | 1366 |
module = self.PluginRoot.GetChildByIECLocation(parent) |
1367 |
if module is None: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1368 |
return "Error: No parent found\n" |
442 | 1369 |
for child in _GetModuleChildren(module): |
1370 |
if child["name"] == name: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1371 |
return "Error: A variable named %s already exists\n" % name |
472
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
1372 |
if child["location"] == location and child["type"] == LOCATION_TYPES[direction]: |
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1373 |
return "Error: A variable with location %s already exists\n" % ".".join(map(str, location)) |
442 | 1374 |
_GetLastModuleGroup(module).append({"name": name, |
1375 |
"location": location, |
|
1376 |
"type": LOCATION_TYPES[direction], |
|
1377 |
"IEC_type": type, |
|
1378 |
"description": description, |
|
1379 |
"retrieve": rcode, |
|
1380 |
"publish": pcode}) |
|
1381 |
self.RestartTimer() |
|
1382 |
||
553 | 1383 |
def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_rcode, new_pcode, new_description=None): |
442 | 1384 |
module = self.PluginRoot.GetChildByIECLocation(parent) |
1385 |
if module is None: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1386 |
return "Error: No parent found\n" |
442 | 1387 |
variable = None |
1388 |
for child in _GetModuleChildren(module): |
|
472
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
1389 |
if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]: |
442 | 1390 |
variable = child |
1391 |
elif child["name"] == new_name: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1392 |
return "Error: A variable named %s already exists\n" % new_name |
442 | 1393 |
if variable is None: |
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1394 |
return "Error: No variable found\n" |
444
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
1395 |
if variable["name"] != new_name: |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
1396 |
self.PluginRoot.UpdateProjectVariableName(variable["name"], new_name) |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
1397 |
variable["name"] = new_name |
442 | 1398 |
variable["type"] = LOCATION_TYPES[new_direction] |
1399 |
variable["IEC_type"] = new_type |
|
1400 |
variable["retrieve"] = new_rcode |
|
1401 |
variable["publish"] = new_pcode |
|
1402 |
if new_description is not None: |
|
1403 |
variable["description"] = new_description |
|
1404 |
self.RestartTimer() |
|
1405 |
||
472
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
1406 |
def RemoveVariable(self, parent, location, direction): |
442 | 1407 |
module = self.PluginRoot.GetChildByIECLocation(parent) |
1408 |
if module is None: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1409 |
return "Error: No parent found\n" |
472
80eb3bde98e3
Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents:
445
diff
changeset
|
1410 |
child = _GetModuleVariable(module, location, direction) |
442 | 1411 |
if child is None: |
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1412 |
return "Error: No variable found\n" |
444
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
1413 |
size = LOCATION_SIZES[self.PluginRoot.GetBaseType(child["IEC_type"])] |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
1414 |
address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location)) |
8eb1186fc9cf
Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents:
442
diff
changeset
|
1415 |
self.PluginRoot.RemoveProjectVariableByAddress(address) |
442 | 1416 |
_RemoveModuleChild(module, child) |
1417 |
self.RestartTimer() |
|
1418 |
||
1419 |
def location(loc): |
|
1420 |
return tuple(map(int, loc.split("."))) |
|
1421 |
||
1422 |
def GetCmdFunction(function, arg_types, opt=0): |
|
1423 |
arg_number = len(arg_types) |
|
1424 |
def CmdFunction(self, line): |
|
1425 |
args_toks = line.split('"') |
|
1426 |
if len(args_toks) % 2 == 0: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1427 |
self.Log.write("Error: Invalid command\n") |
526 | 1428 |
sys.stdout.flush() |
442 | 1429 |
return |
1430 |
args = [] |
|
1431 |
for num, arg in enumerate(args_toks): |
|
1432 |
if num % 2 == 0: |
|
1433 |
stripped = arg.strip() |
|
1434 |
if stripped: |
|
1435 |
args.extend(stripped.split(" ")) |
|
1436 |
else: |
|
1437 |
args.append(arg) |
|
1438 |
number = None |
|
1439 |
extra = "" |
|
1440 |
if opt == 0 and len(args) != arg_number: |
|
1441 |
number = arg_number |
|
1442 |
elif len(args) > arg_number: |
|
1443 |
number = arg_number |
|
1444 |
extra = " at most" |
|
1445 |
elif len(args) < arg_number - opt: |
|
1446 |
number = arg_number - opt |
|
1447 |
extra = " at least" |
|
1448 |
if number is not None: |
|
1449 |
if number == 0: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1450 |
self.Log.write("Error: No argument%s expected\n" % extra) |
442 | 1451 |
elif number == 1: |
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1452 |
self.Log.write("Error: 1 argument%s expected\n" % extra) |
442 | 1453 |
else: |
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1454 |
self.Log.write("Error: %d arguments%s expected\n" % (number, extra)) |
526 | 1455 |
sys.stdout.flush() |
442 | 1456 |
return |
1457 |
for num, arg in enumerate(args): |
|
1458 |
try: |
|
1459 |
args[num] = arg_types[num](arg) |
|
1460 |
except: |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1461 |
self.Log.write("Error: Invalid value for argument %d\n" % (num + 1)) |
526 | 1462 |
sys.stdout.flush() |
442 | 1463 |
return |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1464 |
|
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1465 |
func = getattr(self, function) |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1466 |
res = evaluator(func,*args) |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1467 |
|
571
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
1468 |
if BMZ_DBG: |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
1469 |
cmdlog.append((function,line,res)) |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
1470 |
if len(cmdlog) > 100: #prevent debug log to grow too much |
427bf9130d12
Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents:
566
diff
changeset
|
1471 |
cmdlog.pop(0) |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1472 |
|
442 | 1473 |
if isinstance(res, (StringType, UnicodeType)): |
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1474 |
self.Log.write(res) |
442 | 1475 |
return False |
1476 |
else: |
|
1477 |
return res |
|
1478 |
return CmdFunction |
|
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1479 |
|
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1480 |
def CmdThreadProc(PluginRoot, Log): |
549 | 1481 |
global lpcberemiz_cmd |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1482 |
for function, (arg_types, opt) in {"Exit": ([], 0), |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1483 |
"Show": ([], 0), |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1484 |
"Refresh": ([], 0), |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1485 |
"Close": ([], 0), |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1486 |
"Compile": ([], 0), |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1487 |
"SetProjectProperties": ([str, str, str, str], 0), |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1488 |
"SetOnlineMode": ([str, str], 1), |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1489 |
"AddBus": ([int, str, str], 1), |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1490 |
"RenameBus": ([int, str], 0), |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1491 |
"ChangeBusIECChannel": ([int, int], 0), |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1492 |
"RemoveBus": ([int], 0), |
553 | 1493 |
"AddModule": ([location, int, str, str, str], 1), |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1494 |
"RenameModule": ([location, str], 0), |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1495 |
"ChangeModuleIECChannel": ([location, int], 0), |
553 | 1496 |
"ChangeModuleInitCode": ([location, str], 0), |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1497 |
"RemoveModule": ([location, int], 0), |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1498 |
"StartGroup": ([location, str, str], 1), |
553 | 1499 |
"AddVariable": ([location, location, str, str, str, str, str, str], 1), |
1500 |
"ChangeVariableParams": ([location, location, str, str, str, str, str, str], 1), |
|
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1501 |
"RemoveVariable": ([location, location], 0)}.iteritems(): |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1502 |
|
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1503 |
setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt)) |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1504 |
lpcberemiz_cmd = LPCBeremiz_Cmd(PluginRoot, Log) |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1505 |
lpcberemiz_cmd.cmdloop() |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1506 |
|
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1507 |
Log = StdoutPseudoFile(port) |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1508 |
|
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1509 |
PluginRoot = LPCPluginsRoot(None, Log) |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1510 |
if projectOpen is not None and os.path.isdir(projectOpen): |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1511 |
result = PluginRoot.LoadProject(projectOpen, buildpath) |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1512 |
if result: |
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1513 |
Log.write("Error: Invalid project directory", result) |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1514 |
else: |
551
d18e86b603bc
Adding support for command line communication by socket instead of stdin/stdout
laurent
parents:
550
diff
changeset
|
1515 |
Log.write("Error: No such file or directory") |
547
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1516 |
|
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1517 |
cmd_thread=Thread(target=CmdThreadProc, args=[PluginRoot, Log]) |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1518 |
cmd_thread.start() |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1519 |
|
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1520 |
# Install a exception handle for bug reports |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1521 |
AddExceptHook(os.getcwd(),__version__) |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1522 |
|
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1523 |
frame = LPCBeremiz(None, plugin_root=PluginRoot, debug=True) |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1524 |
|
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1525 |
app.MainLoop() |
5748d695beee
Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents:
543
diff
changeset
|
1526 |