59 # lambda is for getattr of GetPLCstatus to happen inside catcher |
59 # lambda is for getattr of GetPLCstatus to happen inside catcher |
60 if PyroCatcher(lambda:RemotePLCObjectProxy.GetPLCstatus())() == None: |
60 if PyroCatcher(lambda:RemotePLCObjectProxy.GetPLCstatus())() == None: |
61 pluginsroot.logger.write_error("Cannot get PLC status - connection failed.\n") |
61 pluginsroot.logger.write_error("Cannot get PLC status - connection failed.\n") |
62 return None |
62 return None |
63 |
63 |
64 # for safe use in from debug thread, must create a copy |
64 |
65 RemotePLCObjectProxyCopy = copy.copy(RemotePLCObjectProxy) |
|
66 |
|
67 class PyroProxyProxy: |
65 class PyroProxyProxy: |
68 """ |
66 """ |
69 A proxy proxy class to handle Beremiz Pyro interface specific behavior. |
67 A proxy proxy class to handle Beremiz Pyro interface specific behavior. |
70 And to put pyro exception catcher in between caller and pyro proxy |
68 And to put pyro exception catcher in between caller and pyro proxy |
71 """ |
69 """ |
|
70 def __init__(self): |
|
71 # for safe use in from debug thread, must create a copy |
|
72 self.RemotePLCObjectProxyCopy = None |
|
73 |
72 def GetPyroProxy(self): |
74 def GetPyroProxy(self): |
73 """ |
75 """ |
74 This func returns the real Pyro Proxy. |
76 This func returns the real Pyro Proxy. |
75 Use this if you musn't keep reference to it. |
77 Use this if you musn't keep reference to it. |
76 """ |
78 """ |
92 pluginsroot._connector.GetPyroProxy().ForceReload() |
94 pluginsroot._connector.GetPyroProxy().ForceReload() |
93 pluginsroot._Disconnect() |
95 pluginsroot._Disconnect() |
94 # let remote PLC time to resurect.(freeze app) |
96 # let remote PLC time to resurect.(freeze app) |
95 sleep(0.5) |
97 sleep(0.5) |
96 pluginsroot._Connect() |
98 pluginsroot._Connect() |
|
99 self.RemotePLCObjectProxyCopy = copy.copy(pluginsroot._connector.GetPyroProxy()) |
97 return pluginsroot._connector.GetPyroProxy().StartPLC(*args, **kwargs) |
100 return pluginsroot._connector.GetPyroProxy().StartPLC(*args, **kwargs) |
98 StartPLC = PyroCatcher(_PyroStartPLC, False) |
101 StartPLC = PyroCatcher(_PyroStartPLC, False) |
99 |
102 |
100 |
103 |
101 def _PyroGetTraceVariables(self): |
104 def _PyroGetTraceVariables(self): |
102 """ |
105 """ |
103 for safe use in from debug thread, must use the copy |
106 for safe use in from debug thread, must use the copy |
104 """ |
107 """ |
105 if RemotePLCObjectProxyCopy.GetPLCstatus() == "Started": |
108 if self.RemotePLCObjectProxyCopy is not None and self.RemotePLCObjectProxyCopy.GetPLCstatus() == "Started": |
106 return RemotePLCObjectProxyCopy.GetTraceVariables() |
109 return self.RemotePLCObjectProxyCopy.GetTraceVariables() |
107 else: |
110 else: |
108 return None,None |
111 return None,None |
109 GetTraceVariables = PyroCatcher(_PyroGetTraceVariables) |
112 GetTraceVariables = PyroCatcher(_PyroGetTraceVariables,(None,None)) |
110 |
113 |
111 |
114 |
112 def __getattr__(self, attrName): |
115 def __getattr__(self, attrName): |
113 member = self.__dict__.get(attrName, None) |
116 member = self.__dict__.get(attrName, None) |
114 if member is None: |
117 if member is None: |