runtime/PLCObject.py
changeset 2608 a332f989f0b8
parent 2602 19dc6b830e7d
child 2612 98eb3d1c56b0
equal deleted inserted replaced
2607:bf0c1a40cf37 2608:a332f989f0b8
   107         # Get the last transfered PLC
   107         # Get the last transfered PLC
   108         try:
   108         try:
   109             self.CurrentPLCFilename = open(
   109             self.CurrentPLCFilename = open(
   110                 self._GetMD5FileName(),
   110                 self._GetMD5FileName(),
   111                 "r").read().strip() + lib_ext
   111                 "r").read().strip() + lib_ext
   112             if self.LoadPLC():
   112             self.PLCStatus = PlcStatus.Stopped
   113                 self.PLCStatus = PlcStatus.Stopped
   113             if autostart:
   114                 if autostart:
   114                 if self.LoadPLC():
   115                     self.StartPLC()
   115                     self.StartPLC()
   116                     return
   116                     return
   117         except Exception:
   117         except Exception:
   118             self.PLCStatus = PlcStatus.Empty
   118             self.PLCStatus = PlcStatus.Empty
   119             self.CurrentPLCFilename = None
   119             self.CurrentPLCFilename = None
   449         self.PythonThreadCond.notify()
   449         self.PythonThreadCond.notify()
   450         self.PythonThreadCondLock.release()
   450         self.PythonThreadCondLock.release()
   451 
   451 
   452     @RunInMain
   452     @RunInMain
   453     def StartPLC(self):
   453     def StartPLC(self):
       
   454 
       
   455         def fail(msg):
       
   456             self.LogMessage(0, msg)
       
   457             self.PLCStatus = PlcStatus.Broken
       
   458             self.StatusChange()
       
   459 
       
   460         if self.PLClibraryHandle is None:
       
   461             if not self.LoadPLC():
       
   462                 fail(_("Problem starting PLC : can't load PLC"))
       
   463 
   454         if self.CurrentPLCFilename is not None and self.PLCStatus == PlcStatus.Stopped:
   464         if self.CurrentPLCFilename is not None and self.PLCStatus == PlcStatus.Stopped:
   455             c_argv = ctypes.c_char_p * len(self.argv)
   465             c_argv = ctypes.c_char_p * len(self.argv)
   456             res = self._startPLC(len(self.argv), c_argv(*self.argv))
   466             res = self._startPLC(len(self.argv), c_argv(*self.argv))
   457             if res == 0:
   467             if res == 0:
   458                 self.PLCStatus = PlcStatus.Started
   468                 self.PLCStatus = PlcStatus.Started
   459                 self.StatusChange()
   469                 self.StatusChange()
   460                 self.PythonThreadCommand("Activate")
   470                 self.PythonThreadCommand("Activate")
   461                 self.LogMessage("PLC started")
   471                 self.LogMessage("PLC started")
   462             else:
   472             else:
   463                 self.LogMessage(0, _("Problem starting PLC : error %d" % res))
   473                 fail(_("Problem starting PLC : error %d" % res))
   464                 self.PLCStatus = PlcStatus.Broken
       
   465                 self.StatusChange()
       
   466 
   474 
   467     @RunInMain
   475     @RunInMain
   468     def StopPLC(self):
   476     def StopPLC(self):
   469         if self.PLCStatus == PlcStatus.Started:
   477         if self.PLCStatus == PlcStatus.Started:
   470             self.LogMessage("PLC stopped")
   478             self.LogMessage("PLC stopped")