64 # python side PLC global variables access stub |
64 # python side PLC global variables access stub |
65 globalstubs = "\n".join(["""\ |
65 globalstubs = "\n".join(["""\ |
66 _%(name)s_ctype, _%(name)s_unpack, _%(name)s_pack = \\ |
66 _%(name)s_ctype, _%(name)s_unpack, _%(name)s_pack = \\ |
67 TypeTranslator["%(IECtype)s"] |
67 TypeTranslator["%(IECtype)s"] |
68 _PySafeGetPLCGlob_%(name)s = PLCBinary.__SafeGetPLCGlob_%(name)s |
68 _PySafeGetPLCGlob_%(name)s = PLCBinary.__SafeGetPLCGlob_%(name)s |
69 _PySafeGetPLCGlob_%(name)s.restype = _%(name)s_ctype |
69 _PySafeGetPLCGlob_%(name)s.restype = None |
70 _PySafeGetPLCGlob_%(name)s.argtypes = [] |
70 _PySafeGetPLCGlob_%(name)s.argtypes = [ctypes.POINTER(_%(name)s_ctype)] |
71 _PySafeSetPLCGlob_%(name)s = PLCBinary.__SafeSetPLCGlob_%(name)s |
71 _PySafeSetPLCGlob_%(name)s = PLCBinary.__SafeSetPLCGlob_%(name)s |
72 _PySafeSetPLCGlob_%(name)s.restype = None |
72 _PySafeSetPLCGlob_%(name)s.restype = None |
73 _PySafeSetPLCGlob_%(name)s.argtypes = [ctypes.POINTER(_%(name)s_ctype)] |
73 _PySafeSetPLCGlob_%(name)s.argtypes = [ctypes.POINTER(_%(name)s_ctype)] |
74 """ % { "name": variable.getname(), |
74 """ % { "name": variable.getname(), |
75 "configname": configname.upper(), |
75 "configname": configname.upper(), |
125 %(IECtype)s __%(name)s_rbuffer = %(initial)s; |
125 %(IECtype)s __%(name)s_rbuffer = %(initial)s; |
126 %(IECtype)s __%(name)s_wbuffer; |
126 %(IECtype)s __%(name)s_wbuffer; |
127 long __%(name)s_rlock = 0; |
127 long __%(name)s_rlock = 0; |
128 long __%(name)s_wlock = 0; |
128 long __%(name)s_wlock = 0; |
129 int __%(name)s_wbuffer_written = 0; |
129 int __%(name)s_wbuffer_written = 0; |
130 %(IECtype)s __SafeGetPLCGlob_%(name)s(){ |
130 void __SafeGetPLCGlob_%(name)s(%(IECtype)s *pvalue){ |
131 %(IECtype)s res; |
131 %(IECtype)s res; |
132 while(AtomicCompareExchange(&__%(name)s_rlock, 0, 1)); |
132 while(AtomicCompareExchange(&__%(name)s_rlock, 0, 1)); |
133 res = __%(name)s_rbuffer; |
133 *pvalue = __%(name)s_rbuffer; |
134 AtomicCompareExchange((long*)&__%(name)s_rlock, 1, 0); |
134 AtomicCompareExchange((long*)&__%(name)s_rlock, 1, 0); |
135 return res; |
|
136 } |
135 } |
137 __SafeSetPLCGlob_%(name)s(%(IECtype)s *value){ |
136 __SafeSetPLCGlob_%(name)s(%(IECtype)s *value){ |
138 while(AtomicCompareExchange(&__%(name)s_wlock, 0, 1)); |
137 while(AtomicCompareExchange(&__%(name)s_wlock, 0, 1)); |
139 __%(name)s_wbuffer = *value; |
138 __%(name)s_wbuffer = *value; |
140 __%(name)s_wbuffer_written = 1; |
139 __%(name)s_wbuffer_written = 1; |
205 matiec_flags = '"-I%s"'%os.path.abspath( |
204 matiec_flags = '"-I%s"'%os.path.abspath( |
206 self.GetCTRoot().GetIECLibPath()) |
205 self.GetCTRoot().GetIECLibPath()) |
207 |
206 |
208 return ([(Gen_PyCfile_path, matiec_flags)], |
207 return ([(Gen_PyCfile_path, matiec_flags)], |
209 "", |
208 "", |
210 False, |
209 True, |
211 ("runtime_%s.py"%location_str, file(runtimefile_path,"rb"))) |
210 ("runtime_%s.py"%location_str, file(runtimefile_path,"rb"))) |
212 |
211 |