connectors/PYRO/__init__.py
changeset 1434 6e0cd0ceabb7
parent 1116 300f98a8d4c6
child 1440 e8daabf2c438
equal deleted inserted replaced
1433:4a45f6642523 1434:6e0cd0ceabb7
    54             r.close()
    54             r.close()
    55         except Exception, msg:
    55         except Exception, msg:
    56             confnodesroot.logger.write_error(_("MDNS resolution failure for '%s'\n")%location)
    56             confnodesroot.logger.write_error(_("MDNS resolution failure for '%s'\n")%location)
    57             confnodesroot.logger.write_error(traceback.format_exc())
    57             confnodesroot.logger.write_error(traceback.format_exc())
    58             return None
    58             return None
    59     
    59 
    60     # Try to get the proxy object
    60     # Try to get the proxy object
    61     try :
    61     try :
    62         RemotePLCObjectProxy = pyro.getAttrProxyForURI("PYROLOC://"+location+"/PLCObject")
    62         RemotePLCObjectProxy = pyro.getAttrProxyForURI("PYROLOC://"+location+"/PLCObject")
    63     except Exception, msg:
    63     except Exception, msg:
    64         confnodesroot.logger.write_error(_("Connection to '%s' failed.\n")%location)
    64         confnodesroot.logger.write_error(_("Connection to '%s' failed.\n")%location)
    85                 print errmess
    85                 print errmess
    86                 confnodesroot._SetConnector(None)
    86                 confnodesroot._SetConnector(None)
    87             return default
    87             return default
    88         return catcher_func
    88         return catcher_func
    89 
    89 
    90     # Check connection is effective. 
    90     # Check connection is effective.
    91     # lambda is for getattr of GetPLCstatus to happen inside catcher
    91     # lambda is for getattr of GetPLCstatus to happen inside catcher
    92     if PyroCatcher(lambda:RemotePLCObjectProxy.GetPLCstatus())() is None:
    92     if PyroCatcher(lambda:RemotePLCObjectProxy.GetPLCstatus())() is None:
    93         confnodesroot.logger.write_error(_("Cannot get PLC status - connection failed.\n"))
    93         confnodesroot.logger.write_error(_("Cannot get PLC status - connection failed.\n"))
    94         return None
    94         return None
    95 
    95 
   110             """
   110             """
   111             return RemotePLCObjectProxy
   111             return RemotePLCObjectProxy
   112 
   112 
   113         def _PyroStartPLC(self, *args, **kwargs):
   113         def _PyroStartPLC(self, *args, **kwargs):
   114             """
   114             """
   115             confnodesroot._connector.GetPyroProxy() is used 
   115             confnodesroot._connector.GetPyroProxy() is used
   116             rather than RemotePLCObjectProxy because
   116             rather than RemotePLCObjectProxy because
   117             object is recreated meanwhile, 
   117             object is recreated meanwhile,
   118             so we must not keep ref to it here
   118             so we must not keep ref to it here
   119             """
   119             """
   120             current_status, log_count = confnodesroot._connector.GetPyroProxy().GetPLCstatus()
   120             current_status, log_count = confnodesroot._connector.GetPyroProxy().GetPLCstatus()
   121             if current_status == "Dirty":
   121             if current_status == "Dirty":
   122                 """
   122                 """
   139             for safe use in from debug thread, must use the copy
   139             for safe use in from debug thread, must use the copy
   140             """
   140             """
   141             if self.RemotePLCObjectProxyCopy is None:
   141             if self.RemotePLCObjectProxyCopy is None:
   142                 self.RemotePLCObjectProxyCopy = copy.copy(confnodesroot._connector.GetPyroProxy())
   142                 self.RemotePLCObjectProxyCopy = copy.copy(confnodesroot._connector.GetPyroProxy())
   143             return self.RemotePLCObjectProxyCopy.GetTraceVariables()
   143             return self.RemotePLCObjectProxyCopy.GetTraceVariables()
   144         GetTraceVariables = PyroCatcher(_PyroGetTraceVariables,("Broken",None,None))
   144         GetTraceVariables = PyroCatcher(_PyroGetTraceVariables,("Broken",None))
   145 
   145 
   146         def _PyroGetPLCstatus(self):
   146         def _PyroGetPLCstatus(self):
   147             return RemotePLCObjectProxy.GetPLCstatus()
   147             return RemotePLCObjectProxy.GetPLCstatus()
   148         GetPLCstatus = PyroCatcher(_PyroGetPLCstatus, ("Broken",None))
   148         GetPLCstatus = PyroCatcher(_PyroGetPLCstatus, ("Broken",None))
   149 
   149 
   159                 member = PyroCatcher(my_local_func, None)
   159                 member = PyroCatcher(my_local_func, None)
   160                 self.__dict__[attrName] = member
   160                 self.__dict__[attrName] = member
   161             return member
   161             return member
   162 
   162 
   163     return PyroProxyProxy()
   163     return PyroProxyProxy()
   164     
       
   165 
   164 
       
   165