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 |
39 def gen_get_function(f): |
40 def gen_get_function(f): |
40 def get_function(v): |
41 def get_function(v): |
41 try: |
42 try: |
42 return f(v) |
43 return f(v) |
43 except: |
44 except: |
44 return None |
45 return None |
45 return get_function |
46 return get_function |
|
47 |
46 |
48 |
47 def gen_get_string(delimiter): |
49 def gen_get_string(delimiter): |
48 STRING_MODEL = re.compile("%(delimiter)s([^%(delimiter)s]*)%(delimiter)s$" % {"delimiter": delimiter}) |
50 STRING_MODEL = re.compile("%(delimiter)s([^%(delimiter)s]*)%(delimiter)s$" % {"delimiter": delimiter}) |
49 def get_string(v): |
51 def get_string(v): |
50 result = STRING_MODEL.match(v) |
52 result = STRING_MODEL.match(v) |
65 |
67 |
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]+)?"}) |
68 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})$") |
69 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]+)?)$") |
70 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]+)?)$") |
71 IEC_TIMEOFDAY_MODEL = re.compile("(?:(?:TOD|TIME_OF_DAY)#)?([0-9]{2}):([0-9]{2}):([0-9]{2}(?:\.[0-9]+)?)$") |
|
72 |
70 |
73 |
71 def gettime(v): |
74 def gettime(v): |
72 result = IEC_TIME_MODEL.match(v.upper()) |
75 result = IEC_TIME_MODEL.match(v.upper()) |
73 if result is not None: |
76 if result is not None: |
74 negative, days, hours, minutes, seconds, milliseconds = result.groups() |
77 negative, days, hours, minutes, seconds, milliseconds = result.groups() |
89 return datetime.timedelta(microseconds=microseconds) |
92 return datetime.timedelta(microseconds=microseconds) |
90 |
93 |
91 else: |
94 else: |
92 return None |
95 return None |
93 |
96 |
|
97 |
94 def getdate(v): |
98 def getdate(v): |
95 result = IEC_DATE_MODEL.match(v.upper()) |
99 result = IEC_DATE_MODEL.match(v.upper()) |
96 if result is not None: |
100 if result is not None: |
97 year, month, day = result.groups() |
101 year, month, day = result.groups() |
98 try: |
102 try: |
102 base_date = datetime.datetime(1970, 1, 1) |
106 base_date = datetime.datetime(1970, 1, 1) |
103 return date - base_date |
107 return date - base_date |
104 else: |
108 else: |
105 return None |
109 return None |
106 |
110 |
|
111 |
107 def getdatetime(v): |
112 def getdatetime(v): |
108 result = IEC_DATETIME_MODEL.match(v.upper()) |
113 result = IEC_DATETIME_MODEL.match(v.upper()) |
109 if result is not None: |
114 if result is not None: |
110 year, month, day, hours, minutes, seconds = result.groups() |
115 year, month, day, hours, minutes, seconds = result.groups() |
111 try: |
116 try: |
114 return None |
119 return None |
115 base_date = datetime.datetime(1970, 1, 1) |
120 base_date = datetime.datetime(1970, 1, 1) |
116 return date - base_date |
121 return date - base_date |
117 else: |
122 else: |
118 return None |
123 return None |
|
124 |
119 |
125 |
120 def gettimeofday(v): |
126 def gettimeofday(v): |
121 result = IEC_TIMEOFDAY_MODEL.match(v.upper()) |
127 result = IEC_TIMEOFDAY_MODEL.match(v.upper()) |
122 if result is not None: |
128 if result is not None: |
123 hours, minutes, seconds = result.groups() |
129 hours, minutes, seconds = result.groups() |
154 |
160 |
155 #------------------------------------------------------------------------------- |
161 #------------------------------------------------------------------------------- |
156 # Force Variable Dialog |
162 # Force Variable Dialog |
157 #------------------------------------------------------------------------------- |
163 #------------------------------------------------------------------------------- |
158 |
164 |
|
165 |
159 class ForceVariableDialog(wx.TextEntryDialog): |
166 class ForceVariableDialog(wx.TextEntryDialog): |
160 |
167 |
161 def __init__(self, parent, iec_type, defaultValue=""): |
168 def __init__(self, parent, iec_type, defaultValue=""): |
162 wx.TextEntryDialog.__init__(self, parent, message = _("Forcing Variable Value"), |
169 wx.TextEntryDialog.__init__(self, parent, message = _("Forcing Variable Value"), |
163 caption = _("Please enter value for a \"%s\" variable:") % iec_type, defaultValue = defaultValue, |
170 caption = _("Please enter value for a \"%s\" variable:") % iec_type, defaultValue = defaultValue, |