PLCControler.py
changeset 24 364320323b4d
parent 13 69075340d6a9
child 27 dae55dd9ee14
--- a/PLCControler.py	Thu Jun 21 10:23:26 2007 +0200
+++ b/PLCControler.py	Mon Jun 25 18:57:14 2007 +0200
@@ -25,12 +25,15 @@
 from minixsv import pyxsval
 import cPickle
 import os,sys,re
+from datetime import *
 
 from plcopen import plcopen
 from plcopen.structures import *
 from graphics.GraphicCommons import *
 from PLCGenerator import *
 
+duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m)?(?:([0-9]{1,2})s)?(?:([0-9]{1,3})ms)?")
+
 [ITEM_UNEDITABLE, ITEM_PROJECT, ITEM_POU, ITEM_CLASS, ITEM_VARIABLE,
  ITEM_TRANSITION, ITEM_ACTION, ITEM_CONFIGURATION, ITEM_RESOURCE] = range(9)
 
@@ -1776,8 +1779,16 @@
             new_task.setName(task["Name"])
             if task["Single"] != "":
                 new_task.setSingle(task["Single"])
-            if task["Interval"] != "":
-                new_task.setInterval(task["Interval"])
+            result = duration_model.match(task["Interval"]).groups()
+            if reduce(lambda x, y: x or y != None, result):
+                values = []
+                for value in result:
+                    if value != None:
+                        values.append(int(value))
+                    else:
+                        values.append(0)
+                values[3] = values[3] * 1000
+                new_task.setInterval(time(*values))
             new_task.priority.setValue(int(task["Priority"]))
             if task["Name"] != "":
                 task_list[task["Name"]] = new_task
@@ -1807,7 +1818,16 @@
                 new_task["Single"] = ""
             interval = task.getInterval()
             if interval:
-                new_task["Interval"] = interval
+                text = ""
+                if interval.hour != 0:
+                    text += "%dh"%interval.hour
+                if interval.minute != 0:
+                    text += "%dm"%interval.minute
+                if interval.second != 0:
+                    text += "%ds"%interval.second
+                if interval.microsecond != 0:
+                    text += "%dms"%(interval.microsecond / 1000)
+                new_task["Interval"] = text
             else:
                 new_task["Interval"] = ""
             new_task["Priority"] = str(task.priority.getValue())