23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
24 |
25 import Pyro.core as pyro |
25 import Pyro.core as pyro |
26 from threading import Timer, Thread |
26 from threading import Timer, Thread |
27 import ctypes, os, commands, types, sys |
27 import ctypes, os, commands, types, sys |
|
28 import time |
28 |
29 |
29 if os.name in ("nt", "ce"): |
30 if os.name in ("nt", "ce"): |
30 from _ctypes import LoadLibrary as dlopen |
31 from _ctypes import LoadLibrary as dlopen |
31 from _ctypes import FreeLibrary as dlclose |
32 from _ctypes import FreeLibrary as dlclose |
32 elif os.name == "posix": |
33 elif os.name == "posix": |
33 from _ctypes import dlopen, dlclose |
34 from _ctypes import dlopen, dlclose |
34 |
35 |
35 import os,sys,traceback |
36 import traceback |
36 |
37 |
37 lib_ext ={ |
38 lib_ext ={ |
38 "linux2":".so", |
39 "linux2":".so", |
39 "win32":".dll", |
40 "win32":".dll", |
40 }.get(sys.platform, "") |
41 }.get(sys.platform, "") |
178 return True |
179 return True |
179 return False |
180 return False |
180 |
181 |
181 def PrepareRuntimePy(self): |
182 def PrepareRuntimePy(self): |
182 self.python_threads_vars = globals().copy() |
183 self.python_threads_vars = globals().copy() |
|
184 self.python_threads_vars["WorkingDir"] = self.workingdir |
183 pyfile = os.path.join(self.workingdir, "runtime.py") |
185 pyfile = os.path.join(self.workingdir, "runtime.py") |
184 hmifile = os.path.join(self.workingdir, "hmi.py") |
186 hmifile = os.path.join(self.workingdir, "hmi.py") |
185 if os.path.exists(hmifile): |
187 if os.path.exists(hmifile): |
186 try: |
188 try: |
187 execfile(hmifile, self.python_threads_vars) |
189 execfile(hmifile, self.python_threads_vars) |
412 res.append(unpack_func(ctypes.cast(buffer, |
416 res.append(unpack_func(ctypes.cast(buffer, |
413 ctypes.POINTER(c_type)).contents)) |
417 ctypes.POINTER(c_type)).contents)) |
414 else: |
418 else: |
415 PLCprint("Debug error idx : %d, expected_idx %d, type : %s"%(idx.value, given_idx,typename.value)) |
419 PLCprint("Debug error idx : %d, expected_idx %d, type : %s"%(idx.value, given_idx,typename.value)) |
416 res.append(None) |
420 res.append(None) |
|
421 time.sleep(0.1) |
417 self._FreeDebugData() |
422 self._FreeDebugData() |
418 return tick, res |
423 return tick, res |
419 return -1, None |
424 return -1, None |
420 |
425 |
421 |
426 |