Added more clear error message in case of access to non declared PLC global from python code
authorEdouard Tisserant
Thu, 16 May 2013 17:40:22 +0900
changeset 1156 9708ed2a4ac2
parent 1155 412e30abf7e5
child 1157 72d14a74c643
Added more clear error message in case of access to non declared PLC global from python code
runtime/PLCObject.py
--- a/runtime/PLCObject.py	Thu May 16 14:47:57 2013 +0900
+++ b/runtime/PLCObject.py	Thu May 16 17:40:22 2013 +0900
@@ -266,11 +266,18 @@
         self.python_runtime_vars["PLCBinary"] = self.PLClibraryHandle
         class PLCSafeGlobals:
             def __getattr__(_self, name):
-                v = self.python_runtime_vars["_"+name+"_ctype"]()
+                try :
+                    t = self.python_runtime_vars["_"+name+"_ctype"]
+                except KeyError:
+                    raise KeyError("Try to get unknown shared global variable : %s"%name)
+                v = t()
                 r = self.python_runtime_vars["_PySafeGetPLCGlob_"+name](ctypes.byref(v))
                 return self.python_runtime_vars["_"+name+"_unpack"](v)
             def __setattr__(_self, name, value):
-                t = self.python_runtime_vars["_"+name+"_ctype"]
+                try :
+                    t = self.python_runtime_vars["_"+name+"_ctype"]
+                except KeyError:
+                    raise KeyError("Try to set unknown shared global variable : %s"%name)
                 v = self.python_runtime_vars["_"+name+"_pack"](t,value)
                 self.python_runtime_vars["_PySafeSetPLCGlob_"+name](ctypes.byref(v))
         self.python_runtime_vars["PLCGlobals"] = PLCSafeGlobals()