connectors/PYRO/__init__.py
changeset 218 71fddab24be9
parent 203 cb9901076a21
child 231 f1db3ce8f40a
equal deleted inserted replaced
217:f3eb35df4d87 218:71fddab24be9
    42     def PyroCatcher(func, default=None):
    42     def PyroCatcher(func, default=None):
    43         """
    43         """
    44         A function that catch a pyro exceptions, write error to logger
    44         A function that catch a pyro exceptions, write error to logger
    45         and return defaul value when it happen
    45         and return defaul value when it happen
    46         """
    46         """
    47         def cather_func(*args,**kwargs):
    47         def catcher_func(*args,**kwargs):
    48             try:
    48             try:
    49                 return func(*args,**kwargs)
    49                 return func(*args,**kwargs)
    50             except PyroError,e:
    50             except PyroError,e:
    51                 #pluginsroot.logger.write_error(traceback.format_exc())
    51                 #pluginsroot.logger.write_error(traceback.format_exc())
    52                 pluginsroot.logger.write_error(str(e))
    52                 pluginsroot.logger.write_error(str(e))
    53                 pluginsroot._Disconnect()
    53                 pluginsroot._Disconnect()
    54                 return default
    54                 return default
    55         return cather_func
    55         return catcher_func
    56 
    56 
    57     # Check connection is effective. 
    57     # Check connection is effective. 
    58     # lambda is for getattr of GetPLCstatus to happen inside catcher
    58     # lambda is for getattr of GetPLCstatus to happen inside catcher
    59     if PyroCatcher(lambda:RemotePLCObjectProxy.GetPLCstatus())() == None:
    59     if PyroCatcher(lambda:RemotePLCObjectProxy.GetPLCstatus())() == None:
    60         pluginsroot.logger.write_error("Cannot get PLC status - connection failed.\n")
    60         pluginsroot.logger.write_error("Cannot get PLC status - connection failed.\n")