equal
deleted
inserted
replaced
49 def PLCprint(message): |
49 def PLCprint(message): |
50 sys.stdout.write("PLCobject : "+message+"\n") |
50 sys.stdout.write("PLCobject : "+message+"\n") |
51 sys.stdout.flush() |
51 sys.stdout.flush() |
52 |
52 |
53 class PLCObject(pyro.ObjBase): |
53 class PLCObject(pyro.ObjBase): |
54 def __init__(self, workingdir, daemon, argv, statuschange, evaluator, website): |
54 def __init__(self, workingdir, daemon, argv, statuschange, evaluator, pyruntimevars): |
55 pyro.ObjBase.__init__(self) |
55 pyro.ObjBase.__init__(self) |
56 self.evaluator = evaluator |
56 self.evaluator = evaluator |
57 self.argv = [workingdir] + argv # force argv[0] to be "path" to exec... |
57 self.argv = [workingdir] + argv # force argv[0] to be "path" to exec... |
58 self.workingdir = workingdir |
58 self.workingdir = workingdir |
59 self.PLCStatus = "Stopped" |
59 self.PLCStatus = "Stopped" |
63 # Creates fake C funcs proxies |
63 # Creates fake C funcs proxies |
64 self._FreePLC() |
64 self._FreePLC() |
65 self.daemon = daemon |
65 self.daemon = daemon |
66 self.statuschange = statuschange |
66 self.statuschange = statuschange |
67 self.hmi_frame = None |
67 self.hmi_frame = None |
68 self.website = website |
68 self.pyruntimevars = pyruntimevars |
69 self._loading_error = None |
69 self._loading_error = None |
70 self.python_runtime_vars = None |
70 self.python_runtime_vars = None |
71 self.TraceThread = None |
71 self.TraceThread = None |
72 self.TraceLock = Lock() |
72 self.TraceLock = Lock() |
73 self.TraceWakeup = Event() |
73 self.TraceWakeup = Event() |
83 self.PLCStatus = "Empty" |
83 self.PLCStatus = "Empty" |
84 self.CurrentPLCFilename=None |
84 self.CurrentPLCFilename=None |
85 |
85 |
86 def StatusChange(self): |
86 def StatusChange(self): |
87 if self.statuschange is not None: |
87 if self.statuschange is not None: |
88 self.statuschange(self.PLCStatus) |
88 for callee in self.statuschange: |
|
89 callee(self.PLCStatus) |
89 |
90 |
90 def LogMessage(self, *args): |
91 def LogMessage(self, *args): |
91 if len(args) == 2: |
92 if len(args) == 2: |
92 level, msg = args |
93 level, msg = args |
93 else: |
94 else: |
260 self.LogMessage(0,'\n'.join(traceback.format_exception(*exp))) |
261 self.LogMessage(0,'\n'.join(traceback.format_exception(*exp))) |
261 |
262 |
262 def PythonRuntimeInit(self): |
263 def PythonRuntimeInit(self): |
263 MethodNames = ["init", "start", "stop", "cleanup"] |
264 MethodNames = ["init", "start", "stop", "cleanup"] |
264 self.python_runtime_vars = globals().copy() |
265 self.python_runtime_vars = globals().copy() |
|
266 self.python_runtime_vars.update(self.pyruntimevars) |
|
267 |
265 self.python_runtime_vars["WorkingDir"] = self.workingdir |
268 self.python_runtime_vars["WorkingDir"] = self.workingdir |
266 self.python_runtime_vars["website"] = self.website |
|
267 for methodname in MethodNames : |
269 for methodname in MethodNames : |
268 self.python_runtime_vars["_runtime_%s"%methodname] = [] |
270 self.python_runtime_vars["_runtime_%s"%methodname] = [] |
269 self.python_runtime_vars["PLCObject"] = self |
271 self.python_runtime_vars["PLCObject"] = self |
270 self.python_runtime_vars["PLCBinary"] = self.PLClibraryHandle |
272 self.python_runtime_vars["PLCBinary"] = self.PLClibraryHandle |
271 class PLCSafeGlobals: |
273 class PLCSafeGlobals: |
298 self.LogMessage(0,traceback.format_exc()) |
300 self.LogMessage(0,traceback.format_exc()) |
299 raise |
301 raise |
300 |
302 |
301 self.PythonRuntimeCall("init") |
303 self.PythonRuntimeCall("init") |
302 |
304 |
303 if self.website is not None: |
|
304 self.website.PLCStarted() |
|
305 |
305 |
306 |
306 |
307 def PythonRuntimeCleanup(self): |
307 def PythonRuntimeCleanup(self): |
308 if self.python_runtime_vars is not None: |
308 if self.python_runtime_vars is not None: |
309 self.PythonRuntimeCall("cleanup") |
309 self.PythonRuntimeCall("cleanup") |
310 |
|
311 if self.website is not None: |
|
312 self.website.PLCStopped() |
|
313 |
310 |
314 self.python_runtime_vars = None |
311 self.python_runtime_vars = None |
315 |
312 |
316 def PythonThreadProc(self): |
313 def PythonThreadProc(self): |
317 self.PLCStatus = "Started" |
314 self.PLCStatus = "Started" |