32 |
32 |
33 LOCATIONDATATYPES = {"X" : ["BOOL"], |
33 LOCATIONDATATYPES = {"X" : ["BOOL"], |
34 "B" : ["SINT", "USINT", "BYTE", "STRING"], |
34 "B" : ["SINT", "USINT", "BYTE", "STRING"], |
35 "W" : ["INT", "UINT", "WORD", "WSTRING"], |
35 "W" : ["INT", "UINT", "WORD", "WSTRING"], |
36 "D" : ["DINT", "UDINT", "REAL", "DWORD"], |
36 "D" : ["DINT", "UDINT", "REAL", "DWORD"], |
37 "L" : ["LINT", "ULINT", "LREAL", "LWORD"]} |
37 "L" : ["LINT", "ULINT", "LREAL", "LWORD"]} |
38 |
38 |
39 def gen_get_function(f): |
39 def gen_get_function(f): |
40 def get_function(v): |
40 def get_function(v): |
41 try: |
41 try: |
42 return f(v) |
42 return f(v) |
66 IEC_TIME_MODEL = re.compile("(?:(?:T|TIME)#)?(-)?(?:(%(float)s)D_?)?(?:(%(float)s)H_?)?(?:(%(float)s)M(?!S)_?)?(?:(%(float)s)S_?)?(?:(%(float)s)MS)?$" % {"float": "[0-9]+(?:\.[0-9]+)?"}) |
66 IEC_TIME_MODEL = re.compile("(?:(?:T|TIME)#)?(-)?(?:(%(float)s)D_?)?(?:(%(float)s)H_?)?(?:(%(float)s)M(?!S)_?)?(?:(%(float)s)S_?)?(?:(%(float)s)MS)?$" % {"float": "[0-9]+(?:\.[0-9]+)?"}) |
67 IEC_DATE_MODEL = re.compile("(?:(?:D|DATE)#)?([0-9]{4})-([0-9]{2})-([0-9]{2})$") |
67 IEC_DATE_MODEL = re.compile("(?:(?:D|DATE)#)?([0-9]{4})-([0-9]{2})-([0-9]{2})$") |
68 IEC_DATETIME_MODEL = re.compile("(?:(?:DT|DATE_AND_TIME)#)?([0-9]{4})-([0-9]{2})-([0-9]{2})-([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]+)?)$") |
68 IEC_DATETIME_MODEL = re.compile("(?:(?:DT|DATE_AND_TIME)#)?([0-9]{4})-([0-9]{2})-([0-9]{2})-([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]+)?)$") |
69 IEC_TIMEOFDAY_MODEL = re.compile("(?:(?:TOD|TIME_OF_DAY)#)?([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]+)?)$") |
69 IEC_TIMEOFDAY_MODEL = re.compile("(?:(?:TOD|TIME_OF_DAY)#)?([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]+)?)$") |
70 |
70 |
71 def gettime(v): |
71 def gettime(v): |
72 result = IEC_TIME_MODEL.match(v.upper()) |
72 result = IEC_TIME_MODEL.match(v.upper()) |
73 if result is not None: |
73 if result is not None: |
74 negative, days, hours, minutes, seconds, milliseconds = result.groups() |
74 negative, days, hours, minutes, seconds, milliseconds = result.groups() |
75 microseconds = 0 |
75 microseconds = 0 |
76 not_null = False |
76 not_null = False |
85 if not not_null: |
85 if not not_null: |
86 return None |
86 return None |
87 if negative is not None: |
87 if negative is not None: |
88 microseconds = -microseconds |
88 microseconds = -microseconds |
89 return datetime.timedelta(microseconds=microseconds) |
89 return datetime.timedelta(microseconds=microseconds) |
90 |
90 |
91 else: |
91 else: |
92 return None |
92 return None |
93 |
93 |
94 def getdate(v): |
94 def getdate(v): |
95 result = IEC_DATE_MODEL.match(v.upper()) |
95 result = IEC_DATE_MODEL.match(v.upper()) |
96 if result is not None: |
96 if result is not None: |
99 date = datetime.datetime(int(year), int(month), int(day)) |
99 date = datetime.datetime(int(year), int(month), int(day)) |
100 except ValueError, e: |
100 except ValueError, e: |
101 return None |
101 return None |
102 base_date = datetime.datetime(1970, 1, 1) |
102 base_date = datetime.datetime(1970, 1, 1) |
103 return date - base_date |
103 return date - base_date |
104 else: |
104 else: |
105 return None |
105 return None |
106 |
106 |
107 def getdatetime(v): |
107 def getdatetime(v): |
108 result = IEC_DATETIME_MODEL.match(v.upper()) |
108 result = IEC_DATETIME_MODEL.match(v.upper()) |
109 if result is not None: |
109 if result is not None: |
112 date = datetime.datetime(int(year), int(month), int(day), int(hours), int(minutes), int(float(seconds)), int((float(seconds) * SECOND) % SECOND)) |
112 date = datetime.datetime(int(year), int(month), int(day), int(hours), int(minutes), int(float(seconds)), int((float(seconds) * SECOND) % SECOND)) |
113 except ValueError, e: |
113 except ValueError, e: |
114 return None |
114 return None |
115 base_date = datetime.datetime(1970, 1, 1) |
115 base_date = datetime.datetime(1970, 1, 1) |
116 return date - base_date |
116 return date - base_date |
117 else: |
117 else: |
118 return None |
118 return None |
119 |
119 |
120 def gettimeofday(v): |
120 def gettimeofday(v): |
121 result = IEC_TIMEOFDAY_MODEL.match(v.upper()) |
121 result = IEC_TIMEOFDAY_MODEL.match(v.upper()) |
122 if result is not None: |
122 if result is not None: |
157 #------------------------------------------------------------------------------- |
157 #------------------------------------------------------------------------------- |
158 |
158 |
159 class ForceVariableDialog(wx.TextEntryDialog): |
159 class ForceVariableDialog(wx.TextEntryDialog): |
160 |
160 |
161 def __init__(self, parent, iec_type, defaultValue=""): |
161 def __init__(self, parent, iec_type, defaultValue=""): |
162 wx.TextEntryDialog.__init__(self, parent, message = _("Forcing Variable Value"), |
162 wx.TextEntryDialog.__init__(self, parent, message = _("Forcing Variable Value"), |
163 caption = _("Please enter value for a \"%s\" variable:") % iec_type, defaultValue = defaultValue, |
163 caption = _("Please enter value for a \"%s\" variable:") % iec_type, defaultValue = defaultValue, |
164 style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition) |
164 style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition) |
165 |
165 |
166 self.IEC_Type = iec_type |
166 self.IEC_Type = iec_type |
167 |
167 |
168 self.Bind(wx.EVT_BUTTON, self.OnOK, |
168 self.Bind(wx.EVT_BUTTON, self.OnOK, |
169 self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton()) |
169 self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton()) |
170 self.ValueTextCtrl=self.GetSizer().GetItem(1).GetWindow() |
170 self.ValueTextCtrl=self.GetSizer().GetItem(1).GetWindow() |
171 if self.IEC_Type == "BOOL": |
171 if self.IEC_Type == "BOOL": |
172 self.ToggleButton = wx.ToggleButton(self, label=_("Toggle value")) |
172 self.ToggleButton = wx.ToggleButton(self, label=_("Toggle value")) |
173 value=GetTypeValue[self.IEC_Type](defaultValue) |
173 value=GetTypeValue[self.IEC_Type](defaultValue) |