etherlab/etherlab.py
author Edouard Tisserant
Fri, 12 Apr 2013 15:41:22 +0900
changeset 2121 11102245e1d4
parent 2111 f2cffda17d00
child 2133 ba0b2ca7db26
permissions -rw-r--r--
Fixed (again) some non-clean exit in case of SDO failure at init
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     1
import os, shutil
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     2
from xml.dom import minidom
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     3
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     4
import wx
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
     5
import csv
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     6
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     7
from xmlclass import *
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents: 2109
diff changeset
     8
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
     9
from ConfigTreeNode import ConfigTreeNode
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
    10
from PLCControler import UndoBuffer, LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents: 2109
diff changeset
    11
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents: 2109
diff changeset
    12
from EthercatSlave import ExtractHexDecValue, ExtractName
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents: 2109
diff changeset
    13
from EthercatMaster import _EthercatCTN
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents: 2109
diff changeset
    14
from ConfigEditor import LibraryEditor, ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    15
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    16
#--------------------------------------------------
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
    17
#                 Ethercat ConfNode
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    18
#--------------------------------------------------
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    19
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    20
EtherCATInfoClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATInfo.xsd")) 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    21
2074
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    22
cls = EtherCATInfoClasses["EtherCATBase.xsd"].get("DictionaryType", None)
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    23
if cls:
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    24
    cls.loadXMLTreeArgs = None
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    25
    
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    26
    setattr(cls, "_loadXMLTree", getattr(cls, "loadXMLTree"))
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    27
    
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    28
    def loadXMLTree(self, *args):
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    29
        self.loadXMLTreeArgs = args
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    30
    setattr(cls, "loadXMLTree", loadXMLTree)
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    31
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    32
    def load(self):
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    33
        if self.loadXMLTreeArgs is not None:
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    34
            self._loadXMLTree(*self.loadXMLTreeArgs)
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    35
            self.loadXMLTreeArgs = None
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    36
    setattr(cls, "load", load)
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    37
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    38
cls = EtherCATInfoClasses["EtherCATInfo.xsd"].get("DeviceType", None)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    39
if cls:
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    40
    cls.DataTypes = None
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    41
    
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    42
    def GetProfileNumbers(self):
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    43
        profiles = []
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    44
        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    45
        for profile in self.getProfile():
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    46
            profile_content = profile.getcontent()
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    47
            if profile_content is None:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    48
                continue
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    49
            
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    50
            for content_element in profile_content["value"]:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    51
                if content_element["name"] == "ProfileNo":
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    52
                    profiles.append(content_element["value"])
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    53
        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    54
        return profiles
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    55
    setattr(cls, "GetProfileNumbers", GetProfileNumbers)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    56
    
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    57
    def GetProfileDictionaries(self):
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    58
        dictionaries = []
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    59
        
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    60
        for profile in self.getProfile():
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    61
        
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    62
            profile_content = profile.getcontent()
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    63
            if profile_content is None:
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
    64
                continue
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    65
            
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    66
            for content_element in profile_content["value"]:
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    67
                if content_element["name"] == "Dictionary":
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    68
                    dictionaries.append(content_element["value"])
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    69
                elif content_element["name"] == "DictionaryFile":
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    70
                    raise ValueError, "DictionaryFile for defining Device Profile is not yet supported!"
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    71
                
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    72
        return dictionaries
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    73
    setattr(cls, "GetProfileDictionaries", GetProfileDictionaries)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    74
    
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    75
    def ExtractDataTypes(self):
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    76
        self.DataTypes = {}
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    77
        
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    78
        for dictionary in self.GetProfileDictionaries():
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    79
            dictionary.load()
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    80
            
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    81
            datatypes = dictionary.getDataTypes()
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    82
            if datatypes is not None:
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    83
                
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    84
                for datatype in datatypes.getDataType():
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    85
                    content = datatype.getcontent()
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    86
                    if content is not None and content["name"] == "SubItem":
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    87
                        self.DataTypes[datatype.getName()] = datatype
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    88
    
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    89
    setattr(cls, "ExtractDataTypes", ExtractDataTypes)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    90
    
2079
49242019a9ca Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents: 2077
diff changeset
    91
    def getCoE(self):
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    92
        mailbox = self.getMailbox()
2079
49242019a9ca Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents: 2077
diff changeset
    93
        if mailbox is not None:
49242019a9ca Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents: 2077
diff changeset
    94
            return mailbox.getCoE()
49242019a9ca Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents: 2077
diff changeset
    95
        return None
49242019a9ca Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents: 2077
diff changeset
    96
    setattr(cls, "getCoE", getCoE)
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    97
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
    98
    def GetEntriesList(self, limits=None):
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
    99
        if self.DataTypes is None:
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   100
            self.ExtractDataTypes()
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   101
        
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   102
        entries = {}
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   103
        
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   104
        for dictionary in self.GetProfileDictionaries():
2074
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
   105
            dictionary.load()
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   106
            
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   107
            for object in dictionary.getObjects().getObject():
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   108
                entry_index = object.getIndex().getcontent()
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   109
                index = ExtractHexDecValue(entry_index)
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   110
                if limits is None or limits[0] <= index <= limits[1]:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   111
                    entry_type = object.getType()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   112
                    entry_name = ExtractName(object.getName())
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   113
                    
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   114
                    entry_type_infos = self.DataTypes.get(entry_type, None)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   115
                    if entry_type_infos is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   116
                        content = entry_type_infos.getcontent()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   117
                        for subitem in content["value"]:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   118
                            entry_subidx = subitem.getSubIdx()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   119
                            if entry_subidx is None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   120
                                entry_subidx = "0"
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   121
                            subidx = ExtractHexDecValue(entry_subidx)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   122
                            subitem_access = ""
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   123
                            subitem_pdomapping = ""
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   124
                            subitem_flags = subitem.getFlags()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   125
                            if subitem_flags is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   126
                                access = subitem_flags.getAccess()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   127
                                if access is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   128
                                    subitem_access = access.getcontent()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   129
                                pdomapping = subitem_flags.getPdoMapping()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   130
                                if pdomapping is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   131
                                    subitem_pdomapping = pdomapping.upper()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   132
                            entries[(index, subidx)] = {
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   133
                                "Index": entry_index,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   134
                                "SubIndex": entry_subidx,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   135
                                "Name": "%s - %s" % 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   136
                                        (entry_name.decode("utf-8"),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   137
                                         ExtractName(subitem.getDisplayName(), 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   138
                                                     subitem.getName()).decode("utf-8")),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   139
                                "Type": subitem.getType(),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   140
                                "BitSize": subitem.getBitSize(),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   141
                                "Access": subitem_access, 
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   142
                                "PDOMapping": subitem_pdomapping}
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   143
                    else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   144
                        entry_access = ""
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   145
                        entry_pdomapping = ""
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   146
                        entry_flags = object.getFlags()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   147
                        if entry_flags is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   148
                            access = entry_flags.getAccess()
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   149
                            if access is not None:
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   150
                                entry_access = access.getcontent()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   151
                            pdomapping = entry_flags.getPdoMapping()
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   152
                            if pdomapping is not None:
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   153
                                entry_pdomapping = pdomapping.upper()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   154
                        entries[(index, 0)] = {
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   155
                             "Index": entry_index,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   156
                             "SubIndex": "0",
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   157
                             "Name": entry_name,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   158
                             "Type": entry_type,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   159
                             "BitSize": object.getBitSize(),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   160
                             "Access": entry_access,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   161
                             "PDOMapping": entry_pdomapping}
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   162
        
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   163
        for TxPdo in self.getTxPdo():
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   164
            ExtractPdoInfos(TxPdo, "Transmit", entries, limits)
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   165
        for RxPdo in self.getRxPdo():
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   166
            ExtractPdoInfos(RxPdo, "Receive", entries, limits)
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   167
        
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   168
        return entries
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   169
    setattr(cls, "GetEntriesList", GetEntriesList)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   170
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   171
    def GetSyncManagers(self):
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   172
        sync_managers = []
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   173
        for sync_manager in self.getSm():
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   174
            sync_manager_infos = {}
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   175
            for name, value in [("Name", sync_manager.getcontent()),
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   176
                                ("Start Address", sync_manager.getStartAddress()),
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   177
                                ("Default Size", sync_manager.getDefaultSize()),
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   178
                                ("Control Byte", sync_manager.getControlByte()),
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   179
                                ("Enable", sync_manager.getEnable())]:
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   180
                if value is None:
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   181
                    value =""
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   182
                sync_manager_infos[name] = value
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   183
            sync_managers.append(sync_manager_infos)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   184
        return sync_managers
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   185
    setattr(cls, "GetSyncManagers", GetSyncManagers)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   186
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   187
def GroupItemCompare(x, y):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   188
    if x["type"] == y["type"]:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   189
        if x["type"] == ETHERCAT_GROUP:
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   190
            return cmp(x["order"], y["order"])
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   191
        else:
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   192
            return cmp(x["name"], y["name"])
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   193
    elif x["type"] == ETHERCAT_GROUP:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   194
        return -1
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   195
    return 1
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   196
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   197
def SortGroupItems(group):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   198
    for item in group["children"]:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   199
        if item["type"] == ETHERCAT_GROUP:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   200
            SortGroupItems(item)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   201
    group["children"].sort(GroupItemCompare)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   202
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   203
def ExtractPdoInfos(pdo, pdo_type, entries, limits=None):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   204
    pdo_index = pdo.getIndex().getcontent()
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   205
    pdo_name = ExtractName(pdo.getName())
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   206
    for pdo_entry in pdo.getEntry():
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   207
        entry_index = pdo_entry.getIndex().getcontent()
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   208
        entry_subindex = pdo_entry.getSubIndex()
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   209
        index = ExtractHexDecValue(entry_index)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   210
        subindex = ExtractHexDecValue(entry_subindex)
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   211
        
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   212
        if limits is None or limits[0] <= index <= limits[1]:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   213
            entry = entries.get((index, subindex), None)
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   214
            if entry is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   215
                entry["PDO index"] = pdo_index
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   216
                entry["PDO name"] = pdo_name
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   217
                entry["PDO type"] = pdo_type
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   218
            else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   219
                entry_type = pdo_entry.getDataType()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   220
                if entry_type is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   221
                    if pdo_type == "Transmit":
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   222
                        access = "ro"
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   223
                        pdomapping = "T"
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   224
                    else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   225
                        access = "wo"
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   226
                        pdomapping = "R"
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   227
                    entries[(index, subindex)] = {
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   228
                        "Index": entry_index,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   229
                        "SubIndex": entry_subindex,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   230
                        "Name": ExtractName(pdo_entry.getName()),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   231
                        "Type": entry_type.getcontent(),
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   232
                        "Access": access,
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   233
                        "PDOMapping": pdomapping}
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   234
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   235
DEFAULT_ALIGNMENT = 8
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   236
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   237
class ModulesLibrary:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   238
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   239
    def __init__(self, path, parent_library=None):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   240
        self.Path = path
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   241
        if not os.path.exists(self.Path):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   242
            os.makedirs(self.Path)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   243
        self.ParentLibrary = parent_library
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   244
        
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   245
        if parent_library is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   246
            self.LoadModules()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   247
        else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   248
            self.Library = None
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   249
        self.LoadAlignments()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   250
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   251
    def GetPath(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   252
        return self.Path
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   253
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   254
    def GetAlignmentFilePath(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   255
        return os.path.join(self.Path, "alignments.cfg")
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   256
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   257
    def LoadModules(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   258
        self.Library = {}
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   259
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   260
        files = os.listdir(self.Path)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   261
        for file in files:
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   262
            filepath = os.path.join(self.Path, file)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   263
            if os.path.isfile(filepath) and os.path.splitext(filepath)[-1] == ".xml":
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   264
                xmlfile = open(filepath, 'r')
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   265
                xml_tree = minidom.parse(xmlfile)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   266
                xmlfile.close()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   267
                
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   268
                modules_infos = None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   269
                for child in xml_tree.childNodes:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   270
                    if child.nodeType == xml_tree.ELEMENT_NODE and child.nodeName == "EtherCATInfo":
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   271
                        modules_infos = EtherCATInfoClasses["EtherCATInfo.xsd"]["EtherCATInfo"]()
2051
13dee9322beb refactoring
laurent
parents: 2047
diff changeset
   272
                        modules_infos.loadXMLTree(child)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   273
                
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   274
                if modules_infos is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   275
                    vendor = modules_infos.getVendor()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   276
                    
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   277
                    vendor_category = self.Library.setdefault(ExtractHexDecValue(vendor.getId()), 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   278
                                                              {"name": ExtractName(vendor.getName(), _("Miscellaneous")), 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   279
                                                               "groups": {}})
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   280
                    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   281
                    for group in modules_infos.getDescriptions().getGroups().getGroup():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   282
                        group_type = group.getType()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   283
                        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   284
                        vendor_category["groups"].setdefault(group_type, {"name": ExtractName(group.getName(), group_type), 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   285
                                                                          "parent": group.getParentGroup(),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   286
                                                                          "order": group.getSortOrder(), 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   287
                                                                          "devices": []})
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   288
                    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   289
                    for device in modules_infos.getDescriptions().getDevices().getDevice():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   290
                        device_group = device.getGroupType()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   291
                        if not vendor_category["groups"].has_key(device_group):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   292
                            raise ValueError, "Not such group \"%\"" % device_group
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   293
                        vendor_category["groups"][device_group]["devices"].append((device.getType().getcontent(), device))
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   294
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   295
    def GetModulesLibrary(self, profile_filter=None):
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   296
        if self.Library is None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   297
            self.LoadModules()
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   298
        library = []
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   299
        for vendor_id, vendor in self.Library.iteritems():
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   300
            groups = []
2073
d14ab97a452a Fix bug modules present in all groups with the same name even if they are defined by different vendors
Laurent Bessard
parents: 2069
diff changeset
   301
            children_dict = {}
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   302
            for group_type, group in vendor["groups"].iteritems():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   303
                group_infos = {"name": group["name"],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   304
                               "order": group["order"],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   305
                               "type": ETHERCAT_GROUP,
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   306
                               "infos": None,
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   307
                               "children": children_dict.setdefault(group_type, [])}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   308
                device_dict = {}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   309
                for device_type, device in group["devices"]:
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   310
                    if profile_filter is None or profile_filter in device.GetProfileNumbers():
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   311
                        product_code = device.getType().getProductCode()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   312
                        revision_number = device.getType().getRevisionNo()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   313
                        alignment = self.GetAlignment(vendor_id, product_code, revision_number)
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   314
                        device_infos = {"name": ExtractName(device.getName()),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   315
                                        "type": ETHERCAT_DEVICE,
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   316
                                        "infos": {"device_type": device_type,
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   317
                                                  "vendor": vendor_id,
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   318
                                                  "product_code": product_code,
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   319
                                                  "revision_number": revision_number,
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   320
                                                  "alignment": alignment},
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   321
                                        "children": []}
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   322
                        group_infos["children"].append(device_infos)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   323
                        device_type_occurrences = device_dict.setdefault(device_type, [])
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   324
                        device_type_occurrences.append(device_infos)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   325
                for device_type_occurrences in device_dict.itervalues():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   326
                    if len(device_type_occurrences) > 1:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   327
                        for occurrence in device_type_occurrences:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   328
                            occurrence["name"] += _(" (rev. %s)") % occurrence["infos"]["revision_number"]
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   329
                if len(group_infos["children"]) > 0:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   330
                    if group["parent"] is not None:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   331
                        parent_children = children_dict.setdefault(group["parent"], [])
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   332
                        parent_children.append(group_infos)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   333
                    else:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   334
                        groups.append(group_infos)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   335
            if len(groups) > 0:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   336
                library.append({"name": vendor["name"],
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   337
                                "type": ETHERCAT_VENDOR,
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   338
                                "infos": None,
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   339
                                "children": groups})
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   340
        library.sort(lambda x, y: cmp(x["name"], y["name"]))
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   341
        return library
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   342
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   343
    def GetVendors(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   344
        return [(vendor_id, vendor["name"]) for vendor_id, vendor in self.Library.items()]
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   345
    
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   346
    def GetModuleInfos(self, module_infos):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   347
        vendor = ExtractHexDecValue(module_infos["vendor"])
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   348
        vendor_infos = self.Library.get(vendor)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   349
        if vendor_infos is not None:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   350
            for group_name, group_infos in vendor_infos["groups"].iteritems():
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   351
                for device_type, device_infos in group_infos["devices"]:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   352
                    product_code = ExtractHexDecValue(device_infos.getType().getProductCode())
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   353
                    revision_number = ExtractHexDecValue(device_infos.getType().getRevisionNo())
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   354
                    if (product_code == ExtractHexDecValue(module_infos["product_code"]) and
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   355
                        revision_number == ExtractHexDecValue(module_infos["revision_number"])):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   356
                        return device_infos, self.GetAlignment(vendor, product_code, revision_number)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   357
        return None, None
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   358
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   359
    def ImportModuleLibrary(self, filepath):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   360
        if os.path.isfile(filepath):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   361
            shutil.copy(filepath, self.Path)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   362
            self.LoadModules()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   363
            return True
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   364
        return False
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   365
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   366
    def LoadAlignments(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   367
        self.Alignments = {}
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   368
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   369
        csvfile_path = self.GetAlignmentFilePath()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   370
        if os.path.exists(csvfile_path):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   371
            csvfile = open(csvfile_path, "rb")
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   372
            sample = csvfile.read(1024)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   373
            csvfile.seek(0)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   374
            dialect = csv.Sniffer().sniff(sample)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   375
            has_header = csv.Sniffer().has_header(sample)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   376
            reader = csv.reader(csvfile, dialect)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   377
            for row in reader:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   378
                if has_header:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   379
                    has_header = False
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   380
                else:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   381
                    try:
2101
da450992572e Added code generation for process variables
Laurent Bessard
parents: 2099
diff changeset
   382
                        self.Alignments[tuple(map(int, row[:3]))] = int(row[3])
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   383
                    except:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   384
                        pass
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   385
            csvfile.close()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   386
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   387
    def SaveAlignments(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   388
        csvfile = open(self.GetAlignmentFilePath(), "wb")
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   389
        writer = csv.writer(csvfile, delimiter=';')
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   390
        writer.writerow(['Vendor', 'product_code', 'revision_number', 'alignment'])
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   391
        for (vendor, product_code, revision_number), alignment in self.Alignments.iteritems():
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   392
            writer.writerow([vendor, product_code, revision_number, alignment])
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   393
        csvfile.close()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   394
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   395
    def SetAlignment(self, vendor, product_code, revision_number, alignment):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   396
        vendor = ExtractHexDecValue(vendor)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   397
        product_code = ExtractHexDecValue(product_code)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   398
        revision_number = ExtractHexDecValue(revision_number)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   399
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   400
        self.Alignments[tuple([vendor, product_code, revision_number])] = alignment
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   401
        self.SaveAlignments()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   402
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   403
    def GetAlignment(self, vendor, product_code, revision_number):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   404
        vendor = ExtractHexDecValue(vendor)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   405
        product_code = ExtractHexDecValue(product_code)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   406
        revision_number = ExtractHexDecValue(revision_number)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   407
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   408
        alignment = self.Alignments.get(tuple([vendor, product_code, revision_number]))
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   409
        if alignment is not None:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   410
            return alignment
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   411
        
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   412
        if self.ParentLibrary is not None:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   413
            return self.ParentLibrary.GetAlignment(vendor, product_code, revision_number)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   414
        return DEFAULT_ALIGNMENT
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   415
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   416
USERDATA_DIR = wx.StandardPaths.Get().GetUserDataDir()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   417
if wx.Platform != '__WXMSW__':
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   418
    USERDATA_DIR += '_files'
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   419
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   420
ModulesDatabase = ModulesLibrary(
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   421
    os.path.join(USERDATA_DIR, "ethercat_modules"))
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   422
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   423
class RootClass:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   424
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   425
    CTNChildrenTypes = [("EthercatNode",_EthercatCTN,"Ethercat Master")]
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   426
    EditorType = LibraryEditor
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   427
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   428
    def __init__(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   429
        self.ModulesLibrary = None
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   430
        self.LoadModulesLibrary()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   431
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   432
    def GetModulesLibraryPath(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   433
        return os.path.join(self.CTNPath(), "modules") 
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   434
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   435
    def CTNGenerate_C(self, buildpath, locations):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   436
        return [],"",False
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   437
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   438
    def LoadModulesLibrary(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   439
        if self.ModulesLibrary is None:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   440
            self.ModulesLibrary = ModulesLibrary(self.GetModulesLibraryPath(), ModulesDatabase)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   441
        else:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   442
            self.ModulesLibrary.LoadModulesLibrary()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   443
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   444
    def GetModulesDatabaseInstance(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   445
        return ModulesDatabase
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   446
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   447
    def GetModulesLibraryInstance(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   448
        return self.ModulesLibrary
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   449
    
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   450
    def GetModulesLibrary(self, profile_filter=None):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   451
        return self.ModulesLibrary.GetModulesLibrary(profile_filter)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   452
    
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   453
    def GetVendors(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   454
        return self.ModulesLibrary.GetVendors()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   455
    
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   456
    def GetModuleInfos(self, module_infos):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   457
        return self.ModulesLibrary.GetModuleInfos(module_infos)
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   458
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   459