39 "win32":".dll", |
39 "win32":".dll", |
40 }.get(sys.platform, "") |
40 }.get(sys.platform, "") |
41 |
41 |
42 class PLCObject(pyro.ObjBase): |
42 class PLCObject(pyro.ObjBase): |
43 _Idxs = [] |
43 _Idxs = [] |
44 def __init__(self, workingdir, daemon, argv): |
44 def __init__(self, workingdir, daemon, argv, statuschange=None): |
45 pyro.ObjBase.__init__(self) |
45 pyro.ObjBase.__init__(self) |
46 self.argv = [workingdir] + argv # force argv[0] to be "path" to exec... |
46 self.argv = [workingdir] + argv # force argv[0] to be "path" to exec... |
47 self.workingdir = workingdir |
47 self.workingdir = workingdir |
48 self.PLCStatus = "Stopped" |
48 self.PLCStatus = "Stopped" |
49 self.PLClibraryHandle = None |
49 self.PLClibraryHandle = None |
50 # Creates fake C funcs proxies |
50 # Creates fake C funcs proxies |
51 self._FreePLC() |
51 self._FreePLC() |
52 self.daemon = daemon |
52 self.daemon = daemon |
|
53 self.statuschange = statuschange |
53 |
54 |
54 # Get the last transfered PLC if connector must be restart |
55 # Get the last transfered PLC if connector must be restart |
55 try: |
56 try: |
56 self.CurrentPLCFilename=open( |
57 self.CurrentPLCFilename=open( |
57 self._GetMD5FileName(), |
58 self._GetMD5FileName(), |
169 c_argv = ctypes.c_char_p * len(self.argv) |
170 c_argv = ctypes.c_char_p * len(self.argv) |
170 if self._LoadNewPLC() and self._startPLC(len(self.argv),c_argv(*self.argv)) == 0: |
171 if self._LoadNewPLC() and self._startPLC(len(self.argv),c_argv(*self.argv)) == 0: |
171 if debug: |
172 if debug: |
172 self._resumeDebug() |
173 self._resumeDebug() |
173 self.PLCStatus = "Started" |
174 self.PLCStatus = "Started" |
|
175 if self.statuschange is not None: |
|
176 self.statuschange(self.PLCStatus) |
174 return True |
177 return True |
175 else: |
178 else: |
176 print "_StartPLC did not return 0 !" |
179 print "_StartPLC did not return 0 !" |
177 self._DoStopPLC() |
180 self._DoStopPLC() |
178 return False |
181 return False |
179 |
182 |
180 def _DoStopPLC(self): |
183 def _DoStopPLC(self): |
181 self._stopPLC() |
184 self._stopPLC() |
182 self.PLCStatus = "Stopped" |
185 self.PLCStatus = "Stopped" |
|
186 if self.statuschange is not None: |
|
187 self.statuschange(self.PLCStatus) |
183 if self._FreePLC(): |
188 if self._FreePLC(): |
184 self.PLCStatus = "Dirty" |
189 self.PLCStatus = "Dirty" |
185 return True |
190 return True |
186 |
191 |
187 def StopPLC(self): |
192 def StopPLC(self): |