runtime/PLCObject.py
changeset 302 d962b3d503b5
parent 301 87c925eaaa3a
child 319 bdd82ac65f5d
equal deleted inserted replaced
301:87c925eaaa3a 302:d962b3d503b5
   191                 # or even call _PythonThreadProc itself.
   191                 # or even call _PythonThreadProc itself.
   192                 if os.path.exists(hmifile):
   192                 if os.path.exists(hmifile):
   193                    execfile(hmifile, self.python_threads_vars)
   193                    execfile(hmifile, self.python_threads_vars)
   194                 execfile(pyfile, self.python_threads_vars)
   194                 execfile(pyfile, self.python_threads_vars)
   195                 try:
   195                 try:
       
   196                    wx = self.python_threads_vars['wx']
   196                    # try to instanciate the first frame found.
   197                    # try to instanciate the first frame found.
   197                    for name, obj in self.python_threads_vars.iteritems():
   198                    for name, obj in self.python_threads_vars.iteritems():
   198                        # obj is a class
   199                        # obj is a class
   199                        if type(obj)==type(type) and issubclass(obj,self.python_threads_vars['wx'].Frame):
   200                        if type(obj)==type(type) and issubclass(obj,wx.Frame):
   200                            self.hmi_frame = obj(None)
   201                            def create_frame():
   201                            self.python_threads_vars['_'+name] = self.hmi_frame
   202                                self.hmi_frame = obj(None)
   202                            self.hmi_frame.Show()
   203                                self.python_threads_vars[name] = self.hmi_frame
       
   204                                # keep track of class... never know
       
   205                                self.python_threads_vars['Class_'+name] = obj
       
   206                                self.hmi_frame.Bind(wx.EVT_CLOSE, OnCloseFrame)
       
   207                                self.hmi_frame.Show()
       
   208                            
       
   209                            def OnCloseFrame(evt):
       
   210                                self.hmi_frame.Destroy()
       
   211                                self.hmi_frame = None
       
   212                                wx.MessageBox("Please stop PLC to close")
       
   213                                #wx.CallAfter(self.StopPLC)
       
   214                                create_frame()
       
   215                                #evt.Skip()
       
   216                            create_frame()
   203                            break
   217                            break
   204                 except:
   218                 except:
   205                     PLCprint(traceback.format_exc())
   219                     PLCprint(traceback.format_exc())
   206             except:
   220             except:
   207                 PLCprint(traceback.format_exc())
   221                 PLCprint(traceback.format_exc())
   351     class IEC_STRING(ctypes.Structure):
   365     class IEC_STRING(ctypes.Structure):
   352         """
   366         """
   353         Must be changed according to changes in iec_types.h
   367         Must be changed according to changes in iec_types.h
   354         """
   368         """
   355         _fields_ = [("len", ctypes.c_uint8),
   369         _fields_ = [("len", ctypes.c_uint8),
   356                     ("body", ctypes.c_char * 40)] 
   370                     ("body", ctypes.c_char * 127)] 
   357     
   371     
   358     TypeTranslator = {"BOOL" :       (ctypes.c_uint8, lambda x:x.value!=0),
   372     TypeTranslator = {"BOOL" :       (ctypes.c_uint8, lambda x:x.value!=0),
   359                       "STEP" :       (ctypes.c_uint8, lambda x:x.value),
   373                       "STEP" :       (ctypes.c_uint8, lambda x:x.value),
   360                       "TRANSITION" : (ctypes.c_uint8, lambda x:x.value),
   374                       "TRANSITION" : (ctypes.c_uint8, lambda x:x.value),
   361                       "ACTION" :     (ctypes.c_uint8, lambda x:x.value),
   375                       "ACTION" :     (ctypes.c_uint8, lambda x:x.value),