示例#1
0
 def _OpenView(self, name=None, onlyopened=False):
     if name == "Generated master":
         app_frame = self.GetCTRoot().AppFrame
         if self._GeneratedMasterView is None:
             buildpath = self._getBuildPath()
             # Eventually create build dir
             if not os.path.exists(buildpath):
                 self.GetCTRoot().logger.write_error(_("Error: No PLC built\n"))
                 return
             
             masterpath = os.path.join(buildpath, "MasterGenerated.od")
             if not os.path.exists(masterpath):
                 self.GetCTRoot().logger.write_error(_("Error: No Master generated\n"))
                 return
             
             manager = MiniNodeManager(self, masterpath, self.CTNFullName())
             self._GeneratedMasterView = MasterViewer(app_frame.TabsOpened, manager, app_frame, name)
             
         if self._GeneratedMasterView is not None:
             app_frame.EditProjectElement(self._GeneratedMasterView, self._GeneratedMasterView.GetInstancePath())
         
         return self._GeneratedMasterView
     else:
         ConfigTreeNode._OpenView(self, name, onlyopened)
         if self._View is not None:
             self._View.SetBusId(self.GetCurrentLocation())
         return self._View
示例#2
0
    def SetParamsAttribute(self, path, value):
        if path == "CanFestivalNode.NodeId":
            nodeid = self.CanFestivalNode.getNodeId()
            if value != nodeid:
                slaves = self.GetSlaveIDs()
                dir = (value - nodeid) // abs(value - nodeid)
                while value in slaves and value >= 0:
                    value += dir
                if value < 0:
                    value = nodeid

        value, refresh = ConfigTreeNode.SetParamsAttribute(self, path, value)
        refresh_network = False

        # Filter IEC_Channel and Name, that have specific behavior
        if path == "BaseParams.IEC_Channel" and self._View is not None:
            self._View.SetBusId(self.GetCurrentLocation())
        elif path == "BaseParams.Name":
            self.SetNetworkName(value)
            refresh_network = True
        elif path == "CanFestivalNode.NodeId":
            refresh_network = True

        if refresh_network and self._View is not None:
            wx.CallAfter(self._View.RefreshBufferState)
        return value, refresh
示例#3
0
 def GetParamsAttributes(self, path=None):
     infos = ConfigTreeNode.GetParamsAttributes(self, path=path)
     for element in infos:
         if element["name"] == "CanFestivalInstance":
             for child in element["children"]:
                 if child["name"] == "CAN_Driver":
                     child["type"] = local_canfestival_config.DLL_LIST
     return infos
示例#4
0
    def SetParamsAttribute(self, path, value):
        result = ConfigTreeNode.SetParamsAttribute(self, path, value)

        # Filter IEC_Channel and Name, that have specific behavior
        if path == "BaseParams.IEC_Channel" and self._View is not None:
            self._View.SetBusId(self.GetCurrentLocation())

        return result
示例#5
0
 def GetParamsAttributes(self, path=None):
     infos = ConfigTreeNode.GetParamsAttributes(self, path=path)
     for element in infos:
         if element["name"] == "ModbusRequest":
             for child in element["children"]:
                 if child["name"] == "Function":
                     list = modbus_function_dict.keys()
                     list.sort()
                     child["type"] = list
     return infos
示例#6
0
 def GetParamsAttributes(self, path=None):
     infos = ConfigTreeNode.GetParamsAttributes(self, path=path)
     for element in infos:
         if element["name"] == "MemoryArea":
             for child in element["children"]:
                 if child["name"] == "MemoryAreaType":
                     list = modbus_memtype_dict.keys()
                     list.sort()
                     child["type"] = list
     return infos
示例#7
0
 def GetParamsAttributes(self, path=None):
     infos = ConfigTreeNode.GetParamsAttributes(self, path=path)
     for element in infos:
         if element["name"] == "ModbusRTUslave":
             for child in element["children"]:
                 if child["name"] == "Baud_Rate":
                     child["type"] = modbus_serial_baudrate_list
                 if child["name"] == "Stop_Bits":
                     child["type"] = modbus_serial_stopbits_list
                 if child["name"] == "Parity":
                     child["type"] = modbus_serial_parity_dict.keys()
     return infos
示例#8
0
    def _Generate_C(self, buildpath, locations):
        current_location = self.GetCurrentLocation()
        # define a unique name for the generated C file
        location_str = "_".join(map(str, current_location))

        Gen_Ethercatfile_path = os.path.join(buildpath,
                                             "ethercat_%s.c" % location_str)

        self.FileGenerator = _EthercatCFileGenerator(self)

        LocationCFilesAndCFLAGS, LDFLAGS, extra_files = ConfigTreeNode._Generate_C(
            self, buildpath, locations)

        for idx, variable in enumerate(self.ProcessVariables.getvariable()):
            name = None
            var_type = None
            read_from = variable.getReadFrom()
            write_to = variable.getWriteTo()
            if read_from is not None:
                pos = read_from.getPosition()
                index = read_from.getIndex()
                subindex = read_from.getSubIndex()
                location = current_location + (idx, )
                var_type = self.GetSlaveVariableDataType(pos, index, subindex)
                name = self.FileGenerator.DeclareVariable(
                    pos, index, subindex, var_type, "I",
                    self.GetProcessVariableName(location, var_type))
            if write_to is not None:
                pos = write_to.getPosition()
                index = write_to.getIndex()
                subindex = write_to.getSubIndex()
                if name is None:
                    location = current_location + (idx, )
                    var_type = self.GetSlaveVariableDataType(
                        pos, index, subindex)
                    name = self.GetProcessVariableName(location, var_type)
                self.FileGenerator.DeclareVariable(pos, index, subindex,
                                                   var_type, "Q", name, True)

        self.FileGenerator.GenerateCFile(Gen_Ethercatfile_path, location_str,
                                         self.BaseParams.getIEC_Channel())

        LocationCFilesAndCFLAGS.insert(0, (current_location, [
            (Gen_Ethercatfile_path,
             '"-I%s"' % os.path.abspath(self.GetCTRoot().GetIECLibPath()))
        ], True))
        LDFLAGS.append("-lethercat_rtdm -lrtdm")

        return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
示例#9
0
    def CTNAddChild(self, CTNName, CTNType, IEC_Channel=0):
        """
        Create the confnodes that may be added as child to this node self
        @param CTNType: string desining the confnode class name (get name from CTNChildrenTypes)
        @param CTNName: string for the name of the confnode instance
        """
        newConfNodeOpj = ConfigTreeNode.CTNAddChild(self, CTNName, CTNType,
                                                    IEC_Channel)

        slave = self.GetSlave(newConfNodeOpj.BaseParams.getIEC_Channel())
        if slave is None:
            slave = EtherCATConfigParser.CreateElement("Slave", "Config")
            self.Config.getConfig().appendSlave(slave)
            slave_infos = slave.getInfo()
            slave_infos.setName("undefined")
            slave_infos.setPhysAddr(newConfNodeOpj.BaseParams.getIEC_Channel())
            slave_infos.setAutoIncAddr(0)
            self.BufferModel()
            self.OnCTNSave()

        return newConfNodeOpj
示例#10
0
 def OnCTNClose(self):
     ConfigTreeNode.OnCTNClose(self)
     self._CloseView(self._GeneratedMasterView)
     return True
示例#11
0
 def OnCloseEditor(self, view):
     ConfigTreeNode.OnCloseEditor(self, view)
     if self._GeneratedMasterView == view:
         self._GeneratedMasterView = None
示例#12
0
 def _OpenView(self, name=None, onlyopened=False):
     ConfigTreeNode._OpenView(self, name, onlyopened)
     if self._View is not None:
         self._View.SetBusId(self.GetCurrentLocation())
     return self._View
示例#13
0
 def _OpenView(self, name=None, onlyopened=False):
     ConfigTreeNode._OpenView(self, name, onlyopened)
     if self._View is not None:
         self._View.SetBusId(self.GetCurrentLocation())
     return self._View