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") |