etherlab/etherlab.py
author Laurent Bessard
Fri, 16 Nov 2012 00:23:35 +0100
changeset 2093 3fdf9d56d803
parent 2092 c9776ae8b5d0
child 2094 72b74099b873
permissions -rw-r--r--
Fix bug in support for Etherlab specific fieldbus interface function blocks
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
import cPickle
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     3
from xml.dom import minidom
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     4
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     5
import wx
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 *
2086
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
     8
from POULibrary import POULibrary
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
2043
27d4cb689a79 Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents: 2042
diff changeset
    11
from ConfigEditor import NodeEditor, CIA402NodeEditor, ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    12
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    13
try:
2049
438a4a1ff188 updated examples also
Edouard Tisserant
parents: 2048
diff changeset
    14
    from MotionLibrary import Headers, AxisXSD
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    15
    HAS_MCL = True
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    16
except:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    17
    HAS_MCL = False
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    18
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    19
TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L",
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    20
    "USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", 
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    21
    "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L"}
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    22
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    23
DATATYPECONVERSION = {"BOOL" : "BIT", "SINT" : "S8", "INT" : "S16", "DINT" : "S32", "LINT" : "S64",
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    24
    "USINT" : "U8", "UINT" : "U16", "UDINT" : "U32", "ULINT" : "U64", 
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    25
    "BYTE" : "U8", "WORD" : "U16", "DWORD" : "U32", "LWORD" : "U64"}
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    26
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    27
VARCLASSCONVERSION = {"T": LOCATION_VAR_INPUT, "R": LOCATION_VAR_OUTPUT, "RT": LOCATION_VAR_MEMORY}
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    28
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    29
#--------------------------------------------------
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    30
#         Remote Exec Etherlab Commands
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    31
#--------------------------------------------------
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    32
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    33
SCAN_COMMAND = """
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    34
import commands
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    35
result = commands.getoutput("ethercat slaves")
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    36
slaves = []
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    37
for slave_line in result.splitlines():
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    38
    chunks = slave_line.split()
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    39
    idx, pos, state, flag = chunks[:4]
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    40
    name = " ".join(chunks[4:])
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    41
    alias, position = pos.split(":")
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    42
    slave = {"idx": int(idx),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    43
             "alias": int(alias),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    44
             "position": int(position),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    45
             "name": name}
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    46
    details = commands.getoutput("ethercat slaves -p %d -v" % slave["idx"])
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    47
    for details_line in details.splitlines():
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    48
        details_line = details_line.strip()
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    49
        for header, param in [("Vendor Id:", "vendor_id"),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    50
                              ("Product code:", "product_code"),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    51
                              ("Revision number:", "revision_number")]:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    52
            if details_line.startswith(header):
2042
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
    53
                slave[param] = details_line.split()[-1]
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    54
                break
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    55
    slaves.append(slave)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    56
returnVal = slaves
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    57
"""
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    58
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    59
#--------------------------------------------------
2086
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    60
#      Etherlab Specific Blocks Library
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    61
#--------------------------------------------------
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    62
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    63
def GetLocalPath(filename):
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    64
    return os.path.join(os.path.split(__file__)[0], filename)
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    65
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    66
class EtherlabLibrary(POULibrary):
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    67
    def GetLibraryPath(self):
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    68
        return GetLocalPath("pous.xml")
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    69
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    70
    def Generate_C(self, buildpath, varlist, IECCFLAGS):
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    71
        etherlab_ext_file = open(GetLocalPath("etherlab_ext.c"), 'r')
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    72
        etherlab_ext_code = etherlab_ext_file.read()
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    73
        etherlab_ext_file.close()
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    74
        
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    75
        Gen_etherlabfile_path = os.path.join(buildpath, "etherlab_ext.c")
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    76
        ethelabfile = open(Gen_etherlabfile_path,'w')
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    77
        ethelabfile.write(etherlab_ext_code)
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    78
        ethelabfile.close()
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    79
        
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    80
        runtimefile_path = os.path.join(os.path.split(__file__)[0], "runtime_etherlab.py")
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    81
        return ((["etherlab_ext"], [(Gen_etherlabfile_path, IECCFLAGS)], True), "", 
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    82
                ("runtime_etherlab.py", file(GetLocalPath("runtime_etherlab.py"))))
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    83
8e4992e0f147 Adding block library for SDO download and SDO upload
Laurent Bessard
parents: 2085
diff changeset
    84
#--------------------------------------------------
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    85
#                    Ethercat Node
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    86
#--------------------------------------------------
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    87
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
    88
class _EthercatSlaveCTN:
2063
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
    89
    
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    90
    NODE_PROFILE = None
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    91
    EditorType = NodeEditor
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
    92
    
2068
05a267b1a362 Adding support using plcopeneditor bitmap library for icon request
Laurent Bessard
parents: 2067
diff changeset
    93
    def GetIconName(self):
05a267b1a362 Adding support using plcopeneditor bitmap library for icon request
Laurent Bessard
parents: 2067
diff changeset
    94
        return "Slave"
2043
27d4cb689a79 Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents: 2042
diff changeset
    95
    
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
    96
    def ExtractHexDecValue(self, value):
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
    97
        return ExtractHexDecValue(value)
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
    98
    
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
    99
    def GetSizeOfType(self, type):
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   100
        return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None)
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   101
    
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   102
    def GetSlavePos(self):
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   103
        return self.BaseParams.getIEC_Channel()
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   104
    
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   105
    def GetParamsAttributes(self, path = None):
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   106
        if path:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   107
            parts = path.split(".", 1)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   108
            if self.MandatoryParams and parts[0] == self.MandatoryParams[0]:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   109
                return self.MandatoryParams[1].getElementInfos(parts[0], parts[1])
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   110
            elif self.CTNParams and parts[0] == self.CTNParams[0]:
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   111
                return self.CTNParams[1].getElementInfos(parts[0], parts[1])
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   112
        else:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   113
            params = []
2063
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   114
            if self.CTNParams:
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   115
                params.append(self.CTNParams[1].getElementInfos(self.CTNParams[0]))
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   116
            else:
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   117
                params.append({
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   118
                    'use': 'required', 
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   119
                    'type': 'element', 
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   120
                    'name': 'SlaveParams', 
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   121
                    'value': None, 
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   122
                    'children': []
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   123
                })
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   124
            
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   125
            slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos())
2063
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   126
            params[0]['children'].insert(0,
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   127
                   {'use': 'optional', 
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   128
                    'type': self.CTNParent.GetSlaveTypesLibrary(self.NODE_PROFILE), 
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   129
                    'name': 'Type', 
2063
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   130
                    'value': (slave_type["device_type"], slave_type)}) 
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   131
            params[0]['children'].insert(1,
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   132
                   {'use': 'optional', 
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   133
                    'type': 'unsignedLong', 
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   134
                    'name': 'Alias', 
2063
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   135
                    'value': self.CTNParent.GetSlaveAlias(self.GetSlavePos())})
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   136
            return params
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   137
        
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   138
    def SetParamsAttribute(self, path, value):
2066
de4817ce8b50 Fix bug when modifying node parameters
Laurent Bessard
parents: 2064
diff changeset
   139
        position = self.BaseParams.getIEC_Channel()
de4817ce8b50 Fix bug when modifying node parameters
Laurent Bessard
parents: 2064
diff changeset
   140
        
2063
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   141
        if path == "SlaveParams.Type":
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   142
            self.CTNParent.SetSlaveType(position, value)
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   143
            slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos())
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   144
            value = (slave_type["device_type"], slave_type)
2067
04cc0295e2c4 Fix bug slave information panel not refreshed when slave type changed
Laurent Bessard
parents: 2066
diff changeset
   145
            if self._View is not None:
04cc0295e2c4 Fix bug slave information panel not refreshed when slave type changed
Laurent Bessard
parents: 2066
diff changeset
   146
                wx.CallAfter(self._View.RefreshSlaveInfos)
2063
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   147
            return value, True
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   148
        elif path == "SlaveParams.Alias":
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   149
            self.CTNParent.SetSlaveAlias(position, value)
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   150
            return value, True
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   151
        
2080
6d0d94cd0fe0 Fix bug when modifying slave position
Laurent Bessard
parents: 2079
diff changeset
   152
        value, refresh = ConfigTreeNode.SetParamsAttribute(self, path, value)
6d0d94cd0fe0 Fix bug when modifying slave position
Laurent Bessard
parents: 2079
diff changeset
   153
        
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   154
        # Filter IEC_Channel, Slave_Type and Alias that have specific behavior
2080
6d0d94cd0fe0 Fix bug when modifying slave position
Laurent Bessard
parents: 2079
diff changeset
   155
        if path == "BaseParams.IEC_Channel" and value != position:
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   156
            self.CTNParent.SetSlavePosition(position, value)
2063
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   157
        
2080
6d0d94cd0fe0 Fix bug when modifying slave position
Laurent Bessard
parents: 2079
diff changeset
   158
        return value, refresh
6d0d94cd0fe0 Fix bug when modifying slave position
Laurent Bessard
parents: 2079
diff changeset
   159
        
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   160
    def GetSlaveInfos(self):
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   161
        return self.CTNParent.GetSlaveInfos(self.GetSlavePos())
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   162
    
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   163
    def GetVariableLocationTree(self):
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   164
        return  {"name": self.BaseParams.getName(),
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   165
                 "type": LOCATION_CONFNODE,
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   166
                 "location": self.GetFullIEC_Channel(),
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   167
                 "children": self.CTNParent.GetDeviceLocationTree(self.GetSlavePos(), self.GetCurrentLocation(), self.BaseParams.getName())
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   168
        }
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   169
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   170
    def CTNGenerate_C(self, buildpath, locations):
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   171
        """
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   172
        Generate C code
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   173
        @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5)
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   174
        @param locations: List of complete variables locations \
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   175
            [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   176
            "NAME" : name of the variable (generally "__IW0_1_2" style)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   177
            "DIR" : direction "Q","I" or "M"
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   178
            "SIZE" : size "X", "B", "W", "D", "L"
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   179
            "LOC" : tuple of interger for IEC location (0,1,2,...)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   180
            }, ...]
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   181
        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   182
        """
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   183
        return [],"",False
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   184
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   185
#--------------------------------------------------
2043
27d4cb689a79 Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents: 2042
diff changeset
   186
#                 Ethercat CIA402 Node
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   187
#--------------------------------------------------
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   188
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   189
if HAS_MCL:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   190
    
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   191
    NODE_VARIABLES = [
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   192
        ("ControlWord", 0x6040, 0x00, "UINT", "Q"),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   193
        ("TargetPosition", 0x607a, 0x00, "DINT", "Q"),
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   194
        ("ModesOfOperation", 0x06060, 0x00, "SINT", "Q"),
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   195
        ("StatusWord", 0x6041, 0x00, "UINT", "I"),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   196
        ("ModesOfOperationDisplay", 0x06061, 0x00, "SINT", "I"),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   197
        ("ActualPosition", 0x6064, 0x00, "DINT", "I"),
2091
d964dbc2c7b0 Adding support for extracting ActualVelocity from CIA402 nodes PDOs
Laurent Bessard
parents: 2088
diff changeset
   198
        ("ActualVelocity", 0x606C, 0x00, "DINT", "I"),
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   199
    ]
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   200
    
2085
ae263886ae92 Fix bug in CIA402 slave digital inputs
Laurent Bessard
parents: 2084
diff changeset
   201
    DEFAULT_RETRIEVE = "    __CIA402Node_%(location)s.axis->%(name)s = *(__CIA402Node_%(location)s.%(name)s);"
ae263886ae92 Fix bug in CIA402 slave digital inputs
Laurent Bessard
parents: 2084
diff changeset
   202
    DEFAULT_PUBLISH = "    *(__CIA402Node_%(location)s.%(name)s) = __CIA402Node_%(location)s.axis->%(name)s;"
2084
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   203
    
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   204
    EXTRA_NODE_VARIABLES = [
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   205
        ("DigitalInputs", [
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   206
            {"description": ("DigitalInputs", 0x60FD, 0x00, "UDINT", "I"),
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   207
             "publish": None}
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   208
            ])
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   209
    ]
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   210
    EXTRA_NODE_VARIABLES_DICT = dict([("Enable" + name, value) for name, value in EXTRA_NODE_VARIABLES])
2092
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   211
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   212
    BLOCK_INPUT_TEMPLATE = "    __SET_VAR(%(blockname)s.,%(input_name)s, %(input_value)s);"
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   213
    BLOCK_OUTPUT_TEMPLATE = "    __SET_VAR(data__->,%(output_name)s, __GET_VAR(%(blockname)s.%(output_name)s));"
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   214
    
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   215
    BLOCK_FUNCTION_TEMPLATE = """
2093
3fdf9d56d803 Fix bug in support for Etherlab specific fieldbus interface function blocks
Laurent Bessard
parents: 2092
diff changeset
   216
extern void ETHERLAB%(ucase_blocktype)s_body__(ETHERLAB%(ucase_blocktype)s* data__);
3fdf9d56d803 Fix bug in support for Etherlab specific fieldbus interface function blocks
Laurent Bessard
parents: 2092
diff changeset
   217
void __%(blocktype)s_%(location)s(MC_%(ucase_blocktype)s *data__) {
2092
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   218
    extern ETHERLAB%(ucase_blocktype)s %(blockname)s;
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   219
%(extract_inputs)s
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   220
    ETHERLAB%(ucase_blocktype)s_body__(&%(blockname)s);
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   221
%(return_outputs)s
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   222
}
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   223
"""
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   224
    
2093
3fdf9d56d803 Fix bug in support for Etherlab specific fieldbus interface function blocks
Laurent Bessard
parents: 2092
diff changeset
   225
    BLOCK_FUNTION_DEFINITION_TEMPLATE = "    __CIA402Node_%(location)s.axis->__mcl_func_MC_%(blocktype)s = &(__%(blocktype)s_%(location)s);"
2092
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   226
    
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   227
    GLOBAL_INSTANCES = [
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   228
        {"blocktype": "GetTorqueLimit", 
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   229
         "inputs": [],
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   230
         "outputs": [{"name": "TorqueLimitPos", "type": "UINT"},
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   231
                     {"name": "TorqueLimitNeg", "type": "UINT"}]},
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   232
        {"blocktype": "SetTorqueLimit", 
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   233
         "inputs": [{"name": "TorqueLimitPos", "type": "UINT"},
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   234
                    {"name": "TorqueLimitNeg", "type": "UINT"}],
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   235
         "outputs": []},
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   236
    ]
2084
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   237
    
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   238
    class _EthercatCIA402SlaveCTN(_EthercatSlaveCTN):
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   239
        XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   240
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2043
27d4cb689a79 Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents: 2042
diff changeset
   241
          <xsd:element name="CIA402SlaveParams">
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   242
            <xsd:complexType>
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   243
              %s
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   244
            </xsd:complexType>
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   245
          </xsd:element>
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   246
        </xsd:schema>
2084
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   247
        """ % ("\n".join(['<xsd:attribute name="Enable%s" type="xsd:boolean" use="optional" default="false"/>' % category 
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   248
                          for category, variables in EXTRA_NODE_VARIABLES]) + AxisXSD)
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   249
        
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   250
        NODE_PROFILE = 402
2043
27d4cb689a79 Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents: 2042
diff changeset
   251
        EditorType = CIA402NodeEditor
27d4cb689a79 Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents: 2042
diff changeset
   252
        
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   253
        ConfNodeMethods = [
2068
05a267b1a362 Adding support using plcopeneditor bitmap library for icon request
Laurent Bessard
parents: 2067
diff changeset
   254
            {"bitmap" : "CIA402AxisRef",
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   255
             "name" : _("Axis Ref"),
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   256
             "tooltip" : _("Initiate Drag'n drop of Axis ref located variable"),
2063
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   257
             "method" : "_getCIA402AxisRef",
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   258
             "push": True},
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   259
        ]
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   260
        
2068
05a267b1a362 Adding support using plcopeneditor bitmap library for icon request
Laurent Bessard
parents: 2067
diff changeset
   261
        def GetIconName(self):
05a267b1a362 Adding support using plcopeneditor bitmap library for icon request
Laurent Bessard
parents: 2067
diff changeset
   262
            return "CIA402Slave"
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   263
        
2063
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   264
        def SetParamsAttribute(self, path, value):
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   265
            if path == "CIA402SlaveParams.Type":
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   266
                path = "SlaveParams.Type"
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   267
            elif path == "CIA402SlaveParams.Alias":
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   268
                path = "SlaveParams.Alias"
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   269
            return _EthercatSlaveCTN.SetParamsAttribute(self, path, value)
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   270
        
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   271
        def GetVariableLocationTree(self):
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   272
            axis_name = self.CTNName()
2063
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   273
            current_location = self.GetCurrentLocation()
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   274
            children = [{"name": "%s Axis Ref" % (axis_name),
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   275
                         "type": LOCATION_VAR_INPUT,
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   276
                         "size": "W",
2083
0f7ab170c862 Fix Axis_Ref type defined in VariableLocationTree
Laurent Bessard
parents: 2082
diff changeset
   277
                         "IEC_type": "AXIS_REF",
2063
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   278
                         "var_name": axis_name,
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   279
                         "location": "%%IW%s.0" % (".".join(map(str, current_location))),
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   280
                         "description": "",
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   281
                         "children": []}]
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   282
            children.extend(self.CTNParent.GetDeviceLocationTree(self.GetSlavePos(), current_location, axis_name))
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   283
            return  {"name": axis_name,
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   284
                     "type": LOCATION_CONFNODE,
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   285
                     "location": self.GetFullIEC_Channel(),
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   286
                     "children": children,
c9a1c5bb51cd Fix bug with AXIS_REF located variable drag'n drop and disable dynamic PDOs support
Laurent Bessard
parents: 2062
diff changeset
   287
            }
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   288
        
2092
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   289
        def CTNGlobalInstances(self):
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   290
            current_location = self.GetCurrentLocation()
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   291
            return [("%s_%s" % (block_infos["blocktype"], "_".join(map(str, current_location))),
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   292
                     "EtherLab%s" % block_infos["blocktype"]) for block_infos in GLOBAL_INSTANCES]
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   293
        
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   294
        def _getCIA402AxisRef(self):
2074
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
   295
            data = wx.TextDataObject(str(("%%IW%s.0" % ".".join(map(str, self.GetCurrentLocation())), 
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   296
                                          "location", "AXIS_REF", self.CTNName(), "")))
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   297
            dragSource = wx.DropSource(self.GetCTRoot().AppFrame)
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   298
            dragSource.SetData(data)
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   299
            dragSource.DoDragDrop()
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   300
        
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   301
        def CTNGenerate_C(self, buildpath, locations):
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   302
            """
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   303
            Generate C code
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   304
            @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5)
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   305
            @param locations: List of complete variables locations \
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   306
                [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   307
                "NAME" : name of the variable (generally "__IW0_1_2" style)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   308
                "DIR" : direction "Q","I" or "M"
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   309
                "SIZE" : size "X", "B", "W", "D", "L"
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   310
                "LOC" : tuple of interger for IEC location (0,1,2,...)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   311
                }, ...]
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   312
            @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   313
            """
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   314
            current_location = self.GetCurrentLocation()
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   315
            
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   316
            location_str = "_".join(map(lambda x:str(x), current_location))
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   317
            
2045
62e102935f3e Adding test project using higen drive
laurent
parents: 2043
diff changeset
   318
            plc_cia402node_filepath = os.path.join(os.path.split(__file__)[0], "plc_cia402node.c")
62e102935f3e Adding test project using higen drive
laurent
parents: 2043
diff changeset
   319
            plc_cia402node_file = open(plc_cia402node_filepath, 'r')
62e102935f3e Adding test project using higen drive
laurent
parents: 2043
diff changeset
   320
            plc_cia402node_code = plc_cia402node_file.read()
62e102935f3e Adding test project using higen drive
laurent
parents: 2043
diff changeset
   321
            plc_cia402node_file.close()
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   322
            
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   323
            str_completion = {
2088
c0952932d74b Adding support for using Etherlab SDO function blocks in MCL
Laurent Bessard
parents: 2086
diff changeset
   324
                "slave_pos": self.GetSlavePos(),
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   325
                "location": location_str,
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   326
                "MCL_headers": Headers,
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   327
                "extern_located_variables_declaration": [],
2092
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   328
                "fieldbus_interface_declaration": [],
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   329
                "fieldbus_interface_definition": [],
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   330
                "entry_variables": [],
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   331
                "init_axis_params": [],
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   332
                "init_entry_variables": [],
2084
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   333
                "extra_variables_retrieve": [],
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   334
                "extra_variables_publish": []
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   335
            }
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   336
            
2092
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   337
            for blocktype_infos in GLOBAL_INSTANCES:
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   338
                texts = {
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   339
                    "blocktype": blocktype_infos["blocktype"],
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   340
                    "ucase_blocktype": blocktype_infos["blocktype"].upper(),
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   341
                    "location": "_".join(map(str, current_location))
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   342
                }
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   343
                texts["blockname"] = "%(ucase_blocktype)s_%(location)s" % texts
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   344
                
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   345
                inputs = [{"input_name": "POS", "input_value": str(self.GetSlavePos())},
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   346
                          {"input_name": "EXECUTE", "input_value": "__GET_VAR(data__->EXECUTE)"}] +\
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   347
                         [{"input_name": input["name"].upper(), 
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   348
                           "input_value": "__GET_VAR(data__->%s)" % input["name"].upper()}
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   349
                          for input in blocktype_infos["inputs"]]
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   350
                input_texts = []
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   351
                for input_infos in inputs:
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   352
                    input_infos.update(texts)
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   353
                    input_texts.append(BLOCK_INPUT_TEMPLATE % input_infos)
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   354
                texts["extract_inputs"] = "\n".join(input_texts)
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   355
                
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   356
                outputs = [{"output_name": output} for output in ["DONE", "BUSY", "ERROR"]] + \
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   357
                          [{"output_name": output["name"].upper()} for output in blocktype_infos["outputs"]]
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   358
                output_texts = []
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   359
                for output_infos in outputs:
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   360
                    output_infos.update(texts)
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   361
                    output_texts.append(BLOCK_OUTPUT_TEMPLATE % output_infos)
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   362
                texts["return_outputs"] = "\n".join(output_texts)
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   363
                
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   364
                str_completion["fieldbus_interface_declaration"].append(
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   365
                        BLOCK_FUNCTION_TEMPLATE % texts)
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   366
                
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   367
                str_completion["fieldbus_interface_definition"].append(
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   368
                        BLOCK_FUNTION_DEFINITION_TEMPLATE % texts)
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   369
                
2084
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   370
            variables = NODE_VARIABLES[:]
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   371
            
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   372
            params = self.CTNParams[1].getElementInfos(self.CTNParams[0])
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   373
            for param in params["children"]:
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   374
                if param["name"] in EXTRA_NODE_VARIABLES_DICT:
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   375
                    if param["value"]:
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   376
                        extra_variables = EXTRA_NODE_VARIABLES_DICT.get(param["name"])
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   377
                        for variable_infos in extra_variables:
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   378
                            var_infos = {
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   379
                                "location": location_str,
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   380
                                "name": variable_infos["description"][0]
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   381
                            }
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   382
                            variables.append(variable_infos["description"])
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   383
                            retrieve_template = variable_infos.get("retrieve", DEFAULT_RETRIEVE)
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   384
                            publish_template = variable_infos.get("publish", DEFAULT_PUBLISH)
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   385
                            
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   386
                            if retrieve_template is not None:
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   387
                                str_completion["extra_variables_retrieve"].append(
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   388
                                    retrieve_template % var_infos)
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   389
                            if publish_template is not None:
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   390
                                str_completion["extra_variables_publish"].append(
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   391
                                    publish_template % var_infos)
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   392
                elif param["value"] is not None:
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   393
                    param_infos = {
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   394
                        "location": location_str,
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   395
                        "param_name": param["name"],
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   396
                    }
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   397
                    if param["type"] == "boolean":
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   398
                        param_infos["param_value"] = {True: "true", False: "false"}[param["value"]]
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   399
                    else:
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   400
                        param_infos["param_value"] = str(param["value"])
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   401
                    str_completion["init_axis_params"].append(
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   402
                        "        __CIA402Node_%(location)s.axis->%(param_name)s = %(param_value)s;" % param_infos)
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   403
            
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   404
            for variable in variables:
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   405
                var_infos = dict(zip(["name", "index", "subindex", "var_type", "dir"], variable))
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   406
                var_infos["location"] = location_str
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   407
                var_infos["var_size"] = self.GetSizeOfType(var_infos["var_type"])
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   408
                var_infos["var_name"] = "__%(dir)s%(var_size)s%(location)s_%(index)d_%(subindex)d" % var_infos
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   409
                
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   410
                str_completion["extern_located_variables_declaration"].append(
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   411
                        "IEC_%(var_type)s *%(var_name)s;" % var_infos)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   412
                str_completion["entry_variables"].append(
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   413
                        "    IEC_%(var_type)s *%(name)s;" % var_infos)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   414
                str_completion["init_entry_variables"].append(
2043
27d4cb689a79 Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents: 2042
diff changeset
   415
                        "    __CIA402Node_%(location)s.%(name)s = %(var_name)s;" % var_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
   416
                
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   417
                self.CTNParent.FileGenerator.DeclareVariable(
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   418
                        self.GetSlavePos(), var_infos["index"], var_infos["subindex"], 
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   419
                        var_infos["var_type"], var_infos["dir"], var_infos["var_name"])
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   420
            
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   421
            for element in ["extern_located_variables_declaration", 
2092
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   422
                            "fieldbus_interface_declaration",
c9776ae8b5d0 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks
Laurent Bessard
parents: 2091
diff changeset
   423
                            "fieldbus_interface_definition",
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   424
                            "entry_variables", 
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   425
                            "init_axis_params", 
2084
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   426
                            "init_entry_variables",
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   427
                            "extra_variables_retrieve",
579af800b359 Adding support to enable CIA402 slave digital inputs
Laurent Bessard
parents: 2083
diff changeset
   428
                            "extra_variables_publish"]:
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   429
                str_completion[element] = "\n".join(str_completion[element])
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   430
            
2045
62e102935f3e Adding test project using higen drive
laurent
parents: 2043
diff changeset
   431
            Gen_CIA402Nodefile_path = os.path.join(buildpath, "cia402node_%s.c"%location_str)
62e102935f3e Adding test project using higen drive
laurent
parents: 2043
diff changeset
   432
            cia402nodefile = open(Gen_CIA402Nodefile_path, 'w')
62e102935f3e Adding test project using higen drive
laurent
parents: 2043
diff changeset
   433
            cia402nodefile.write(plc_cia402node_code % str_completion)
62e102935f3e Adding test project using higen drive
laurent
parents: 2043
diff changeset
   434
            cia402nodefile.close()
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   435
            
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   436
            return [(Gen_CIA402Nodefile_path, '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()))],"",True
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
   437
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   438
#--------------------------------------------------
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   439
#                 Ethercat MASTER
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   440
#--------------------------------------------------
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   441
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   442
EtherCATConfigClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATConfig.xsd")) 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   443
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   444
def ExtractHexDecValue(value):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   445
    try:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   446
        return int(value)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   447
    except:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   448
        pass
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   449
    try:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   450
        return int(value.replace("#", "0"), 16)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   451
    except:
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
   452
        raise ValueError, "Invalid value for HexDecValue \"%s\"" % value
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   453
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   454
def GenerateHexDecValue(value, base=10):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   455
    if base == 10:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   456
        return str(value)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   457
    elif base == 16:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   458
        return "#x%.8x" % value
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   459
    else:
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
   460
        raise ValueError, "Not supported base"
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   461
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   462
cls = EtherCATConfigClasses.get("Config_Slave", None)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   463
if cls:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   464
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   465
    def getType(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   466
        slave_info = self.getInfo()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   467
        return {"device_type": slave_info.getName(),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   468
                "vendor": GenerateHexDecValue(slave_info.getVendorId()),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   469
                "product_code": GenerateHexDecValue(slave_info.getProductCode(), 16),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   470
                "revision_number": GenerateHexDecValue(slave_info.getRevisionNo(), 16)}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   471
    setattr(cls, "getType", getType)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   472
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   473
    def setType(self, type_infos):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   474
        slave_info = self.getInfo()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   475
        slave_info.setName(type_infos["device_type"])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   476
        slave_info.setVendorId(ExtractHexDecValue(type_infos["vendor"]))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   477
        slave_info.setProductCode(ExtractHexDecValue(type_infos["product_code"]))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   478
        slave_info.setRevisionNo(ExtractHexDecValue(type_infos["revision_number"]))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   479
    setattr(cls, "setType", setType)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   480
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   481
class _EthercatCTN:
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   482
    XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   483
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   484
      <xsd:element name="EtherlabNode">
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   485
        <xsd:complexType>
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   486
          <xsd:attribute name="MasterNumber" type="xsd:integer" use="optional" default="0"/>
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   487
        </xsd:complexType>
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   488
      </xsd:element>
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   489
    </xsd:schema>
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   490
    """
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   491
    
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   492
    CTNChildrenTypes = [("EthercatSlave", _EthercatSlaveCTN, "Ethercat Slave")]
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   493
    if HAS_MCL:
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   494
        CTNChildrenTypes.append(("EthercatCIA402Slave", _EthercatCIA402SlaveCTN, "Ethercat CIA402 Slave"))
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   495
    
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   496
    def __init__(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   497
        filepath = self.ConfigFileName()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   498
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   499
        self.Config = EtherCATConfigClasses["EtherCATConfig"]()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   500
        if os.path.isfile(filepath):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   501
            xmlfile = open(filepath, 'r')
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   502
            tree = minidom.parse(xmlfile)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   503
            xmlfile.close()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   504
            
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   505
            for child in tree.childNodes:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   506
                if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "EtherCATConfig":
2051
13dee9322beb refactoring
laurent
parents: 2047
diff changeset
   507
                    self.Config.loadXMLTree(child)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   508
                    self.CreateConfigBuffer(True)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   509
        else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   510
            self.CreateConfigBuffer(False)
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   511
            self.OnCTNSave()
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   512
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   513
    def ExtractHexDecValue(self, value):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   514
        return ExtractHexDecValue(value)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   515
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   516
    def GetSizeOfType(self, type):
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   517
        return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   518
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   519
    def ConfigFileName(self):
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   520
        return os.path.join(self.CTNPath(), "config.xml")
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   521
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   522
    def GetSlaves(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   523
        slaves = []
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   524
        for slave in self.Config.getConfig().getSlave():
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   525
            slaves.append(slave.getInfo().getPhysAddr())
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   526
        slaves.sort()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   527
        return slaves
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   528
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   529
    def GetSlave(self, slave_pos):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   530
        for slave in self.Config.getConfig().getSlave():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   531
            slave_info = slave.getInfo()
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   532
            if slave_info.getPhysAddr() == slave_pos:
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   533
                return slave
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   534
        return None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   535
2042
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   536
    def _ScanNetwork(self):
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   537
        app_frame = self.GetCTRoot().AppFrame
2042
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   538
        
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   539
        execute = True
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   540
        if len(self.Children) > 0:
2042
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   541
            dialog = wx.MessageDialog(app_frame, 
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   542
                _("The current network configuration will be deleted.\nDo you want to continue?"), 
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   543
                _("Scan Network"), 
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   544
                wx.YES_NO|wx.ICON_QUESTION)
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   545
            execute = dialog.ShowModal() == wx.ID_YES
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   546
            dialog.Destroy()
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   547
        
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   548
        if execute:
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   549
            error, returnVal = self.RemoteExec(SCAN_COMMAND, returnVal = None)
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   550
            if error != 0:
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   551
                dialog = wx.MessageDialog(app_frame, returnVal, "Error", wx.OK|wx.ICON_ERROR)
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   552
                dialog.ShowModal()
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   553
                dialog.Destroy()
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   554
            elif returnVal is not None:
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   555
                for child in self.IECSortedChildren():
2042
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   556
                    self._doRemoveChild(child)
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   557
                
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   558
                for slave in returnVal:
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   559
                    type_infos = {
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   560
                        "vendor": slave["vendor_id"],
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   561
                        "product_code": slave["product_code"],
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   562
                        "revision_number":slave["revision_number"],
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   563
                    }
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   564
                    device = self.GetModuleInfos(type_infos)
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   565
                    if device is not None:
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   566
                        if HAS_MCL and _EthercatCIA402SlaveCTN.NODE_PROFILE in device.GetProfileNumbers():
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   567
                            CTNType = "EthercatCIA402Slave"
2042
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   568
                        else:
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   569
                            CTNType = "EthercatSlave"
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   570
                        self.CTNAddChild("slave%s" % slave["idx"], CTNType, slave["idx"])
2042
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   571
                        self.SetSlaveAlias(slave["idx"], slave["alias"])
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   572
                        type_infos["device_type"] = device.getType().getcontent()
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   573
                        self.SetSlaveType(slave["idx"], type_infos)
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   574
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   575
    def CTNAddChild(self, CTNName, CTNType, IEC_Channel=0):
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   576
        """
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   577
        Create the confnodes that may be added as child to this node self
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   578
        @param CTNType: string desining the confnode class name (get name from CTNChildrenTypes)
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   579
        @param CTNName: string for the name of the confnode instance
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   580
        """
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   581
        newConfNodeOpj = ConfigTreeNode.CTNAddChild(self, CTNName, CTNType, IEC_Channel)
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   582
        
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   583
        slave = self.GetSlave(newConfNodeOpj.BaseParams.getIEC_Channel())
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   584
        if slave is None:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   585
            slave = EtherCATConfigClasses["Config_Slave"]()
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   586
            slave_infos = slave.getInfo()
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   587
            slave_infos.setName("undefined")
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   588
            slave_infos.setPhysAddr(newConfNodeOpj.BaseParams.getIEC_Channel())
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   589
            slave_infos.setAutoIncAddr(0)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   590
            self.Config.getConfig().appendSlave(slave)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   591
            self.BufferConfig()
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   592
            self.OnCTNSave()
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   593
        
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   594
        return newConfNodeOpj
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   595
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   596
    def _doRemoveChild(self, CTNInstance):
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   597
        slave_pos = CTNInstance.GetSlavePos()
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   598
        config = self.Config.getConfig()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   599
        for idx, slave in enumerate(config.getSlave()):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   600
            slave_infos = slave.getInfo()
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   601
            if slave_infos.getPhysAddr() == slave_pos:
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   602
                config.removeSlave(idx)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   603
                self.BufferConfig()
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   604
                self.OnCTNSave()
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   605
        ConfigTreeNode._doRemoveChild(self, CTNInstance)
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   606
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   607
    def SetSlavePosition(self, slave_pos, new_pos):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   608
        slave = self.GetSlave(slave_pos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   609
        if slave is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   610
            slave_info = slave.getInfo()
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   611
            slave_info.setPhysAddr(new_pos)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   612
            self.BufferConfig()
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   613
    
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   614
    def GetSlaveAlias(self, slave_pos):
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   615
        slave = self.GetSlave(slave_pos)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   616
        if slave 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
   617
            slave_info = slave.getInfo()
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   618
            return slave_info.getAutoIncAddr()
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   619
        return None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   620
    
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   621
    def SetSlaveAlias(self, slave_pos, alias):
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   622
        slave = self.GetSlave(slave_pos)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   623
        if slave 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
   624
            slave_info = slave.getInfo()
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   625
            slave_info.setAutoIncAddr(alias)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   626
            self.BufferConfig()
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   627
    
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   628
    def GetSlaveType(self, slave_pos):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   629
        slave = self.GetSlave(slave_pos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   630
        if slave is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   631
            return slave.getType()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   632
        return None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   633
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   634
    def SetSlaveType(self, slave_pos, type_infos):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   635
        slave = self.GetSlave(slave_pos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   636
        if slave is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   637
            slave.setType(type_infos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   638
            self.BufferConfig()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   639
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   640
    def GetSlaveInfos(self, slave_pos):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   641
        slave = self.GetSlave(slave_pos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   642
        if slave is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   643
            type_infos = slave.getType()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   644
            device = self.GetModuleInfos(type_infos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   645
            if device is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   646
                infos = type_infos.copy()
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
   647
                entries = device.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
   648
                entries_list = entries.items()
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
   649
                entries_list.sort()
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   650
                entries = []
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   651
                current_index = None
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   652
                current_entry = None
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   653
                for (index, subindex), entry in entries_list:
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   654
                    entry["children"] = []
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   655
                    if index != current_index:
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   656
                        current_index = index
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   657
                        current_entry = entry
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   658
                        entries.append(entry)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   659
                    elif current_entry is not None:
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   660
                        current_entry["children"].append(entry)
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   661
                    else:
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   662
                        entries.append(entry)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   663
                infos.update({"physics": device.getPhysics(),
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
   664
                              "sync_managers": device.GetSyncManagers(),
2038
6f78c4ac22f9 Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents: 2037
diff changeset
   665
                              "entries": entries})
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   666
                return infos
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   667
        return None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   668
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   669
    def GetModuleInfos(self, type_infos):
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   670
        return self.CTNParent.GetModuleInfos(type_infos)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   671
    
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   672
    def GetSlaveTypesLibrary(self, profile_filter=None):
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   673
        return self.CTNParent.GetModulesLibrary(profile_filter)
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   674
    
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   675
    def GetDeviceLocationTree(self, slave_pos, current_location, device_name):
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   676
        slave = self.GetSlave(slave_pos)
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
   677
        vars = []    
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   678
        if slave 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
   679
            type_infos = slave.getType()
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   680
        
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   681
            device = self.GetModuleInfos(type_infos)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   682
            if device 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
   683
                sync_managers = []
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   684
                for sync_manager in device.getSm():
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   685
                    sync_manager_control_byte = ExtractHexDecValue(sync_manager.getControlByte())
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   686
                    sync_manager_direction = sync_manager_control_byte & 0x0c
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   687
                    if sync_manager_direction:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   688
                        sync_managers.append(LOCATION_VAR_OUTPUT)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   689
                    else:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   690
                        sync_managers.append(LOCATION_VAR_INPUT)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   691
                
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   692
                entries = device.GetEntriesList().items()
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   693
                entries.sort()
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   694
                for (index, subindex), entry in entries:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   695
                    var_size = self.GetSizeOfType(entry["Type"])
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   696
                    if var_size 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
   697
                        var_class = VARCLASSCONVERSION.get(entry["PDOMapping"], None)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   698
                        if var_class 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
   699
                            if var_class == LOCATION_VAR_INPUT:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   700
                                var_dir = "%I"
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   701
                            else:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   702
                                var_dir = "%Q"    
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   703
                        
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   704
                            vars.append({"name": "0x%4.4x-0x%2.2x: %s" % (index, subindex, entry["Name"]),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   705
                                         "type": var_class,
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   706
                                         "size": var_size,
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   707
                                         "IEC_type": entry["Type"],
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   708
                                         "var_name": "%s_%4.4x_%2.2x" % ("_".join(device_name.split()), index, subindex),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   709
                                         "location": "%s%s%s"%(var_dir, var_size, ".".join(map(str, current_location + 
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   710
                                                                                                    (index, subindex)))),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   711
                                         "description": "",
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   712
                                         "children": []})
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   713
        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   714
        return vars
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   715
    
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   716
    def CTNTestModified(self):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   717
        return self.ChangesToSave or not self.ConfigIsSaved()    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   718
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   719
    def OnCTNSave(self):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   720
        filepath = self.ConfigFileName()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   721
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   722
        text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   723
        extras = {"xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance",
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   724
                  "xsi:noNamespaceSchemaLocation" : "EtherCATInfo.xsd"}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   725
        text += self.Config.generateXMLText("EtherCATConfig", 0, extras)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   726
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   727
        xmlfile = open(filepath,"w")
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   728
        xmlfile.write(text.encode("utf-8"))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   729
        xmlfile.close()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   730
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   731
        self.ConfigBuffer.CurrentSaved()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   732
        return True
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   733
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   734
    def _Generate_C(self, buildpath, locations):
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   735
        current_location = self.GetCurrentLocation()
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   736
        # define a unique name for the generated C file
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   737
        location_str = "_".join(map(lambda x:str(x), current_location))
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   738
        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   739
        Gen_Ethercatfile_path = os.path.join(buildpath, "ethercat_%s.c"%location_str)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   740
        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   741
        self.FileGenerator = _EthercatCFileGenerator(self)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   742
        
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   743
        LocationCFilesAndCFLAGS, LDFLAGS, extra_files = ConfigTreeNode._Generate_C(self, buildpath, locations)
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   744
        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   745
        self.FileGenerator.GenerateCFile(Gen_Ethercatfile_path, location_str, self.EtherlabNode)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   746
        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   747
        LocationCFilesAndCFLAGS.append(
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   748
            (current_location, 
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   749
             [(Gen_Ethercatfile_path, '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()))], 
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   750
             True))
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   751
        LDFLAGS.append("-lethercat -lrtdm")
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   752
        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   753
        return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   754
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   755
    ConfNodeMethods = [
2068
05a267b1a362 Adding support using plcopeneditor bitmap library for icon request
Laurent Bessard
parents: 2067
diff changeset
   756
        {"bitmap" : "ScanNetwork",
2042
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   757
         "name" : _("Scan Network"), 
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   758
         "tooltip" : _("Scan Network"),
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   759
         "method" : "_ScanNetwork"},
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   760
    ]
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
   761
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   762
    def CTNGenerate_C(self, buildpath, locations):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   763
        """
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   764
        Generate C code
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
   765
        @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   766
        @param locations: List of complete variables locations \
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   767
            [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   768
            "NAME" : name of the variable (generally "__IW0_1_2" style)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   769
            "DIR" : direction "Q","I" or "M"
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   770
            "SIZE" : size "X", "B", "W", "D", "L"
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   771
            "LOC" : tuple of interger for IEC location (0,1,2,...)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   772
            }, ...]
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   773
        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   774
        """
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   775
        current_location = self.GetCurrentLocation()
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   776
        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   777
        slaves = self.GetSlaves()
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   778
        for slave_pos in slaves:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   779
            slave = self.GetSlave(slave_pos)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   780
            if slave is not None:
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
   781
                self.FileGenerator.DeclareSlave(slave_pos, slave.getInfo().getAutoIncAddr(), slave.getType())
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   782
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   783
        for location in locations:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   784
            loc = location["LOC"][len(current_location):]
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   785
            slave_pos = loc[0]
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   786
            if slave_pos in slaves and len(loc) == 3:
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   787
                self.FileGenerator.DeclareVariable(
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   788
                    slave_pos, loc[1], loc[2], location["IEC_TYPE"], location["DIR"], location["NAME"])
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   789
        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   790
        return [],"",False
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   791
        
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   792
#-------------------------------------------------------------------------------
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   793
#                      Current Buffering Management Functions
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   794
#-------------------------------------------------------------------------------
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   795
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   796
    """
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   797
    Return a copy of the config
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   798
    """
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   799
    def Copy(self, model):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   800
        return cPickle.loads(cPickle.dumps(model))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   801
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   802
    def CreateConfigBuffer(self, saved):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   803
        self.ConfigBuffer = UndoBuffer(cPickle.dumps(self.Config), saved)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   804
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   805
    def BufferConfig(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   806
        self.ConfigBuffer.Buffering(cPickle.dumps(self.Config))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   807
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   808
    def ConfigIsSaved(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   809
        if self.ConfigBuffer is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   810
            return self.ConfigBuffer.IsCurrentSaved()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   811
        else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   812
            return True
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   813
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   814
    def LoadPrevious(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   815
        self.Config = cPickle.loads(self.ConfigBuffer.Previous())
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   816
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   817
    def LoadNext(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   818
        self.Config = cPickle.loads(self.ConfigBuffer.Next())
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   819
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   820
    def GetBufferState(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   821
        first = self.ConfigBuffer.IsFirst()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   822
        last = self.ConfigBuffer.IsLast()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   823
        return not first, not last
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   824
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   825
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   826
SLAVE_PDOS_CONFIGURATION_DECLARATION = """
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   827
/* Slave %(slave)d, "%(device_type)s"
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   828
 * Vendor ID:       0x%(vendor).8x
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   829
 * Product code:    0x%(product_code).8x
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   830
 * Revision number: 0x%(revision_number).8x
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   831
 */
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   832
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   833
ec_pdo_entry_info_t slave_%(slave)d_pdo_entries[] = {
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   834
%(pdos_entries_infos)s
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   835
};
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   836
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   837
ec_pdo_info_t slave_%(slave)d_pdos[] = {
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   838
%(pdos_infos)s
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   839
};
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   840
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   841
ec_sync_info_t slave_%(slave)d_syncs[] = {
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   842
%(pdos_sync_infos)s
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   843
    {0xff}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   844
};
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   845
"""
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   846
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   847
SLAVE_CONFIGURATION_TEMPLATE = """
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   848
    if (!(slave%(slave)d = ecrt_master_slave_config(master, %(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x))) {
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   849
        fprintf(stderr, "Failed to get slave %(device_type)s configuration at alias %(alias)d and position %(position)d.\\n");
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   850
        return -1;
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   851
    }
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   852
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   853
    if (ecrt_slave_config_pdos(slave%(slave)d, EC_END, slave_%(slave)d_syncs)) {
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   854
        fprintf(stderr, "Failed to configure PDOs for slave %(device_type)s at alias %(alias)d and position %(position)d.\\n");
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   855
        return -1;
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   856
    }
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   857
"""
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   858
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   859
SLAVE_INITIALIZATION_TEMPLATE = """
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   860
    {
2081
b1801bf4365c Fix bug in endianization in value transmit and received by SDO
Laurent Bessard
parents: 2080
diff changeset
   861
        uint8_t value[%(data_size)d];
b1801bf4365c Fix bug in endianization in value transmit and received by SDO
Laurent Bessard
parents: 2080
diff changeset
   862
        EC_WRITE_%(data_type)s((uint8_t *)value, %(data)s);
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   863
        if (ecrt_master_sdo_download(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &abort_code)) {
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   864
            fprintf(stderr, "Failed to initialize slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%d\\n", abort_code);
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   865
            return -1;
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   866
        }
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   867
    }
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   868
"""
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   869
2039
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   870
SLAVE_OUTPUT_PDO_DEFAULT_VALUE = """
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   871
    {
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   872
        uint8_t value[%(data_size)d];
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   873
        if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) {
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   874
            fprintf(stderr, "Failed to get default value for output PDO in slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%d\\n", abort_code);
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   875
            return -1;
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   876
        }
2081
b1801bf4365c Fix bug in endianization in value transmit and received by SDO
Laurent Bessard
parents: 2080
diff changeset
   877
        %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value);
2039
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   878
    }
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   879
"""
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   880
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
   881
def ConfigureVariable(entry_infos, str_completion):
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   882
    entry_infos["data_type"] = DATATYPECONVERSION.get(entry_infos["var_type"], None)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   883
    if entry_infos["data_type"] is 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
   884
        raise ValueError, _("Type of location \"%s\" not yet supported!") % entry_infos["var_name"]
2039
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   885
    
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   886
    if entry_infos.has_key("real_var"):
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   887
        str_completion["located_variables_declaration"].append(
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   888
            "IEC_%(var_type)s %(real_var)s;" % entry_infos)
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   889
    else:
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   890
        entry_infos["real_var"] = "beremiz" + entry_infos["var_name"]
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   891
        str_completion["located_variables_declaration"].extend(
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   892
            ["IEC_%(var_type)s %(real_var)s;" % entry_infos,
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   893
             "IEC_%(var_type)s *%(var_name)s = &%(real_var)s;" % entry_infos])
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   894
    
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   895
    str_completion["used_pdo_entry_offset_variables_declaration"].append(
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   896
        "unsigned int slave%(slave)d_%(index).4x_%(subindex).2x;" % entry_infos)
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   897
    
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   898
    if entry_infos["data_type"] == "BIT":
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   899
        str_completion["used_pdo_entry_offset_variables_declaration"].append(
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   900
            "unsigned int slave%(slave)d_%(index).4x_%(subindex).2x_bit;" % entry_infos)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   901
        
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   902
        str_completion["used_pdo_entry_configuration"].append(
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   903
             ("    {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, " + 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   904
              "0x%(index).4x, %(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x, " + 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   905
              "&slave%(slave)d_%(index).4x_%(subindex).2x_bit},") % entry_infos)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   906
        
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   907
        if entry_infos["dir"] == "I":
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   908
            str_completion["retrieve_variables"].append(
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   909
              ("    %(real_var)s = EC_READ_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + 
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   910
               "slave%(slave)d_%(index).4x_%(subindex).2x_bit);") % entry_infos)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   911
        elif entry_infos["dir"] == "Q":
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   912
            str_completion["publish_variables"].append(
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   913
              ("    EC_WRITE_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + 
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   914
               "slave%(slave)d_%(index).4x_%(subindex).2x_bit, %(real_var)s);") % entry_infos)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   915
    
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   916
    else:
2034
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   917
        str_completion["used_pdo_entry_configuration"].append(
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   918
            ("    {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, 0x%(index).4x, " + 
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   919
             "%(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x},") % entry_infos)
ae8fecf082a1 Adding support for MCL
laurent
parents: 2032
diff changeset
   920
        
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   921
        if entry_infos["dir"] == "I":
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   922
            str_completion["retrieve_variables"].append(
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   923
                ("    %(real_var)s = EC_READ_%(data_type)s(domain1_pd + " + 
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   924
                 "slave%(slave)d_%(index).4x_%(subindex).2x);") % entry_infos)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   925
        elif entry_infos["dir"] == "Q":
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   926
            str_completion["publish_variables"].append(
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   927
                ("    EC_WRITE_%(data_type)s(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + 
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   928
                 "%(real_var)s);") % entry_infos)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   929
2082
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
   930
def ExclusionSortFunction(x, y):
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
   931
    if x["matching"] == y["matching"]:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
   932
        if x["assigned"] and not y["assigned"]:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
   933
            return -1
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
   934
        elif not x["assigned"] and y["assigned"]:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
   935
            return 1
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
   936
        return cmp(x["count"], y["count"])
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
   937
    return -cmp(x["matching"], y["matching"])
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
   938
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   939
class _EthercatCFileGenerator:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   940
    
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   941
    def __init__(self, controler):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   942
        self.Controler = controler
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   943
        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   944
        self.Slaves = []
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   945
        self.UsedVariables = {}
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   946
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   947
    def __del__(self):
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   948
        self.Controler = None            
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
   949
    
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
   950
    def DeclareSlave(self, slave_index, slave_alias, slave):
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
   951
        self.Slaves.append((slave_index, slave_alias, slave))
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   952
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   953
    def DeclareVariable(self, slave_index, index, subindex, iec_type, dir, name):
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   954
        slave_variables = self.UsedVariables.setdefault(slave_index, {})
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   955
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   956
        entry_infos = slave_variables.get((index, subindex), None)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   957
        if entry_infos is 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
   958
            slave_variables[(index, 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
   959
                "infos": (iec_type, dir, name),
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
   960
                "mapped": False}
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
   961
        elif entry_infos["infos"] != (iec_type, dir, name):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   962
            raise ValueError, _("Definition conflict for location \"%s\"") % name 
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
   963
        
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   964
    def GenerateCFile(self, filepath, location_str, etherlab_node_infos):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   965
        
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
   966
        # Extract etherlab master code template
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   967
        plc_etherlab_filepath = os.path.join(os.path.split(__file__)[0], "plc_etherlab.c")
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   968
        plc_etherlab_file = open(plc_etherlab_filepath, 'r')
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   969
        plc_etherlab_code = plc_etherlab_file.read()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   970
        plc_etherlab_file.close()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   971
        
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
   972
        # Initialize strings for formatting master code template
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   973
        str_completion = {
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   974
            "location": location_str,
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   975
            "master_number": etherlab_node_infos.getMasterNumber(),
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   976
            "located_variables_declaration": [],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   977
            "used_pdo_entry_offset_variables_declaration": [],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   978
            "used_pdo_entry_configuration": [],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   979
            "pdos_configuration_declaration": "",
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   980
            "slaves_declaration": "",
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   981
            "slaves_configuration": "",
2039
3a218f6bd805 Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents: 2038
diff changeset
   982
            "slaves_output_pdos_default_values_extraction": "",
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   983
            "slaves_initialization": "",
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   984
            "retrieve_variables": [],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   985
            "publish_variables": [],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   986
        }
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   987
        
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
   988
        # Initialize variable storing variable mapping state
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
   989
        for slave_entries in self.UsedVariables.itervalues():
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
   990
            for entry_infos in slave_entries.itervalues():
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
   991
                entry_infos["mapped"] = False
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
   992
        
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
   993
        # Sort slaves by position (IEC_Channel)
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   994
        self.Slaves.sort()
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
   995
        # Initialize dictionary storing alias auto-increment position values
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   996
        alias = {}
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
   997
        
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
   998
        # Generating code for each slave
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
   999
        for (slave_idx, slave_alias, type_infos) in self.Slaves:
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
  1000
            
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
  1001
            # Defining slave alias and auto-increment position
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1002
            if alias.get(slave_alias) 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
  1003
                alias[slave_alias] += 1
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1004
            else:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1005
                alias[slave_alias] = 0
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1006
            slave_pos = (slave_alias, alias[slave_alias])
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1007
            
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
  1008
            # Extract slave device informations
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1009
            device = self.Controler.GetModuleInfos(type_infos)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1010
            if device is not None:
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
  1011
                
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
  1012
                # Extract slaves variables to be mapped
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1013
                slave_variables = self.UsedVariables.get(slave_idx, {})
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
  1014
                
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
  1015
                # Extract slave device object dictionary entries
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1016
                device_entries = device.GetEntriesList()
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1017
                
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
  1018
                # Adding code for declaring slave in master code template strings
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
  1019
                for element in ["vendor", "product_code", "revision_number"]:
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
  1020
                    type_infos[element] = ExtractHexDecValue(type_infos[element])
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
  1021
                type_infos.update(dict(zip(["slave", "alias", "position"], (slave_idx,) + slave_pos)))
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
  1022
                
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
  1023
                # Extract slave device CoE informations
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
  1024
                device_coe = device.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
  1025
                if device_coe is not None:
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1026
                    
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
  1027
                    # If device support CanOpen over Ethernet, adding code for calling 
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
  1028
                    # init commands when initializing slave in master code template strings
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
  1029
                    for initCmd in device_coe.getInitCmd():
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1030
                        index = ExtractHexDecValue(initCmd.getIndex())
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1031
                        subindex = ExtractHexDecValue(initCmd.getSubIndex())
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1032
                        entry = device_entries.get((index, subindex), None)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1033
                        if entry is not None:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1034
                            data_size = entry["BitSize"] / 8
2081
b1801bf4365c Fix bug in endianization in value transmit and received by SDO
Laurent Bessard
parents: 2080
diff changeset
  1035
                            data_str = ("0x%%.%dx" % (data_size * 2)) % initCmd.getData().getcontent()
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1036
                            init_cmd_infos = {
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1037
                                "index": index,
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1038
                                "subindex": subindex,
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1039
                                "data": data_str,
2081
b1801bf4365c Fix bug in endianization in value transmit and received by SDO
Laurent Bessard
parents: 2080
diff changeset
  1040
                                "data_type": DATATYPECONVERSION.get(entry["Type"]),
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1041
                                "data_size": data_size
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1042
                            }
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1043
                            init_cmd_infos.update(type_infos)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1044
                            str_completion["slaves_initialization"] += SLAVE_INITIALIZATION_TEMPLATE % init_cmd_infos
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
  1045
                
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
  1046
                    # Extract slave device PDO configuration capabilities
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
  1047
                    PdoAssign = device_coe.getPdoAssign()
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
  1048
                    PdoConfig = device_coe.getPdoConfig()
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
  1049
                else:
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
  1050
                    PdoAssign = PdoConfig = False
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
  1051
                
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
  1052
                # Test if slave has a configuration or need one
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
  1053
                if len(device.getTxPdo() + device.getRxPdo()) > 0 or len(slave_variables) > 0 and PdoConfig and PdoAssign:
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
  1054
                    
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
  1055
                    str_completion["slaves_declaration"] += "static ec_slave_config_t *slave%(slave)d = NULL;\n" % type_infos
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
  1056
                    str_completion["slaves_configuration"] += SLAVE_CONFIGURATION_TEMPLATE % type_infos
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
  1057
                    
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
  1058
                    # Initializing 
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1059
                    pdos_infos = {
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1060
                        "pdos_entries_infos": [],
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1061
                        "pdos_infos": [],
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1062
                        "pdos_sync_infos": [], 
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1063
                    }
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1064
                    pdos_infos.update(type_infos)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1065
                    
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1066
                    sync_managers = []
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1067
                    for sync_manager_idx, sync_manager in enumerate(device.getSm()):
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1068
                        sync_manager_infos = {
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1069
                            "index": sync_manager_idx, 
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1070
                            "name": sync_manager.getcontent(),
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1071
                            "slave": slave_idx,
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1072
                            "pdos": [], 
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1073
                            "pdos_number": 0,
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1074
                        }
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1075
                        
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1076
                        sync_manager_control_byte = ExtractHexDecValue(sync_manager.getControlByte())
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1077
                        sync_manager_direction = sync_manager_control_byte & 0x0c
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1078
                        sync_manager_watchdog = sync_manager_control_byte & 0x40
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1079
                        if sync_manager_direction:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1080
                            sync_manager_infos["sync_manager_type"] = "EC_DIR_OUTPUT"
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1081
                        else:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1082
                            sync_manager_infos["sync_manager_type"] = "EC_DIR_INPUT"
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1083
                        if sync_manager_watchdog:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1084
                            sync_manager_infos["watchdog"] = "EC_WD_ENABLE"
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1085
                        else:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1086
                            sync_manager_infos["watchdog"] = "EC_WD_DISABLE"
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1087
                        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1088
                        sync_managers.append(sync_manager_infos)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1089
                    
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1090
                    pdos_index = []
2082
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1091
                    exclusive_pdos = {}
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1092
                    selected_pdos = []
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1093
                    for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] +
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1094
                                          [(pdo, "Outputs") for pdo in device.getRxPdo()]):
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1095
                        
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1096
                        pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent())
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1097
                        pdos_index.append(pdo_index)
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1098
                        
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1099
                        excluded_list = pdo.getExclude()
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1100
                        if len(excluded_list) > 0:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1101
                            exclusion_list = [pdo_index]
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1102
                            for excluded in excluded_list:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1103
                                exclusion_list.append(ExtractHexDecValue(excluded.getcontent()))
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1104
                            exclusion_list.sort()
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1105
                            
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1106
                            exclusion_scope = exclusive_pdos.setdefault(tuple(exclusion_list), [])
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1107
                            
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1108
                            entries = pdo.getEntry()
2082
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1109
                            pdo_mapping_match = {
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1110
                                "index": pdo_index, 
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1111
                                "matching": 0, 
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1112
                                "count": len(entries), 
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1113
                                "assigned": pdo.getSm() is not None
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1114
                            }
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1115
                            exclusion_scope.append(pdo_mapping_match)
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1116
                            
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1117
                            for entry in entries:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1118
                                index = ExtractHexDecValue(entry.getIndex().getcontent())
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1119
                                subindex = ExtractHexDecValue(entry.getSubIndex())
2082
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1120
                                if slave_variables.get((index, subindex), None) is not None:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1121
                                    pdo_mapping_match["matching"] += 1
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1122
                        
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1123
                        elif pdo.getMandatory():
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1124
                            selected_pdos.append(pdo_index)
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1125
                    
2082
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1126
                    excluded_pdos = []
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1127
                    for exclusion_scope in exclusive_pdos.itervalues():
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1128
                        exclusion_scope.sort(ExclusionSortFunction)
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1129
                        start_excluding_index = 0
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1130
                        if exclusion_scope[0]["matching"] > 0:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1131
                            selected_pdos.append(exclusion_scope[0]["index"])
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1132
                            start_excluding_index = 1
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1133
                        excluded_pdos.extend([pdo["index"] for pdo in exclusion_scope[start_excluding_index:] if PdoAssign or not pdo["assigned"]])
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1134
                    
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1135
                    for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] +
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1136
                                          [(pdo, "Outputs") for pdo in device.getRxPdo()]):
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1137
                        entries = pdo.getEntry()
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1138
                        
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1139
                        pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent())
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1140
                        if pdo_index in excluded_pdos:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1141
                            continue
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1142
                        
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1143
                        pdo_needed = pdo_index in selected_pdos
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1144
                        
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1145
                        entries_infos = []
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1146
                        
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1147
                        for entry in entries:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1148
                            index = ExtractHexDecValue(entry.getIndex().getcontent())
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1149
                            subindex = ExtractHexDecValue(entry.getSubIndex())
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1150
                            entry_infos = {
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1151
                                "index": index,
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1152
                                "subindex": subindex,
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1153
                                "name": ExtractName(entry.getName()),
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1154
                                "bitlen": entry.getBitLen(),
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1155
                            }
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1156
                            entry_infos.update(type_infos)
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1157
                            entries_infos.append("    {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos)
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1158
                            
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1159
                            entry_declaration = slave_variables.get((index, subindex), None)
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1160
                            if entry_declaration is not None and not entry_declaration["mapped"]:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1161
                                pdo_needed = True
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1162
                                
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1163
                                entry_infos.update(dict(zip(["var_type", "dir", "var_name"], entry_declaration["infos"])))
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1164
                                entry_declaration["mapped"] = True
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1165
                                
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1166
                                entry_type = entry.getDataType().getcontent()
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1167
                                if entry_infos["var_type"] != entry_type:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1168
                                    message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"]
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1169
                                    if (self.Controler.GetSizeOfType(entry_infos["var_type"]) != 
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1170
                                        self.Controler.GetSizeOfType(entry_type)):
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1171
                                        raise ValueError, message
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1172
                                    else:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1173
                                        self.Controler.GetCTRoot().logger.write_warning(_("Warning: ") + message + "\n")
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1174
                                
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1175
                                if (entry_infos["dir"] == "I" and pdo_type != "Inputs" or 
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1176
                                    entry_infos["dir"] == "Q" and pdo_type != "Outputs"):
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1177
                                    raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"]
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1178
                                
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1179
                                ConfigureVariable(entry_infos, str_completion)
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1180
                            
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1181
                            elif pdo_type == "Outputs" and entry.getDataType() is not None and device_coe is not None:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1182
                                data_type = entry.getDataType().getcontent()
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1183
                                entry_infos["dir"] = "Q"
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1184
                                entry_infos["data_size"] = max(1, entry_infos["bitlen"] / 8)
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1185
                                entry_infos["data_type"] = DATATYPECONVERSION.get(data_type)
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1186
                                entry_infos["var_type"] = data_type
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1187
                                entry_infos["real_var"] = "slave%(slave)d_%(index).4x_%(subindex).2x_default" % entry_infos
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1188
                                
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1189
                                ConfigureVariable(entry_infos, str_completion)
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1190
                                
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1191
                                str_completion["slaves_output_pdos_default_values_extraction"] += \
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1192
                                    SLAVE_OUTPUT_PDO_DEFAULT_VALUE % entry_infos
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1193
                                
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1194
                        if pdo_needed:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1195
                            for excluded in pdo.getExclude():
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1196
                                excluded_index = ExtractHexDecValue(excluded.getcontent())
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1197
                                if excluded_index not in excluded_pdos:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1198
                                    excluded_pdos.append(excluded_index)
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1199
                            
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1200
                            sm = pdo.getSm()
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1201
                            if sm is None:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1202
                                for sm_idx, sync_manager in enumerate(sync_managers):
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1203
                                    if sync_manager["name"] == pdo_type:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1204
                                        sm = sm_idx
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1205
                            if sm is None:
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1206
                                raise ValueError, _("No sync manager available for %s pdo!") % pdo_type
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1207
                                
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1208
                            sync_managers[sm]["pdos_number"] += 1
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1209
                            sync_managers[sm]["pdos"].append(
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1210
                                {"slave": slave_idx,
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1211
                                 "index": pdo_index,
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1212
                                 "name": ExtractName(pdo.getName()),
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1213
                                 "type": pdo_type, 
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1214
                                 "entries": entries_infos,
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1215
                                 "entries_number": len(entries_infos),
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1216
                                 "fixed": pdo.getFixed() == True})
caae3ad2d03b Adding support for selecting a PDO in a list of mutually exclusive configured PDOs in Ethercat Network Configurator
Laurent Bessard
parents: 2081
diff changeset
  1217
                
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
  1218
                    if PdoConfig and PdoAssign:
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1219
                        dynamic_pdos = {}
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1220
                        dynamic_pdos_number = 0
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1221
                        for category, min_index, max_index in [("Inputs", 0x1600, 0x1800), 
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1222
                                                               ("Outputs", 0x1a00, 0x1C00)]:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1223
                            for sync_manager in sync_managers:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1224
                                if sync_manager["name"] == category:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1225
                                    category_infos = dynamic_pdos.setdefault(category, {})
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1226
                                    category_infos["sync_manager"] = sync_manager
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1227
                                    category_infos["pdos"] = [pdo for pdo in category_infos["sync_manager"]["pdos"] 
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1228
                                                              if not pdo["fixed"] and pdo["type"] == category]
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1229
                                    category_infos["current_index"] = min_index
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1230
                                    category_infos["max_index"] = max_index
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1231
                                    break
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1232
                        
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1233
                        for (index, subindex), entry_declaration in slave_variables.iteritems():
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1234
                            
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1235
                            if not entry_declaration["mapped"]:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1236
                                entry = device_entries.get((index, subindex), None)
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1237
                                if entry is None:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1238
                                    raise ValueError, _("Unknown entry index 0x%4.4x, subindex 0x%2.2x for device %s") % \
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1239
                                                     (index, subindex, type_infos["device_type"])
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1240
                                
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1241
                                entry_infos = {
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1242
                                    "index": index,
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1243
                                    "subindex": subindex,
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1244
                                    "name": entry["Name"],
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1245
                                    "bitlen": entry["BitSize"],
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1246
                                }
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1247
                                entry_infos.update(type_infos)
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1248
                                
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1249
                                entry_infos.update(dict(zip(["var_type", "dir", "var_name", "real_var"], entry_declaration["infos"])))
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1250
                                entry_declaration["mapped"] = True
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1251
                                
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1252
                                if entry_infos["var_type"] != entry["Type"]:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1253
                                    message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"]
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1254
                                    if (self.Controler.GetSizeOfType(entry_infos["var_type"]) != 
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1255
                                        self.Controler.GetSizeOfType(entry["Type"])):
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1256
                                        raise ValueError, message
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1257
                                    else:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1258
                                        self.Controler.GetCTRoot().logger.write_warning(message + "\n")
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1259
                                
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1260
                                if entry_infos["dir"] == "I" and entry["PDOMapping"] in ["T", "RT"]:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1261
                                    pdo_type = "Inputs"
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1262
                                elif entry_infos["dir"] == "Q" and entry["PDOMapping"] in ["R", "RT"]:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1263
                                    pdo_type = "Outputs"
2045
62e102935f3e Adding test project using higen drive
laurent
parents: 2043
diff changeset
  1264
                                else:
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1265
                                    raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"]
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
  1266
                                
2062
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1267
                                if not dynamic_pdos.has_key(pdo_type):
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1268
                                    raise ValueError, _("No Sync manager defined for %s!") % pdo_type
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1269
                                
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1270
                                ConfigureVariable(entry_infos, str_completion)
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1271
                                
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1272
                                if len(dynamic_pdos[pdo_type]["pdos"]) > 0:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1273
                                    pdo = dynamic_pdos[pdo_type]["pdos"][0]
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1274
                                else:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1275
                                    while dynamic_pdos[pdo_type]["current_index"] in pdos_index:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1276
                                        dynamic_pdos[pdo_type]["current_index"] += 1
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1277
                                    if dynamic_pdos[pdo_type]["current_index"] >= dynamic_pdos[pdo_type]["max_index"]:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1278
                                        raise ValueError, _("No more free PDO index available for %s!") % pdo_type
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1279
                                    pdos_index.append(dynamic_pdos[pdo_type]["current_index"])
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1280
                                    
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1281
                                    dynamic_pdos_number += 1
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1282
                                    pdo = {"slave": slave_idx,
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1283
                                           "index": dynamic_pdos[pdo_type]["current_index"],
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1284
                                           "name": "Dynamic PDO %d" % dynamic_pdos_number,
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1285
                                           "type": pdo_type, 
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1286
                                           "entries": [],
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1287
                                           "entries_number": 0,
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1288
                                           "fixed": False}
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1289
                                    dynamic_pdos[pdo_type]["sync_manager"]["pdos_number"] += 1
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1290
                                    dynamic_pdos[pdo_type]["sync_manager"]["pdos"].append(pdo)
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1291
                                    dynamic_pdos[pdo_type]["pdos"].append(pdo)
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1292
                                
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1293
                                pdo["entries"].append("    {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos)
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1294
                                pdo["entries_number"] += 1
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1295
                                
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1296
                                if pdo["entries_number"] == 255:
c485269ec443 Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality
Laurent Bessard
parents: 2057
diff changeset
  1297
                                    dynamic_pdos[pdo_type]["pdos"].pop(0)
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
  1298
                    
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1299
                    pdo_offset = 0
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1300
                    entry_offset = 0
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1301
                    for sync_manager_infos in sync_managers:
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
  1302
                    
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1303
                        for pdo_infos in sync_manager_infos["pdos"]:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1304
                            pdo_infos["offset"] = entry_offset
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1305
                            pdo_entries = pdo_infos["entries"]
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1306
                            pdos_infos["pdos_infos"].append(
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1307
                                ("    {0x%(index).4x, %(entries_number)d, " + 
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1308
                                 "slave_%(slave)d_pdo_entries + %(offset)d}, /* %(name)s */") % pdo_infos)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1309
                            entry_offset += len(pdo_entries)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1310
                            pdos_infos["pdos_entries_infos"].extend(pdo_entries)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1311
                        
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1312
                        sync_manager_infos["offset"] = pdo_offset
2047
b0b7bd288b6e Fixed wrong PDO in unused sync managers\nFix higen drive ethercat example
edouard_and_laurent
parents: 2045
diff changeset
  1313
                        pdo_offset_shift = sync_manager_infos["pdos_number"]
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1314
                        pdos_infos["pdos_sync_infos"].append(
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1315
                            ("    {%(index)d, %(sync_manager_type)s, %(pdos_number)d, " + 
2047
b0b7bd288b6e Fixed wrong PDO in unused sync managers\nFix higen drive ethercat example
edouard_and_laurent
parents: 2045
diff changeset
  1316
                             ("slave_%(slave)d_pdos + %(offset)d" if pdo_offset_shift else "NULL") +
b0b7bd288b6e Fixed wrong PDO in unused sync managers\nFix higen drive ethercat example
edouard_and_laurent
parents: 2045
diff changeset
  1317
                             ", %(watchdog)s},") % sync_manager_infos)
b0b7bd288b6e Fixed wrong PDO in unused sync managers\nFix higen drive ethercat example
edouard_and_laurent
parents: 2045
diff changeset
  1318
                        pdo_offset += pdo_offset_shift  
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1319
                    
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1320
                    for element in ["pdos_entries_infos", "pdos_infos", "pdos_sync_infos"]:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1321
                        pdos_infos[element] = "\n".join(pdos_infos[element])
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1322
                    
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1323
                    str_completion["pdos_configuration_declaration"] += SLAVE_PDOS_CONFIGURATION_DECLARATION % pdos_infos
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
  1324
                
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
  1325
                for (index, subindex), entry_declaration in slave_variables.iteritems():
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
  1326
                    if not entry_declaration["mapped"]:
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
  1327
                        message = _("Entry index 0x%4.4x, subindex 0x%2.2x not mapped for device %s") % \
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
  1328
                                        (index, subindex, type_infos["device_type"])
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
  1329
                        self.Controler.GetCTRoot().logger.write_warning(_("Warning: ") + message + "\n")
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
  1330
                    
2023
f9f884cf3033 Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents: 2022
diff changeset
  1331
        for element in ["used_pdo_entry_offset_variables_declaration", 
f9f884cf3033 Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents: 2022
diff changeset
  1332
                        "used_pdo_entry_configuration", 
f9f884cf3033 Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents: 2022
diff changeset
  1333
                        "located_variables_declaration", 
f9f884cf3033 Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents: 2022
diff changeset
  1334
                        "retrieve_variables", 
f9f884cf3033 Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents: 2022
diff changeset
  1335
                        "publish_variables"]:
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1336
            str_completion[element] = "\n".join(str_completion[element])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1337
        
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1338
        etherlabfile = open(filepath, 'w')
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1339
        etherlabfile.write(plc_etherlab_code % str_completion)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1340
        etherlabfile.close()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1341
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1342
#--------------------------------------------------
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
  1343
#                 Ethercat ConfNode
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1344
#--------------------------------------------------
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1345
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1346
EtherCATInfoClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATInfo.xsd")) 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1347
2074
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1348
cls = EtherCATInfoClasses["EtherCATBase.xsd"].get("DictionaryType", None)
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1349
if cls:
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1350
    cls.loadXMLTreeArgs = None
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1351
    
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1352
    setattr(cls, "_loadXMLTree", getattr(cls, "loadXMLTree"))
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1353
    
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1354
    def loadXMLTree(self, *args):
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1355
        self.loadXMLTreeArgs = args
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1356
    setattr(cls, "loadXMLTree", loadXMLTree)
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1357
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1358
    def load(self):
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1359
        if self.loadXMLTreeArgs is not None:
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1360
            self._loadXMLTree(*self.loadXMLTreeArgs)
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1361
            self.loadXMLTreeArgs = None
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1362
    setattr(cls, "load", load)
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1363
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
  1364
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
  1365
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
  1366
    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
  1367
    
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1368
    def GetProfileNumbers(self):
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1369
        profiles = []
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1370
        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1371
        for profile in self.getProfile():
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1372
            profile_content = profile.getcontent()
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1373
            if profile_content is None:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1374
                continue
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1375
            
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1376
            for content_element in profile_content["value"]:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1377
                if content_element["name"] == "ProfileNo":
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1378
                    profiles.append(content_element["value"])
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1379
        
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1380
        return profiles
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1381
    setattr(cls, "GetProfileNumbers", GetProfileNumbers)
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1382
    
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
  1383
    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
  1384
        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
  1385
        
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
  1386
        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
  1387
        
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
  1388
            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
  1389
            if profile_content is None:
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1390
                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
  1391
            
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
  1392
            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
  1393
                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
  1394
                    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
  1395
                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
  1396
                    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
  1397
                
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
  1398
        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
  1399
    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
  1400
    
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
  1401
    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
  1402
        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
  1403
        
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
  1404
        for dictionary in self.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
  1405
            
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
  1406
            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
  1407
            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
  1408
                
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
  1409
                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
  1410
                    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
  1411
                    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
  1412
                        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
  1413
    
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
  1414
    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
  1415
    
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
  1416
    def getCoE(self):
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1417
        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
  1418
        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
  1419
            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
  1420
        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
  1421
    setattr(cls, "getCoE", getCoE)
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1422
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
  1423
    def GetEntriesList(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
  1424
        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
  1425
            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
  1426
        
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
  1427
        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
  1428
        
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
  1429
        for dictionary in self.GetProfileDictionaries():
2074
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
  1430
            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
  1431
            
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
  1432
            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
  1433
                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
  1434
                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
  1435
                entry_type = object.getType()
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
  1436
                entry_name = ExtractName(object.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
  1437
                
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
  1438
                entry_type_infos = self.DataTypes.get(entry_type, 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
  1439
                if entry_type_infos 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
  1440
                    content = entry_type_infos.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
  1441
                    for subitem in 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
  1442
                        entry_subidx = subitem.getSubIdx()
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
  1443
                        if entry_subidx 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
  1444
                            entry_subidx = "0"
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
  1445
                        subidx = ExtractHexDecValue(entry_subidx)
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
  1446
                        subitem_access = ""
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1447
                        subitem_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
  1448
                        subitem_flags = subitem.getFlags()
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
  1449
                        if subitem_flags 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
  1450
                            access = subitem_flags.getAccess()
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
  1451
                            if access 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
  1452
                                subitem_access = access.getcontent()
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1453
                            pdomapping = subitem_flags.getPdoMapping()
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1454
                            if pdomapping is not None:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1455
                                subitem_pdomapping = pdomapping.upper()
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
  1456
                        entries[(index, subidx)] = {
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
  1457
                            "Index": 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
  1458
                            "SubIndex": entry_subidx,
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
  1459
                            "Name": "%s - %s" % 
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
  1460
                                    (entry_name.decode("utf-8"),
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
  1461
                                     ExtractName(subitem.getDisplayName(), 
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
  1462
                                                 subitem.getName()).decode("utf-8")),
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
  1463
                            "Type": subitem.getType(),
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
  1464
                            "BitSize": subitem.getBitSize(),
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
  1465
                            "Access": subitem_access, 
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1466
                            "PDOMapping": subitem_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
  1467
                            "PDO 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
  1468
                            "PDO name": "", 
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
  1469
                            "PDO type": ""}
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
  1470
                else:
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
  1471
                    entry_access = ""
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1472
                    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
  1473
                    entry_flags = object.getFlags()
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
  1474
                    if entry_flags 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
  1475
                        access = entry_flags.getAccess()
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
  1476
                        if access 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
  1477
                            entry_access = access.getcontent()
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1478
                        pdomapping = entry_flags.getPdoMapping()
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1479
                        if pdomapping is not None:
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1480
                            entry_pdomapping = pdomapping.upper()
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
  1481
                    entries[(index, 0)] = {
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
  1482
                         "Index": 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
  1483
                         "SubIndex": "0",
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
  1484
                         "Name": entry_name,
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
  1485
                         "Type": entry_type,
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
  1486
                         "BitSize": object.getBitSize(),
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
  1487
                         "Access": entry_access,
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1488
                         "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
  1489
                         "PDO 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
  1490
                         "PDO name": "", 
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
  1491
                         "PDO type": ""}
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
  1492
        
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
  1493
        for TxPdo in self.getTxPdo():
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
  1494
            ExtractPdoInfos(TxPdo, "Transmit", 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
  1495
        for RxPdo in self.getRxPdo():
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
  1496
            ExtractPdoInfos(RxPdo, "Receive", 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
  1497
        
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
  1498
        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
  1499
    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
  1500
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
  1501
    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
  1502
        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
  1503
        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
  1504
            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
  1505
            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
  1506
                                ("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
  1507
                                ("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
  1508
                                ("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
  1509
                                ("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
  1510
                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
  1511
                    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
  1512
                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
  1513
            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
  1514
        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
  1515
    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
  1516
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1517
def GroupItemCompare(x, y):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1518
    if x["type"] == y["type"]:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1519
        if x["type"] == ETHERCAT_GROUP:
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1520
            return cmp(x["order"], y["order"])
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1521
        else:
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1522
            return cmp(x["name"], y["name"])
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1523
    elif x["type"] == ETHERCAT_GROUP:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1524
        return -1
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1525
    return 1
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1526
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1527
def SortGroupItems(group):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1528
    for item in group["children"]:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1529
        if item["type"] == ETHERCAT_GROUP:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1530
            SortGroupItems(item)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1531
    group["children"].sort(GroupItemCompare)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1532
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1533
def ExtractName(names, default=None):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1534
    if len(names) == 1:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1535
        return names[0].getcontent()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1536
    else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1537
        for name in names:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1538
            if name.getLcId() == 1033:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1539
                return name.getcontent()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1540
    return default
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1541
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
  1542
def ExtractPdoInfos(pdo, pdo_type, entries):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1543
    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
  1544
    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
  1545
    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
  1546
        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
  1547
        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
  1548
        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
  1549
        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
  1550
        
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
  1551
        entry = entries.get((index, subindex), 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
  1552
        if entry 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
  1553
            entry["PDO index"] = pdo_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
  1554
            entry["PDO name"] = pdo_name
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
  1555
            entry["PDO type"] = pdo_type
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
  1556
        else:
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1557
            entry_type = pdo_entry.getDataType()
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1558
            if entry_type is not None:
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1559
                if pdo_type == "Transmit":
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1560
                    access = "ro"
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1561
                    pdomapping = "T"
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1562
                else:
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1563
                    access = "wo"
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1564
                    pdomapping = "R"
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1565
                entries[(index, subindex)] = {
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1566
                    "Index": entry_index,
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1567
                    "SubIndex": entry_subindex,
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1568
                    "Name": ExtractName(pdo_entry.getName()),
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1569
                    "Type": entry_type.getcontent(),
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1570
                    "Access": access,
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
  1571
                    "PDOMapping": pdomapping,
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1572
                    "PDO index": pdo_index, 
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1573
                    "PDO name": pdo_name, 
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1574
                    "PDO type": pdo_type}
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1575
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1576
class RootClass:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1577
    
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
  1578
    CTNChildrenTypes = [("EthercatNode",_EthercatCTN,"Ethercat Master")]
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1579
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1580
    def __init__(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1581
        self.LoadModulesLibrary()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1582
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1583
    def GetModulesLibraryPath(self):
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
  1584
        library_path = os.path.join(self.CTNPath(), "modules")
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1585
        if not os.path.exists(library_path):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1586
            os.mkdir(library_path)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1587
        return library_path
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1588
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1589
    def _ImportModuleLibrary(self):
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
  1590
        dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose an XML file"), os.getcwd(), "",  _("XML files (*.xml)|*.xml|All files|*.*"), wx.OPEN)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1591
        if dialog.ShowModal() == wx.ID_OK:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1592
            filepath = dialog.GetPath()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1593
            if os.path.isfile(filepath):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1594
                shutil.copy(filepath, self.GetModulesLibraryPath())
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1595
                self.LoadModulesLibrary()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1596
            else:
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
  1597
                self.GetCTRoot().logger.write_error(_("No such XML file: %s\n") % filepath)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1598
        dialog.Destroy()  
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1599
    
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
  1600
    ConfNodeMethods = [
2068
05a267b1a362 Adding support using plcopeneditor bitmap library for icon request
Laurent Bessard
parents: 2067
diff changeset
  1601
        {"bitmap" : "ImportESI",
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1602
         "name" : _("Import module library"), 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1603
         "tooltip" : _("Import module library"),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1604
         "method" : "_ImportModuleLibrary"},
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1605
    ]
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1606
    
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
  1607
    def CTNGenerate_C(self, buildpath, locations):
2023
f9f884cf3033 Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents: 2022
diff changeset
  1608
        return [],"",False
f9f884cf3033 Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents: 2022
diff changeset
  1609
    
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1610
    def LoadModulesLibrary(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1611
        self.ModulesLibrary = {}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1612
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1613
        library_path = self.GetModulesLibraryPath()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1614
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1615
        files = os.listdir(library_path)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1616
        for file in files:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1617
            filepath = os.path.join(library_path, file)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1618
            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
  1619
                xmlfile = open(filepath, 'r')
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1620
                xml_tree = minidom.parse(xmlfile)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1621
                xmlfile.close()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1622
                
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1623
                modules_infos = None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1624
                for child in xml_tree.childNodes:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1625
                    if child.nodeType == xml_tree.ELEMENT_NODE and child.nodeName == "EtherCATInfo":
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1626
                        modules_infos = EtherCATInfoClasses["EtherCATInfo.xsd"]["EtherCATInfo"]()
2051
13dee9322beb refactoring
laurent
parents: 2047
diff changeset
  1627
                        modules_infos.loadXMLTree(child)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1628
                
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1629
                if modules_infos is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1630
                    vendor = modules_infos.getVendor()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1631
                    
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1632
                    vendor_category = self.ModulesLibrary.setdefault(ExtractHexDecValue(vendor.getId()), 
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1633
                                                                     {"name": ExtractName(vendor.getName(), _("Miscellaneous")), 
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1634
                                                                      "groups": {}})
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1635
                    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1636
                    for group in modules_infos.getDescriptions().getGroups().getGroup():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1637
                        group_type = group.getType()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1638
                        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1639
                        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
  1640
                                                                          "parent": group.getParentGroup(),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1641
                                                                          "order": group.getSortOrder(), 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1642
                                                                          "devices": []})
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1643
                    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1644
                    for device in modules_infos.getDescriptions().getDevices().getDevice():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1645
                        device_group = device.getGroupType()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1646
                        if not vendor_category["groups"].has_key(device_group):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1647
                            raise ValueError, "Not such group \"%\"" % device_group
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1648
                        vendor_category["groups"][device_group]["devices"].append((device.getType().getcontent(), device))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1649
    
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1650
    def GetModulesLibrary(self, profile_filter=None):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1651
        library = []
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1652
        for vendor_id, vendor in self.ModulesLibrary.iteritems():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1653
            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
  1654
            children_dict = {}
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1655
            for group_type, group in vendor["groups"].iteritems():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1656
                group_infos = {"name": group["name"],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1657
                               "order": group["order"],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1658
                               "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
  1659
                               "infos": None,
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1660
                               "children": children_dict.setdefault(group_type, [])}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1661
                device_dict = {}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1662
                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
  1663
                    if profile_filter is None or profile_filter in device.GetProfileNumbers():
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1664
                        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
  1665
                                        "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
  1666
                                        "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
  1667
                                                  "vendor": vendor_id,
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1668
                                                  "product_code": device.getType().getProductCode(),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1669
                                                  "revision_number": device.getType().getRevisionNo()},
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1670
                                        "children": []}
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1671
                        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
  1672
                        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
  1673
                        device_type_occurrences.append(device_infos)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1674
                for device_type_occurrences in device_dict.itervalues():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1675
                    if len(device_type_occurrences) > 1:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1676
                        for occurrence in device_type_occurrences:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1677
                            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
  1678
                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
  1679
                    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
  1680
                        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
  1681
                        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
  1682
                    else:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1683
                        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
  1684
            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
  1685
                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
  1686
                                "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
  1687
                                "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
  1688
                                "children": groups})
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1689
        library.sort(lambda x, y: cmp(x["name"], y["name"]))
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1690
        return library
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1691
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1692
    def GetModuleInfos(self, type_infos):
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
  1693
        vendor = self.ModulesLibrary.get(ExtractHexDecValue(type_infos["vendor"]), None)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1694
        if vendor is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1695
            for group_name, group in vendor["groups"].iteritems():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1696
                for device_type, device in group["devices"]:
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
  1697
                    product_code = ExtractHexDecValue(device.getType().getProductCode())
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
  1698
                    revision_number = ExtractHexDecValue(device.getType().getRevisionNo())
2042
563ccc918ded Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents: 2041
diff changeset
  1699
                    if (product_code == ExtractHexDecValue(type_infos["product_code"]) and
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
  1700
                        revision_number == ExtractHexDecValue(type_infos["revision_number"])):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1701
                        return device
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1702
        return None
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1703
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
  1704