etherlab/EthercatSlave.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Sat, 29 Sep 2018 17:00:01 +0300
changeset 2402 a1df3102327d
parent 2397 25f16349644b
child 2405 af050469fc5c
permissions -rw-r--r--
ignore missing MotionLibrary

to fix pylint error 'E0401 # (import-error) Unable to import 'X'
2165
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2152
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: 2152
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: 2152
diff changeset
     3
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2152
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: 2152
diff changeset
     5
#
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2152
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: 2152
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: 2152
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: 2152
diff changeset
     9
#
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2152
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: 2152
diff changeset
    11
2396
41adf1dfc7a7 clean etherlab: pylint, W0611 # (unused-import) Unused import X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
    12
from PLCControler import LOCATION_CONFNODE, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    13
from ConfigTreeNode import ConfigTreeNode
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    14
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    15
from ConfigEditor import NodeEditor
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    16
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    17
# ------------------------------------------
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    18
from CommonEtherCATFunction import _CommonSlave
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    19
# ------------------------------------------
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: 2131
diff changeset
    20
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: 2131
diff changeset
    21
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
    22
TYPECONVERSION = {"BOOL": "X", "SINT": "B", "INT": "W", "DINT": "D", "LINT": "L",
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
    23
                  "USINT": "B", "UINT": "W", "UDINT": "D", "ULINT": "L",
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
    24
                  "BYTE": "B", "WORD": "W", "DWORD": "D", "LWORD": "L"}
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    25
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
    26
DATATYPECONVERSION = {"BOOL": "BIT", "SINT": "S8", "INT": "S16", "DINT": "S32", "LINT": "S64",
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
    27
                      "USINT": "U8", "UINT": "U16", "UDINT": "U32", "ULINT": "U64",
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
    28
                      "BYTE": "U8", "WORD": "U16", "DWORD": "U32", "LWORD": "U64"}
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    29
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    30
VARCLASSCONVERSION = {"T": LOCATION_VAR_INPUT, "R": LOCATION_VAR_OUTPUT, "RT": LOCATION_VAR_MEMORY}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    31
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
    32
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    33
def ExtractHexDecValue(value):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    34
    try:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    35
        return int(value)
2353
8f1a2846b2f5 cleanup etherlab: pep8, E722 do not use bare except
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
    36
    except Exception:
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    37
        pass
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    38
    try:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    39
        return int(value.replace("#", "0"), 16)
2353
8f1a2846b2f5 cleanup etherlab: pep8, E722 do not use bare except
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2165
diff changeset
    40
    except Exception:
2378
7aa47c09f8f5 clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2375
diff changeset
    41
        raise ValueError("Invalid value for HexDecValue \"%s\"" % value)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    42
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
    43
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    44
def GenerateHexDecValue(value, base=10):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    45
    if base == 10:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    46
        return str(value)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    47
    elif base == 16:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    48
        return "#x%.8x" % value
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    49
    else:
2378
7aa47c09f8f5 clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2375
diff changeset
    50
        raise ValueError("Not supported base")
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    51
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
    52
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    53
def ExtractName(names, default=None):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    54
    if len(names) == 1:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    55
        return names[0].getcontent()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    56
    else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    57
        for name in names:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    58
            if name.getLcId() == 1033:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    59
                return name.getcontent()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    60
    return default
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    61
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: 2131
diff changeset
    62
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    63
# --------------------------------------------------
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    64
#                    Ethercat Node
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    65
# --------------------------------------------------
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    66
2397
25f16349644b clean etherlab: pylint, C1001 # (old-style-class) Old-style class defined.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2396
diff changeset
    67
class _EthercatSlaveCTN(object):
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    68
    NODE_PROFILE = None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    69
    EditorType = NodeEditor
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    70
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: 2131
diff changeset
    71
    def __init__(self):
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: 2131
diff changeset
    72
        # ----------- 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: 2131
diff changeset
    73
        self.CommonMethod = _CommonSlave(self)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    74
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    75
    def GetIconName(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    76
        return "Slave"
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    77
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    78
    def ExtractHexDecValue(self, value):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    79
        return ExtractHexDecValue(value)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    80
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    81
    def GetSizeOfType(self, type):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    82
        return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    83
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    84
    def GetSlavePos(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    85
        return self.BaseParams.getIEC_Channel()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    86
2366
d635680e4c2c cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2363
diff changeset
    87
    def GetParamsAttributes(self, path=None):
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    88
        if path:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    89
            parts = path.split(".", 1)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    90
            if self.MandatoryParams and parts[0] == self.MandatoryParams[0]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    91
                return self.MandatoryParams[1].getElementInfos(parts[0], parts[1])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    92
            elif self.CTNParams and parts[0] == self.CTNParams[0]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    93
                return self.CTNParams[1].getElementInfos(parts[0], parts[1])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    94
        else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    95
            params = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    96
            if self.CTNParams:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    97
                params.append(self.CTNParams[1].getElementInfos(self.CTNParams[0]))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    98
            else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    99
                params.append({
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   100
                    'use': 'required',
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   101
                    'type': 'element',
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   102
                    'name': 'SlaveParams',
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   103
                    'value': None,
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   104
                    'children': []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   105
                })
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   106
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   107
            slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos())
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   108
            params[0]['children'].insert(
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   109
                0,
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   110
                {
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   111
                    'use': 'optional',
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   112
                    'type': self.CTNParent.GetSlaveTypesLibrary(self.NODE_PROFILE),
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   113
                    'name': 'Type',
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   114
                    'value': (slave_type["device_type"], slave_type)
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   115
                })
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   116
            params[0]['children'].insert(
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   117
                1,
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   118
                {
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   119
                    'use': 'optional',
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   120
                    'type': 'unsignedLong',
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   121
                    'name': 'Alias',
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   122
                    'value': self.CTNParent.GetSlaveAlias(self.GetSlavePos())
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
   123
                })
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   124
            return params
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   125
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   126
    def SetParamsAttribute(self, path, value):
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: 2131
diff changeset
   127
        self.GetSlaveInfos()
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   128
        position = self.BaseParams.getIEC_Channel()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   129
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   130
        if path == "SlaveParams.Type":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   131
            self.CTNParent.SetSlaveType(position, value)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   132
            slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   133
            value = (slave_type["device_type"], slave_type)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   134
            # if self._View is not None:
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   135
            #     wx.CallAfter(self._View.EtherCATManagementTreebook.SlaveStatePanel.RefreshSlaveInfos())
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   136
            #     self._View.EtherCATManagementTreebook.SlaveStatePanel.RefreshSlaveInfos()
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   137
            #     self._View.EtherCATManagementTreebook.PDOMonitoringPanel.PDOInfoUpdate()
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   138
            #     self._View.EtherCATManagementTreebook.SmartView.Create_SmartView()
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   139
            return value, True
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   140
        elif path == "SlaveParams.Alias":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   141
            self.CTNParent.SetSlaveAlias(position, value)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   142
            return value, True
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   143
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   144
        value, refresh = ConfigTreeNode.SetParamsAttribute(self, path, value)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   145
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   146
        # Filter IEC_Channel, Slave_Type and Alias that have specific behavior
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   147
        if path == "BaseParams.IEC_Channel" and value != position:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   148
            self.CTNParent.SetSlavePosition(position, value)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   149
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   150
        return value, refresh
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   151
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   152
    def GetSlaveInfos(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   153
        return self.CTNParent.GetSlaveInfos(self.GetSlavePos())
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   154
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   155
    def GetSlaveVariables(self, limits):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   156
        return self.CTNParent.GetSlaveVariables(self.GetSlavePos(), limits)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   157
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   158
    def GetVariableLocationTree(self):
2362
6d31ef14f396 cleanup etherlab: pep8, E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   159
        return {
6d31ef14f396 cleanup etherlab: pep8, E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   160
            "name": self.BaseParams.getName(),
6d31ef14f396 cleanup etherlab: pep8, E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   161
            "type": LOCATION_CONFNODE,
6d31ef14f396 cleanup etherlab: pep8, E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   162
            "location": self.GetFullIEC_Channel(),
6d31ef14f396 cleanup etherlab: pep8, E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   163
            "children": self.CTNParent.GetDeviceLocationTree(self.GetSlavePos(), self.GetCurrentLocation(), self.BaseParams.getName())
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   164
        }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   165
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   166
    def CTNGenerate_C(self, buildpath, locations):
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2362
diff changeset
   167
        return [], "", False