etherlab/etherlab.py
author Edouard Tisserant
Tue, 19 Feb 2019 11:27:29 +0100
changeset 2490 2d72d8a8d7e5
parent 2434 07f48018b6f5
child 2643 b98d9e08231f
permissions -rw-r--r--
Allow using one XSD based target description for many targets. Target description XSD can now use %(target_name)s to refer to target name.
2165
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2162
diff changeset
     1
#!/usr/bin/env python
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2162
diff changeset
     2
# -*- coding: utf-8 -*-
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2162
diff changeset
     3
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2162
diff changeset
     4
# This file is part of Beremiz
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2162
diff changeset
     5
#
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2162
diff changeset
     6
# Copyright (C) 2011-2014: Laurent BESSARD, Edouard TISSERANT
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2162
diff changeset
     7
#                          RTES Lab : CRKim, JBLee, youcu
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2162
diff changeset
     8
#                          Higen Motor : Donggu Kang
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2162
diff changeset
     9
#
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2162
diff changeset
    10
# See COPYING file for copyrights details.
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2162
diff changeset
    11
2405
af050469fc5c clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2397
diff changeset
    12
from __future__ import absolute_import
2357
7c67286cddbe cleanup etherlab: pep8, E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
    13
import os
7c67286cddbe cleanup etherlab: pep8, E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
    14
import shutil
2390
81116c5db60f clean etherlab: pylint, C0411 # (wrong-import-order) standard import "import x" comes before "import y"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2387
diff changeset
    15
import csv
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2425
diff changeset
    16
from builtins import str as text
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2425
diff changeset
    17
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    18
from lxml import etree
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    19
import wx
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    20
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    21
from xmlclass import *
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents: 2109
diff changeset
    22
2396
41adf1dfc7a7 clean etherlab: pylint, W0611 # (unused-import) Unused import X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2390
diff changeset
    23
from ConfigTreeNode import XSDSchemaErrorMessage
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents: 2109
diff changeset
    24
2405
af050469fc5c clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2397
diff changeset
    25
from etherlab.EthercatSlave import ExtractHexDecValue, ExtractName
af050469fc5c clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2397
diff changeset
    26
from etherlab.EthercatMaster import _EthercatCTN
af050469fc5c clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2397
diff changeset
    27
from etherlab.ConfigEditor import LibraryEditor, ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    28
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    29
ScriptDirectory = os.path.split(os.path.realpath(__file__))[0]
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    30
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    31
# --------------------------------------------------
2048
5726f2bbdace reflected changes in beremiz extension mechanism
Edouard Tisserant
parents: 2047
diff changeset
    32
#                 Ethercat ConfNode
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    33
# --------------------------------------------------
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
    34
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
    35
EtherCATInfoParser = GenerateParserFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATInfo.xsd"))
2376
47775c9367bd clean etherlab: pep8, E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2370
diff changeset
    36
47775c9367bd clean etherlab: pep8, E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2370
diff changeset
    37
47775c9367bd clean etherlab: pep8, E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2370
diff changeset
    38
def EtherCATInfo_XPath(xpath):
47775c9367bd clean etherlab: pep8, E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2370
diff changeset
    39
    return etree.XPath(xpath)
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    40
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2359
diff changeset
    41
2162
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    42
def HexDecValue(context, *args):
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    43
    return str(ExtractHexDecValue(args[0][0]))
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    44
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2359
diff changeset
    45
2162
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    46
def EntryName(context, *args):
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
    47
    return ExtractName(args[0], args[1][0] if len(args) > 1 else None)
2162
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    48
2370
e40f3914e55f cleanup etherlab: pep8, E305 expected 2 blank lines after class or function definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
    49
2162
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    50
ENTRY_INFOS_KEYS = [
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    51
    ("Index", lambda x: "#x%4.4X" % int(x), "#x0000"),
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    52
    ("SubIndex", str, "0"),
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    53
    ("Name", str, ""),
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    54
    ("Type", str, ""),
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    55
    ("BitSize", int, 0),
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    56
    ("Access", str, ""),
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    57
    ("PDOMapping", str, ""),
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    58
    ("PDO index", str, ""),
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    59
    ("PDO name", str, ""),
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    60
    ("PDO type", str, "")]
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    61
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2359
diff changeset
    62
2397
25f16349644b clean etherlab: pylint, C1001 # (old-style-class) Old-style class defined.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2396
diff changeset
    63
class EntryListFactory(object):
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    64
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    65
    def __init__(self, entries):
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    66
        self.Entries = entries
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
    67
2162
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    68
    def AddEntry(self, context, *args):
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    69
        index, subindex = map(lambda x: int(x[0]), args[:2])
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    70
        new_entry_infos = {
2162
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    71
            key: translate(arg[0]) if len(arg) > 0 else default
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    72
            for (key, translate, default), arg
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    73
            in zip(ENTRY_INFOS_KEYS, args)}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
    74
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    75
        if (index, subindex) != (0, 0):
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    76
            entry_infos = self.Entries.get((index, subindex))
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    77
            if entry_infos is not None:
2162
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    78
                for param in ["PDO index", "PDO name", "PDO type"]:
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    79
                    value = new_entry_infos.get(param)
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    80
                    if value is not None:
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
    81
                        entry_infos[param] = value
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    82
            else:
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    83
                self.Entries[(index, subindex)] = new_entry_infos
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    84
2370
e40f3914e55f cleanup etherlab: pep8, E305 expected 2 blank lines after class or function definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
    85
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    86
entries_list_xslt = etree.parse(
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    87
    os.path.join(ScriptDirectory, "entries_list.xslt"))
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    88
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    89
cls = EtherCATInfoParser.GetElementClass("DeviceType")
2074
bf2fa4cb62a9 Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents: 2073
diff changeset
    90
if cls:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
    91
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    92
    profile_numbers_xpath = EtherCATInfo_XPath("Profile/ProfileNo")
2387
5cf1d70b5395 clean etherlab: pep8, E301 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2384
diff changeset
    93
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    94
    def GetProfileNumbers(self):
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    95
        return [number.text for number in profile_numbers_xpath(self)]
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    96
    setattr(cls, "GetProfileNumbers", GetProfileNumbers)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
    97
2079
49242019a9ca Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents: 2077
diff changeset
    98
    def getCoE(self):
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
    99
        mailbox = self.getMailbox()
2079
49242019a9ca Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents: 2077
diff changeset
   100
        if mailbox is not None:
49242019a9ca Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents: 2077
diff changeset
   101
            return mailbox.getCoE()
49242019a9ca Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents: 2077
diff changeset
   102
        return None
49242019a9ca Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents: 2077
diff changeset
   103
    setattr(cls, "getCoE", getCoE)
2032
766078d83e22 Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents: 2031
diff changeset
   104
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   105
    def GetEntriesList(self, limits=None):
2029
7c848efa21c6 Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents: 2026
diff changeset
   106
        entries = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   107
2162
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
   108
        factory = EntryListFactory(entries)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   109
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   110
        entries_list_xslt_tree = etree.XSLT(
2366
d635680e4c2c cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2365
diff changeset
   111
            entries_list_xslt, extensions={
2162
43ab74687f45 Fixed xslt stylesheet for extracting entries defined in module, rewiting xslt stylesheet to yslt
Laurent Bessard
parents: 2160
diff changeset
   112
                ("entries_list_ns", "AddEntry"): factory.AddEntry,
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   113
                ("entries_list_ns", "HexDecValue"): HexDecValue,
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   114
                ("entries_list_ns", "EntryName"): EntryName})
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   115
        entries_list_xslt_tree(self, **dict(zip(
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   116
            ["min_index", "max_index"],
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   117
            map(lambda x: etree.XSLT.strparam(str(x)),
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   118
                limits if limits is not None else [0x0000, 0xFFFF])
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   119
            )))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   120
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
   121
        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
   122
    setattr(cls, "GetEntriesList", GetEntriesList)
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   123
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
   124
    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
   125
        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
   126
        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
   127
            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
   128
            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
   129
                                ("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
   130
                                ("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
   131
                                ("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
   132
                                ("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
   133
                if value is None:
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
   134
                    value = ""
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
   135
                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
   136
            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
   137
        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
   138
    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
   139
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2359
diff changeset
   140
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   141
def GroupItemCompare(x, y):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   142
    if x["type"] == y["type"]:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   143
        if x["type"] == ETHERCAT_GROUP:
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   144
            return cmp(x["order"], y["order"])
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   145
        else:
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   146
            return cmp(x["name"], y["name"])
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   147
    elif x["type"] == ETHERCAT_GROUP:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   148
        return -1
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   149
    return 1
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   150
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2359
diff changeset
   151
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   152
def SortGroupItems(group):
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   153
    for item in group["children"]:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   154
        if item["type"] == ETHERCAT_GROUP:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   155
            SortGroupItems(item)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   156
    group["children"].sort(GroupItemCompare)
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   157
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2359
diff changeset
   158
2397
25f16349644b clean etherlab: pylint, C1001 # (old-style-class) Old-style class defined.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2396
diff changeset
   159
class ModulesLibrary(object):
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   160
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   161
    MODULES_EXTRA_PARAMS = [
2384
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   162
        (
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   163
            "pdo_alignment",
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   164
            {
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   165
                "column_label": _("PDO alignment"),
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   166
                "column_size": 150,
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   167
                "default": 8,
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   168
                "description": _("Minimal size in bits between 2 pdo entries")
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   169
            }
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   170
        ),
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   171
        (
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   172
            "max_pdo_size",
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   173
            {
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   174
                "column_label": _("Max entries by PDO"),
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   175
                "column_size": 150,
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   176
                "default": 255,
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   177
                "description": _("""Maximal number of entries mapped in a PDO
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   178
including empty entries used for PDO alignment""")
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   179
            }
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   180
        ),
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   181
        (
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   182
            "add_pdo",
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   183
            {
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   184
                "column_label": _("Creating new PDO"),
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   185
                "column_size": 150,
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   186
                "default": 0,
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   187
                "description": _("""Adding a PDO not defined in default configuration
2138
79dc2d15c580 Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2137
diff changeset
   188
for mapping needed location variables
2384
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   189
(1 if possible)""")
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   190
            }
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   191
        )
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   192
    ]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   193
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   194
    def __init__(self, path, parent_library=None):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   195
        self.Path = path
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   196
        if not os.path.exists(self.Path):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   197
            os.makedirs(self.Path)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   198
        self.ParentLibrary = parent_library
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   199
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   200
        if parent_library is not None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   201
            self.LoadModules()
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   202
        else:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   203
            self.Library = None
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   204
        self.LoadModulesExtraParams()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   205
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   206
    def GetPath(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   207
        return self.Path
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   208
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   209
    def GetModulesExtraParamsFilePath(self):
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   210
        return os.path.join(self.Path, "modules_extra_params.cfg")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   211
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   212
    groups_xpath = EtherCATInfo_XPath("Descriptions/Groups/Group")
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   213
    devices_xpath = EtherCATInfo_XPath("Descriptions/Devices/Device")
2387
5cf1d70b5395 clean etherlab: pep8, E301 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2384
diff changeset
   214
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   215
    def LoadModules(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   216
        self.Library = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   217
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   218
        files = os.listdir(self.Path)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   219
        for file in files:
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   220
            filepath = os.path.join(self.Path, file)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   221
            if os.path.isfile(filepath) and os.path.splitext(filepath)[-1] == ".xml":
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   222
                self.modules_infos = None
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   223
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   224
                xmlfile = open(filepath, 'r')
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   225
                try:
2160
75349c51a34b Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 2159
diff changeset
   226
                    self.modules_infos, error = EtherCATInfoParser.LoadXMLString(xmlfile.read())
75349c51a34b Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 2159
diff changeset
   227
                    if error is not None:
75349c51a34b Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 2159
diff changeset
   228
                        self.GetCTRoot().logger.write_warning(
75349c51a34b Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 2159
diff changeset
   229
                            XSDSchemaErrorMessage % (filepath + error))
2418
5587c490a070 Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2412
diff changeset
   230
                except Exception as exc:
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2425
diff changeset
   231
                    self.modules_infos, error = None, text(exc)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   232
                xmlfile.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   233
2152
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2149
diff changeset
   234
                if self.modules_infos is not None:
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2149
diff changeset
   235
                    vendor = self.modules_infos.getVendor()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   236
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   237
                    vendor_category = self.Library.setdefault(
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   238
                        ExtractHexDecValue(vendor.getId()),
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   239
                        {"name": ExtractName(vendor.getName(), _("Miscellaneous")),
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   240
                         "groups": {}})
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   241
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   242
                    for group in self.groups_xpath(self.modules_infos):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   243
                        group_type = group.getType()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   244
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
   245
                        vendor_category["groups"].setdefault(
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
   246
                            group_type,
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
   247
                            {
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
   248
                                "name": ExtractName(group.getName(), group_type),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
   249
                                "parent": group.getParentGroup(),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
   250
                                "order": group.getSortOrder(),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
   251
                                # "value": group.getcontent()["value"],
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
   252
                                "devices": [],
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
   253
                            })
2359
e945fcb54cd4 cleanup etherlab: pep8, W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2357
diff changeset
   254
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   255
                    for device in self.devices_xpath(self.modules_infos):
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   256
                        device_group = device.getGroupType()
2377
88a9d64560d3 clean etherlab: pep8, W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2376
diff changeset
   257
                        if device_group not in vendor_category["groups"]:
2412
22b1879a3c15 cleanup: pylint, E1300 # (bad-format-character) Unsupported format character '"' (0x22) at index 17
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
   258
                            raise ValueError("Not such group \"%s\"" % device_group)
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   259
                        vendor_category["groups"][device_group]["devices"].append(
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   260
                            (device.getType().getcontent(), device))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   261
2160
75349c51a34b Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 2159
diff changeset
   262
                else:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   263
2160
75349c51a34b Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 2159
diff changeset
   264
                    self.GetCTRoot().logger.write_error(
2425
68e7da937162 Fix 'msgid' format string with unnamed arguments cannot be properly localized
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2418
diff changeset
   265
                        _("Couldn't load {a1} XML file:\n{a2}").format(a1=filepath, a2=error))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   266
2160
75349c51a34b Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 2159
diff changeset
   267
        return self.Library
2152
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2149
diff changeset
   268
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   269
    def GetModulesLibrary(self, profile_filter=None):
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   270
        if self.Library is None:
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   271
            self.LoadModules()
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   272
        library = []
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   273
        for vendor_id, vendor in self.Library.iteritems():
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   274
            groups = []
2073
d14ab97a452a Fix bug modules present in all groups with the same name even if they are defined by different vendors
Laurent Bessard
parents: 2069
diff changeset
   275
            children_dict = {}
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   276
            for group_type, group in vendor["groups"].iteritems():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   277
                group_infos = {"name": group["name"],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   278
                               "order": group["order"],
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   279
                               "type": ETHERCAT_GROUP,
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   280
                               "infos": None,
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   281
                               "children": children_dict.setdefault(group_type, [])}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   282
                device_dict = {}
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   283
                for device_type, device in group["devices"]:
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   284
                    if profile_filter is None or profile_filter in device.GetProfileNumbers():
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   285
                        product_code = device.getType().getProductCode()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   286
                        revision_number = device.getType().getRevisionNo()
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   287
                        module_infos = {"device_type": device_type,
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   288
                                        "vendor": vendor_id,
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   289
                                        "product_code": product_code,
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   290
                                        "revision_number": revision_number}
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   291
                        module_infos.update(self.GetModuleExtraParams(vendor_id, product_code, revision_number))
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   292
                        device_infos = {"name": ExtractName(device.getName()),
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   293
                                        "type": ETHERCAT_DEVICE,
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   294
                                        "infos": module_infos,
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   295
                                        "children": []}
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   296
                        group_infos["children"].append(device_infos)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   297
                        device_type_occurrences = device_dict.setdefault(device_type, [])
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   298
                        device_type_occurrences.append(device_infos)
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   299
                for device_type_occurrences in device_dict.itervalues():
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   300
                    if len(device_type_occurrences) > 1:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   301
                        for occurrence in device_type_occurrences:
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   302
                            occurrence["name"] += _(" (rev. %s)") % occurrence["infos"]["revision_number"]
2041
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   303
                if len(group_infos["children"]) > 0:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   304
                    if group["parent"] is not None:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   305
                        parent_children = children_dict.setdefault(group["parent"], [])
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   306
                        parent_children.append(group_infos)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   307
                    else:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   308
                        groups.append(group_infos)
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   309
            if len(groups) > 0:
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   310
                library.append({"name": vendor["name"],
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   311
                                "type": ETHERCAT_VENDOR,
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   312
                                "infos": None,
ce3727171207 Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents: 2039
diff changeset
   313
                                "children": groups})
2031
c6f32810723e Fix some issues regarding arbitrary variable mapping
laurent
parents: 2030
diff changeset
   314
        library.sort(lambda x, y: cmp(x["name"], y["name"]))
2022
c2295d311402 First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff changeset
   315
        return library
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   316
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   317
    def GetVendors(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   318
        return [(vendor_id, vendor["name"]) for vendor_id, vendor in self.Library.items()]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   319
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   320
    def GetModuleInfos(self, module_infos):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   321
        vendor = ExtractHexDecValue(module_infos["vendor"])
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   322
        vendor_infos = self.Library.get(vendor)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   323
        if vendor_infos is not None:
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   324
            for _group_name, group_infos in vendor_infos["groups"].iteritems():
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   325
                for device_type, device_infos in group_infos["devices"]:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   326
                    product_code = ExtractHexDecValue(device_infos.getType().getProductCode())
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   327
                    revision_number = ExtractHexDecValue(device_infos.getType().getRevisionNo())
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   328
                    if product_code == ExtractHexDecValue(module_infos["product_code"]) and \
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   329
                       revision_number == ExtractHexDecValue(module_infos["revision_number"]):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   330
                        self.cntdevice = device_infos
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   331
                        self.cntdeviceType = device_type
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   332
                        return device_infos, self.GetModuleExtraParams(vendor, product_code, revision_number)
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   333
        return None, None
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   334
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   335
    def ImportModuleLibrary(self, filepath):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   336
        if os.path.isfile(filepath):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   337
            shutil.copy(filepath, self.Path)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   338
            self.LoadModules()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   339
            return True
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   340
        return False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   341
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   342
    def LoadModulesExtraParams(self):
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   343
        self.ModulesExtraParams = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   344
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   345
        csvfile_path = self.GetModulesExtraParamsFilePath()
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   346
        if os.path.exists(csvfile_path):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   347
            csvfile = open(csvfile_path, "rb")
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   348
            sample = csvfile.read(1024)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   349
            csvfile.seek(0)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   350
            dialect = csv.Sniffer().sniff(sample)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   351
            has_header = csv.Sniffer().has_header(sample)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   352
            reader = csv.reader(csvfile, dialect)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   353
            for row in reader:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   354
                if has_header:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   355
                    has_header = False
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   356
                else:
2138
79dc2d15c580 Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2137
diff changeset
   357
                    params_values = {}
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   358
                    for (param, _param_infos), value in zip(
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   359
                            self.MODULES_EXTRA_PARAMS, row[3:]):
2138
79dc2d15c580 Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2137
diff changeset
   360
                        if value != "":
79dc2d15c580 Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2137
diff changeset
   361
                            params_values[param] = int(value)
79dc2d15c580 Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2137
diff changeset
   362
                    self.ModulesExtraParams[
79dc2d15c580 Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2137
diff changeset
   363
                        tuple(map(int, row[:3]))] = params_values
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   364
            csvfile.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   365
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   366
    def SaveModulesExtraParams(self):
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   367
        csvfile = open(self.GetModulesExtraParamsFilePath(), "wb")
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   368
        extra_params = [param for param, _params_infos in self.MODULES_EXTRA_PARAMS]
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   369
        writer = csv.writer(csvfile, delimiter=';')
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   370
        writer.writerow(['Vendor', 'product_code', 'revision_number'] + extra_params)
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   371
        for (vendor, product_code, revision_number), module_extra_params in self.ModulesExtraParams.iteritems():
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   372
            writer.writerow([vendor, product_code, revision_number] +
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   373
                            [module_extra_params.get(param, '')
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   374
                             for param in extra_params])
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   375
        csvfile.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   376
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   377
    def SetModuleExtraParam(self, vendor, product_code, revision_number, param, value):
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   378
        vendor = ExtractHexDecValue(vendor)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   379
        product_code = ExtractHexDecValue(product_code)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   380
        revision_number = ExtractHexDecValue(revision_number)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   381
2138
79dc2d15c580 Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2137
diff changeset
   382
        module_infos = (vendor, product_code, revision_number)
79dc2d15c580 Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2137
diff changeset
   383
        self.ModulesExtraParams.setdefault(module_infos, {})
79dc2d15c580 Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2137
diff changeset
   384
        self.ModulesExtraParams[module_infos][param] = value
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   385
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   386
        self.SaveModulesExtraParams()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   387
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   388
    def GetModuleExtraParams(self, vendor, product_code, revision_number):
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   389
        vendor = ExtractHexDecValue(vendor)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   390
        product_code = ExtractHexDecValue(product_code)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   391
        revision_number = ExtractHexDecValue(revision_number)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   392
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   393
        if self.ParentLibrary is not None:
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   394
            extra_params = self.ParentLibrary.GetModuleExtraParams(vendor, product_code, revision_number)
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   395
        else:
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   396
            extra_params = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   397
2138
79dc2d15c580 Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2137
diff changeset
   398
        extra_params.update(self.ModulesExtraParams.get((vendor, product_code, revision_number), {}))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   399
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   400
        for param, param_infos in self.MODULES_EXTRA_PARAMS:
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   401
            extra_params.setdefault(param, param_infos["default"])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   402
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   403
        return extra_params
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   404
2370
e40f3914e55f cleanup etherlab: pep8, E305 expected 2 blank lines after class or function definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
   405
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   406
USERDATA_DIR = wx.StandardPaths.Get().GetUserDataDir()
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   407
if wx.Platform != '__WXMSW__':
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   408
    USERDATA_DIR += '_files'
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   409
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   410
ModulesDatabase = ModulesLibrary(
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   411
    os.path.join(USERDATA_DIR, "ethercat_modules"))
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   412
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2359
diff changeset
   413
2397
25f16349644b clean etherlab: pylint, C1001 # (old-style-class) Old-style class defined.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2396
diff changeset
   414
class RootClass(object):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   415
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   416
    CTNChildrenTypes = [("EthercatNode", _EthercatCTN, "Ethercat Master")]
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   417
    EditorType = LibraryEditor
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   418
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   419
    def __init__(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   420
        self.ModulesLibrary = None
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   421
        self.LoadModulesLibrary()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   422
2149
7f473761c932 Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents: 2139
diff changeset
   423
    def GetIconName(self):
7f473761c932 Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents: 2139
diff changeset
   424
        return "Ethercat"
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   425
2133
ba0b2ca7db26 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 2111
diff changeset
   426
    def GetModulesLibraryPath(self, project_path=None):
ba0b2ca7db26 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 2111
diff changeset
   427
        if project_path is None:
ba0b2ca7db26 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 2111
diff changeset
   428
            project_path = self.CTNPath()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   429
        return os.path.join(project_path, "modules")
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   430
2133
ba0b2ca7db26 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 2111
diff changeset
   431
    def OnCTNSave(self, from_project_path=None):
ba0b2ca7db26 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 2111
diff changeset
   432
        if from_project_path is not None:
ba0b2ca7db26 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 2111
diff changeset
   433
            shutil.copytree(self.GetModulesLibraryPath(from_project_path),
ba0b2ca7db26 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 2111
diff changeset
   434
                            self.GetModulesLibraryPath())
ba0b2ca7db26 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 2111
diff changeset
   435
        return True
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   436
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   437
    def CTNGenerate_C(self, buildpath, locations):
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   438
        return [], "", False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   439
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   440
    def LoadModulesLibrary(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   441
        if self.ModulesLibrary is None:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   442
            self.ModulesLibrary = ModulesLibrary(self.GetModulesLibraryPath(), ModulesDatabase)
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   443
        else:
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   444
            self.ModulesLibrary.LoadModulesLibrary()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   445
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   446
    def GetModulesDatabaseInstance(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   447
        return ModulesDatabase
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   448
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   449
    def GetModulesLibraryInstance(self):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   450
        return self.ModulesLibrary
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   451
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   452
    def GetModulesLibrary(self, profile_filter=None):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   453
        return self.ModulesLibrary.GetModulesLibrary(profile_filter)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   454
2098
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   455
    def GetVendors(self):
392791b5cc04 Improved Ethercat Network Configurator panels
Laurent Bessard
parents: 2097
diff changeset
   456
        return self.ModulesLibrary.GetVendors()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
   457
2097
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   458
    def GetModuleInfos(self, module_infos):
58d07e039896 Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents: 2096
diff changeset
   459
        return self.ModulesLibrary.GetModuleInfos(module_infos)