plugger.py
changeset 107 65fe90d49bf7
parent 106 9810689febb0
child 108 280b458e42e5
equal deleted inserted replaced
106:9810689febb0 107:65fe90d49bf7
     6 import plugins
     6 import plugins
     7 import types
     7 import types
     8 import shutil
     8 import shutil
     9 from xml.dom import minidom
     9 from xml.dom import minidom
    10 import wx
    10 import wx
       
    11 import subprocess, ctypes, time
    11 
    12 
    12 #Quick hack to be able to find Beremiz IEC tools. Should be config params.
    13 #Quick hack to be able to find Beremiz IEC tools. Should be config params.
    13 base_folder = os.path.split(sys.path[0])[0]
    14 base_folder = os.path.split(sys.path[0])[0]
    14 sys.path.append(os.path.join(base_folder, "plcopeneditor"))
    15 sys.path.append(os.path.join(base_folder, "plcopeneditor"))
    15 
    16 
  1021 
  1022 
  1022     def _Clean(self, logger):
  1023     def _Clean(self, logger):
  1023         logger.write_error("Not impl\n")
  1024         logger.write_error("Not impl\n")
  1024     
  1025     
  1025     def _Run(self, logger):
  1026     def _Run(self, logger):
  1026         logger.write_error("Not impl\n")
  1027         logger.write("\n")
       
  1028         self.pid_plc = 0
       
  1029         command_start_plc = os.path.join(self._getBuildPath(),self.GetProjectName() + exe_ext)
       
  1030         if os.path.isfile(command_start_plc):
       
  1031             logger.write("Starting PLC\n")
       
  1032             self.pid_plc = subprocess.Popen(command_start_plc).pid
       
  1033         else:
       
  1034             logger.write("%s doesn't exist\n" %command_start_plc)
  1027 
  1035 
  1028     def _Stop(self, logger):
  1036     def _Stop(self, logger):
  1029         logger.write_error("Not impl\n")
  1037         PROCESS_TERMINATE = 1
       
  1038         if self.pid_plc != 0:
       
  1039             logger.write("Stopping PLC\n")
       
  1040             handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, self.pid_plc)
       
  1041             ctypes.windll.kernel32.TerminateProcess(handle, -1)
       
  1042             ctypes.windll.kernel32.CloseHandle(handle)
  1030 
  1043 
  1031     PluginMethods = [
  1044     PluginMethods = [
  1032         {"bitmap" : os.path.join("images", "editPLC"),
  1045         {"bitmap" : os.path.join("images", "editPLC"),
  1033          "name" : "Edit PLC",
  1046          "name" : "Edit PLC",
  1034          "tooltip" : "Edit PLC program with PLCOpenEditor",
  1047          "tooltip" : "Edit PLC program with PLCOpenEditor",