etherlab/CommonEtherCATFunction.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 09 Oct 2018 14:03:44 +0300
changeset 2442 b13f021c68a5
parent 2437 105c20fdeb19
child 2446 922f0d84f869
permissions -rw-r--r--
python3 support: pylint, W1607 # (file-builtin) file built-in referenced
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     1
#!/usr/bin/env python
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     2
# -*- coding: utf-8 -*-
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     3
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     4
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     5
# This file is part of Beremiz
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     6
#
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     7
# Copyright (C) 2013: Real-Time & Embedded Systems (RTES) Lab. University of Seoul, Korea
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     8
#
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     9
# See COPYING file for copyrights details.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    10
2405
af050469fc5c clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2400
diff changeset
    11
from __future__ import absolute_import
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
    12
from __future__ import division
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2423
diff changeset
    13
from builtins import str as text
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    14
import wx
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    15
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2423
diff changeset
    16
2373
73d35ba8f982 clean etherlab: pep8, E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2370
diff changeset
    17
mailbox_protocols = ["AoE", "EoE", "CoE", "FoE", "SoE", "VoE"]
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    18
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
    19
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    20
def ExtractHexDecValue(value):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    21
    """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    22
     convert numerical value in string format into decimal or hex format.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    23
     @param value : hex or decimal data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    24
     @return integer data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    25
    """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    26
    try:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    27
        return int(value)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    28
    except Exception:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    29
        pass
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    30
    try:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    31
        return int(value.replace("#", "0"), 16)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    32
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    33
    except Exception:
2423
2c7b7ae24d57 Improve localization support in etherlab (mostly)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2421
diff changeset
    34
        raise ValueError(_("Invalid value for HexDecValue \"%s\"") % value)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    35
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
    36
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    37
def ExtractName(names, default=None):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    38
    """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    39
     Extract "name" field from XML entries.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    40
     @param names : XML entry
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    41
     @default : if it fails to extract from the designated XML entry, return the default value ("None").
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    42
     @return default or the name extracted
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    43
    """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    44
    if len(names) == 1:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    45
        return names[0].getcontent()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    46
    else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    47
        for name in names:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    48
            if name.getLcId() == 1033:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    49
                return name.getcontent()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    50
    return default
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    51
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    52
# --------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    53
#         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
    54
# --------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    55
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
    56
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    57
# --------------------- for master ---------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    58
MASTER_STATE = """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    59
import commands
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    60
result = commands.getoutput("ethercat master")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    61
returnVal =result
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    62
"""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    63
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    64
# --------------------- for slave ----------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    65
# ethercat state -p (slave position) (state (INIT, PREOP, SAFEOP, OP))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    66
SLAVE_STATE = """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    67
import commands
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    68
result = commands.getoutput("ethercat state -p %d %s")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    69
returnVal = result
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    70
"""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    71
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    72
# ethercat slave
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    73
GET_SLAVE = """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    74
import commands
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    75
result = commands.getoutput("ethercat slaves")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    76
returnVal =result
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    77
"""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    78
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    79
# ethercat xml -p (slave position)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    80
SLAVE_XML = """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    81
import commands
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    82
result = commands.getoutput("ethercat xml -p %d")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    83
returnVal = result
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    84
"""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    85
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    86
# ethercat sdos -p (slave position)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    87
SLAVE_SDO = """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    88
import commands
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    89
result = commands.getoutput("ethercat sdos -p %d")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    90
returnVal =result
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    91
"""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    92
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    93
# ethercat upload -p (slave position) (main index) (sub index)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    94
GET_SLOW_SDO = """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    95
import commands
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    96
result = commands.getoutput("ethercat upload -p %d %s %s")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    97
returnVal =result
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    98
"""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    99
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   100
# ethercat download -p (slave position) (main index) (sub index) (value)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   101
SDO_DOWNLOAD = """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   102
import commands
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   103
result = commands.getoutput("ethercat download --type %s -p %d %s %s %s")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   104
returnVal =result
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   105
"""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   106
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   107
# ethercat sii_read -p (slave position)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   108
SII_READ = """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   109
import commands
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   110
result = commands.getoutput("ethercat sii_read -p %d")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   111
returnVal =result
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   112
"""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   113
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   114
# ethercat reg_read -p (slave position) (address) (size)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   115
REG_READ = """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   116
import commands
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   117
result = commands.getoutput("ethercat reg_read -p %d %s %s")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   118
returnVal =result
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   119
"""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   120
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   121
# ethercat sii_write -p (slave position) - (contents)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   122
SII_WRITE = """
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   123
import subprocess
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   124
process = subprocess.Popen(
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   125
    ["ethercat", "-f", "sii_write", "-p", "%d", "-"],
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   126
    stdin=subprocess.PIPE)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   127
process.communicate(sii_data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   128
returnVal = process.returncode
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   129
"""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   130
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   131
# ethercat reg_write -p (slave position) -t (uinit16) (address) (data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   132
REG_WRITE = """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   133
import commands
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   134
result = commands.getoutput("ethercat reg_write -p %d -t uint16 %s %s")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   135
returnVal =result
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   136
"""
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   137
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   138
# ethercat rescan -p (slave position)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   139
RESCAN = """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   140
import commands
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   141
result = commands.getoutput("ethercat rescan -p %d")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   142
returnVal =result
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   143
"""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   144
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
   145
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   146
# --------------------------------------------------
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   147
#    Common Method For EtherCAT Management
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   148
# --------------------------------------------------
2397
25f16349644b clean etherlab: pylint, C1001 # (old-style-class) Old-style class defined.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2396
diff changeset
   149
class _CommonSlave(object):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   150
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   151
    # ----- Data Structure for ethercat management ----
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   152
    SlaveState = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   153
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   154
    # category of SDO data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   155
    DatatypeDescription, CommunicationObject, ManufacturerSpecific, \
2384
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2383
diff changeset
   156
        ProfileSpecific, Reserved, AllSDOData = range(6)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   157
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   158
    # store the execution result of "ethercat sdos" command into SaveSDOData.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   159
    SaveSDOData = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   160
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   161
    # Flags for checking "write" permission of OD entries
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   162
    CheckPREOP = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   163
    CheckSAFEOP = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   164
    CheckOP = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   165
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   166
    # Save PDO Data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   167
    TxPDOInfo = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   168
    TxPDOCategory = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   169
    RxPDOInfo = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   170
    RxPDOCategory = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   171
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   172
    # Save EEPROM Data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   173
    SiiData = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   174
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   175
    # Save Register Data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   176
    RegData = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   177
    CrtRegSpec = {"ESCType": "",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   178
                  "FMMUNumber": "",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   179
                  "SMNumber": "",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   180
                  "PDIType": ""}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   181
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   182
    def __init__(self, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   183
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   184
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   185
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   186
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   187
        self.Controler = controler
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   188
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   189
        self.ClearSDODataSet()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   190
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   191
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   192
    #                        Used Master State
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   193
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   194
    def GetMasterState(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   195
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   196
        Execute "ethercat master" command and parse the execution result
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   197
        @return MasterState
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   198
        """
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   199
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   200
        # exectute "ethercat master" command
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   201
        _error, return_val = self.Controler.RemoteExec(MASTER_STATE, return_val=None)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   202
        master_state = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   203
        # parse the reslut
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   204
        for each_line in return_val.splitlines():
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   205
            if len(each_line) > 0:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   206
                chunks = each_line.strip().split(':', 1)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   207
                key = chunks[0]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   208
                value = []
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   209
                if len(chunks) > 1:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   210
                    value = chunks[1].split()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   211
                if '(attached)' in value:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   212
                    value.remove('(attached)')
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   213
                master_state[key] = value
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   214
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   215
        return master_state
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   216
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   217
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   218
    #                        Used Slave State
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   219
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   220
    def RequestSlaveState(self, command):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   221
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   222
        Set slave state to the specified one using "ethercat states -p %d %s" command.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   223
        Command example : "ethercat states -p 0 PREOP" (target slave position and target state are given.)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   224
        @param command : target slave state
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   225
        """
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   226
        _error, _return_val = self.Controler.RemoteExec(
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   227
            SLAVE_STATE % (self.Controler.GetSlavePos(), command),
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   228
            return_val=None)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   229
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   230
    def GetSlaveStateFromSlave(self):
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   231
        """
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   232
        Get slave information using "ethercat slaves" command and store the information into internal data structure
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   233
        (self.SlaveState) for "Slave State"
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   234
        return_val example : 0  0:0  PREOP  +  EL9800 (V4.30) (PIC24, SPI, ET1100)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   235
        """
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   236
        _error, return_val = self.Controler.RemoteExec(GET_SLAVE, return_val=None)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   237
        self.SlaveState = return_val
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   238
        return return_val
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   239
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   240
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   241
    #                        Used SDO Management
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   242
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   243
    def GetSlaveSDOFromSlave(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   244
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   245
        Get SDO objects information of current slave using "ethercat sdos -p %d" command.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   246
        Command example : "ethercat sdos -p 0"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   247
        @return return_val : execution results of "ethercat sdos" command (need to be parsed later)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   248
        """
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   249
        _error, return_val = self.Controler.RemoteExec(SLAVE_SDO % (self.Controler.GetSlavePos()), return_val=None)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   250
        return return_val
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   251
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   252
    def SDODownload(self, data_type, idx, sub_idx, value):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   253
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   254
        Set an SDO object value to user-specified value using "ethercat download" command.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   255
        Command example : "ethercat download --type int32 -p 0 0x8020 0x12 0x00000000"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   256
        @param data_type : data type of SDO entry
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   257
        @param idx : index of the SDO entry
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   258
        @param sub_idx : subindex of the SDO entry
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   259
        @param value : value of SDO entry
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   260
        """
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   261
        _error, _return_val = self.Controler.RemoteExec(
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   262
            SDO_DOWNLOAD % (data_type, self.Controler.GetSlavePos(), idx, sub_idx, value),
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   263
            return_val=None)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   264
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   265
    def BackupSDODataSet(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   266
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   267
        Back-up current SDO entry information to restore the SDO data
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
   268
        in case that the user cancels SDO update operation.
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
   269
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   270
        self.BackupDatatypeDescription = self.SaveDatatypeDescription
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   271
        self.BackupCommunicationObject = self.SaveCommunicationObject
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   272
        self.BackupManufacturerSpecific = self.SaveManufacturerSpecific
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   273
        self.BackupProfileSpecific = self.SaveProfileSpecific
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   274
        self.BackupReserved = self.SaveReserved
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   275
        self.BackupAllSDOData = self.SaveAllSDOData
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   276
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   277
    def ClearSDODataSet(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   278
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   279
        Clear the specified SDO entry information.
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   280
        """
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   281
        for dummy in range(6):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   282
            self.SaveSDOData.append([])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   283
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   284
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   285
    #                        Used PDO Monitoring
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   286
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   287
    def RequestPDOInfo(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   288
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   289
        Load slave information from RootClass (XML data) and parse the information (calling SlavePDOData() method).
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   290
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   291
        # Load slave information from ESI XML file (def EthercatMaster.py)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   292
        slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos())
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   293
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   294
        type_infos = slave.getType()
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   295
        device, _alignment = self.Controler.CTNParent.GetModuleInfos(type_infos)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   296
        # Initialize PDO data set
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   297
        self.ClearDataSet()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   298
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   299
        # if 'device' object is valid, call SavePDOData() to parse PDO data
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   300
        if device is not None:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   301
            self.SavePDOData(device)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   302
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   303
    def SavePDOData(self, device):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   304
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   305
        Parse PDO data and store the results in TXPDOCategory and RXPDOCategory
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   306
        Tx(Rx)PDOCategory : index, name, entry number
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   307
        Tx(Rx)Info : entry index, sub index, name, length, type
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   308
        @param device : Slave information extracted from ESI XML file
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   309
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   310
        # Parsing TXPDO entries
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   311
        for pdo, _pdo_info in ([(pdo, "Inputs") for pdo in device.getTxPdo()]):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   312
            # Save pdo_index, entry, and name of each entry
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   313
            pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   314
            entries = pdo.getEntry()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   315
            pdo_name = ExtractName(pdo.getName())
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   316
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   317
            # Initialize entry number count
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   318
            count = 0
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   319
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   320
            # Parse entries
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   321
            for entry in entries:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   322
                # Save index and subindex
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   323
                index = ExtractHexDecValue(entry.getIndex().getcontent())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   324
                subindex = ExtractHexDecValue(entry.getSubIndex())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   325
                # if entry name exists, save entry data
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   326
                if ExtractName(entry.getName()) is not None:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   327
                    entry_infos = {
2407
5f2b1bb464a0 clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
   328
                        "entry_index": index,
5f2b1bb464a0 clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
   329
                        "subindex": subindex,
5f2b1bb464a0 clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
   330
                        "name": ExtractName(entry.getName()),
5f2b1bb464a0 clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
   331
                        "bitlen": entry.getBitLen(),
5f2b1bb464a0 clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
   332
                        "type": entry.getDataType().getcontent()
5f2b1bb464a0 clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
   333
                    }
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   334
                    self.TxPDOInfo.append(entry_infos)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   335
                    count += 1
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   336
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   337
            categorys = {"pdo_index": pdo_index, "name": pdo_name, "number_of_entry": count}
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   338
            self.TxPDOCategory.append(categorys)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   339
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   340
        # Parsing RxPDO entries
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   341
        for pdo, _pdo_info in ([(rxpdo, "Outputs") for rxpdo in device.getRxPdo()]):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   342
            # Save pdo_index, entry, and name of each entry
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   343
            pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   344
            entries = pdo.getEntry()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   345
            pdo_name = ExtractName(pdo.getName())
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   346
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   347
            # Initialize entry number count
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   348
            count = 0
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   349
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   350
            # Parse entries
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   351
            for entry in entries:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   352
                # Save index and subindex
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   353
                index = ExtractHexDecValue(entry.getIndex().getcontent())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   354
                subindex = ExtractHexDecValue(entry.getSubIndex())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   355
                # if entry name exists, save entry data
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   356
                if ExtractName(entry.getName()) is not None:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   357
                    entry_infos = {
2407
5f2b1bb464a0 clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
   358
                        "entry_index": index,
5f2b1bb464a0 clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
   359
                        "subindex": subindex,
5f2b1bb464a0 clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
   360
                        "name": ExtractName(entry.getName()),
5f2b1bb464a0 clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
   361
                        "bitlen": str(entry.getBitLen()),
5f2b1bb464a0 clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
   362
                        "type": entry.getDataType().getcontent()
5f2b1bb464a0 clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
   363
                    }
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   364
                    self.RxPDOInfo.append(entry_infos)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   365
                    count += 1
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   366
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   367
            categorys = {"pdo_index": pdo_index, "name": pdo_name, "number_of_entry": count}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   368
            self.RxPDOCategory.append(categorys)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   369
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   370
    def GetTxPDOCategory(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   371
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   372
        Get TxPDOCategory data structure (Meta informaton of TxPDO).
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   373
        TxPDOCategorys : index, name, number of entries
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   374
        @return TxPDOCategorys
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   375
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   376
        return self.TxPDOCategory
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   377
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   378
    def GetRxPDOCategory(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   379
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   380
        Get RxPDOCategory data structure (Meta information of RxPDO).
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   381
        RxPDOCategorys : index, name, number of entries
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   382
        @return RxPDOCategorys
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   383
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   384
        return self.RxPDOCategory
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   385
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   386
    def GetTxPDOInfo(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   387
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   388
        Get TxPDOInfo data structure (Detailed information on TxPDO entries).
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   389
        TxPDOInfos : entry index, sub index, name, length, type
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   390
        @return TxPDOInfos
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   391
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   392
        return self.TxPDOInfo
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   393
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   394
    def GetRxPDOInfo(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   395
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   396
        Get RxPDOInfo data structure (Detailed information on RxPDO entries).
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   397
        RxPDOInfos : entry index, sub index, name, length, type
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   398
        @return RxPDOInfos
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   399
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   400
        return self.RxPDOInfo
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   401
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   402
    def ClearDataSet(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   403
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   404
        Initialize PDO management data structure.
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   405
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   406
        self.TxPDOInfos = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   407
        self.TxPDOCategorys = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   408
        self.RxPDOInfos = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   409
        self.RxPDOCategorys = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   410
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   411
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   412
    #                        Used EEPROM Management
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   413
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   414
    # Base data types in ETG2000; format = {"Name": "BitSize"}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   415
    BaseDataTypeDict = {"BOOL": "01",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   416
                        "SINT": "02",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   417
                        "INT": "03",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   418
                        "DINT": "04",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   419
                        "USINT": "05",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   420
                        "UINT": "06",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   421
                        "UDINT": "07",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   422
                        "REAL": "08",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   423
                        "INT24": "10",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   424
                        "LREAL": "11",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   425
                        "INT40": "12",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   426
                        "INT48": "13",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   427
                        "INT56": "14",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   428
                        "LINT": "15",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   429
                        "UINT24": "16",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   430
                        "UINT40": "18",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   431
                        "UINT48": "19",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   432
                        "UINT56": "1a",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   433
                        "ULINT": "1b",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   434
                        "BITARR8": "2d",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   435
                        "BITARR16": "2e",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   436
                        "BITARR32": "2f",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   437
                        "BIT1": "30",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   438
                        "BIT2": "31",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   439
                        "BIT3": "32",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   440
                        "BIT4": "33",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   441
                        "BIT5": "34",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   442
                        "BIT6": "35",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   443
                        "BIT7": "36",
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   444
                        "BIT8": "37"}
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   445
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   446
    def GetSmartViewInfos(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   447
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   448
        Parse XML data for "Smart View" of EEPROM contents.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   449
        @return smartview_infos : EEPROM contents dictionary
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   450
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   451
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   452
        smartview_infos = {"eeprom_size": 128,
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   453
                           "pdi_type": 0,
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   454
                           "device_emulation": "False",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   455
                           "vendor_id": '0x00000000',
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   456
                           "product_code": '0x00000000',
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   457
                           "revision_no": '0x00000000',
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   458
                           "serial_no": '0x00000000',
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   459
                           "supported_mailbox": "",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   460
                           "mailbox_bootstrapconf_outstart": '0',
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   461
                           "mailbox_bootstrapconf_outlength": '0',
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   462
                           "mailbox_bootstrapconf_instart": '0',
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   463
                           "mailbox_bootstrapconf_inlength": '0',
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   464
                           "mailbox_standardconf_outstart": '0',
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   465
                           "mailbox_standardconf_outlength": '0',
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   466
                           "mailbox_standardconf_instart": '0',
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   467
                           "mailbox_standardconf_inlength": '0'}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   468
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   469
        slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   470
        type_infos = slave.getType()
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   471
        device, _alignment = self.Controler.CTNParent.GetModuleInfos(type_infos)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   472
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   473
        # 'device' represents current slave device selected by user
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   474
        if device is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   475
            for eeprom_element in device.getEeprom().getcontent():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   476
                # get EEPROM size; <Device>-<Eeprom>-<ByteSize>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   477
                if eeprom_element["name"] == "ByteSize":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   478
                    smartview_infos["eeprom_size"] = eeprom_element
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   479
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   480
                elif eeprom_element["name"] == "ConfigData":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   481
                    configData_data = self.DecimalToHex(eeprom_element)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   482
                    # get PDI type; <Device>-<Eeprom>-<ConfigData> address 0x00
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   483
                    smartview_infos["pdi_type"] = int(configData_data[0:2], 16)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   484
                    # get state of device emulation; <Device>-<Eeprom>-<ConfigData> address 0x01
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   485
                    if "{:0>8b}".format(int(configData_data[2:4], 16))[7] == '1':
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   486
                        smartview_infos["device_emulation"] = "True"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   487
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   488
                elif eeprom_element["name"] == "BootStrap":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   489
                    bootstrap_data = "{:0>16x}".format(eeprom_element)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   490
                    # get bootstrap configuration; <Device>-<Eeprom>-<BootStrap>
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   491
                    for cfg, iter in [("mailbox_bootstrapconf_outstart", 0),
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   492
                                      ("mailbox_bootstrapconf_outlength", 1),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   493
                                      ("mailbox_bootstrapconf_instart", 2),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   494
                                      ("mailbox_bootstrapconf_inlength", 3)]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   495
                        smartview_infos[cfg] = str(int(bootstrap_data[4*iter+2:4*(iter+1)]+bootstrap_data[4*iter:4*iter+2], 16))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   496
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   497
            # get protocol (profile) types supported by mailbox; <Device>-<Mailbox>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   498
            mb = device.getMailbox()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   499
            if mb is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   500
                for mailbox_protocol in mailbox_protocols:
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   501
                    if getattr(mb, "get%s" % mailbox_protocol)() is not None:
2358
8e5a9830867e cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
   502
                        smartview_infos["supported_mailbox"] += "%s,  " % mailbox_protocol
2410
4e7ebd6ec248 cleanup: pylint, E1310 (bad-str-strip-call) Suspicious argument in str.strip call
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2407
diff changeset
   503
            smartview_infos["supported_mailbox"] = smartview_infos["supported_mailbox"].strip(", ")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   504
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   505
            # get standard configuration of mailbox; <Device>-<Sm>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   506
            for sm_element in device.getSm():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   507
                if sm_element.getcontent() == "MBoxOut":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   508
                    smartview_infos["mailbox_standardconf_outstart"] = str(ExtractHexDecValue(sm_element.getStartAddress()))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   509
                    smartview_infos["mailbox_standardconf_outlength"] = str(ExtractHexDecValue(sm_element.getDefaultSize()))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   510
                elif sm_element.getcontent() == "MBoxIn":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   511
                    smartview_infos["mailbox_standardconf_instart"] = str(ExtractHexDecValue(sm_element.getStartAddress()))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   512
                    smartview_infos["mailbox_standardconf_inlength"] = str(ExtractHexDecValue(sm_element.getDefaultSize()))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   513
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   514
                    pass
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   515
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   516
            # get device identity from <Device>-<Type>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   517
            #  vendor ID; by default, pre-defined value in self.ModulesLibrary
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   518
            #             if device type in 'vendor' item equals to actual slave device type, set 'vendor_id' to vendor ID.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   519
            for vendor_id, vendor in self.Controler.CTNParent.CTNParent.ModulesLibrary.Library.iteritems():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   520
                for available_device in vendor["groups"][vendor["groups"].keys()[0]]["devices"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   521
                    if available_device[0] == type_infos["device_type"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   522
                        smartview_infos["vendor_id"] = "0x" + "{:0>8x}".format(vendor_id)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   523
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   524
            #  product code;
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   525
            if device.getType().getProductCode() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   526
                product_code = device.getType().getProductCode()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   527
                smartview_infos["product_code"] = "0x"+"{:0>8x}".format(ExtractHexDecValue(product_code))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   528
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   529
            #  revision number;
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   530
            if device.getType().getRevisionNo() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   531
                revision_no = device.getType().getRevisionNo()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   532
                smartview_infos["revision_no"] = "0x"+"{:0>8x}".format(ExtractHexDecValue(revision_no))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   533
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   534
            #  serial number;
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   535
            if device.getType().getSerialNo() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   536
                serial_no = device.getType().getSerialNo()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   537
                smartview_infos["serial_no"] = "0x"+"{:0>8x}".format(ExtractHexDecValue(serial_no))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   538
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   539
            return smartview_infos
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   540
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   541
        else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   542
            return None
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   543
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   544
    def DecimalToHex(self, decnum):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   545
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   546
        Convert decimal value into hexadecimal representation.
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   547
        @param decnum : decimal value
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   548
        @return hex_data : hexadecimal representation of input value in decimal
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   549
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   550
        value = "%x" % decnum
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   551
        value_len = len(value)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   552
        if (value_len % 2) == 0:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   553
            hex_len = value_len
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   554
        else:
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
   555
            hex_len = (value_len // 2) * 2 + 2
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   556
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   557
        hex_data = ("{:0>"+str(hex_len)+"x}").format(decnum)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   558
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   559
        return hex_data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   560
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   561
    def SiiRead(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   562
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   563
        Get slave EEPROM contents maintained by master device using "ethercat sii_read -p %d" command.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   564
        Command example : "ethercat sii_read -p 0"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   565
        @return return_val : result of "ethercat sii_read" (binary data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   566
        """
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   567
        _error, return_val = self.Controler.RemoteExec(SII_READ % (self.Controler.GetSlavePos()), return_val=None)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   568
        self.SiiData = return_val
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   569
        return return_val
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   570
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   571
    def SiiWrite(self, binary):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   572
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   573
        Overwrite slave EEPROM contents using "ethercat sii_write -p %d" command.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   574
        Command example : "ethercat sii_write -p 0 - (binary contents)"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   575
        @param binary : EEPROM contents in binary data format
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   576
        @return return_val : result of "ethercat sii_write" (If it succeeds, the return value is NULL.)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   577
        """
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   578
        _error, return_val = self.Controler.RemoteExec(
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   579
            SII_WRITE % (self.Controler.GetSlavePos()),
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   580
            return_val=None,
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   581
            sii_data=binary)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   582
        return return_val
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   583
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   584
    def LoadData(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   585
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   586
        Loading data from EEPROM use Sii_Read Method
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   587
        @return self.BinaryCode : slave EEPROM data in binary format (zero-padded)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   588
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   589
        return_val = self.Controler.CommonMethod.SiiRead()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   590
        self.BinaryCode = return_val
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   591
        self.Controler.SiiData = self.BinaryCode
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   592
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   593
        # append zero-filled padding data up to EEPROM size
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   594
        for dummy in range(self.SmartViewInfosFromXML["eeprom_size"] - len(self.BinaryCode)):
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2363
diff changeset
   595
            self.BinaryCode = self.BinaryCode + 'ff'.decode('hex')
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   596
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   597
        return self.BinaryCode
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   598
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   599
    def HexRead(self, binary):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   600
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   601
        Convert binary digit representation into hexadecimal representation for "Hex View" menu.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   602
        @param binary : binary digits
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   603
        @return hexCode : hexadecimal digits
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   604
        @return hexview_table_row, hexview_table_col : Grid size for "Hex View" UI
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   605
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   606
        row_code = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   607
        row_text = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   608
        row = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   609
        hex_code = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   610
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   611
        hexview_table_col = 17
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   612
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   613
        for index in range(0, len(binary)):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   614
            if len(binary[index]) != 1:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   615
                break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   616
            else:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   617
                digithexstr = hex(ord(binary[index]))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   618
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   619
                tempvar2 = digithexstr[2:4]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   620
                if len(tempvar2) == 1:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   621
                    tempvar2 = "0" + tempvar2
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   622
                row_code.append(tempvar2)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   623
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2363
diff changeset
   624
                if int(digithexstr, 16) >= 32 and int(digithexstr, 16) <= 126:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   625
                    row_text = row_text + chr(int(digithexstr, 16))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   626
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   627
                    row_text = row_text + "."
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   628
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   629
                if index != 0:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   630
                    if len(row_code) == (hexview_table_col - 1):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   631
                        row_code.append(row_text)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   632
                        hex_code.append(row_code)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   633
                        row_text = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   634
                        row_code = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   635
                        row = row + 1
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   636
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   637
        hexview_table_row = row
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   638
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   639
        return hex_code, hexview_table_row, hexview_table_col
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   640
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   641
    def GenerateEEPROMList(self, data, direction, length):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   642
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   643
        Generate EEPROM data list by reconstructing 'data' string.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   644
        example : data="12345678", direction=0, length=8 -> eeprom_list=['12', '34', '56', '78']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   645
                  data="12345678", direction=1, length=8 -> eeprom_list=['78', '56', '34', '12']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   646
        @param data : string to be reconstructed
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   647
        @param direction : endianness
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   648
        @param length : data length
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   649
        @return eeprom_list : reconstructed list data structure
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   650
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   651
        eeprom_list = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   652
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   653
        if direction is 0 or 1:
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
   654
            for dummy in range(length//2):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   655
                if data == "":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   656
                    eeprom_list.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   657
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   658
                    eeprom_list.append(data[direction*(length-2):direction*(length-2)+2])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   659
                data = data[(1-direction)*2:length-direction*2]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   660
                length -= 2
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   661
        return eeprom_list
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   662
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   663
    def XmlToEeprom(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   664
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   665
        Extract slave EEPROM contents using slave ESI XML file.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   666
          - Mandatory parts
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   667
          - String category : ExtractEEPROMStringCategory()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   668
          - General category : ExtractEEPROMGeneralCategory()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   669
          - FMMU category : ExtractEEPROMFMMUCategory
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   670
          - SyncM category : ExtractEEPROMSyncMCategory()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   671
          - Tx/RxPDO category : ExtractEEPROMPDOCategory()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   672
          - DC category : ExtractEEPROMDCCategory()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   673
        @return eeprom_binary
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   674
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   675
        eeprom = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   676
        data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   677
        eeprom_size = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   678
        eeprom_binary = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   679
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   680
        # 'device' is the slave device of the current EtherCAT slave plugin
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   681
        slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   682
        type_infos = slave.getType()
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   683
        device, _alignment = self.Controler.CTNParent.GetModuleInfos(type_infos)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   684
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   685
        if device is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   686
            # get ConfigData for EEPROM offset 0x0000-0x000d; <Device>-<Eeprom>-<ConfigData>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   687
            for eeprom_element in device.getEeprom().getcontent():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   688
                if eeprom_element["name"] == "ConfigData":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   689
                    data = self.DecimalToHex(eeprom_element)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   690
            eeprom += self.GenerateEEPROMList(data, 0, 28)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   691
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   692
            # calculate CRC for EEPROM offset 0x000e-0x000f
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   693
            crc = 0x48
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   694
            for segment in eeprom:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   695
                for i in range(8):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   696
                    bit = crc & 0x80
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   697
                    crc = (crc << 1) | ((int(segment, 16) >> (7 - i)) & 0x01)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   698
                    if bit:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   699
                        crc ^= 0x07
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   700
            for dummy in range(8):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   701
                bit = crc & 0x80
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   702
                crc <<= 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   703
                if bit:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   704
                    crc ^= 0x07
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   705
            eeprom.append(hex(crc)[len(hex(crc))-3:len(hex(crc))-1])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   706
            eeprom.append("00")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   707
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   708
            # get VendorID for EEPROM offset 0x0010-0x0013;
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   709
            data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   710
            for vendor_id, vendor in self.Controler.CTNParent.CTNParent.ModulesLibrary.Library.iteritems():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   711
                for available_device in vendor["groups"][vendor["groups"].keys()[0]]["devices"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   712
                    if available_device[0] == type_infos["device_type"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   713
                        data = "{:0>8x}".format(vendor_id)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   714
            eeprom += self.GenerateEEPROMList(data, 1, 8)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   715
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   716
            # get Product Code for EEPROM offset 0x0014-0x0017;
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   717
            data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   718
            if device.getType().getProductCode() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   719
                data = "{:0>8x}".format(ExtractHexDecValue(device.getType().getProductCode()))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   720
            eeprom += self.GenerateEEPROMList(data, 1, 8)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   721
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   722
            # get Revision Number for EEPROM offset 0x0018-0x001b;
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   723
            data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   724
            if device.getType().getRevisionNo() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   725
                data = "{:0>8x}".format(ExtractHexDecValue(device.getType().getRevisionNo()))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   726
            eeprom += self.GenerateEEPROMList(data, 1, 8)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   727
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   728
            # get Serial Number for EEPROM 0x001c-0x001f;
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   729
            data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   730
            if device.getType().getSerialNo() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   731
                data = "{:0>8x}".format(ExtractHexDecValue(device.getType().getSerialNo()))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   732
            eeprom += self.GenerateEEPROMList(data, 1, 8)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   733
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   734
            # get Execution Delay for EEPROM 0x0020-0x0021; not analyzed yet
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   735
            eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   736
            eeprom.append("00")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   737
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   738
            # get Port0/1 Delay for EEPROM offset 0x0022-0x0025; not analyzed yet
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   739
            eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   740
            eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   741
            eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   742
            eeprom.append("00")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   743
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   744
            # reserved for EEPROM offset 0x0026-0x0027;
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   745
            eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   746
            eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   747
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   748
            # get BootStrap for EEPROM offset 0x0028-0x002e; <Device>-<Eeprom>-<BootStrap>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   749
            data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   750
            for eeprom_element in device.getEeprom().getcontent():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   751
                if eeprom_element["name"] == "BootStrap":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   752
                    data = "{:0>16x}".format(eeprom_element)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   753
            eeprom += self.GenerateEEPROMList(data, 0, 16)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   754
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   755
            # get Standard Mailbox for EEPROM offset 0x0030-0x0037; <Device>-<sm>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   756
            data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   757
            standard_send_mailbox_offset = None
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   758
            standard_send_mailbox_size = None
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   759
            standard_receive_mailbox_offset = None
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   760
            standard_receive_mailbox_size = None
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   761
            for sm_element in device.getSm():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   762
                if sm_element.getcontent() == "MBoxOut":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   763
                    standard_receive_mailbox_offset = "{:0>4x}".format(ExtractHexDecValue(sm_element.getStartAddress()))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   764
                    standard_receive_mailbox_size = "{:0>4x}".format(ExtractHexDecValue(sm_element.getDefaultSize()))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   765
                elif sm_element.getcontent() == "MBoxIn":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   766
                    standard_send_mailbox_offset = "{:0>4x}".format(ExtractHexDecValue(sm_element.getStartAddress()))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   767
                    standard_send_mailbox_size = "{:0>4x}".format(ExtractHexDecValue(sm_element.getDefaultSize()))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   768
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   769
            if standard_receive_mailbox_offset is None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   770
                eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   771
                eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   772
            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   773
                eeprom.append(standard_receive_mailbox_offset[2:4])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   774
                eeprom.append(standard_receive_mailbox_offset[0:2])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   775
            if standard_receive_mailbox_size is None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   776
                eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   777
                eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   778
            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   779
                eeprom.append(standard_receive_mailbox_size[2:4])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   780
                eeprom.append(standard_receive_mailbox_size[0:2])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   781
            if standard_send_mailbox_offset is None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   782
                eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   783
                eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   784
            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   785
                eeprom.append(standard_send_mailbox_offset[2:4])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   786
                eeprom.append(standard_send_mailbox_offset[0:2])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   787
            if standard_send_mailbox_size is None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   788
                eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   789
                eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   790
            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   791
                eeprom.append(standard_send_mailbox_size[2:4])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   792
                eeprom.append(standard_send_mailbox_size[0:2])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   793
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   794
            # get supported mailbox protocols for EEPROM offset 0x0038-0x0039;
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   795
            data = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   796
            mb = device.getMailbox()
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   797
            if mb is not None:
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   798
                for bit, mbprot in enumerate(mailbox_protocols):
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   799
                    if getattr(mb, "get%s" % mbprot)() is not None:
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
   800
                        data += 1 << bit
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   801
            data = "{:0>4x}".format(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   802
            eeprom.append(data[2:4])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   803
            eeprom.append(data[0:2])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   804
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   805
            # resereved for EEPROM offset 0x003a-0x007b;
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   806
            for i in range(0x007b-0x003a+0x0001):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   807
                eeprom.append("00")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   808
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   809
            # get EEPROM size for EEPROM offset 0x007c-0x007d;
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   810
            data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   811
            for eeprom_element in device.getEeprom().getcontent():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   812
                if eeprom_element["name"] == "ByteSize":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   813
                    eeprom_size = int(str(eeprom_element))
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
   814
                    data = "{:0>4x}".format(int(eeprom_element)//1024*8-1)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   815
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   816
            if data == "":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   817
                eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   818
                eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   819
            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   820
                eeprom.append(data[2:4])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   821
                eeprom.append(data[0:2])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   822
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   823
            # Version for EEPROM 0x007e-0x007f;
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   824
            #  According to "EtherCAT Slave Device Description(V0.3.0)"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   825
            eeprom.append("01")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   826
            eeprom.append("00")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   827
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   828
            # append String Category data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   829
            for data in self.ExtractEEPROMStringCategory(device):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   830
                eeprom.append(data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   831
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   832
            # append General Category data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   833
            for data in self.ExtractEEPROMGeneralCategory(device):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   834
                eeprom.append(data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   835
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   836
            # append FMMU Category data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   837
            for data in self.ExtractEEPROMFMMUCategory(device):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   838
                eeprom.append(data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   839
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   840
            # append SyncM Category data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   841
            for data in self.ExtractEEPROMSyncMCategory(device):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   842
                eeprom.append(data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   843
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   844
            # append TxPDO Category data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   845
            for data in self.ExtractEEPROMPDOCategory(device, "TxPdo"):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   846
                eeprom.append(data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   847
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   848
            # append RxPDO Category data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   849
            for data in self.ExtractEEPROMPDOCategory(device, "RxPdo"):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   850
                eeprom.append(data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   851
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   852
            # append DC Category data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   853
            for data in self.ExtractEEPROMDCCategory(device):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   854
                eeprom.append(data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   855
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   856
            # append padding
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   857
            padding = eeprom_size-len(eeprom)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   858
            for i in range(padding):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   859
                eeprom.append("ff")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   860
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   861
            # convert binary code
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   862
            for index in range(eeprom_size):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   863
                eeprom_binary = eeprom_binary + eeprom[index].decode('hex')
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   864
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   865
            return eeprom_binary
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   866
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   867
    def ExtractEEPROMStringCategory(self, device):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   868
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   869
        Extract "Strings" category data from slave ESI XML and generate EEPROM image data.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   870
        @param device : 'device' object in the slave ESI XML
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   871
        @return eeprom : "Strings" category EEPROM image data
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   872
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   873
        eeprom = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   874
        self.Strings = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   875
        data = ""
2361
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   876
        count = 0        # string counter
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
   877
        padflag = False  # padding flag if category length is odd
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   878
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   879
        # index information for General Category in EEPROM
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   880
        self.GroupIdx = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   881
        self.ImgIdx = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   882
        self.OrderIdx = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   883
        self.NameIdx = 0
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   884
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   885
        # flag for preventing duplicated vendor specific data
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   886
        typeflag = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   887
        grouptypeflag = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   888
        groupnameflag = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   889
        devnameflag = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   890
        imageflag = False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   891
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   892
        # vendor specific data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   893
        #   element1; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Type>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   894
        #   vendor_specific_data : vendor specific data (binary type)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   895
        vendor_specific_data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   896
        #   vendor_spec_strings : list of vendor specific "strings" for preventing duplicated strings
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   897
        vendor_spec_strings = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   898
        for element in device.getType().getcontent():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   899
            data += element
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2423
diff changeset
   900
        if data != "" and isinstance(data, text):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   901
            for vendor_spec_string in vendor_spec_strings:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   902
                if data == vendor_spec_string:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   903
                    self.OrderIdx = vendor_spec_strings.index(data)+1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   904
                    typeflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   905
                    break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   906
            if typeflag is False:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   907
                count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   908
                self.Strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   909
                vendor_spec_strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   910
                typeflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   911
                self.OrderIdx = count
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   912
                vendor_specific_data += "{:0>2x}".format(len(data))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   913
                for character in range(len(data)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   914
                    vendor_specific_data += "{:0>2x}".format(ord(data[character]))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   915
        data = ""
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   916
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   917
        #  element2-1; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<GroupType>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   918
        data = device.getGroupType()
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2423
diff changeset
   919
        if data is not None and isinstance(data, text):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   920
            for vendor_spec_string in vendor_spec_strings:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   921
                if data == vendor_spec_string:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   922
                    self.GroupIdx = vendor_spec_strings.index(data)+1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   923
                    grouptypeflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   924
                    break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   925
            if grouptypeflag is False:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   926
                count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   927
                self.Strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   928
                vendor_spec_strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   929
                grouptypeflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   930
                self.GroupIdx = count
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   931
                vendor_specific_data += "{:0>2x}".format(len(data))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   932
                for character in range(len(data)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   933
                    vendor_specific_data += "{:0>2x}".format(ord(data[character]))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   934
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   935
        #  element2-2; <EtherCATInfo>-<Groups>-<Group>-<Type>
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   936
        if grouptypeflag is False:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   937
            if self.Controler.CTNParent.CTNParent.ModulesLibrary.Library is not None:
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   938
                for _vendor_id, vendor in self.Controler.CTNParent.CTNParent.ModulesLibrary.Library.iteritems():
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   939
                    for group_type, group_etc in vendor["groups"].iteritems():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   940
                        for device_item in group_etc["devices"]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   941
                            if device == device_item[1]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   942
                                data = group_type
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2423
diff changeset
   943
                if data is not None and isinstance(data, text):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   944
                    for vendor_spec_string in vendor_spec_strings:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   945
                        if data == vendor_spec_string:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   946
                            self.GroupIdx = vendor_spec_strings.index(data)+1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   947
                            grouptypeflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   948
                            break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   949
                    if grouptypeflag is False:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   950
                        count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   951
                        self.Strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   952
                        vendor_spec_strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   953
                        grouptypeflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   954
                        self.GroupIdx = count
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   955
                        vendor_specific_data += "{:0>2x}".format(len(data))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   956
                        for character in range(len(data)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   957
                            vendor_specific_data += "{:0>2x}".format(ord(data[character]))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   958
        data = ""
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   959
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   960
        #  element3; <EtherCATInfo>-<Descriptions>-<Groups>-<Group>-<Name(LcId is "1033")>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   961
        if self.Controler.CTNParent.CTNParent.ModulesLibrary.Library is not None:
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   962
            for _vendorId, vendor in self.Controler.CTNParent.CTNParent.ModulesLibrary.Library.iteritems():
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   963
                for group_type, group_etc in vendor["groups"].iteritems():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   964
                    for device_item in group_etc["devices"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   965
                        if device == device_item[1]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   966
                            data = group_etc["name"]
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2423
diff changeset
   967
        if data != "" and isinstance(data, text):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   968
            for vendor_spec_string in vendor_spec_strings:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   969
                if data == vendor_spec_string:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   970
                    groupnameflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   971
                    break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   972
            if groupnameflag is False:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   973
                count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   974
                self.Strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   975
                vendor_spec_strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   976
                groupnameflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   977
                vendor_specific_data += "{:0>2x}".format(len(data))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   978
                for character in range(len(data)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   979
                    vendor_specific_data += "{:0>2x}".format(ord(data[character]))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   980
        data = ""
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   981
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   982
        #  element4; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Name(LcId is "1033" or "1"?)>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   983
        for element in device.getName():
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2363
diff changeset
   984
            if element.getLcId() == 1 or element.getLcId() == 1033:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   985
                data = element.getcontent()
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2423
diff changeset
   986
        if data != "" and isinstance(data, text):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   987
            for vendor_spec_string in vendor_spec_strings:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   988
                if data == vendor_spec_string:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   989
                    self.NameIdx = vendor_spec_strings.index(data)+1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   990
                    devnameflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   991
                    break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   992
            if devnameflag is False:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   993
                count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   994
                self.Strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   995
                vendor_spec_strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   996
                devnameflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   997
                self.NameIdx = count
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   998
                vendor_specific_data += "{:0>2x}".format(len(data))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   999
                for character in range(len(data)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1000
                    vendor_specific_data += "{:0>2x}".format(ord(data[character]))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1001
        data = ""
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1002
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1003
        #  element5-1; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Image16x14>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1004
        if device.getcontent() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1005
            data = device.getcontent()
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2423
diff changeset
  1006
            if data is not None and isinstance(data, text):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1007
                for vendor_spec_string in vendor_spec_strings:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1008
                    if data == vendor_spec_string:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1009
                        self.ImgIdx = vendor_spec_strings.index(data)+1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1010
                        imageflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1011
                        break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1012
                if imageflag is False:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1013
                    count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1014
                    self.Strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1015
                    vendor_spec_strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1016
                    imageflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1017
                    self.ImgIdx = count
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1018
                    vendor_specific_data += "{:0>2x}".format(len(data))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1019
                    for character in range(len(data)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1020
                        vendor_specific_data += "{:0>2x}".format(ord(data[character]))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1021
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1022
        #  element5-2; <EtherCATInfo>-<Descriptions>-<Groups>-<Group>-<Image16x14>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1023
        if imageflag is False:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1024
            if self.Controler.CTNParent.CTNParent.ModulesLibrary.Library is not None:
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1025
                for _vendor_id, vendor in self.Controler.CTNParent.CTNParent.ModulesLibrary.Library.iteritems():
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1026
                    for group_type, group_etc in vendor["groups"].iteritems():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1027
                        for device_item in group_etc["devices"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1028
                            if device == device_item[1]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1029
                                data = group_etc
2434
07f48018b6f5 python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2423
diff changeset
  1030
                if data is not None and isinstance(data, text):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1031
                    for vendor_spec_string in vendor_spec_strings:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1032
                        if data == vendor_spec_string:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1033
                            self.ImgIdx = vendor_spec_strings.index(data)+1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1034
                            imageflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1035
                            break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1036
                    if imageflag is False:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1037
                        count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1038
                        self.Strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1039
                        vendor_spec_strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1040
                        imageflag = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1041
                        self.ImgIdx = count
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1042
                        vendor_specific_data += "{:0>2x}".format(len(data))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1043
                        for character in range(len(data)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1044
                            vendor_specific_data += "{:0>2x}".format(ord(data[character]))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1045
        data = ""
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1046
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1047
        # DC related elements
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1048
        #  <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Dc>-<OpMode>-<Name>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1049
        dc_related_elements = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1050
        if device.getDc() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1051
            for element in device.getDc().getOpMode():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1052
                data = element.getName()
2417
316ee9fff395 cleanup: pylint, R0123 # (literal-comparison) Comparison to literal
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2410
diff changeset
  1053
                if data != "":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1054
                    count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1055
                    self.Strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1056
                    dc_related_elements += "{:0>2x}".format(len(data))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1057
                    for character in range(len(data)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1058
                        dc_related_elements += "{:0>2x}".format(ord(data[character]))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1059
                    data = ""
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1060
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1061
        # Input elements(TxPDO)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1062
        #  <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<TxPdo>; Name
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1063
        input_elements = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1064
        inputs = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1065
        for element in device.getTxPdo():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1066
            for name in element.getName():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1067
                data = name.getcontent()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1068
            for input in inputs:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1069
                if data == input:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1070
                    data = ""
2417
316ee9fff395 cleanup: pylint, R0123 # (literal-comparison) Comparison to literal
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2410
diff changeset
  1071
            if data != "":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1072
                count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1073
                self.Strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1074
                inputs.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1075
                input_elements += "{:0>2x}".format(len(data))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1076
                for character in range(len(data)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1077
                    input_elements += "{:0>2x}".format(ord(data[character]))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1078
                data = ""
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1079
            for entry in element.getEntry():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1080
                for name in entry.getName():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1081
                    data = name.getcontent()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1082
                for input in inputs:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1083
                    if data == input:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1084
                        data = ""
2417
316ee9fff395 cleanup: pylint, R0123 # (literal-comparison) Comparison to literal
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2410
diff changeset
  1085
                if data != "":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1086
                    count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1087
                    self.Strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1088
                    inputs.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1089
                    input_elements += "{:0>2x}".format(len(data))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1090
                    for character in range(len(data)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1091
                        input_elements += "{:0>2x}".format(ord(data[character]))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1092
                    data = ""
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1093
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1094
        # Output elements(RxPDO)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1095
        #  <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<RxPdo>; Name
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1096
        output_elements = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1097
        outputs = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1098
        for element in device.getRxPdo():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1099
            for name in element.getName():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1100
                data = name.getcontent()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1101
            for output in outputs:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1102
                if data == output:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1103
                    data = ""
2417
316ee9fff395 cleanup: pylint, R0123 # (literal-comparison) Comparison to literal
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2410
diff changeset
  1104
            if data != "":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1105
                count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1106
                self.Strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1107
                outputs.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1108
                output_elements += "{:0>2x}".format(len(data))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1109
                for character in range(len(data)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1110
                    output_elements += "{:0>2x}".format(ord(data[character]))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1111
                data = ""
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1112
            for entry in element.getEntry():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1113
                for name in entry.getName():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1114
                    data = name.getcontent()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1115
                for output in outputs:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1116
                    if data == output:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1117
                        data = ""
2417
316ee9fff395 cleanup: pylint, R0123 # (literal-comparison) Comparison to literal
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2410
diff changeset
  1118
                if data != "":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1119
                    count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1120
                    self.Strings.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1121
                    outputs.append(data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1122
                    output_elements += "{:0>2x}".format(len(data))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1123
                    for character in range(len(data)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1124
                        output_elements += "{:0>2x}".format(ord(data[character]))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1125
                    data = ""
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1126
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1127
        # form eeprom data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1128
        #  category header
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1129
        eeprom.append("0a")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1130
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1131
        #  category length (word); 1 word is 4 bytes. "+2" is the length of string's total number
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1132
        length = len(vendor_specific_data + dc_related_elements + input_elements + output_elements) + 2
2358
8e5a9830867e cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
  1133
        if length % 4 == 0:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1134
            pass
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1135
        else:
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2363
diff changeset
  1136
            length += length % 4
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1137
            padflag = True
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1138
        eeprom.append("{:0>4x}".format(length//4)[2:4])
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1139
        eeprom.append("{:0>4x}".format(length//4)[0:2])
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1140
        #  total numbers of strings
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1141
        eeprom.append("{:0>2x}".format(count))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1142
        for element in [vendor_specific_data,
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1143
                        dc_related_elements,
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1144
                        input_elements,
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1145
                        output_elements]:
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1146
            for dummy in range(len(element)//2):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1147
                if element == "":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1148
                    eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1149
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1150
                    eeprom.append(element[0:2])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1151
                element = element[2:len(element)]
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1152
        # padding if length is odd bytes
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1153
        if padflag is True:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1154
            eeprom.append("ff")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1155
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1156
        return eeprom
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1157
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1158
    def ExtractEEPROMGeneralCategory(self, device):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1159
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1160
        Extract "General" category data from slave ESI XML and generate EEPROM image data.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1161
        @param device : 'device' object in the slave ESI XML
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1162
        @return eeprom : "Strings" category EEPROM image data
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1163
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1164
        eeprom = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1165
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1166
        # category header
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1167
        eeprom.append("1e")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1168
        eeprom.append("00")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1169
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1170
        # category length
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1171
        eeprom.append("10")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1172
        eeprom.append("00")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1173
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1174
        # word 1 : Group Type index and Image index in STRINGS Category
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1175
        eeprom.append("{:0>2x}".format(self.GroupIdx))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1176
        eeprom.append("{:0>2x}".format(self.ImgIdx))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1177
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1178
        # word 2 : Device Type index and Device Name index in STRINGS Category
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1179
        eeprom.append("{:0>2x}".format(self.OrderIdx))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1180
        eeprom.append("{:0>2x}".format(self.NameIdx))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1181
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1182
        # word 3 : Physical Layer Port info. and CoE Details
2361
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
  1183
        eeprom.append("01")  # Physical Layer Port info - assume 01
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1184
        #  CoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<CoE>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1185
        coe_details = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1186
        mb = device.getMailbox()
2361
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
  1187
        coe_details = 1  # sdo enabled
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1188
        if mb is not None:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1189
            coe = mb.getCoE()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1190
            if coe is not None:
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1191
                for bit, flag in enumerate(["SdoInfo", "PdoAssign", "PdoConfig",
2407
5f2b1bb464a0 clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2406
diff changeset
  1192
                                            "PdoUpload", "CompleteAccess"]):
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1193
                    if getattr(coe, "get%s" % flag)() is not None:
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
  1194
                        coe_details += 1 << bit
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1195
        eeprom.append("{:0>2x}".format(coe_details))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1196
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1197
        # word 4 : FoE Details and EoE Details
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1198
        #  FoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<FoE>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1199
        if mb is not None and mb.getFoE() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1200
            eeprom.append("01")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1201
        else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1202
            eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1203
        #  EoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<EoE>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1204
        if mb is not None and mb.getEoE() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1205
            eeprom.append("01")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1206
        else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1207
            eeprom.append("00")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1208
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1209
        # word 5 : SoE Channels(reserved) and DS402 Channels
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1210
        #  SoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<SoE>
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1211
        if mb is not None and mb.getSoE() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1212
            eeprom.append("01")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1213
        else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1214
            eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1215
        #  DS402Channels; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<CoE>: DS402Channels
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1216
        ds402ch = False
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1217
        if mb is not None:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1218
            coe = mb.getCoE()
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1219
            if coe is not None:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1220
                ds402ch = coe.getDS402Channels()
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1221
        eeprom.append("01" if ds402ch in [True, 1] else "00")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1222
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1223
        # word 6 : SysmanClass(reserved) and Flags
2361
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
  1224
        eeprom.append("00")  # reserved
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1225
        #  Flags
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1226
        en_safeop = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1227
        en_lrw = False
2374
aed3ca79a10a clean etherlab: pep8, E712 comparison to True should be 'if cond is True:' or 'if cond:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2373
diff changeset
  1228
        if device.getType().getTcCfgModeSafeOp() is True \
2384
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2383
diff changeset
  1229
           or device.getType().getTcCfgModeSafeOp() == 1:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1230
            en_safeop = True
2374
aed3ca79a10a clean etherlab: pep8, E712 comparison to True should be 'if cond is True:' or 'if cond:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2373
diff changeset
  1231
        if device.getType().getUseLrdLwr() is True \
2384
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2383
diff changeset
  1232
           or device.getType().getUseLrdLwr() == 1:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1233
            en_lrw = True
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1234
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1235
        flags = "0b"+"000000"+str(int(en_lrw))+str(int(en_safeop))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1236
        eeprom.append("{:0>2x}".format(int(flags, 2)))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1237
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1238
        # word 7 : Current On EBus (assume 0x0000)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1239
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1240
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1241
        # after word 7; couldn't analyze yet
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1242
        eeprom.append("03")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1243
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1244
        eeprom.append("11")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1245
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1246
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1247
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1248
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1249
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1250
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1251
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1252
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1253
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1254
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1255
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1256
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1257
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1258
        eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1259
        eeprom.append("00")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1260
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1261
        return eeprom
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1262
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1263
    def ExtractEEPROMFMMUCategory(self, device):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1264
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1265
        Extract "FMMU" category data from slave ESI XML and generate EEPROM image data.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1266
        @param device : 'device' object in the slave ESI XML
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1267
        @return eeprom : "Strings" category EEPROM image data
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1268
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1269
        eeprom = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1270
        data = ""
2361
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
  1271
        count = 0  # number of FMMU
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1272
        padflag = False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1273
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1274
        for fmmu in device.getFmmu():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1275
            count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1276
            if fmmu.getcontent() == "Outputs":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1277
                data += "01"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1278
            if fmmu.getcontent() == "Inputs":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1279
                data += "02"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1280
            if fmmu.getcontent() == "MBoxState":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1281
                data += "03"
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1282
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1283
        # construct of EEPROM data
2417
316ee9fff395 cleanup: pylint, R0123 # (literal-comparison) Comparison to literal
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2410
diff changeset
  1284
        if data != "":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1285
            #  category header
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1286
            eeprom.append("28")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1287
            eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1288
            #  category length
2358
8e5a9830867e cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
  1289
            if count % 2 == 1:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1290
                padflag = True
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1291
                eeprom.append("{:0>4x}".format((count+1)//2)[2:4])
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1292
                eeprom.append("{:0>4x}".format((count+1)//2)[0:2])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1293
            else:
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1294
                eeprom.append("{:0>4x}".format((count)//2)[2:4])
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1295
                eeprom.append("{:0>4x}".format((count)//2)[0:2])
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1296
            for dummy in range(count):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1297
                if data == "":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1298
                    eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1299
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1300
                    eeprom.append(data[0:2])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1301
                data = data[2:len(data)]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1302
            #  padding if length is odd bytes
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1303
            if padflag is True:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1304
                eeprom.append("ff")
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1305
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1306
        return eeprom
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1307
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1308
    def ExtractEEPROMSyncMCategory(self, device):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1309
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1310
        Extract "SyncM" category data from slave ESI XML and generate EEPROM image data.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1311
        @param device : 'device' object in the slave ESI XML
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1312
        @return eeprom : "Strings" category EEPROM image data
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1313
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1314
        eeprom = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1315
        data = ""
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1316
        number = {"MBoxOut": "01", "MBoxIn": "02", "Outputs": "03", "Inputs": "04"}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1317
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1318
        for sm in device.getSm():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1319
            for attr in [sm.getStartAddress(),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1320
                         sm.getDefaultSize(),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1321
                         sm.getControlByte()]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1322
                if attr is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1323
                    data += "{:0>4x}".format(ExtractHexDecValue(attr))[2:4]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1324
                    data += "{:0>4x}".format(ExtractHexDecValue(attr))[0:2]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1325
                else:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1326
                    data += "0000"
2374
aed3ca79a10a clean etherlab: pep8, E712 comparison to True should be 'if cond is True:' or 'if cond:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2373
diff changeset
  1327
            if sm.getEnable() == "1" or sm.getEnable() is True:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1328
                data += "01"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1329
            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1330
                data += "00"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1331
            data += number[sm.getcontent()]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1332
2417
316ee9fff395 cleanup: pylint, R0123 # (literal-comparison) Comparison to literal
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2410
diff changeset
  1333
        if data != "":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1334
            #  category header
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1335
            eeprom.append("29")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1336
            eeprom.append("00")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1337
            #  category length
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1338
            eeprom.append("{:0>4x}".format(len(data)//4)[2:4])
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1339
            eeprom.append("{:0>4x}".format(len(data)//4)[0:2])
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1340
            for dummy in range(len(data)//2):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1341
                if data == "":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1342
                    eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1343
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1344
                    eeprom.append(data[0:2])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1345
                data = data[2:len(data)]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1346
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1347
        return eeprom
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1348
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1349
    def ExtractEEPROMPDOCategory(self, device, pdotype):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1350
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1351
        Extract ""PDO (Tx, Rx)"" category data from slave ESI XML and generate EEPROM image data.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1352
        @param device : 'device' object in the slave ESI XML
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1353
        @param pdotype : identifier whether "TxPDO" or "RxPDO".
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1354
        @return eeprom : "Strings" category EEPROM image data
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1355
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1356
        eeprom = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1357
        data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1358
        count = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1359
        en_fixed = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1360
        en_mandatory = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1361
        en_virtual = False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1362
2358
8e5a9830867e cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
  1363
        for element in eval("device.get%s()" % pdotype):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1364
            #  PDO Index
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1365
            data += "{:0>4x}".format(ExtractHexDecValue(element.getIndex().getcontent()))[2:4]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1366
            data += "{:0>4x}".format(ExtractHexDecValue(element.getIndex().getcontent()))[0:2]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1367
            #  Number of Entries
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1368
            data += "{:0>2x}".format(len(element.getEntry()))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1369
            #  About Sync Manager
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1370
            if element.getSm() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1371
                data += "{:0>2x}".format(element.getSm())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1372
            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1373
                data += "ff"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1374
            #  Reference to DC Synch (according to ET1100 documentation) - assume 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1375
            data += "00"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1376
            #  Name Index
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1377
            objname = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1378
            for name in element.getName():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1379
                objname = name.getcontent()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1380
            for name in self.Strings:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1381
                count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1382
                if objname == name:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1383
                    break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1384
            if len(self.Strings)+1 == count:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1385
                data += "00"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1386
            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1387
                data += "{:0>2x}".format(count)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1388
            count = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1389
            #  Flags; by Fixed, Mandatory, Virtual attributes ?
2374
aed3ca79a10a clean etherlab: pep8, E712 comparison to True should be 'if cond is True:' or 'if cond:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2373
diff changeset
  1390
            if element.getFixed() is True or 1:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1391
                en_fixed = True
2374
aed3ca79a10a clean etherlab: pep8, E712 comparison to True should be 'if cond is True:' or 'if cond:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2373
diff changeset
  1392
            if element.getMandatory() is True or 1:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1393
                en_mandatory = True
2374
aed3ca79a10a clean etherlab: pep8, E712 comparison to True should be 'if cond is True:' or 'if cond:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2373
diff changeset
  1394
            if element.getVirtual() is True or element.getVirtual():
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1395
                en_virtual = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1396
            data += str(int(en_fixed)) + str(int(en_mandatory)) + str(int(en_virtual)) + "0"
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1397
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1398
            for entry in element.getEntry():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1399
                #   Entry Index
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1400
                data += "{:0>4x}".format(ExtractHexDecValue(entry.getIndex().getcontent()))[2:4]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1401
                data += "{:0>4x}".format(ExtractHexDecValue(entry.getIndex().getcontent()))[0:2]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1402
                #   Subindex
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1403
                data += "{:0>2x}".format(int(entry.getSubIndex()))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1404
                #   Entry Name Index
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1405
                objname = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1406
                for name in entry.getName():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1407
                    objname = name.getcontent()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1408
                for name in self.Strings:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1409
                    count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1410
                    if objname == name:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1411
                        break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1412
                if len(self.Strings)+1 == count:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1413
                    data += "00"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1414
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1415
                    data += "{:0>2x}".format(count)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1416
                count = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1417
                #   DataType
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1418
                if entry.getDataType() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1419
                    if entry.getDataType().getcontent() in self.BaseDataTypeDict:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1420
                        data += self.BaseDataTypeDict[entry.getDataType().getcontent()]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1421
                    else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1422
                        data += "00"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1423
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1424
                    data += "00"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1425
                #   BitLen
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1426
                if entry.getBitLen() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1427
                    data += "{:0>2x}".format(int(entry.getBitLen()))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1428
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1429
                    data += "00"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1430
                #   Flags; by Fixed attributes ?
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1431
                en_fixed = False
2374
aed3ca79a10a clean etherlab: pep8, E712 comparison to True should be 'if cond is True:' or 'if cond:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2373
diff changeset
  1432
                if entry.getFixed() is True or entry.getFixed() == 1:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1433
                    en_fixed = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1434
                data += str(int(en_fixed)) + "000"
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1435
2417
316ee9fff395 cleanup: pylint, R0123 # (literal-comparison) Comparison to literal
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2410
diff changeset
  1436
        if data != "":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1437
            #  category header
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1438
            if pdotype == "TxPdo":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1439
                eeprom.append("32")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1440
            elif pdotype == "RxPdo":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1441
                eeprom.append("33")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1442
            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1443
                eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1444
            eeprom.append("00")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1445
            #  category length
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1446
            eeprom.append("{:0>4x}".format(len(data)//4)[2:4])
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1447
            eeprom.append("{:0>4x}".format(len(data)//4)[0:2])
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1448
            data = str(data.lower())
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1449
            for dummy in range(len(data)//2):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1450
                if data == "":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1451
                    eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1452
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1453
                    eeprom.append(data[0:2])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1454
                data = data[2:len(data)]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1455
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1456
        return eeprom
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1457
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1458
    def ExtractEEPROMDCCategory(self, device):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1459
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1460
        Extract "DC(Distributed Clock)" category data from slave ESI XML and generate EEPROM image data.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1461
        @param device : 'device' object in the slave ESI XML
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1462
        @return eeprom : "Strings" category EEPROM image data
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1463
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1464
        eeprom = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1465
        data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1466
        count = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1467
        namecount = 0
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1468
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1469
        if device.getDc() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1470
            for element in device.getDc().getOpMode():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1471
                count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1472
                #  assume that word 1-7 are 0x0000
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1473
                data += "0000"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1474
                data += "0000"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1475
                data += "0000"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1476
                data += "0000"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1477
                data += "0000"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1478
                data += "0000"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1479
                data += "0000"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1480
                #  word 8-10
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1481
                #  AssignActivate
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1482
                if element.getAssignActivate() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1483
                    data += "{:0>4x}".format(ExtractHexDecValue(element.getAssignActivate()))[2:4]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1484
                    data += "{:0>4x}".format(ExtractHexDecValue(element.getAssignActivate()))[0:2]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1485
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1486
                    data += "0000"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1487
                #  Factor of CycleTimeSync0 ? and default is 1?
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1488
                if element.getCycleTimeSync0() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1489
                    if element.getCycleTimeSync0().getFactor() is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1490
                        data += "{:0>2x}".format(int(element.getCycleTimeSync0().getFactor()))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1491
                        data += "00"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1492
                    else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1493
                        data += "0100"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1494
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1495
                    data += "0100"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1496
                #  Index of Name in STRINGS Category
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1497
                #  Name Index
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1498
                objname = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1499
                for name in element.getName():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1500
                    objname += name
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1501
                for name in self.Strings:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1502
                    namecount += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1503
                    if objname == name:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1504
                        break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1505
                if len(self.Strings)+1 == namecount:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1506
                    data += "00"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1507
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1508
                    data += "{:0>2x}".format(namecount)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1509
                namecount = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1510
                data += "00"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1511
                #  assume that word 11-12 are 0x0000
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1512
                data += "0000"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1513
                data += "0000"
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1514
2417
316ee9fff395 cleanup: pylint, R0123 # (literal-comparison) Comparison to literal
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2410
diff changeset
  1515
        if data != "":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1516
            #  category header
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1517
            eeprom.append("3c")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1518
            eeprom.append("00")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1519
            #  category length
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1520
            eeprom.append("{:0>4x}".format(len(data)//4)[2:4])
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1521
            eeprom.append("{:0>4x}".format(len(data)//4)[0:2])
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1522
            data = str(data.lower())
2437
105c20fdeb19 python3 support: pylint, W1619 #(old-division) division w/o __future__ statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2434
diff changeset
  1523
            for dummy in range(len(data)//2):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1524
                if data == "":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1525
                    eeprom.append("00")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1526
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1527
                    eeprom.append(data[0:2])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1528
                data = data[2:len(data)]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1529
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1530
        return eeprom
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1531
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1532
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1533
    #                        Used Register Access
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1534
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1535
    def RegRead(self, offset, length):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1536
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1537
        Read slave ESC register content using "ethercat reg_read -p %d %s %s" command.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1538
        Command example : "ethercat reg_read -p 0 0x0c00 0x0400"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1539
        @param offset : register address
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1540
        @param length : register length
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1541
        @return return_val : register data
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1542
        """
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1543
        _error, return_val = self.Controler.RemoteExec(
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1544
            REG_READ % (self.Controler.GetSlavePos(), offset, length),
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1545
            return_val=None)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1546
        return return_val
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1547
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1548
    def RegWrite(self, address, data):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1549
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1550
        Write data to slave ESC register using "ethercat reg_write -p %d %s %s" command.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1551
        Command example : "ethercat reg_write -p 0 0x0c04 0x0001"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1552
        @param address : register address
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1553
        @param data : data to write
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1554
        @return return_val : the execution result of "ethercat reg_write" (for error check)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1555
        """
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1556
        _error, return_val = self.Controler.RemoteExec(
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1557
            REG_WRITE % (self.Controler.GetSlavePos(), address, data),
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1558
            return_val=None)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1559
        return return_val
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1560
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1561
    def Rescan(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1562
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1563
        Synchronize EEPROM data in master controller with the data in slave device after EEPROM write.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1564
        Command example : "ethercat rescan -p 0"
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1565
        """
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1566
        _error, _return_val = self.Controler.RemoteExec(RESCAN % (self.Controler.GetSlavePos()), return_val=None)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1567
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1568
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1569
    #                        Common Use Methods
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1570
    # -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1571
    def CheckConnect(self, cyclic_flag):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1572
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1573
        Check connection status (1) between Beremiz and the master (2) between the master and the slave.
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1574
        @param cyclic_flag: 0 - one shot, 1 - periodic
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1575
        @return True or False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1576
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1577
        if self.Controler.GetCTRoot()._connector is not None:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1578
            # Check connection between the master and the slave.
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1579
            # Command example : "ethercat xml -p 0"
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1580
            _error, return_val = self.Controler.RemoteExec(SLAVE_XML % (self.Controler.GetSlavePos()), return_val=None)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1581
            number_of_lines = return_val.split("\n")
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1582
            if len(number_of_lines) <= 2:  # No slave connected to the master controller
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1583
                if not cyclic_flag:
2423
2c7b7ae24d57 Improve localization support in etherlab (mostly)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2421
diff changeset
  1584
                    self.CreateErrorDialog(_('No connected slaves'))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1585
                return False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1586
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1587
            elif len(number_of_lines) > 2:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1588
                return True
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1589
        else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1590
            # The master controller is not connected to Beremiz host
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1591
            if not cyclic_flag:
2423
2c7b7ae24d57 Improve localization support in etherlab (mostly)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2421
diff changeset
  1592
                self.CreateErrorDialog(_('PLC not connected!'))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1593
            return False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1594
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1595
    def CreateErrorDialog(self, mention):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1596
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1597
        Create a dialog to indicate error or warning.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1598
        @param mention : Error String
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1599
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1600
        app_frame = self.Controler.GetCTRoot().AppFrame
2382
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
  1601
        dlg = wx.MessageDialog(app_frame, mention,
2423
2c7b7ae24d57 Improve localization support in etherlab (mostly)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2421
diff changeset
  1602
                               _(' Warning...'),
2382
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2378
diff changeset
  1603
                               wx.OK | wx.ICON_INFORMATION)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1604
        dlg.ShowModal()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1605
        dlg.Destroy()