etherlab/EthercatMaster.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Sat, 29 Sep 2018 13:30:41 +0300
changeset 2376 47775c9367bd
parent 2375 cfa68a06a24d
child 2380 b35bce45bc5a
permissions -rw-r--r--
clean etherlab: pep8, E731 do not assign a lambda expression, use a def
2165
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2160
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: 2160
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: 2160
diff changeset
     3
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2160
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: 2160
diff changeset
     5
#
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2160
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: 2160
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: 2160
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: 2160
diff changeset
     9
#
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2160
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: 2160
diff changeset
    11
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    12
import os
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    13
import cPickle
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    14
from lxml import etree
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
    15
from copy import deepcopy
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    16
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    17
import wx
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    18
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    19
from xmlclass import *
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    20
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    21
from PLCControler import UndoBuffer, LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    22
from ConfigTreeNode import ConfigTreeNode
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    23
from dialogs import BrowseValuesLibraryDialog
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    24
from IDEFrame import TITLE, FILEMENU, PROJECTTREE
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    25
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
    26
from EthercatSlave import _EthercatSlaveCTN, ExtractHexDecValue, GenerateHexDecValue, TYPECONVERSION, VARCLASSCONVERSION, _CommonSlave
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    27
from EthercatCFileGenerator import _EthercatCFileGenerator
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    28
from ConfigEditor import MasterEditor
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    29
from POULibrary import POULibrary
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    30
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    31
try:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    32
    from EthercatCIA402Slave import _EthercatCIA402SlaveCTN
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    33
    HAS_MCL = True
2353
8f1a2846b2f5 cleanup etherlab: pep8, E722 do not use bare except
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
    34
except Exception:
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    35
    HAS_MCL = False
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    36
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    37
# --------------------------------------------------
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    38
#         Remote Exec Etherlab Commands
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    39
# --------------------------------------------------
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    40
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    41
SCAN_COMMAND = """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    42
import commands
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    43
result = commands.getoutput("ethercat slaves")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    44
slaves = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    45
for slave_line in result.splitlines():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    46
    chunks = slave_line.split()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    47
    idx, pos, state, flag = chunks[:4]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    48
    name = " ".join(chunks[4:])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    49
    alias, position = pos.split(":")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    50
    slave = {"idx": int(idx),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    51
             "alias": int(alias),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    52
             "position": int(position),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    53
             "name": name}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    54
    details = commands.getoutput("ethercat slaves -p %d -v" % slave["idx"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    55
    for details_line in details.splitlines():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    56
        details_line = details_line.strip()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    57
        for header, param in [("Vendor Id:", "vendor_id"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    58
                              ("Product code:", "product_code"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    59
                              ("Revision number:", "revision_number")]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    60
            if details_line.startswith(header):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    61
                slave[param] = details_line.split()[-1]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    62
                break
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    63
    slaves.append(slave)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    64
returnVal = slaves
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    65
"""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    66
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    67
# --------------------------------------------------
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    68
#      Etherlab Specific Blocks Library
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    69
# --------------------------------------------------
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    70
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
    71
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    72
def GetLocalPath(filename):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    73
    return os.path.join(os.path.split(__file__)[0], filename)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    74
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
    75
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    76
class EtherlabLibrary(POULibrary):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    77
    def GetLibraryPath(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    78
        return GetLocalPath("pous.xml")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    79
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    80
    def Generate_C(self, buildpath, varlist, IECCFLAGS):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    81
        etherlab_ext_file = open(GetLocalPath("etherlab_ext.c"), 'r')
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    82
        etherlab_ext_code = etherlab_ext_file.read()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    83
        etherlab_ext_file.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    84
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    85
        Gen_etherlabfile_path = os.path.join(buildpath, "etherlab_ext.c")
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
    86
        ethelabfile = open(Gen_etherlabfile_path, 'w')
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    87
        ethelabfile.write(etherlab_ext_code)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    88
        ethelabfile.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    89
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
    90
        runtimefile_path = os.path.join(os.path.split(__file__)[0], "runtime_etherlab.py")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    91
        return ((["etherlab_ext"], [(Gen_etherlabfile_path, IECCFLAGS)], True), "",
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    92
                ("runtime_etherlab.py", file(GetLocalPath("runtime_etherlab.py"))))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    93
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    94
# --------------------------------------------------
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    95
#                 Ethercat MASTER
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    96
# --------------------------------------------------
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    97
2370
e40f3914e55f cleanup etherlab: pep8, E305 expected 2 blank lines after class or function definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2367
diff changeset
    98
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    99
EtherCATConfigParser = GenerateParserFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATConfig.xsd"))
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   100
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
   101
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   102
def sort_commands(x, y):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   103
    if x["Index"] == y["Index"]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   104
        return cmp(x["Subindex"], y["Subindex"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   105
    return cmp(x["Index"], y["Index"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   106
2370
e40f3914e55f cleanup etherlab: pep8, E305 expected 2 blank lines after class or function definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2367
diff changeset
   107
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   108
cls = EtherCATConfigParser.GetElementClass("Slave", "Config")
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   109
if cls:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   110
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   111
    def getType(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   112
        slave_info = self.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   113
        return {"device_type": slave_info.getName(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   114
                "vendor": GenerateHexDecValue(slave_info.getVendorId()),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   115
                "product_code": GenerateHexDecValue(slave_info.getProductCode(), 16),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   116
                "revision_number": GenerateHexDecValue(slave_info.getRevisionNo(), 16)}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   117
    setattr(cls, "getType", getType)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   118
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   119
    def setType(self, type_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   120
        slave_info = self.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   121
        slave_info.setName(type_infos["device_type"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   122
        slave_info.setVendorId(ExtractHexDecValue(type_infos["vendor"]))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   123
        slave_info.setProductCode(ExtractHexDecValue(type_infos["product_code"]))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   124
        slave_info.setRevisionNo(ExtractHexDecValue(type_infos["revision_number"]))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   125
    setattr(cls, "setType", setType)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   126
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   127
    def getInitCmds(self, create_default=False):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   128
        Mailbox = self.getMailbox()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   129
        if Mailbox is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   130
            if create_default:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   131
                self.addMailbox()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   132
                Mailbox = self.getMailbox()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   133
            else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   134
                return None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   135
        CoE = Mailbox.getCoE()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   136
        if CoE is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   137
            if create_default:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   138
                Mailbox.addCoE()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   139
                CoE = Mailbox.getCoE()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   140
            else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   141
                return None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   142
        InitCmds = CoE.getInitCmds()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   143
        if InitCmds is None and create_default:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   144
            CoE.addInitCmds()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   145
            InitCmds = CoE.getInitCmds()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   146
        return InitCmds
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   147
    setattr(cls, "getInitCmds", getInitCmds)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   148
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   149
    def getStartupCommands(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   150
        pos = self.getInfo().getPhysAddr()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   151
        InitCmds = self.getInitCmds()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   152
        if InitCmds is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   153
            return []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   154
        commands = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   155
        for idx, InitCmd in enumerate(InitCmds.getInitCmd()):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   156
            comment = InitCmd.getComment()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   157
            if comment is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   158
                comment = ""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   159
            commands.append({
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   160
                "command_idx": idx,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   161
                "Position": pos,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   162
                "Index": InitCmd.getIndex(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   163
                "Subindex": InitCmd.getSubIndex(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   164
                "Value": InitCmd.getData(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   165
                "Description": comment})
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   166
        commands.sort(sort_commands)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   167
        return commands
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   168
    setattr(cls, "getStartupCommands", getStartupCommands)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   169
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   170
    def appendStartupCommand(self, command_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   171
        InitCmds = self.getInitCmds(True)
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   172
        command = EtherCATConfigParser.CreateElement("InitCmd", "InitCmds", 1)
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   173
        InitCmds.appendInitCmd(command)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   174
        command.setIndex(command_infos["Index"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   175
        command.setSubIndex(command_infos["Subindex"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   176
        command.setData(command_infos["Value"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   177
        command.setComment(command_infos["Description"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   178
        return len(InitCmds.getInitCmd()) - 1
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   179
    setattr(cls, "appendStartupCommand", appendStartupCommand)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   180
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   181
    def setStartupCommand(self, command_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   182
        InitCmds = self.getInitCmds()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   183
        if InitCmds is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   184
            commands = InitCmds.getInitCmd()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   185
            if command_infos["command_idx"] < len(commands):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   186
                command = commands[command_infos["command_idx"]]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   187
                command.setIndex(command_infos["Index"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   188
                command.setSubIndex(command_infos["Subindex"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   189
                command.setData(command_infos["Value"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   190
                command.setComment(command_infos["Description"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   191
    setattr(cls, "setStartupCommand", setStartupCommand)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   192
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   193
    def removeStartupCommand(self, command_idx):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   194
        InitCmds = self.getInitCmds()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   195
        if InitCmds is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   196
            if command_idx < len(InitCmds.getInitCmd()):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   197
                InitCmds.removeInitCmd(command_idx)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   198
    setattr(cls, "removeStartupCommand", removeStartupCommand)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   199
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   200
ProcessVariablesXSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   201
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   202
      <xsd:element name="ProcessVariables">
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   203
        <xsd:complexType>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   204
          <xsd:sequence>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   205
            <xsd:element name="variable" minOccurs="0" maxOccurs="unbounded">
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   206
              <xsd:complexType>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   207
                <xsd:sequence>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   208
                  <xsd:element name="ReadFrom" type="LocationDesc" minOccurs="0"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   209
                  <xsd:element name="WriteTo" type="LocationDesc" minOccurs="0"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   210
                </xsd:sequence>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   211
                <xsd:attribute name="Name" type="xsd:string" use="required"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   212
                <xsd:attribute name="Comment" type="xsd:string" use="required"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   213
              </xsd:complexType>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   214
            </xsd:element>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   215
          </xsd:sequence>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   216
        </xsd:complexType>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   217
      </xsd:element>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   218
      <xsd:complexType name="LocationDesc">
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   219
        <xsd:attribute name="Position" type="xsd:integer" use="required"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   220
        <xsd:attribute name="Index" type="xsd:integer" use="required"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   221
        <xsd:attribute name="SubIndex" type="xsd:integer" use="required"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   222
      </xsd:complexType>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   223
    </xsd:schema>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   224
"""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   225
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   226
ProcessVariablesParser = GenerateParserFromXSDstring(ProcessVariablesXSD)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   227
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
   228
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   229
class _EthercatCTN:
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
   230
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   231
    CTNChildrenTypes = [("EthercatSlave", _EthercatSlaveCTN, "Ethercat Slave")]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   232
    if HAS_MCL:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   233
        CTNChildrenTypes.append(("EthercatCIA402Slave", _EthercatCIA402SlaveCTN, "Ethercat CIA402 Slave"))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   234
    EditorType = MasterEditor
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   235
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   236
    def __init__(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   237
        config_filepath = self.ConfigFileName()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   238
        config_is_saved = False
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: 2157
diff changeset
   239
        self.Config = None
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   240
        if os.path.isfile(config_filepath):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   241
            config_xmlfile = open(config_filepath, 'r')
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: 2157
diff changeset
   242
            try:
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: 2157
diff changeset
   243
                self.Config, error = \
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: 2157
diff changeset
   244
                    EtherCATConfigParser.LoadXMLString(config_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: 2157
diff changeset
   245
                if error is 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: 2157
diff changeset
   246
                    config_is_saved = True
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: 2157
diff changeset
   247
            except Exception, e:
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: 2157
diff changeset
   248
                error = e.message
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   249
            config_xmlfile.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   250
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: 2157
diff changeset
   251
            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: 2157
diff changeset
   252
                self.GetCTRoot().logger.write_error(
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   253
                    _("Couldn't load %s network configuration file.") % CTNName)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   254
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: 2157
diff changeset
   255
        if self.Config is None:
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   256
            self.Config = EtherCATConfigParser.CreateElement("EtherCATConfig")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   257
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   258
        process_filepath = self.ProcessVariablesFileName()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   259
        process_is_saved = False
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: 2157
diff changeset
   260
        self.ProcessVariables = None
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   261
        if os.path.isfile(process_filepath):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   262
            process_xmlfile = open(process_filepath, 'r')
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: 2157
diff changeset
   263
            try:
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: 2157
diff changeset
   264
                self.ProcessVariables, error = \
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: 2157
diff changeset
   265
                    ProcessVariablesParser.LoadXMLString(process_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: 2157
diff changeset
   266
                if error is 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: 2157
diff changeset
   267
                    process_is_saved = True
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: 2157
diff changeset
   268
            except Exception, e:
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: 2157
diff changeset
   269
                error = e.message
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   270
            process_xmlfile.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   271
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: 2157
diff changeset
   272
            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: 2157
diff changeset
   273
                self.GetCTRoot().logger.write_error(
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   274
                    _("Couldn't load %s network process variables file.") % CTNName)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   275
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: 2157
diff changeset
   276
        if self.ProcessVariables is None:
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   277
            self.ProcessVariables = ProcessVariablesParser.CreateElement("ProcessVariables")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   278
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   279
        if config_is_saved and process_is_saved:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   280
            self.CreateBuffer(True)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   281
        else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   282
            self.CreateBuffer(False)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   283
            self.OnCTNSave()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   284
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
   285
        # ----------- call ethercat mng. function --------------
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
   286
        self.CommonMethod = _CommonSlave(self)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   287
2149
7f473761c932 Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents: 2147
diff changeset
   288
    def GetIconName(self):
7f473761c932 Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents: 2147
diff changeset
   289
        return "Ethercat"
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   290
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   291
    def GetContextualMenuItems(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   292
        return [("Add Ethercat Slave", "Add Ethercat Slave to Master", self.OnAddEthercatSlave)]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   293
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   294
    def OnAddEthercatSlave(self, event):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   295
        app_frame = self.GetCTRoot().AppFrame
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   296
        dialog = BrowseValuesLibraryDialog(app_frame,
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   297
            "Ethercat Slave Type", self.GetSlaveTypesLibrary())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   298
        if dialog.ShowModal() == wx.ID_OK:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   299
            type_infos = dialog.GetValueInfos()
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   300
            device, module_extra_params = self.GetModuleInfos(type_infos)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   301
            if device is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   302
                if HAS_MCL and _EthercatCIA402SlaveCTN.NODE_PROFILE in device.GetProfileNumbers():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   303
                    ConfNodeType = "EthercatCIA402Slave"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   304
                else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   305
                    ConfNodeType = "EthercatSlave"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   306
                new_child = self.CTNAddChild("%s_0" % ConfNodeType, ConfNodeType)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   307
                new_child.SetParamsAttribute("SlaveParams.Type", type_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   308
                self.CTNRequestSave()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   309
                new_child._OpenView()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   310
                app_frame._Refresh(TITLE, FILEMENU, PROJECTTREE)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   311
        dialog.Destroy()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   312
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   313
    def ExtractHexDecValue(self, value):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   314
        return ExtractHexDecValue(value)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   315
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   316
    def GetSizeOfType(self, type):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   317
        return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   318
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   319
    def ConfigFileName(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   320
        return os.path.join(self.CTNPath(), "config.xml")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   321
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   322
    def ProcessVariablesFileName(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   323
        return os.path.join(self.CTNPath(), "process_variables.xml")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   324
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   325
    def FilterSlave(self, slave, vendor=None, slave_pos=None, slave_profile=None):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   326
        if slave_pos is not None and slave.getInfo().getPhysAddr() != slave_pos:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   327
            return False
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   328
        type_infos = slave.getType()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   329
        if vendor is not None and ExtractHexDecValue(type_infos["vendor"]) != vendor:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   330
            return False
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   331
        device, module_extra_params = self.GetModuleInfos(type_infos)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   332
        if slave_profile is not None and slave_profile not in device.GetProfileNumbers():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   333
            return False
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   334
        return True
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   335
2124
1f2c3fdd70d0 Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents: 2113
diff changeset
   336
    def GetSlaveName(self, slave_pos):
1f2c3fdd70d0 Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents: 2113
diff changeset
   337
        CTNChild = self.GetChildByIECLocation((slave_pos,))
1f2c3fdd70d0 Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents: 2113
diff changeset
   338
        if CTNChild is not None:
1f2c3fdd70d0 Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents: 2113
diff changeset
   339
            return CTNChild.CTNName()
1f2c3fdd70d0 Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents: 2113
diff changeset
   340
        return self.CTNName()
1f2c3fdd70d0 Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents: 2113
diff changeset
   341
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   342
    def GetSlaves(self, vendor=None, slave_pos=None, slave_profile=None):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   343
        slaves = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   344
        for slave in self.Config.getConfig().getSlave():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   345
            if self.FilterSlave(slave, vendor, slave_pos, slave_profile):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   346
                slaves.append(slave.getInfo().getPhysAddr())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   347
        slaves.sort()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   348
        return slaves
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   349
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   350
    def GetSlave(self, slave_pos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   351
        for slave in self.Config.getConfig().getSlave():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   352
            slave_info = slave.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   353
            if slave_info.getPhysAddr() == slave_pos:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   354
                return slave
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   355
        return None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   356
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   357
    def GetStartupCommands(self, vendor=None, slave_pos=None, slave_profile=None):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   358
        commands = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   359
        for slave in self.Config.getConfig().getSlave():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   360
            if self.FilterSlave(slave, vendor, slave_pos, slave_profile):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   361
                commands.append((slave.getInfo().getPhysAddr(), slave.getStartupCommands()))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   362
        commands.sort()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   363
        return reduce(lambda x, y: x + y[1], commands, [])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   364
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   365
    def AppendStartupCommand(self, command_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   366
        slave = self.GetSlave(command_infos["Position"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   367
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   368
            command_idx = slave.appendStartupCommand(command_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   369
            self.BufferModel()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   370
            return command_idx
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   371
        return None
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   372
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   373
    def SetStartupCommandInfos(self, command_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   374
        slave = self.GetSlave(command_infos["Position"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   375
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   376
            slave.setStartupCommand(command_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   377
            self.BufferModel()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   378
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   379
    def RemoveStartupCommand(self, slave_pos, command_idx, buffer=True):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   380
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   381
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   382
            slave.removeStartupCommand(command_idx)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   383
            if buffer:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   384
                self.BufferModel()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   385
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   386
    def SetProcessVariables(self, variables):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   387
        vars = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   388
        for var in variables:
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   389
            variable = ProcessVariablesParser.CreateElement("variable", "ProcessVariables")
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   390
            variable.setName(var["Name"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   391
            variable.setComment(var["Description"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   392
            if var["ReadFrom"] != "":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   393
                position, index, subindex = var["ReadFrom"]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   394
                if variable.getReadFrom() is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   395
                    variable.addReadFrom()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   396
                read_from = variable.getReadFrom()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   397
                read_from.setPosition(position)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   398
                read_from.setIndex(index)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   399
                read_from.setSubIndex(subindex)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   400
            elif variable.getReadFrom() is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   401
                variable.deleteReadFrom()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   402
            if var["WriteTo"] != "":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   403
                position, index, subindex = var["WriteTo"]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   404
                if variable.getWriteTo() is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   405
                    variable.addWriteTo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   406
                write_to = variable.getWriteTo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   407
                write_to.setPosition(position)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   408
                write_to.setIndex(index)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   409
                write_to.setSubIndex(subindex)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   410
            elif variable.getWriteTo() is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   411
                variable.deleteWriteTo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   412
            vars.append(variable)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   413
        self.ProcessVariables.setvariable(vars)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   414
        self.BufferModel()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   415
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   416
    def GetProcessVariables(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   417
        variables = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   418
        idx = 0
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   419
        for variable in self.ProcessVariables.getvariable():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   420
            var = {"Name": variable.getName(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   421
                   "Number": idx,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   422
                   "Description": variable.getComment()}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   423
            read_from = variable.getReadFrom()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   424
            if read_from is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   425
                var["ReadFrom"] = (read_from.getPosition(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   426
                                   read_from.getIndex(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   427
                                   read_from.getSubIndex())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   428
            else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   429
                var["ReadFrom"] = ""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   430
            write_to = variable.getWriteTo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   431
            if write_to is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   432
                var["WriteTo"] = (write_to.getPosition(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   433
                                   write_to.getIndex(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   434
                                   write_to.getSubIndex())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   435
            else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   436
                var["WriteTo"] = ""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   437
            variables.append(var)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   438
            idx += 1
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   439
        return variables
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   440
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   441
    def _ScanNetwork(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   442
        app_frame = self.GetCTRoot().AppFrame
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   443
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   444
        execute = True
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   445
        if len(self.Children) > 0:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   446
            dialog = wx.MessageDialog(app_frame,
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   447
                _("The current network configuration will be deleted.\nDo you want to continue?"),
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   448
                _("Scan Network"),
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
   449
                wx.YES_NO | wx.ICON_QUESTION)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   450
            execute = dialog.ShowModal() == wx.ID_YES
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   451
            dialog.Destroy()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   452
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   453
        if execute:
2366
d635680e4c2c cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2363
diff changeset
   454
            error, returnVal = self.RemoteExec(SCAN_COMMAND, returnVal=None)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   455
            if error != 0:
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
   456
                dialog = wx.MessageDialog(app_frame, returnVal, "Error", wx.OK | wx.ICON_ERROR)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   457
                dialog.ShowModal()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   458
                dialog.Destroy()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   459
            elif returnVal is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   460
                for child in self.IECSortedChildren():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   461
                    self._doRemoveChild(child)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   462
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   463
                for slave in returnVal:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   464
                    type_infos = {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   465
                        "vendor": slave["vendor_id"],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   466
                        "product_code": slave["product_code"],
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   467
                        "revision_number": slave["revision_number"],
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   468
                    }
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   469
                    device, module_extra_params = self.GetModuleInfos(type_infos)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   470
                    if device is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   471
                        if HAS_MCL and _EthercatCIA402SlaveCTN.NODE_PROFILE in device.GetProfileNumbers():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   472
                            CTNType = "EthercatCIA402Slave"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   473
                        else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   474
                            CTNType = "EthercatSlave"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   475
                        self.CTNAddChild("slave%s" % slave["idx"], CTNType, slave["idx"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   476
                        self.SetSlaveAlias(slave["idx"], slave["alias"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   477
                        type_infos["device_type"] = device.getType().getcontent()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   478
                        self.SetSlaveType(slave["idx"], type_infos)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   479
2127
32255ca50fb0 Fix scan network functionality, project tree not refreshed after adding slaves
Laurent Bessard
parents: 2124
diff changeset
   480
                if app_frame:
32255ca50fb0 Fix scan network functionality, project tree not refreshed after adding slaves
Laurent Bessard
parents: 2124
diff changeset
   481
                    app_frame.RefreshProjectTree()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   482
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   483
    def CTNAddChild(self, CTNName, CTNType, IEC_Channel=0):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   484
        """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   485
        Create the confnodes that may be added as child to this node self
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   486
        @param CTNType: string desining the confnode class name (get name from CTNChildrenTypes)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   487
        @param CTNName: string for the name of the confnode instance
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   488
        """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   489
        newConfNodeOpj = ConfigTreeNode.CTNAddChild(self, CTNName, CTNType, IEC_Channel)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   490
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   491
        slave = self.GetSlave(newConfNodeOpj.BaseParams.getIEC_Channel())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   492
        if slave is None:
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   493
            slave = EtherCATConfigParser.CreateElement("Slave", "Config")
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   494
            self.Config.getConfig().appendSlave(slave)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   495
            slave_infos = slave.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   496
            slave_infos.setName("undefined")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   497
            slave_infos.setPhysAddr(newConfNodeOpj.BaseParams.getIEC_Channel())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   498
            slave_infos.setAutoIncAddr(0)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   499
            self.BufferModel()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   500
            self.OnCTNSave()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   501
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   502
        return newConfNodeOpj
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   503
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   504
    def _doRemoveChild(self, CTNInstance):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   505
        slave_pos = CTNInstance.GetSlavePos()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   506
        config = self.Config.getConfig()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   507
        for idx, slave in enumerate(config.getSlave()):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   508
            slave_infos = slave.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   509
            if slave_infos.getPhysAddr() == slave_pos:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   510
                config.removeSlave(idx)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   511
                self.BufferModel()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   512
                self.OnCTNSave()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   513
        ConfigTreeNode._doRemoveChild(self, CTNInstance)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   514
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   515
    def SetSlavePosition(self, slave_pos, new_pos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   516
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   517
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   518
            slave_info = slave.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   519
            slave_info.setPhysAddr(new_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   520
            for variable in self.ProcessVariables.getvariable():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   521
                read_from = variable.getReadFrom()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   522
                if read_from is not None and read_from.getPosition() == slave_pos:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   523
                    read_from.setPosition(new_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   524
                write_to = variable.getWriteTo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   525
                if write_to is not None and write_to.getPosition() == slave_pos:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   526
                    write_to.setPosition(new_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   527
            self.CreateBuffer(True)
2147
a8b095de63e8 Fix bug in when moving Ethercat slaves fixed
Laurent Bessard
parents: 2141
diff changeset
   528
            self.CTNRequestSave()
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   529
            if self._View is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   530
                self._View.RefreshView()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   531
                self._View.RefreshBuffer()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   532
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   533
    def GetSlaveAlias(self, slave_pos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   534
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   535
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   536
            slave_info = slave.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   537
            return slave_info.getAutoIncAddr()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   538
        return None
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   539
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   540
    def SetSlaveAlias(self, slave_pos, alias):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   541
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   542
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   543
            slave_info = slave.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   544
            slave_info.setAutoIncAddr(alias)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   545
            self.BufferModel()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   546
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   547
    def GetSlaveType(self, slave_pos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   548
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   549
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   550
            return slave.getType()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   551
        return None
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   552
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   553
    def SetSlaveType(self, slave_pos, type_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   554
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   555
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   556
            slave.setType(type_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   557
            self.BufferModel()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   558
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   559
    def GetSlaveInfos(self, slave_pos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   560
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   561
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   562
            type_infos = slave.getType()
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   563
            device, module_extra_params = self.GetModuleInfos(type_infos)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   564
            if device is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   565
                infos = type_infos.copy()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   566
                infos.update({"physics": device.getPhysics(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   567
                              "sync_managers": device.GetSyncManagers(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   568
                              "entries": self.GetSlaveVariables(device)})
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   569
                return infos
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   570
        return None
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   571
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   572
    def GetSlaveVariables(self, slave_pos=None, limits=None, device=None):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   573
        if device is None and slave_pos is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   574
            slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   575
            if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   576
                type_infos = slave.getType()
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   577
                device, module_extra_params = self.GetModuleInfos(type_infos)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   578
        if device is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   579
            entries = device.GetEntriesList(limits)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   580
            entries_list = entries.items()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   581
            entries_list.sort()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   582
            entries = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   583
            current_index = None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   584
            current_entry = None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   585
            for (index, subindex), entry in entries_list:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   586
                entry["children"] = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   587
                if slave_pos is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   588
                    entry["Position"] = str(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   589
                entry
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   590
                if index != current_index:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   591
                    current_index = index
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   592
                    current_entry = entry
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   593
                    entries.append(entry)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   594
                elif current_entry is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   595
                    current_entry["children"].append(entry)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   596
                else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   597
                    entries.append(entry)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   598
            return entries
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   599
        return []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   600
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   601
    def GetSlaveVariableDataType(self, slave_pos, index, subindex):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   602
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   603
        if slave is not None:
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   604
            device, module_extra_params = self.GetModuleInfos(slave.getType())
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   605
            if device is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   606
                entries = device.GetEntriesList()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   607
                entry_infos = entries.get((index, subindex))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   608
                if entry_infos is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   609
                    return entry_infos["Type"]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   610
        return None
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   611
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   612
    def GetNodesVariables(self, vendor=None, slave_pos=None, slave_profile=None, limits=None):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   613
        entries = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   614
        for slave_position in self.GetSlaves():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   615
            if slave_pos is not None and slave_position != slave_pos:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   616
                continue
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   617
            slave = self.GetSlave(slave_position)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   618
            type_infos = slave.getType()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   619
            if vendor is not None and ExtractHexDecValue(type_infos["vendor"]) != vendor:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   620
                continue
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   621
            device, module_extra_params = self.GetModuleInfos(type_infos)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   622
            if slave_profile is not None and slave_profile not in device.GetProfileNumbers():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   623
                continue
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   624
            entries.extend(self.GetSlaveVariables(slave_position, limits, device))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   625
        return entries
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   626
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   627
    def GetModuleInfos(self, type_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   628
        return self.CTNParent.GetModuleInfos(type_infos)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   629
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   630
    def GetSlaveTypesLibrary(self, profile_filter=None):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   631
        return self.CTNParent.GetModulesLibrary(profile_filter)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   632
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   633
    def GetLibraryVendors(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   634
        return self.CTNParent.GetVendors()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   635
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   636
    def GetDeviceLocationTree(self, slave_pos, current_location, device_name):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   637
        slave = self.GetSlave(slave_pos)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   638
        vars = []
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   639
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   640
            type_infos = slave.getType()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   641
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2133
diff changeset
   642
            device, module_extra_params = self.GetModuleInfos(type_infos)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   643
            if device is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   644
                sync_managers = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   645
                for sync_manager in device.getSm():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   646
                    sync_manager_control_byte = ExtractHexDecValue(sync_manager.getControlByte())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   647
                    sync_manager_direction = sync_manager_control_byte & 0x0c
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   648
                    if sync_manager_direction:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   649
                        sync_managers.append(LOCATION_VAR_OUTPUT)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   650
                    else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   651
                        sync_managers.append(LOCATION_VAR_INPUT)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   652
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   653
                entries = device.GetEntriesList().items()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   654
                entries.sort()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   655
                for (index, subindex), entry in entries:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   656
                    var_size = self.GetSizeOfType(entry["Type"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   657
                    if var_size is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   658
                        var_class = VARCLASSCONVERSION.get(entry["PDOMapping"], None)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   659
                        if var_class is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   660
                            if var_class == LOCATION_VAR_INPUT:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   661
                                var_dir = "%I"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   662
                            else:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   663
                                var_dir = "%Q"
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   664
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   665
                            vars.append({"name": "0x%4.4x-0x%2.2x: %s" % (index, subindex, entry["Name"]),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   666
                                         "type": var_class,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   667
                                         "size": var_size,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   668
                                         "IEC_type": entry["Type"],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   669
                                         "var_name": "%s_%4.4x_%2.2x" % ("_".join(device_name.split()), index, subindex),
2358
8e5a9830867e cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
   670
                                         "location": "%s%s%s" % (var_dir, var_size, ".".join(map(str, current_location +
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   671
                                                                                                    (index, subindex)))),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   672
                                         "description": "",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   673
                                         "children": []})
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   674
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   675
        return vars
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   676
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   677
    def CTNTestModified(self):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   678
        return self.ChangesToSave or not self.ModelIsSaved()
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   679
2133
ba0b2ca7db26 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 2127
diff changeset
   680
    def OnCTNSave(self, from_project_path=None):
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   681
        config_filepath = self.ConfigFileName()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   682
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   683
        config_xmlfile = open(config_filepath, "w")
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   684
        config_xmlfile.write(etree.tostring(
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   685
            self.Config,
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   686
            pretty_print=True,
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   687
            xml_declaration=True,
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   688
            encoding='utf-8'))
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   689
        config_xmlfile.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   690
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   691
        process_filepath = self.ProcessVariablesFileName()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   692
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   693
        process_xmlfile = open(process_filepath, "w")
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   694
        process_xmlfile.write(etree.tostring(
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   695
            self.ProcessVariables,
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   696
            pretty_print=True,
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   697
            xml_declaration=True,
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   698
            encoding='utf-8'))
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   699
        process_xmlfile.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   700
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   701
        self.Buffer.CurrentSaved()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   702
        return True
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   703
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   704
    def GetProcessVariableName(self, location, var_type):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   705
        return "__M%s_%s" % (self.GetSizeOfType(var_type), "_".join(map(str, location)))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   706
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   707
    def _Generate_C(self, buildpath, locations):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   708
        current_location = self.GetCurrentLocation()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   709
        # define a unique name for the generated C file
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   710
        location_str = "_".join(map(lambda x: str(x), current_location))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   711
2358
8e5a9830867e cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
   712
        Gen_Ethercatfile_path = os.path.join(buildpath, "ethercat_%s.c" % location_str)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   713
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   714
        self.FileGenerator = _EthercatCFileGenerator(self)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   715
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   716
        LocationCFilesAndCFLAGS, LDFLAGS, extra_files = ConfigTreeNode._Generate_C(self, buildpath, locations)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   717
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   718
        for idx, variable in enumerate(self.ProcessVariables.getvariable()):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   719
            name = None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   720
            var_type = None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   721
            read_from = variable.getReadFrom()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   722
            write_to = variable.getWriteTo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   723
            if read_from is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   724
                pos = read_from.getPosition()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   725
                index = read_from.getIndex()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   726
                subindex = read_from.getSubIndex()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   727
                location = current_location + (idx, )
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   728
                var_type = self.GetSlaveVariableDataType(pos, index, subindex)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   729
                name = self.FileGenerator.DeclareVariable(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   730
                            pos, index, subindex, var_type, "I",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   731
                            self.GetProcessVariableName(location, var_type))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   732
            if write_to is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   733
                pos = write_to.getPosition()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   734
                index = write_to.getIndex()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   735
                subindex = write_to.getSubIndex()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   736
                if name is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   737
                    location = current_location + (idx, )
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   738
                    var_type = self.GetSlaveVariableDataType(pos, index, subindex)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   739
                    name = self.GetProcessVariableName(location, var_type)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   740
                self.FileGenerator.DeclareVariable(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   741
                            pos, index, subindex, var_type, "Q", name, True)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   742
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   743
        self.FileGenerator.GenerateCFile(Gen_Ethercatfile_path, location_str, self.BaseParams.getIEC_Channel())
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   744
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   745
        LocationCFilesAndCFLAGS.insert(0,
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   746
            (current_location,
2358
8e5a9830867e cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
   747
             [(Gen_Ethercatfile_path, '"-I%s"' % os.path.abspath(self.GetCTRoot().GetIECLibPath()))],
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   748
             True))
2112
e88cd6ff885e Fixed linking with non RTDM etherlab lib. Now with rtdm...
Edouard Tisserant
parents: 2111
diff changeset
   749
        LDFLAGS.append("-lethercat_rtdm -lrtdm")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   750
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   751
        return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   752
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   753
    ConfNodeMethods = [
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2370
diff changeset
   754
        {
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2370
diff changeset
   755
            "bitmap": "ScanNetwork",
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2370
diff changeset
   756
            "name": _("Scan Network"),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2370
diff changeset
   757
            "tooltip": _("Scan Network"),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2370
diff changeset
   758
            "method": "_ScanNetwork",
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2370
diff changeset
   759
        },
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   760
    ]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   761
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   762
    def CTNGenerate_C(self, buildpath, locations):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   763
        current_location = self.GetCurrentLocation()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   764
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   765
        slaves = self.GetSlaves()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   766
        for slave_pos in slaves:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   767
            slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   768
            if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   769
                self.FileGenerator.DeclareSlave(slave_pos, slave)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   770
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   771
        for location in locations:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   772
            loc = location["LOC"][len(current_location):]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   773
            slave_pos = loc[0]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   774
            if slave_pos in slaves and len(loc) == 3 and location["DIR"] != "M":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   775
                self.FileGenerator.DeclareVariable(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   776
                    slave_pos, loc[1], loc[2], location["IEC_TYPE"], location["DIR"], location["NAME"])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   777
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   778
        return [], "", False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   779
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   780
# -------------------------------------------------------------------------------
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   781
#                      Current Buffering Management Functions
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   782
# -------------------------------------------------------------------------------
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   783
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   784
    """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   785
    Return a copy of the config
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   786
    """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   787
    def Copy(self, model):
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   788
        return deepcopy(model)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   789
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   790
    def CreateBuffer(self, saved):
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   791
        self.Buffer = UndoBuffer(
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   792
            (EtherCATConfigParser.Dumps(self.Config),
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   793
             ProcessVariablesParser.Dumps(self.ProcessVariables)),
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   794
            saved)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   795
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   796
    def BufferModel(self):
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   797
        self.Buffer.Buffering(
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   798
            (EtherCATConfigParser.Dumps(self.Config),
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   799
             ProcessVariablesParser.Dumps(self.ProcessVariables)))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   800
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   801
    def ModelIsSaved(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   802
        if self.Buffer is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   803
            return self.Buffer.IsCurrentSaved()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   804
        else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   805
            return True
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   806
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   807
    def LoadPrevious(self):
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   808
        config, process_variables = self.Buffer.Previous()
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   809
        self.Config = EtherCATConfigParser.Loads(config)
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   810
        self.ProcessVariables = ProcessVariablesParser.Loads(process_variables)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   811
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   812
    def LoadNext(self):
2157
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   813
        config, process_variables = self.Buffer.Next()
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   814
        self.Config = EtherCATConfigParser.Loads(config)
a2385e535cf5 Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents: 2152
diff changeset
   815
        self.ProcessVariables = ProcessVariablesParser.Loads(process_variables)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   816
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   817
    def GetBufferState(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   818
        first = self.Buffer.IsFirst()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   819
        last = self.Buffer.IsLast()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   820
        return not first, not last