runtime/PLCObject.py
changeset 283 d0e6fc0701fb
parent 280 f2ef79f3dba0
child 286 a2a8a52b0d4f
equal deleted inserted replaced
282:2221e99d2f8f 283:d0e6fc0701fb
    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
    27 import ctypes, os, commands
    28 import time
       
    29 
    28 
    30 if os.name in ("nt", "ce"):
    29 if os.name in ("nt", "ce"):
    31     from _ctypes import LoadLibrary as dlopen
    30     from _ctypes import LoadLibrary as dlopen
    32     from _ctypes import FreeLibrary as dlclose
    31     from _ctypes import FreeLibrary as dlclose
    33 elif os.name == "posix":
    32 elif os.name == "posix":
   168                     #dlclose(badhandle)
   167                     #dlclose(badhandle)
   169                     return True
   168                     return True
   170         return False
   169         return False
   171 
   170 
   172     def PythonThreadProc(self):
   171     def PythonThreadProc(self):
       
   172         pyfile = os.path.join(self.workingdir, "runtime.py")
       
   173         if os.path.exists(pyfile):
       
   174             # TODO handle exceptions in runtime.py
       
   175             execfile(pyfile)
   173         res = ""
   176         res = ""
   174         print "PythonThreadProc started"
   177         print "PythonThreadProc started"
   175         while self.PLCStatus == "Started":
   178         while self.PLCStatus == "Started":
   176             cmd = self._PythonIterator(res)
   179             cmd = self._PythonIterator(res)
   177             print "_PythonIterator(", res, ") -> ", cmd
   180             #print "_PythonIterator(", res, ") -> ", cmd
   178             try :
   181             try :
   179                 res = eval(cmd)
   182                 res = eval(cmd)
   180             except Exception,e:
   183             except Exception,e:
   181                 res = "#EXCEPTION : "+str(e)
   184                 res = "#EXCEPTION : "+str(e)
   182                 print res
   185                 print res