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