678 # import necessary stuff from PLCOpenEditor |
678 # import necessary stuff from PLCOpenEditor |
679 from PLCOpenEditor import PLCOpenEditor, ProjectDialog |
679 from PLCOpenEditor import PLCOpenEditor, ProjectDialog |
680 from TextViewer import TextViewer |
680 from TextViewer import TextViewer |
681 from plcopen.structures import IEC_KEYWORDS, TypeHierarchy_list |
681 from plcopen.structures import IEC_KEYWORDS, TypeHierarchy_list |
682 |
682 |
683 # Construct debugger natively supported types |
|
684 DebugTypes = [t for t in zip(*TypeHierarchy_list)[0] if not t.startswith("ANY")] |
|
685 DebugTypesSize = {"BOOL" : 1, |
|
686 "SINT" : 1, |
|
687 "USINT" : 1, |
|
688 "BYTE" : 1, |
|
689 "STRING" : 128, |
|
690 "INT" : 2, |
|
691 "UINT" : 2, |
|
692 "WORD" : 2, |
|
693 "WSTRING" : 0, #TODO |
|
694 "DINT" : 4, |
|
695 "UDINT" : 4, |
|
696 "DWORD" : 4, |
|
697 "LINT" : 4, |
|
698 "ULINT" : 8, |
|
699 "LWORD" : 8, |
|
700 "REAL" : 4, |
|
701 "LREAL" : 8, |
|
702 } |
|
703 |
683 |
704 import re, tempfile |
684 import re, tempfile |
705 import targets |
685 import targets |
|
686 from targets.typemapping import DebugTypesSize |
|
687 |
706 import connectors |
688 import connectors |
707 from discovery import DiscoveryDialog |
689 from discovery import DiscoveryDialog |
708 from weakref import WeakKeyDictionary |
690 from weakref import WeakKeyDictionary |
709 |
691 |
710 MATIEC_ERROR_MODEL = re.compile(".*\.st:(\d+)-(\d+)\.\.(\d+)-(\d+): error : (.*)$") |
692 MATIEC_ERROR_MODEL = re.compile(".*\.st:(\d+)-(\d+)\.\.(\d+)-(\d+): error : (.*)$") |
1344 "for_each_variable_do_code":"\n".join([ |
1326 "for_each_variable_do_code":"\n".join([ |
1345 {"EXT":" (*fp)((void*)&%(C_path)s,%(type)s_P_ENUM);\n", |
1327 {"EXT":" (*fp)((void*)&%(C_path)s,%(type)s_P_ENUM);\n", |
1346 "IN":" (*fp)((void*)&%(C_path)s,%(type)s_P_ENUM);\n", |
1328 "IN":" (*fp)((void*)&%(C_path)s,%(type)s_P_ENUM);\n", |
1347 "OUT":" (*fp)((void*)&%(C_path)s,%(type)s_O_ENUM);\n", |
1329 "OUT":" (*fp)((void*)&%(C_path)s,%(type)s_O_ENUM);\n", |
1348 "VAR":" (*fp)((void*)&%(C_path)s,%(type)s_ENUM);\n"}[v["vartype"]]%v |
1330 "VAR":" (*fp)((void*)&%(C_path)s,%(type)s_ENUM);\n"}[v["vartype"]]%v |
1349 for v in self._VariablesList if v["vartype"] != "FB" and v["type"] in DebugTypes ]), |
1331 for v in self._VariablesList if v["vartype"] != "FB" and v["type"] in DebugTypesSize ]), |
1350 "find_variable_case_code":"\n".join([ |
1332 "find_variable_case_code":"\n".join([ |
1351 " case %(num)s:\n"%v+ |
1333 " case %(num)s:\n"%v+ |
1352 " *varp = (void*)&%(C_path)s;\n"%v+ |
1334 " *varp = (void*)&%(C_path)s;\n"%v+ |
1353 {"EXT":" return %(type)s_P_ENUM;\n", |
1335 {"EXT":" return %(type)s_P_ENUM;\n", |
1354 "IN":" return %(type)s_P_ENUM;\n", |
1336 "IN":" return %(type)s_P_ENUM;\n", |
1355 "OUT":" return %(type)s_O_ENUM;\n", |
1337 "OUT":" return %(type)s_O_ENUM;\n", |
1356 "VAR":" return %(type)s_ENUM;\n"}[v["vartype"]]%v |
1338 "VAR":" return %(type)s_ENUM;\n"}[v["vartype"]]%v |
1357 for v in self._VariablesList if v["vartype"] != "FB" and v["type"] in DebugTypes ])} |
1339 for v in self._VariablesList if v["vartype"] != "FB" and v["type"] in DebugTypesSize ])} |
1358 |
1340 |
1359 return debug_code |
1341 return debug_code |
1360 |
1342 |
1361 def Generate_plc_common_main(self): |
1343 def Generate_plc_common_main(self): |
1362 """ |
1344 """ |
1602 IECPathsToPop.append(IECPath) |
1584 IECPathsToPop.append(IECPath) |
1603 elif IECPath != "__tick__": |
1585 elif IECPath != "__tick__": |
1604 # Convert |
1586 # Convert |
1605 Idx, IEC_Type = self._IECPathToIdx.get(IECPath,(None,None)) |
1587 Idx, IEC_Type = self._IECPathToIdx.get(IECPath,(None,None)) |
1606 if Idx is not None: |
1588 if Idx is not None: |
1607 Idxs.append((Idx, IEC_Type, fvalue, IECPath)) |
1589 if IEC_Type in DebugTypesSize: |
|
1590 Idxs.append((Idx, IEC_Type, fvalue, IECPath)) |
|
1591 else: |
|
1592 self.logger.write_warning(_("Debug : Unsuppoted type to debug %s\n")%IEC_Type) |
1608 else: |
1593 else: |
1609 self.logger.write_warning(_("Debug : Unknown variable %s\n")%IECPath) |
1594 self.logger.write_warning(_("Debug : Unknown variable %s\n")%IECPath) |
1610 for IECPathToPop in IECPathsToPop: |
1595 for IECPathToPop in IECPathsToPop: |
1611 self.IECdebug_datas.pop(IECPathToPop) |
1596 self.IECdebug_datas.pop(IECPathToPop) |
1612 |
1597 |