add Run and Stop implementation
authorgreg
Fri, 22 Feb 2008 14:57:24 +0100
changeset 107 65fe90d49bf7
parent 106 9810689febb0
child 108 280b458e42e5
add Run and Stop implementation
plugger.py
--- a/plugger.py	Fri Feb 22 12:20:21 2008 +0100
+++ b/plugger.py	Fri Feb 22 14:57:24 2008 +0100
@@ -8,6 +8,7 @@
 import shutil
 from xml.dom import minidom
 import wx
+import subprocess, ctypes, time
 
 #Quick hack to be able to find Beremiz IEC tools. Should be config params.
 base_folder = os.path.split(sys.path[0])[0]
@@ -1023,10 +1024,22 @@
         logger.write_error("Not impl\n")
     
     def _Run(self, logger):
-        logger.write_error("Not impl\n")
+        logger.write("\n")
+        self.pid_plc = 0
+        command_start_plc = os.path.join(self._getBuildPath(),self.GetProjectName() + exe_ext)
+        if os.path.isfile(command_start_plc):
+            logger.write("Starting PLC\n")
+            self.pid_plc = subprocess.Popen(command_start_plc).pid
+        else:
+            logger.write("%s doesn't exist\n" %command_start_plc)
 
     def _Stop(self, logger):
-        logger.write_error("Not impl\n")
+        PROCESS_TERMINATE = 1
+        if self.pid_plc != 0:
+            logger.write("Stopping PLC\n")
+            handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, self.pid_plc)
+            ctypes.windll.kernel32.TerminateProcess(handle, -1)
+            ctypes.windll.kernel32.CloseHandle(handle)
 
     PluginMethods = [
         {"bitmap" : os.path.join("images", "editPLC"),