ProjectController.py
changeset 1847 6198190bc121
parent 1846 14b40afccd69
child 1850 614396cbffbf
equal deleted inserted replaced
1846:14b40afccd69 1847:6198190bc121
    69 ITEM_CONFNODE = 25
    69 ITEM_CONFNODE = 25
    70 
    70 
    71 
    71 
    72 def ExtractChildrenTypesFromCatalog(catalog):
    72 def ExtractChildrenTypesFromCatalog(catalog):
    73     children_types = []
    73     children_types = []
    74     for n, d, h, c in catalog:
    74     for n, d, _h, c in catalog:
    75         if isinstance(c, ListType):
    75         if isinstance(c, ListType):
    76             children_types.extend(ExtractChildrenTypesFromCatalog(c))
    76             children_types.extend(ExtractChildrenTypesFromCatalog(c))
    77         else:
    77         else:
    78             children_types.append((n, GetClassImporter(c), d))
    78             children_types.append((n, GetClassImporter(c), d))
    79     return children_types
    79     return children_types
   146         options = ["-f", "-l", "-p"]
   146         options = ["-f", "-l", "-p"]
   147 
   147 
   148         buildopt = ""
   148         buildopt = ""
   149         try:
   149         try:
   150             # Invoke compiler. Output files are listed to stdout, errors to stderr
   150             # Invoke compiler. Output files are listed to stdout, errors to stderr
   151             status, result, err_result = ProcessLogger(None, buildcmd,
   151             _status, result, _err_result = ProcessLogger(None, buildcmd,
   152                                                        no_stdout=True,
   152                                                          no_stdout=True,
   153                                                        no_stderr=True).spin()
   153                                                          no_stderr=True).spin()
   154         except Exception:
   154         except Exception:
   155             return buildopt
   155             return buildopt
   156 
   156 
   157         for opt in options:
   157         for opt in options:
   158             if opt in result:
   158             if opt in result:
   194             <xsd:element name="Libraries" minOccurs="0">
   194             <xsd:element name="Libraries" minOccurs="0">
   195               <xsd:complexType>
   195               <xsd:complexType>
   196               """+"\n".join(['<xsd:attribute name=' +
   196               """+"\n".join(['<xsd:attribute name=' +
   197                              '"Enable_' + libname + '_Library" ' +
   197                              '"Enable_' + libname + '_Library" ' +
   198                              'type="xsd:boolean" use="optional" default="true"/>'
   198                              'type="xsd:boolean" use="optional" default="true"/>'
   199                              for libname, lib in features.libraries])+"""
   199                              for libname, _lib in features.libraries])+"""
   200               </xsd:complexType>
   200               </xsd:complexType>
   201             </xsd:element>""") if len(features.libraries) > 0 else '') + """
   201             </xsd:element>""") if len(features.libraries) > 0 else '') + """
   202           </xsd:sequence>
   202           </xsd:sequence>
   203           <xsd:attribute name="URI_location" type="xsd:string" use="optional" default=""/>
   203           <xsd:attribute name="URI_location" type="xsd:string" use="optional" default=""/>
   204           <xsd:attribute name="Disable_Extensions" type="xsd:boolean" use="optional" default="false"/>
   204           <xsd:attribute name="Disable_Extensions" type="xsd:boolean" use="optional" default="false"/>
   722         # Update PLCOpenEditor ConfNode Block types before generate ST code
   722         # Update PLCOpenEditor ConfNode Block types before generate ST code
   723         self.RefreshConfNodesBlockLists()
   723         self.RefreshConfNodesBlockLists()
   724 
   724 
   725         self.logger.write(_("Generating SoftPLC IEC-61131 ST/IL/SFC code...\n"))
   725         self.logger.write(_("Generating SoftPLC IEC-61131 ST/IL/SFC code...\n"))
   726         # ask PLCOpenEditor controller to write ST/IL/SFC code file
   726         # ask PLCOpenEditor controller to write ST/IL/SFC code file
   727         program, errors, warnings = self.GenerateProgram(self._getIECgeneratedcodepath())
   727         _program, errors, warnings = self.GenerateProgram(self._getIECgeneratedcodepath())
   728         if len(warnings) > 0:
   728         if len(warnings) > 0:
   729             self.logger.write_warning(_("Warnings in ST/IL/SFC code generator :\n"))
   729             self.logger.write_warning(_("Warnings in ST/IL/SFC code generator :\n"))
   730             for warning in warnings:
   730             for warning in warnings:
   731                 self.logger.write_warning("%s\n" % warning)
   731                 self.logger.write_warning("%s\n" % warning)
   732         if len(errors) > 0:
   732         if len(errors) > 0:
   740             plc_file.write(open(self._getIECrawcodepath(), "r").read())
   740             plc_file.write(open(self._getIECrawcodepath(), "r").read())
   741             plc_file.write("\n")
   741             plc_file.write("\n")
   742         plc_file.close()
   742         plc_file.close()
   743         plc_file = open(self._getIECcodepath(), "r")
   743         plc_file = open(self._getIECcodepath(), "r")
   744         self.ProgramOffset = 0
   744         self.ProgramOffset = 0
   745         for line in plc_file.xreadlines():
   745         for dummy in plc_file.xreadlines():
   746             self.ProgramOffset += 1
   746             self.ProgramOffset += 1
   747         plc_file.close()
   747         plc_file.close()
   748         plc_file = open(self._getIECcodepath(), "a")
   748         plc_file = open(self._getIECcodepath(), "a")
   749         plc_file.write(open(self._getIECgeneratedcodepath(), "r").read())
   749         plc_file.write(open(self._getIECgeneratedcodepath(), "r").read())
   750         plc_file.close()
   750         plc_file.close()
   782             for err_line in err_result.split('\n'):
   782             for err_line in err_result.split('\n'):
   783                 self.logger.write_warning(err_line + "\n")
   783                 self.logger.write_warning(err_line + "\n")
   784 
   784 
   785                 m_result = MATIEC_ERROR_MODEL.match(err_line)
   785                 m_result = MATIEC_ERROR_MODEL.match(err_line)
   786                 if m_result is not None:
   786                 if m_result is not None:
   787                     first_line, first_column, last_line, last_column, error = m_result.groups()
   787                     first_line, _first_column, last_line, _last_column, _error = m_result.groups()
   788                     first_line, last_line = int(first_line), int(last_line)
   788                     first_line, last_line = int(first_line), int(last_line)
   789 
   789 
   790                     last_section = None
   790                     last_section = None
   791                     f = open(self._getIECcodepath())
   791                     f = open(self._getIECcodepath())
   792 
   792 
  1021         generate glue code that dispatch calls to all confnodes
  1021         generate glue code that dispatch calls to all confnodes
  1022         """
  1022         """
  1023         # filter location that are related to code that will be called
  1023         # filter location that are related to code that will be called
  1024         # in retreive, publish, init, cleanup
  1024         # in retreive, publish, init, cleanup
  1025         locstrs = map(lambda x: "_".join(map(str, x)),
  1025         locstrs = map(lambda x: "_".join(map(str, x)),
  1026                       [loc for loc, Cfiles, DoCalls in
  1026                       [loc for loc, _Cfiles, DoCalls in
  1027                        self.LocationCFilesAndCFLAGS if loc and DoCalls])
  1027                        self.LocationCFilesAndCFLAGS if loc and DoCalls])
  1028 
  1028 
  1029         # Generate main, based on template
  1029         # Generate main, based on template
  1030         if not self.BeremizRoot.getDisable_Extensions():
  1030         if not self.BeremizRoot.getDisable_Extensions():
  1031             plc_main_code = targets.GetCode("plc_main_head.c") % {
  1031             plc_main_code = targets.GetCode("plc_main_head.c") % {
  1417     def PullPLCStatusProc(self, event):
  1417     def PullPLCStatusProc(self, event):
  1418         self.UpdateMethodsFromPLCStatus()
  1418         self.UpdateMethodsFromPLCStatus()
  1419 
  1419 
  1420     def SnapshotAndResetDebugValuesBuffers(self):
  1420     def SnapshotAndResetDebugValuesBuffers(self):
  1421         buffers, self.DebugValuesBuffers = (self.DebugValuesBuffers,
  1421         buffers, self.DebugValuesBuffers = (self.DebugValuesBuffers,
  1422                                             [list() for n in xrange(len(self.TracedIECPath))])
  1422                                             [list() for dummy in xrange(len(self.TracedIECPath))])
  1423         ticks, self.DebugTicks = self.DebugTicks, []
  1423         ticks, self.DebugTicks = self.DebugTicks, []
  1424         return ticks, buffers
  1424         return ticks, buffers
  1425 
  1425 
  1426     def RegisterDebugVarToConnector(self):
  1426     def RegisterDebugVarToConnector(self):
  1427         self.DebugTimer = None
  1427         self.DebugTimer = None
  1430         self.TracedIECTypes = []
  1430         self.TracedIECTypes = []
  1431         if self._connector is not None:
  1431         if self._connector is not None:
  1432             self.IECdebug_lock.acquire()
  1432             self.IECdebug_lock.acquire()
  1433             IECPathsToPop = []
  1433             IECPathsToPop = []
  1434             for IECPath, data_tuple in self.IECdebug_datas.iteritems():
  1434             for IECPath, data_tuple in self.IECdebug_datas.iteritems():
  1435                 WeakCallableDict, data_log, status, fvalue, buffer_list = data_tuple
  1435                 WeakCallableDict, _data_log, _status, fvalue, _buffer_list = data_tuple
  1436                 if len(WeakCallableDict) == 0:
  1436                 if len(WeakCallableDict) == 0:
  1437                     # Callable Dict is empty.
  1437                     # Callable Dict is empty.
  1438                     # This variable is not needed anymore!
  1438                     # This variable is not needed anymore!
  1439                     IECPathsToPop.append(IECPath)
  1439                     IECPathsToPop.append(IECPath)
  1440                 elif IECPath != "__tick__":
  1440                 elif IECPath != "__tick__":
  1478             self.DebugTimer = Timer(0.5, wx.CallAfter, args=[self.RegisterDebugVarToConnector])
  1478             self.DebugTimer = Timer(0.5, wx.CallAfter, args=[self.RegisterDebugVarToConnector])
  1479             # Rearm anti-rapid-fire timer
  1479             # Rearm anti-rapid-fire timer
  1480             self.DebugTimer.start()
  1480             self.DebugTimer.start()
  1481 
  1481 
  1482     def GetDebugIECVariableType(self, IECPath):
  1482     def GetDebugIECVariableType(self, IECPath):
  1483         Idx, IEC_Type = self._IECPathToIdx.get(IECPath, (None, None))
  1483         _Idx, IEC_Type = self._IECPathToIdx.get(IECPath, (None, None))
  1484         return IEC_Type
  1484         return IEC_Type
  1485 
  1485 
  1486     def SubscribeDebugIECVariable(self, IECPath, callableobj, buffer_list=False):
  1486     def SubscribeDebugIECVariable(self, IECPath, callableobj, buffer_list=False):
  1487         """
  1487         """
  1488         Dispatching use a dictionnary linking IEC variable paths
  1488         Dispatching use a dictionnary linking IEC variable paths
  1568         self.ReArmDebugRegisterTimer()
  1568         self.ReArmDebugRegisterTimer()
  1569 
  1569 
  1570     def CallWeakcallables(self, IECPath, function_name, *cargs):
  1570     def CallWeakcallables(self, IECPath, function_name, *cargs):
  1571         data_tuple = self.IECdebug_datas.get(IECPath, None)
  1571         data_tuple = self.IECdebug_datas.get(IECPath, None)
  1572         if data_tuple is not None:
  1572         if data_tuple is not None:
  1573             WeakCallableDict, data_log, status, fvalue, buffer_list = data_tuple
  1573             WeakCallableDict, _data_log, _status, _fvalue, buffer_list = data_tuple
  1574             # data_log.append((debug_tick, value))
  1574             # data_log.append((debug_tick, value))
  1575             for weakcallable, buffer_list in WeakCallableDict.iteritems():
  1575             for weakcallable, buffer_list in WeakCallableDict.iteritems():
  1576                 function = getattr(weakcallable, function_name, None)
  1576                 function = getattr(weakcallable, function_name, None)
  1577                 if function is not None:
  1577                 if function is not None:
  1578                     if buffer_list:
  1578                     if buffer_list: