runtime/PLCObject.py
changeset 2646 d692e01d94f4
parent 2635 ae099881d800
child 2651 231f8bd2cd7d
equal deleted inserted replaced
2645:d15a997859b1 2646:d692e01d94f4
   449         self.PythonThreadCondLock.acquire()
   449         self.PythonThreadCondLock.acquire()
   450         self.PythonThreadCmd = cmd
   450         self.PythonThreadCmd = cmd
   451         self.PythonThreadCond.notify()
   451         self.PythonThreadCond.notify()
   452         self.PythonThreadCondLock.release()
   452         self.PythonThreadCondLock.release()
   453 
   453 
       
   454     def _fail(msg):
       
   455         self.LogMessage(0, msg)
       
   456         self.PLCStatus = PlcStatus.Broken
       
   457         self.StatusChange()
       
   458 
       
   459     def PreStartPLC(self):
       
   460         """ 
       
   461         Here goes actions to be taken just before PLC starts, 
       
   462         with all libraries and python object already created.
       
   463         For example : restore saved proprietary parameters
       
   464         """
       
   465         pass
       
   466 
   454     @RunInMain
   467     @RunInMain
   455     def StartPLC(self):
   468     def StartPLC(self):
   456 
       
   457         def fail(msg):
       
   458             self.LogMessage(0, msg)
       
   459             self.PLCStatus = PlcStatus.Broken
       
   460             self.StatusChange()
       
   461 
   469 
   462         if self.PLClibraryHandle is None:
   470         if self.PLClibraryHandle is None:
   463             if not self.LoadPLC():
   471             if not self.LoadPLC():
   464                 fail(_("Problem starting PLC : can't load PLC"))
   472                 self._fail(_("Problem starting PLC : can't load PLC"))
       
   473 
       
   474         self.PreStartPLC()
   465 
   475 
   466         if self.CurrentPLCFilename is not None and self.PLCStatus == PlcStatus.Stopped:
   476         if self.CurrentPLCFilename is not None and self.PLCStatus == PlcStatus.Stopped:
   467             c_argv = ctypes.c_char_p * len(self.argv)
   477             c_argv = ctypes.c_char_p * len(self.argv)
   468             res = self._startPLC(len(self.argv), c_argv(*self.argv))
   478             res = self._startPLC(len(self.argv), c_argv(*self.argv))
   469             if res == 0:
   479             if res == 0:
   470                 self.PLCStatus = PlcStatus.Started
   480                 self.PLCStatus = PlcStatus.Started
   471                 self.StatusChange()
   481                 self.StatusChange()
   472                 self.PythonThreadCommand("Activate")
   482                 self.PythonThreadCommand("Activate")
   473                 self.LogMessage("PLC started")
   483                 self.LogMessage("PLC started")
   474             else:
   484             else:
   475                 fail(_("Problem starting PLC : error %d" % res))
   485                 self._fail(_("Problem starting PLC : error %d" % res))
   476 
   486 
   477     @RunInMain
   487     @RunInMain
   478     def StopPLC(self):
   488     def StopPLC(self):
   479         if self.PLCStatus == PlcStatus.Started:
   489         if self.PLCStatus == PlcStatus.Started:
   480             self.LogMessage("PLC stopped")
   490             self.LogMessage("PLC stopped")