etherlab/etherlab.py
author laurent
Tue, 07 Feb 2012 19:45:45 +0100
changeset 2031 c6f32810723e
parent 2030 7147f20c23e3
child 2032 766078d83e22
permissions -rw-r--r--
Fix some issues regarding arbitrary variable mapping
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 *
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
     8
from PLCControler import UndoBuffer, LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
     9
from ConfigEditor import ConfigEditor, ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    10
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    11
TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L",
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    12
    "USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    13
    "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L"}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    14
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    15
DATATYPECONVERSION = {"BOOL" : "BIT", "SINT" : "S8", "INT" : "S16", "DINT" : "S32", "LINT" : "S64",
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    16
    "USINT" : "U8", "UINT" : "U16", "UDINT" : "U32", "ULINT" : "U64", 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    17
    "BYTE" : "U8", "WORD" : "U16", "DWORD" : "U32", "LWORD" : "U64"}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    18
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
    19
VARCLASSCONVERSION = {"ro": LOCATION_VAR_INPUT, "wo": LOCATION_VAR_OUTPUT, "rw": LOCATION_VAR_MEMORY}
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
    20
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    21
#--------------------------------------------------
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    22
#                 Ethercat MASTER
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    23
#--------------------------------------------------
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    24
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    25
EtherCATConfigClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATConfig.xsd")) 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    26
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    27
def ExtractHexDecValue(value):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    28
    try:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    29
        return int(value)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    30
    except:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    31
        pass
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    32
    try:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    33
        return int(value.replace("#", "0"), 16)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    34
    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
    35
        raise ValueError, "Invalid value for HexDecValue \"%s\"" % value
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    36
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    37
def GenerateHexDecValue(value, base=10):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    38
    if base == 10:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    39
        return str(value)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    40
    elif base == 16:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    41
        return "#x%.8x" % value
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    42
    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
    43
        raise ValueError, "Not supported base"
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    44
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    45
cls = EtherCATConfigClasses.get("Config_Slave", None)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    46
if cls:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    47
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    48
    def getType(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    49
        slave_info = self.getInfo()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    50
        return {"device_type": slave_info.getName(),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    51
                "vendor": GenerateHexDecValue(slave_info.getVendorId()),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    52
                "product_code": GenerateHexDecValue(slave_info.getProductCode(), 16),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    53
                "revision_number": GenerateHexDecValue(slave_info.getRevisionNo(), 16)}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    54
    setattr(cls, "getType", getType)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    55
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    56
    def setType(self, type_infos):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    57
        slave_info = self.getInfo()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    58
        slave_info.setName(type_infos["device_type"])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    59
        slave_info.setVendorId(ExtractHexDecValue(type_infos["vendor"]))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    60
        slave_info.setProductCode(ExtractHexDecValue(type_infos["product_code"]))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    61
        slave_info.setRevisionNo(ExtractHexDecValue(type_infos["revision_number"]))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    62
    setattr(cls, "setType", setType)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    63
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    64
cls = EtherCATConfigClasses.get("Slave_Info", None)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    65
if cls:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    66
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    67
    def getSlavePosition(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    68
        return self.getPhysAddr(), self.getAutoIncAddr()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    69
    setattr(cls, "getSlavePosition", getSlavePosition)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    70
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    71
    def setSlavePosition(self, alias, pos):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    72
        self.setPhysAddr(alias)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    73
        self.setAutoIncAddr(pos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    74
    setattr(cls, "setSlavePosition", setSlavePosition)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    75
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    76
class _EthercatPlug:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    77
    XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    78
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    79
      <xsd:element name="EtherlabNode">
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    80
        <xsd:complexType>
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    81
          <xsd:attribute name="MasterNumber" type="xsd:integer" use="optional" default="0"/>
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    82
          <xsd:attribute name="ConfigurePDOs" type="xsd:boolean" use="optional" default="true"/>
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    83
        </xsd:complexType>
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    84
      </xsd:element>
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    85
    </xsd:schema>
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    86
    """
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
    87
    EditorType = ConfigEditor
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    88
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    89
    def __init__(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    90
        filepath = self.ConfigFileName()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    91
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    92
        self.Config = EtherCATConfigClasses["EtherCATConfig"]()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    93
        if os.path.isfile(filepath):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    94
            xmlfile = open(filepath, 'r')
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    95
            tree = minidom.parse(xmlfile)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    96
            xmlfile.close()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    97
            
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    98
            for child in tree.childNodes:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    99
                if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "EtherCATConfig":
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   100
                    self.Config.loadXMLTree(child, ["xmlns:xsi", "xsi:noNamespaceSchemaLocation"])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   101
                    self.CreateConfigBuffer(True)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   102
        else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   103
            self.CreateConfigBuffer(False)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   104
            self.OnPlugSave()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   105
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   106
    def ExtractHexDecValue(self, value):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   107
        return ExtractHexDecValue(value)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   108
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   109
    def GetSizeOfType(self, type):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   110
        return TYPECONVERSION.get(self.GetPlugRoot().GetBaseType(type), None)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   111
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   112
    def ConfigFileName(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   113
        return os.path.join(self.PlugPath(), "config.xml")
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   114
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   115
    def GetSlaves(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   116
        slaves = []
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   117
        for slave in self.Config.getConfig().getSlave():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   118
            slaves.append(slave.getInfo().getSlavePosition())
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   119
        slaves.sort()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   120
        return slaves
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   121
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   122
    def GetSlave(self, slave_pos):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   123
        for slave in self.Config.getConfig().getSlave():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   124
            slave_info = slave.getInfo()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   125
            if slave_info.getSlavePosition() == slave_pos:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   126
                return slave
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   127
        return None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   128
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   129
    def AddSlave(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   130
        slaves = self.GetSlaves()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   131
        if len(slaves) > 0:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   132
            new_pos = (slaves[-1][0] + 1, 0)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   133
        else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   134
            new_pos = (0, 0)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   135
        slave = EtherCATConfigClasses["Config_Slave"]()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   136
        slave_infos = slave.getInfo()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   137
        slave_infos.setName("undefined")
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   138
        slave_infos.setSlavePosition(new_pos[0], new_pos[1])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   139
        self.Config.getConfig().appendSlave(slave)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   140
        self.BufferConfig()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   141
        return new_pos
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   142
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   143
    def RemoveSlave(self, slave_pos):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   144
        config = self.Config.getConfig()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   145
        for idx, slave in enumerate(config.getSlave()):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   146
            slave_infos = slave.getInfo()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   147
            if slave_infos.getSlavePosition() == slave_pos:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   148
                config.removeSlave(idx)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   149
                self.BufferConfig()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   150
                return True
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   151
        return False
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   152
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   153
    def SetSlavePos(self, slave_pos, alias=None, position=None):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   154
        slave = self.GetSlave(slave_pos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   155
        if slave is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   156
            slave_info = slave.getInfo()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   157
            new_pos = slave_pos
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   158
            if alias is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   159
                new_pos = (alias, new_pos[1])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   160
            if position is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   161
                new_pos = (new_pos[0], position)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   162
            if self.GetSlave(new_pos) is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   163
                return _("Slave with position \"%d:%d\" already exists!" % new_pos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   164
            slave_info.setSlavePosition(*new_pos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   165
            self.BufferConfig()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   166
        return None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   167
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   168
    def GetSlaveType(self, slave_pos):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   169
        slave = self.GetSlave(slave_pos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   170
        if slave is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   171
            return slave.getType()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   172
        return None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   173
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   174
    def SetSlaveType(self, slave_pos, type_infos):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   175
        slave = self.GetSlave(slave_pos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   176
        if slave is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   177
            slave.setType(type_infos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   178
            self.BufferConfig()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   179
        return None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   180
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   181
    def GetSlaveInfos(self, slave_pos):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   182
        slave = self.GetSlave(slave_pos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   183
        if slave is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   184
            type_infos = slave.getType()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   185
            device = self.GetModuleInfos(type_infos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   186
            if device is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   187
                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
   188
                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
   189
                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
   190
                entries_list.sort()
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   191
                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
   192
                              "sync_managers": device.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
   193
                              "entries": [entry[1] for entry in entries_list]})
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   194
                return infos
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   195
        return None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   196
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   197
    def GetModuleInfos(self, type_infos):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   198
        return self.PlugParent.GetModuleInfos(type_infos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   199
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   200
    def GetSlaveTypesLibrary(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   201
        return self.PlugParent.GetModulesLibrary()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   202
    
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
   203
    def GetVariableLocationTree(self):
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
   204
        '''See PlugTemplate.GetVariableLocationTree() for a description.'''
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
   205
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
   206
        current_location = self.GetCurrentLocation()
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
   207
        
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
   208
        groups = []
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
   209
        for slave_pos in self.GetSlaves():
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
   210
            
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
   211
            slave = self.GetSlave(slave_pos)
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
   212
            if slave is not None:
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
   213
                type_infos = slave.getType()
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   214
                
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
   215
                device = self.GetModuleInfos(type_infos)
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
   216
                if device is not None:
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
   217
                    vars = []
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
   218
                    
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
   219
                    sync_managers = []
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
   220
                    for sync_manager in device.getSm():
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
   221
                        sync_manager_control_byte = ExtractHexDecValue(sync_manager.getControlByte())
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
   222
                        sync_manager_direction = sync_manager_control_byte & 0x0c
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
   223
                        if sync_manager_direction:
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
   224
                            sync_managers.append(LOCATION_VAR_OUTPUT)
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
   225
                        else:
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
   226
                            sync_managers.append(LOCATION_VAR_INPUT)
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
   227
                    
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
   228
                    entries = device.GetEntriesList().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
   229
                    entries.sort()
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
   230
                    for (index, subindex), entry in 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
   231
                        var_size = self.GetSizeOfType(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
   232
                        if var_size 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
   233
                            var_class = VARCLASSCONVERSION.get(entry["Access"], LOCATION_VAR_MEMORY)
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
   234
                            if var_class == LOCATION_VAR_INPUT:
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
   235
                                var_dir = "%I"
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
   236
                            else:
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
   237
                                var_dir = "%Q"    
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
   238
                            
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
   239
                            vars.append({"name": "0x%4.4x-0x%2.2x: %s" % (index, subindex, entry["Name"]),
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
   240
                                         "type": var_class,
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
   241
                                         "size": var_size,
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
   242
                                         "IEC_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
   243
                                         "var_name": "%s_%4.4x_%2.2x" % (type_infos["device_type"], index, subindex),
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
   244
                                         "location": "%s%s%s"%(var_dir, var_size, ".".join(map(str, current_location + 
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
   245
                                                                                                    slave_pos + 
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
   246
                                                                                                    (index, subindex)))),
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
   247
                                         "description": "",
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
   248
                                         "children": []})
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
   249
                    
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
   250
                    groups.append({"name": "%s (%d,%d)" % ((type_infos["device_type"],) + slave_pos),
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
   251
                                   "type": LOCATION_GROUP,
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
   252
                                   "location": ".".join(map(str, current_location + slave_pos)) + ".x",
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
   253
                                   "children": vars})
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
   254
                
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
   255
        return  {"name": self.BaseParams.getName(),
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
   256
                 "type": LOCATION_PLUGIN,
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
   257
                 "location": self.GetFullIEC_Channel(),
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
   258
                 "children": groups}
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
   259
    
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   260
    PluginMethods = [
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   261
        {"bitmap" : os.path.join("images", "EditCfile"),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   262
         "name" : _("Edit Config"), 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   263
         "tooltip" : _("Edit Config"),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   264
         "method" : "_OpenView"},
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   265
    ]
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   266
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   267
    def PlugTestModified(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   268
        return self.ChangesToSave or not self.ConfigIsSaved()    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   269
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   270
    def OnPlugSave(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   271
        filepath = self.ConfigFileName()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   272
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   273
        text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   274
        extras = {"xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance",
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   275
                  "xsi:noNamespaceSchemaLocation" : "EtherCATInfo.xsd"}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   276
        text += self.Config.generateXMLText("EtherCATConfig", 0, extras)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   277
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   278
        xmlfile = open(filepath,"w")
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   279
        xmlfile.write(text.encode("utf-8"))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   280
        xmlfile.close()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   281
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   282
        self.ConfigBuffer.CurrentSaved()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   283
        return True
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   284
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   285
    def PlugGenerate_C(self, buildpath, locations):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   286
        """
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   287
        Generate C code
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   288
        @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   289
        @param locations: List of complete variables locations \
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   290
            [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   291
            "NAME" : name of the variable (generally "__IW0_1_2" style)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   292
            "DIR" : direction "Q","I" or "M"
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   293
            "SIZE" : size "X", "B", "W", "D", "L"
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   294
            "LOC" : tuple of interger for IEC location (0,1,2,...)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   295
            }, ...]
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   296
        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   297
        """
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   298
        current_location = self.GetCurrentLocation()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   299
        # define a unique name for the generated C file
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   300
        location_str = "_".join(map(lambda x:str(x), current_location))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   301
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   302
        Gen_Ethercatfile_path = os.path.join(buildpath, "ethercat_%s.c"%location_str)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   303
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   304
        file_generator = _EthercatCFileGenerator(self, Gen_Ethercatfile_path)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   305
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   306
        for location in locations:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   307
            loc = location["LOC"][len(current_location):]
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   308
            file_generator.DeclareVariable(loc[:2], loc[2], loc[3], location["IEC_TYPE"], location["DIR"], location["NAME"])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   309
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   310
        file_generator.GenerateCFile()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   311
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   312
        return [(Gen_Ethercatfile_path, '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath()))], "-lethercat -lrtdm", True
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   313
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   314
#-------------------------------------------------------------------------------
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   315
#                      Current Buffering Management Functions
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   316
#-------------------------------------------------------------------------------
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   317
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   318
    """
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   319
    Return a copy of the config
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   320
    """
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   321
    def Copy(self, model):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   322
        return cPickle.loads(cPickle.dumps(model))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   323
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   324
    def CreateConfigBuffer(self, saved):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   325
        self.ConfigBuffer = UndoBuffer(cPickle.dumps(self.Config), saved)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   326
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   327
    def BufferConfig(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   328
        self.ConfigBuffer.Buffering(cPickle.dumps(self.Config))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   329
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   330
    def ConfigIsSaved(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   331
        if self.ConfigBuffer is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   332
            return self.ConfigBuffer.IsCurrentSaved()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   333
        else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   334
            return True
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   335
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   336
    def LoadPrevious(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   337
        self.Config = cPickle.loads(self.ConfigBuffer.Previous())
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   338
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   339
    def LoadNext(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   340
        self.Config = cPickle.loads(self.ConfigBuffer.Next())
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   341
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   342
    def GetBufferState(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   343
        first = self.ConfigBuffer.IsFirst()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   344
        last = self.ConfigBuffer.IsLast()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   345
        return not first, not last
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   346
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   347
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   348
SLAVE_PDOS_CONFIGURATION_DECLARATION = """
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   349
/* Slave %(slave)d, "%(device_type)s"
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   350
 * Vendor ID:       0x%(vendor).8x
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   351
 * Product code:    0x%(product_code).8x
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   352
 * Revision number: 0x%(revision_number).8x
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   353
 */
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   354
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   355
ec_pdo_entry_info_t slave_%(slave)d_pdo_entries[] = {
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   356
%(pdos_entries_infos)s
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   357
};
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   358
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   359
ec_pdo_info_t slave_%(slave)d_pdos[] = {
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   360
%(pdos_infos)s
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   361
};
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   362
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   363
ec_sync_info_t slave_%(slave)d_syncs[] = {
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   364
%(pdos_sync_infos)s
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   365
    {0xff}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   366
};
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   367
"""
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   368
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   369
SLAVE_CONFIGURATION_TEMPLATE = """
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   370
    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
   371
        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
   372
        return -1;
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   373
    }
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   374
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   375
    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
   376
        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
   377
        return -1;
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   378
    }
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   379
"""
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   380
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
   381
def ConfigureVariable(entry_infos, str_completion):
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
   382
    data_type = DATATYPECONVERSION.get(entry_infos["var_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
   383
    if data_type 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
   384
        raise ValueError, _("Type of location \"%s\" not yet supported!") % entry_infos["var_name"]
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   385
    
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
   386
    str_completion["located_variables_declaration"].extend(
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
   387
        ["IEC_%(var_type)s beremiz%(var_name)s;" % entry_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
   388
         "IEC_%(var_type)s *%(var_name)s = &beremiz%(var_name)s;" % entry_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
   389
    
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
   390
    if data_type == "BIT":
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
   391
        str_completion["used_pdo_entry_offset_variables_declaration"].extend(
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
   392
            ["static unsigned int slave%(slave)d_%(index).4x_%(subindex).2x;" % entry_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
   393
             "static unsigned int slave%(slave)d_%(index).4x_%(subindex).2x_bit;" % entry_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
   394
        
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
   395
        str_completion["used_pdo_entry_configuration"].append(
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
   396
             ("    {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, " + 
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
   397
              "0x%(index).4x, %(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x, " + 
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
   398
              "&slave%(slave)d_%(index).4x_%(subindex).2x_bit},") % entry_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
   399
        
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
   400
        if entry_infos["dir"] == "I":
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
   401
            str_completion["retrieve_variables"].append(
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
   402
              ("    beremiz%(name)s = EC_READ_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + 
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
   403
               "slave%(slave)d_%(index).4x_%(subindex).2x_bit);") % entry_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
   404
        elif entry_infos["dir"] == "Q":
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
   405
            str_completion["publish_variables"].append(
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
   406
              ("    EC_WRITE_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + 
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
   407
               "slave%(slave)d_%(index).4x_%(subindex).2x_bit, beremiz%(var_name)s);") % entry_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
   408
    
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
   409
    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
   410
        entry_infos["data_type"] = data_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
   411
        
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
   412
        str_completion["used_pdo_entry_offset_variables_declaration"].append(
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
   413
            "static unsigned int slave%(slave)d_%(index).4x_%(subindex).2x;" % entry_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
   414
        
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
   415
        str_completion["used_pdo_entry_configuration"].append(
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
   416
            ("    {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, 0x%(index).4x, " + 
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
   417
             "%(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x},") % entry_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
   418
        
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
   419
        if entry_infos["dir"] == "I":
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
   420
            str_completion["retrieve_variables"].append(
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   421
                ("    beremiz%(var_name)s = EC_READ_%(data_type)s(domain1_pd + " + 
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
   422
                 "slave%(slave)d_%(index).4x_%(subindex).2x);") % entry_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
   423
        elif entry_infos["dir"] == "Q":
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
   424
            str_completion["publish_variables"].append(
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   425
                ("    EC_WRITE_%(data_type)s(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + 
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
   426
                 "beremiz%(var_name)s);") % entry_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
   427
        
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
   428
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   429
class _EthercatCFileGenerator:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   430
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   431
    def __init__(self, controler, filepath):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   432
        self.Controler = controler
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   433
        self.FilePath = filepath
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   434
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   435
        self.UsedVariables = {}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   436
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   437
    def __del__(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   438
        self.Controler = None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   439
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   440
    def DeclareVariable(self, slave_identifier, index, subindex, iec_type, dir, name):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   441
        slave_variables = self.UsedVariables.setdefault(slave_identifier, {})
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   442
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   443
        entry_infos = slave_variables.get((index, subindex), None)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   444
        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
   445
            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
   446
                "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
   447
                "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
   448
        elif entry_infos["infos"] != (iec_type, dir, name):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   449
            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
   450
        
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   451
    def GenerateCFile(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   452
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   453
        current_location = self.Controler.GetCurrentLocation()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   454
        # define a unique name for the generated C file
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   455
        location_str = "_".join(map(lambda x:str(x), current_location))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   456
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   457
        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
   458
        plc_etherlab_file = open(plc_etherlab_filepath, 'r')
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   459
        plc_etherlab_code = plc_etherlab_file.read()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   460
        plc_etherlab_file.close()
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
        str_completion = {
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   463
            "location": location_str,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   464
            "configure_pdos": int(self.Controler.EtherlabNode.getConfigurePDOs()),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   465
            "master_number": self.Controler.EtherlabNode.getMasterNumber(),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   466
            "located_variables_declaration": [],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   467
            "used_pdo_entry_offset_variables_declaration": [],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   468
            "used_pdo_entry_configuration": [],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   469
            "pdos_configuration_declaration": "",
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   470
            "slaves_declaration": "",
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   471
            "slaves_configuration": "",
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   472
            "retrieve_variables": [],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   473
            "publish_variables": [],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   474
        }
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   475
        
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
   476
        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
   477
            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
   478
                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
   479
        
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   480
        for slave_idx, slave_pos in enumerate(self.Controler.GetSlaves()):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   481
            
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   482
            slave = self.Controler.GetSlave(slave_pos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   483
            if slave is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   484
                type_infos = slave.getType()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   485
                
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   486
                device = self.Controler.GetModuleInfos(type_infos)
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
   487
                if device is not 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
   488
                    slave_variables = self.UsedVariables.get(slave_pos, {})
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
   489
                    device_entries = device.GetEntriesList()
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   490
                    
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
   491
                    if len(device.getTxPdo() + device.getRxPdo()) > 0 or len(slave_variables) > 0:
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   492
                        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   493
                        for element in ["vendor", "product_code", "revision_number"]:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   494
                            type_infos[element] = ExtractHexDecValue(type_infos[element])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   495
                        type_infos.update(dict(zip(["slave", "alias", "position"], (slave_idx,) + slave_pos)))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   496
                    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   497
                        str_completion["slaves_declaration"] += "static ec_slave_config_t *slave%(slave)d = NULL;\n" % type_infos
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   498
                        str_completion["slaves_configuration"] += SLAVE_CONFIGURATION_TEMPLATE % type_infos
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   499
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   500
                        pdos_infos = {
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   501
                            "pdos_entries_infos": [],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   502
                            "pdos_infos": [],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   503
                            "pdos_sync_infos": [], 
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
                        pdos_infos.update(type_infos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   506
                        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   507
                        sync_managers = []
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   508
                        for sync_manager_idx, sync_manager in enumerate(device.getSm()):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   509
                            sync_manager_infos = {
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   510
                                "index": sync_manager_idx, 
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
   511
                                "name": sync_manager.getcontent(),
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   512
                                "slave": slave_idx,
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
   513
                                "pdos": [], 
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   514
                                "pdos_number": 0,
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
                            
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   517
                            sync_manager_control_byte = ExtractHexDecValue(sync_manager.getControlByte())
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   518
                            sync_manager_direction = sync_manager_control_byte & 0x0c
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   519
                            sync_manager_watchdog = sync_manager_control_byte & 0x40
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   520
                            if sync_manager_direction:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   521
                                sync_manager_infos["sync_manager_type"] = "EC_DIR_OUTPUT"
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   522
                            else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   523
                                sync_manager_infos["sync_manager_type"] = "EC_DIR_INPUT"
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   524
                            if sync_manager_watchdog:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   525
                                sync_manager_infos["watchdog"] = "EC_WD_ENABLE"
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   526
                            else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   527
                                sync_manager_infos["watchdog"] = "EC_WD_DISABLE"
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
                            sync_managers.append(sync_manager_infos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   530
                        
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
   531
                        pdos_index = []
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   532
                        for only_mandatory in [True, False]:
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   533
                            for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] +
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   534
                                                  [(pdo, "Outputs") for pdo in device.getRxPdo()]):
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   535
                                entries = pdo.getEntry()
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   536
                                
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   537
                                pdo_needed = pdo.getMandatory()
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   538
                                if only_mandatory != pdo_needed:
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   539
                                    continue
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   540
                                
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   541
                                pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent())
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   542
                                pdos_index.append(pdo_index)
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   543
                                entries_infos = []
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   544
                                
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   545
                                for entry in entries:
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   546
                                    index = ExtractHexDecValue(entry.getIndex().getcontent())
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   547
                                    subindex = ExtractHexDecValue(entry.getSubIndex())
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   548
                                    entry_infos = {
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   549
                                        "index": index,
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   550
                                        "subindex": subindex,
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   551
                                        "name": ExtractName(entry.getName()),
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   552
                                        "bitlen": entry.getBitLen(),
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   553
                                    }
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   554
                                    entry_infos.update(type_infos)
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   555
                                    entries_infos.append("    {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos)
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
   556
                                    
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   557
                                    entry_declaration = slave_variables.get((index, subindex), None)
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   558
                                    if entry_declaration is not None and not entry_declaration["mapped"]:
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   559
                                        pdo_needed = True
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   560
                                        
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   561
                                        entry_infos.update(dict(zip(["var_type", "dir", "var_name"], entry_declaration["infos"])))
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   562
                                        entry_declaration["mapped"] = True
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   563
                                        
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   564
                                        if entry_infos["var_type"] != entry.getDataType().getcontent():
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   565
                                            raise ValueError, _("Wrong type for location \"%s\"!") % entry_infos["var_name"]
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   566
                                        
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   567
                                        if (entry_infos["dir"] == "I" and pdo_type != "Inputs" or 
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   568
                                            entry_infos["dir"] == "Q" and pdo_type != "Outputs"):
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   569
                                            raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"]
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   570
                                        
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   571
                                        ConfigureVariable(entry_infos, str_completion)
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   572
                                
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   573
                                if pdo_needed:
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   574
                                    sm = pdo.getSm()
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   575
                                    if sm is None:
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   576
                                        for sm_idx, sync_manager in enumerate(sync_managers):
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   577
                                            if sync_manager["name"] == pdo_type:
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   578
                                                sm = sm_idx
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   579
                                    if sm is None:
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   580
                                        raise ValueError, _("No sync manager available for %s pdo!") % pdo_type
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   581
                                        
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   582
                                    sync_managers[sm]["pdos_number"] += 1
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   583
                                    sync_managers[sm]["pdos"].append(
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   584
                                        {"slave": slave_idx,
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   585
                                         "index": pdo_index,
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   586
                                         "name": ExtractName(pdo.getName()),
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   587
                                         "type": pdo_type, 
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   588
                                         "entries": entries_infos,
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   589
                                         "entries_number": len(entries_infos),
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   590
                                         "fixed": pdo.getFixed() == 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
   591
                        
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
   592
                        dynamic_pdos = {}
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
   593
                        dynamic_pdos_number = 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
   594
                        for category, min_index, max_index in [("Inputs", 0x1600, 0x1800), 
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
   595
                                                               ("Outputs", 0x1a00, 0x1C00)]:
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
   596
                            for sync_manager in 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
   597
                                if sync_manager["name"] == category:
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
   598
                                    category_infos = dynamic_pdos.setdefault(category, {})
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
   599
                                    category_infos["sync_manager"] = sync_manager
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
   600
                                    category_infos["pdos"] = [pdo for pdo in category_infos["sync_manager"]["pdos"] 
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
   601
                                                              if not pdo["fixed"] and pdo["type"] == category]
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
   602
                                    category_infos["current_index"] = min_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
   603
                                    category_infos["max_index"] = max_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
   604
                                    break
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
   605
                        
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
   606
                        for (index, subindex), entry_declaration in slave_variables.iteritems():
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
   607
                            
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
   608
                            if not entry_declaration["mapped"]:
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
   609
                                entry = device_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
   610
                                if entry 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
   611
                                    raise ValueError, _("Unknown entry index 0x%4.4x, subindex 0x%2.2x for device %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
   612
                                                     (index, subindex, type_infos["device_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
   613
                                
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
   614
                                entry_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
   615
                                    "index": 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
   616
                                    "subindex": 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
   617
                                    "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
   618
                                    "bitlen": entry["BitSize"],
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
   619
                                }
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
   620
                                entry_infos.update(type_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
   621
                                
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
   622
                                entry_infos.update(dict(zip(["var_type", "dir", "var_name"], entry_declaration["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
   623
                                entry_declaration["mapped"] = True
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
   624
                                
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
   625
                                if entry_infos["var_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
   626
                                    raise ValueError, _("Wrong type for location \"%s\"!") % entry_infos["var_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
   627
                                
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
   628
                                if entry_infos["dir"] == "I" and entry["Access"] in ["ro", "rw"]:
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
   629
                                    pdo_type = "Inputs"
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
   630
                                elif entry_infos["dir"] == "Q" and entry["Access"] in ["wo", "rw"]:
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
   631
                                    pdo_type = "Outputs"
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
   632
                                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
   633
                                    raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_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
   634
                                
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
   635
                                if not dynamic_pdos.has_key(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
   636
                                    raise ValueError, _("No Sync manager defined for %s!") % 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
   637
                                
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
   638
                                ConfigureVariable(entry_infos, str_completion)
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
   639
                                
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
   640
                                if len(dynamic_pdos[pdo_type]["pdos"]) > 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
   641
                                    pdo = dynamic_pdos[pdo_type]["pdos"][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
   642
                                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
   643
                                    while dynamic_pdos[pdo_type]["current_index"] in pdos_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
   644
                                        dynamic_pdos[pdo_type]["current_index"] += 1
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
   645
                                    if dynamic_pdos[pdo_type]["current_index"] >= dynamic_pdos[pdo_type]["max_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
   646
                                        raise ValueError, _("No more free PDO index available for %s!") % 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
   647
                                    pdos_index.append(dynamic_pdos[pdo_type]["current_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
   648
                                    
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
                                    dynamic_pdos_number += 1
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
   650
                                    pdo = {"slave": slave_idx,
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
   651
                                           "index": dynamic_pdos[pdo_type]["current_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
   652
                                           "name": "Dynamic PDO %d" % dynamic_pdos_number,
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
   653
                                           "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
   654
                                           "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
   655
                                           "entries_number": 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
   656
                                           "fixed": 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
   657
                                    dynamic_pdos[pdo_type]["sync_manager"]["pdos_number"] += 1
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
   658
                                    dynamic_pdos[pdo_type]["sync_manager"]["pdos"].append(pdo)
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
   659
                                    dynamic_pdos[pdo_type]["pdos"].append(pdo)
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
   660
                                
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
   661
                                pdo["entries"].append("    {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_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
   662
                                pdo["entries_number"] += 1
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
   663
                                
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
                                if pdo["entries_number"] == 255:
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
   665
                                    dynamic_pdos[pdo_type]["pdos"].pop(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
   666
                                
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
   667
                        pdo_offset = 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
   668
                        entry_offset = 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
   669
                        for sync_manager_infos in 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
   670
                            
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
   671
                            for pdo_infos in sync_manager_infos["pdos"]:
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
   672
                                pdo_infos["offset"] = entry_offset
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
   673
                                pdo_entries = pdo_infos["entries"]
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
   674
                                pdos_infos["pdos_infos"].append(
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
   675
                                    ("    {0x%(index).4x, %(entries_number)d, " + 
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
   676
                                     "slave_%(slave)d_pdo_entries + %(offset)d}, /* %(name)s */") % pdo_infos)
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
   677
                                entry_offset += len(pdo_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
   678
                                pdos_infos["pdos_entries_infos"].extend(pdo_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
   679
                            
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   680
                            sync_manager_infos["offset"] = pdo_offset
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
   681
                            pdos_infos["pdos_sync_infos"].append(
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
   682
                                ("    {%(index)d, %(sync_manager_type)s, %(pdos_number)d, " + 
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
   683
                                 "slave_%(slave)d_pdos + %(offset)d, %(watchdog)s},") % sync_manager_infos)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   684
                            pdo_offset += sync_manager_infos["pdos_number"]
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   685
                        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   686
                        for element in ["pdos_entries_infos", "pdos_infos", "pdos_sync_infos"]:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   687
                            pdos_infos[element] = "\n".join(pdos_infos[element])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   688
                        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   689
                        str_completion["pdos_configuration_declaration"] += SLAVE_PDOS_CONFIGURATION_DECLARATION % pdos_infos
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   690
        
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
   691
        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
   692
                        "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
   693
                        "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
   694
                        "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
   695
                        "publish_variables"]:
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   696
            str_completion[element] = "\n".join(str_completion[element])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   697
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   698
        etherlabfile = open(self.FilePath,'w')
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   699
        etherlabfile.write(plc_etherlab_code % str_completion)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   700
        etherlabfile.close()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   701
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   702
#--------------------------------------------------
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   703
#                 Ethercat Plugin
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   704
#--------------------------------------------------
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   705
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   706
EtherCATInfoClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATInfo.xsd")) 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   707
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
   708
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
   709
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
   710
    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
   711
    
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
   712
    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
   713
        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
   714
        
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
   715
        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
   716
        
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
   717
            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
   718
            if profile_content is None:
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   719
                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
   720
            
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
   721
            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
   722
                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
   723
                    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
   724
                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
   725
                    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
   726
                
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
   727
        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
   728
    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
   729
    
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
   730
    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
   731
        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
   732
        
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
   733
        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
   734
            
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
   735
            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
   736
            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
   737
                
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
   738
                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
   739
                    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
   740
                    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
   741
                        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
   742
    
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
   743
    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
   744
    
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
   745
    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
   746
        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
   747
            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
   748
        
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
   749
        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
   750
        
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
   751
        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
   752
            
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
   753
            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
   754
                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
   755
                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
   756
                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
   757
                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
   758
                
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
   759
                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
   760
                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
   761
                    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
   762
                    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
   763
                        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
   764
                        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
   765
                            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
   766
                        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
   767
                        subitem_access = ""
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
   768
                        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
   769
                        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
   770
                            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
   771
                            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
   772
                                subitem_access = access.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
   773
                        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
   774
                            "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
   775
                            "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
   776
                            "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
   777
                                    (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
   778
                                     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
   779
                                                 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
   780
                            "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
   781
                            "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
   782
                            "Access": subitem_access, 
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
   783
                            "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
   784
                            "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
   785
                            "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
   786
                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
   787
                    entry_access = ""
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
   788
                    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
   789
                    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
   790
                        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
   791
                        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
   792
                            entry_access = access.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
   793
                    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
   794
                         "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
   795
                         "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
   796
                         "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
   797
                         "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
   798
                         "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
   799
                         "Access": entry_access,
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
   800
                         "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
   801
                         "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
   802
                         "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
   803
        
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
   804
        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
   805
            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
   806
        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
   807
            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
   808
        
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
   809
        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
   810
    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
   811
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
   812
    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
   813
        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
   814
        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
   815
            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
   816
            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
   817
                                ("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
   818
                                ("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
   819
                                ("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
   820
                                ("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
   821
                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
   822
                    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
   823
                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
   824
            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
   825
        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
   826
    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
   827
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   828
def GroupItemCompare(x, y):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   829
    if x["type"] == y["type"]:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   830
        if x["type"] == ETHERCAT_GROUP:
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   831
            return cmp(x["order"], y["order"])
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   832
        else:
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   833
            return cmp(x["name"], y["name"])
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   834
    elif x["type"] == ETHERCAT_GROUP:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   835
        return -1
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   836
    return 1
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   837
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   838
def SortGroupItems(group):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   839
    for item in group["children"]:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   840
        if item["type"] == ETHERCAT_GROUP:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   841
            SortGroupItems(item)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   842
    group["children"].sort(GroupItemCompare)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   843
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   844
def ExtractName(names, default=None):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   845
    if len(names) == 1:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   846
        return names[0].getcontent()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   847
    else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   848
        for name in names:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   849
            if name.getLcId() == 1033:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   850
                return name.getcontent()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   851
    return default
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   852
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
   853
def ExtractPdoInfos(pdo, pdo_type, entries):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   854
    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
   855
    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
   856
    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
   857
        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
   858
        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
   859
        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
   860
        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
   861
        
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
   862
        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
   863
        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
   864
            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
   865
            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
   866
            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
   867
        else:
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   868
            entry_type = pdo_entry.getDataType()
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   869
            if entry_type is not None:
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   870
                if pdo_type == "Transmit":
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   871
                    access = "ro"
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   872
                else:
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   873
                    access = "wo"
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   874
                entries[(index, subindex)] = {
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   875
                    "Index": entry_index,
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   876
                    "SubIndex": entry_subindex,
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   877
                    "Name": ExtractName(pdo_entry.getName()),
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   878
                    "Type": entry_type.getcontent(),
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   879
                    "Access": access,
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   880
                    "PDO index": pdo_index, 
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   881
                    "PDO name": pdo_name, 
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   882
                    "PDO type": pdo_type}
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   883
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   884
class RootClass:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   885
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   886
    PlugChildsTypes = [("EthercatNode",_EthercatPlug,"Ethercat Master")]
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   887
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   888
    def __init__(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   889
        self.LoadModulesLibrary()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   890
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   891
    def GetModulesLibraryPath(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   892
        library_path = os.path.join(self.PlugPath(), "modules")
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   893
        if not os.path.exists(library_path):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   894
            os.mkdir(library_path)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   895
        return library_path
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   896
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   897
    def _ImportModuleLibrary(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   898
        dialog = wx.FileDialog(self.GetPlugRoot().AppFrame, _("Choose an XML file"), os.getcwd(), "",  _("XML files (*.xml)|*.xml|All files|*.*"), wx.OPEN)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   899
        if dialog.ShowModal() == wx.ID_OK:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   900
            filepath = dialog.GetPath()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   901
            if os.path.isfile(filepath):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   902
                shutil.copy(filepath, self.GetModulesLibraryPath())
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   903
                self.LoadModulesLibrary()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   904
            else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   905
                self.GetPlugRoot().logger.write_error(_("No such XML file: %s\n") % filepath)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   906
        dialog.Destroy()  
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   907
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   908
    PluginMethods = [
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   909
        {"bitmap" : os.path.join("images", "ImportDEF"),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   910
         "name" : _("Import module library"), 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   911
         "tooltip" : _("Import module library"),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   912
         "method" : "_ImportModuleLibrary"},
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   913
    ]
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   914
    
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
   915
    def PlugGenerate_C(self, buildpath, locations):
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
   916
        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
   917
    
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   918
    def LoadModulesLibrary(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   919
        self.ModulesLibrary = {}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   920
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   921
        library_path = self.GetModulesLibraryPath()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   922
        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   923
        files = os.listdir(library_path)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   924
        for file in files:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   925
            filepath = os.path.join(library_path, file)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   926
            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
   927
                xmlfile = open(filepath, 'r')
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   928
                xml_tree = minidom.parse(xmlfile)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   929
                xmlfile.close()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   930
                
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   931
                modules_infos = None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   932
                for child in xml_tree.childNodes:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   933
                    if child.nodeType == xml_tree.ELEMENT_NODE and child.nodeName == "EtherCATInfo":
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   934
                        modules_infos = EtherCATInfoClasses["EtherCATInfo.xsd"]["EtherCATInfo"]()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   935
                        modules_infos.loadXMLTree(child, ["xmlns:xsi", "xsi:noNamespaceSchemaLocation"])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   936
                
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   937
                if modules_infos is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   938
                    vendor = modules_infos.getVendor()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   939
                    
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   940
                    vendor_category = self.ModulesLibrary.setdefault(ExtractHexDecValue(vendor.getId()), 
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   941
                                                                     {"name": ExtractName(vendor.getName(), _("Miscellaneous")), 
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   942
                                                                      "groups": {}})
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   943
                    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   944
                    for group in modules_infos.getDescriptions().getGroups().getGroup():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   945
                        group_type = group.getType()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   946
                        
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   947
                        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
   948
                                                                          "parent": group.getParentGroup(),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   949
                                                                          "order": group.getSortOrder(), 
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   950
                                                                          "devices": []})
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   951
                    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   952
                    for device in modules_infos.getDescriptions().getDevices().getDevice():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   953
                        device_group = device.getGroupType()
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   954
                        if not vendor_category["groups"].has_key(device_group):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   955
                            raise ValueError, "Not such group \"%\"" % device_group
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   956
                        vendor_category["groups"][device_group]["devices"].append((device.getType().getcontent(), device))
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   957
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   958
    def GetModulesLibrary(self):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   959
        library = []
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   960
        children_dict = {}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   961
        for vendor_id, vendor in self.ModulesLibrary.iteritems():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   962
            groups = []
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   963
            library.append({"name": vendor["name"],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   964
                            "type": ETHERCAT_VENDOR,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   965
                            "children": groups})
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   966
            for group_type, group in vendor["groups"].iteritems():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   967
                group_infos = {"name": group["name"],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   968
                               "order": group["order"],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   969
                               "type": ETHERCAT_GROUP,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   970
                               "children": children_dict.setdefault(group_type, [])}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   971
                if group["parent"] is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   972
                    parent_children = children_dict.setdefault(group["parent"], [])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   973
                    parent_children.append(group_infos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   974
                else:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   975
                    groups.append(group_infos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   976
                device_dict = {}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   977
                for device_type, device in group["devices"]:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   978
                    device_infos = {"name": ExtractName(device.getName()),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   979
                                    "type": ETHERCAT_DEVICE,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   980
                                    "infos": {"device_type": device_type,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   981
                                              "vendor": vendor_id,
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   982
                                              "product_code": device.getType().getProductCode(),
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   983
                                              "revision_number": device.getType().getRevisionNo()}}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   984
                    group_infos["children"].append(device_infos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   985
                    device_type_occurrences = device_dict.setdefault(device_type, [])
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   986
                    device_type_occurrences.append(device_infos)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   987
                for device_type_occurrences in device_dict.itervalues():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   988
                    if len(device_type_occurrences) > 1:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   989
                        for occurrence in device_type_occurrences:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   990
                            occurrence["name"] += _(" (rev. %s)") % occurrence["infos"]["revision_number"]
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   991
        library.sort(lambda x, y: cmp(x["name"], y["name"]))
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   992
        return library
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   993
    
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   994
    def GetModuleInfos(self, type_infos):
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   995
        vendor = self.ModulesLibrary.get(ExtractHexDecValue(type_infos["vendor"]), None)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   996
        if vendor is not None:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   997
            for group_name, group in vendor["groups"].iteritems():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   998
                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
   999
                    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
  1000
                    revision_number = ExtractHexDecValue(device.getType().getRevisionNo())
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1001
                    if (device_type == type_infos["device_type"] 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
  1002
                        product_code == ExtractHexDecValue(type_infos["product_code"]) and
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
  1003
                        revision_number == ExtractHexDecValue(type_infos["revision_number"])):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1004
                        return device
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1005
        return None
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
  1006