etherlab/EtherCATManagementEditor.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Sat, 29 Sep 2018 18:59:41 +0300
changeset 2406 ffd091b51cd0
parent 2405 af050469fc5c
child 2407 5f2b1bb464a0
permissions -rw-r--r--
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
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
# 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
     5
#
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     6
# Copyright (C) 2013: Real-Time & Embedded Systems (RTES) Lab., University of Seoul
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     7
#
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
     8
# 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
     9
2405
af050469fc5c clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2390
diff changeset
    10
from __future__ import absolute_import
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    11
import os
2390
81116c5db60f clean etherlab: pylint, C0411 # (wrong-import-order) standard import "import x" comes before "import y"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2389
diff changeset
    12
import string
81116c5db60f clean etherlab: pylint, C0411 # (wrong-import-order) standard import "import x" comes before "import y"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2389
diff changeset
    13
from xml.dom import minidom
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    14
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    15
import wx
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    16
import wx.grid
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    17
import wx.gizmos
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    18
import wx.lib.buttons
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    19
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    20
# --------------------------------------------------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    21
from controls import CustomGrid, CustomTable
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    22
# --------------------------------------------------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    23
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    24
# ------------ for register management ---------------
2390
81116c5db60f clean etherlab: pylint, C0411 # (wrong-import-order) standard import "import x" comes before "import y"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2389
diff changeset
    25
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
    26
from util.TranslationCatalogs import NoTranslate
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    27
# -------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    28
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
    29
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    30
# ----------------------------- For Sync Manager Table -----------------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    31
def GetSyncManagersTableColnames():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    32
    """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    33
    Returns column names of SyncManager Table in Slave state panel.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    34
    """
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
    35
    _ = NoTranslate
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    36
    return ["#", _("Name"), _("Start Address"), _("Default Size"), _("Control Byte"), _("Enable")]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    37
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
    38
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    39
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    40
#                    Sync Managers Table
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    41
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    42
class SyncManagersTable(CustomTable):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    43
    def GetValue(self, row, col):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    44
        if row < self.GetNumberRows():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    45
            if col == 0:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    46
                return row
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    47
            return self.data[row].get(self.GetColLabelValue(col, False), "")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    48
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
    49
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    50
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    51
#                    EtherCAT Management Treebook
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
class EtherCATManagementTreebook(wx.Treebook):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    54
    def __init__(self, parent, controler, node_editor):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    55
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    56
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    57
        @param parent: Reference to the parent wx.ScrolledWindow object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    58
        @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
    59
        @param node_editor: Reference to Beremiz frame
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    60
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    61
        wx.Treebook.__init__(self, parent, -1, size=wx.DefaultSize, style=wx.BK_DEFAULT)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    62
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    63
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    64
        self.NodeEditor = node_editor
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    65
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    66
        self.EtherCATManagementClassObject = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    67
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    68
        # fill EtherCAT Management Treebook
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    69
        panels = [
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    70
            ("Slave State",        SlaveStatePanelClass, []),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    71
            ("SDO Management",     SDOPanelClass, []),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    72
            ("PDO Monitoring",     PDOPanelClass, []),
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    73
            ("ESC Management",     EEPROMAccessPanel, [
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    74
                ("Smart View", SlaveSiiSmartView),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    75
                ("Hex View", HexView)]),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    76
            ("Register Access",     RegisterAccessPanel, [])
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    77
        ]
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    78
        for pname, pclass, subs in panels:
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    79
            self.AddPage(pclass(self, self.Controler), pname)
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    80
            for spname, spclass in subs:
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
    81
                self.AddSubPage(spclass(self, self.Controler), spname)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    82
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
    83
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    84
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    85
#                    For SlaveState Panel
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
    86
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    87
class SlaveStatePanelClass(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    88
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    89
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    90
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    91
        @param parent: Reference to the parent EtherCATManagementTreebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    92
        @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
    93
        """
2366
d635680e4c2c cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2365
diff changeset
    94
        wx.Panel.__init__(self, parent, -1, (0, 0), size=wx.DefaultSize, style=wx.SUNKEN_BORDER)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    95
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    96
        self.parent = parent
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
    97
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    98
        # initialize SlaveStatePanel UI dictionaries
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
    99
        self.StaticBoxDic = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   100
        self.StaticTextDic = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   101
        self.TextCtrlDic = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   102
        self.ButtonDic = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   103
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   104
        # iniitalize BoxSizer and FlexGridSizer
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   105
        self.SizerDic = {
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   106
            "SlaveState_main_sizer": wx.BoxSizer(wx.VERTICAL),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   107
            "SlaveState_inner_main_sizer": wx.FlexGridSizer(cols=1, hgap=50, rows=3, vgap=10),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   108
            "SlaveInfosDetailsInnerSizer": wx.FlexGridSizer(cols=4, hgap=10, rows=2, vgap=10),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   109
            "SyncManagerInnerSizer": wx.FlexGridSizer(cols=1, hgap=5, rows=1, vgap=5),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   110
            "SlaveState_sizer": wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   111
            "SlaveState_up_sizer": wx.FlexGridSizer(cols=4, hgap=10, rows=2, vgap=10),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   112
            "SlaveState_down_sizer": wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=10)}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   113
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   114
        # initialize StaticBox and StaticBoxSizer
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   115
        for box_name, box_label in [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   116
                ("SlaveInfosDetailsBox", "Slave Informations"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   117
                ("SyncManagerBox", "Sync Manager"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   118
                ("SlaveStateBox", "Slave State Transition && Monitoring")]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   119
            self.StaticBoxDic[box_name] = wx.StaticBox(self, label=_(box_label))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   120
            self.SizerDic[box_name] = wx.StaticBoxSizer(self.StaticBoxDic[box_name])
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   121
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   122
        for statictext_name, statictext_label, textctrl_name in [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   123
                ("VendorLabel", "Vendor:", "vendor"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   124
                ("ProductcodeLabel", "Product code:", "product_code"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   125
                ("RevisionnumberLabel", "Slave Count:", "revision_number"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   126
                ("PhysicsLabel", "Physics:", "physics")]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   127
            self.StaticTextDic[statictext_name] = wx.StaticText(self, label=_(statictext_label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   128
            self.TextCtrlDic[textctrl_name] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   129
            self.SizerDic["SlaveInfosDetailsInnerSizer"].AddMany([self.StaticTextDic[statictext_name],
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   130
                                                                  self.TextCtrlDic[textctrl_name]])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   131
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   132
        self.SizerDic["SlaveInfosDetailsBox"].AddSizer(self.SizerDic["SlaveInfosDetailsInnerSizer"])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   133
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   134
        self.SyncManagersGrid = CustomGrid(self, size=wx.Size(605, 155), style=wx.VSCROLL)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   135
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   136
        self.SizerDic["SyncManagerInnerSizer"].Add(self.SyncManagersGrid)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   137
        self.SizerDic["SyncManagerBox"].Add(self.SizerDic["SyncManagerInnerSizer"])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   138
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   139
        buttons = [
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   140
            ("InitButton",   0, "INIT", "State Transition to \"Init\" State",     self.OnButtonClick, []),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   141
            ("PreOPButton",  1, "PREOP", "State Transition to \"PreOP\" State",   self.OnButtonClick, [
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   142
                ("TargetStateLabel", "Target State:", "TargetState")]),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   143
            ("SafeOPButton", 2, "SAFEOP", "State Transition to \"SafeOP\" State", self.OnButtonClick, []),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   144
            ("OPButton",     3, "OP",  "State Transition to \"OP\" State",        self.OnButtonClick, [
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   145
                ("CurrentStateLabel", "Current State:", "CurrentState")])
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   146
        ]
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   147
        for button_name, button_id, button_label, button_tooltipstring, event_method, sub_item in buttons:
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   148
            self.ButtonDic[button_name] = wx.Button(self, id=button_id, label=_(button_label))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   149
            self.ButtonDic[button_name].Bind(wx.EVT_BUTTON, event_method)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   150
            self.ButtonDic[button_name].SetToolTipString(button_tooltipstring)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   151
            self.SizerDic["SlaveState_up_sizer"].Add(self.ButtonDic[button_name])
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   152
            for statictext_name, statictext_label, textctrl_name in sub_item:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   153
                self.StaticTextDic[statictext_name] = wx.StaticText(self, label=_(statictext_label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   154
                self.TextCtrlDic[textctrl_name] = wx.TextCtrl(self, size=wx.DefaultSize, style=wx.TE_READONLY)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   155
                self.SizerDic["SlaveState_up_sizer"].AddMany([self.StaticTextDic[statictext_name],
2380
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
   156
                                                              self.TextCtrlDic[textctrl_name]])
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
        for button_name, button_label, button_tooltipstring, event_method in [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   159
                ("StartTimerButton", "Start State Monitoring", "Slave State Update Restart", self.StartTimer),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   160
                ("StopTimerButton", "Stop State Monitoring", "Slave State Update Stop", self.CurrentStateThreadStop)]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   161
            self.ButtonDic[button_name] = wx.Button(self, label=_(button_label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   162
            self.ButtonDic[button_name].Bind(wx.EVT_BUTTON, event_method)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   163
            self.ButtonDic[button_name].SetToolTipString(button_tooltipstring)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   164
            self.SizerDic["SlaveState_down_sizer"].Add(self.ButtonDic[button_name])
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   165
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   166
        self.SizerDic["SlaveState_sizer"].AddMany([self.SizerDic["SlaveState_up_sizer"],
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   167
                                                   self.SizerDic["SlaveState_down_sizer"]])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   168
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   169
        self.SizerDic["SlaveStateBox"].Add(self.SizerDic["SlaveState_sizer"])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   170
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   171
        self.SizerDic["SlaveState_inner_main_sizer"].AddMany([
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   172
            self.SizerDic["SlaveInfosDetailsBox"], self.SizerDic["SyncManagerBox"],
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   173
            self.SizerDic["SlaveStateBox"]])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   174
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   175
        self.SizerDic["SlaveState_main_sizer"].Add(self.SizerDic["SlaveState_inner_main_sizer"])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   176
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   177
        self.SetSizer(self.SizerDic["SlaveState_main_sizer"])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   178
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   179
        # register a timer for periodic exectuion of slave state update (period: 1000 ms)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   180
        self.Bind(wx.EVT_TIMER, self.GetCurrentState)
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
        self.CreateSyncManagerTable()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   183
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   184
        self.Centre()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   185
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   186
    def CreateSyncManagerTable(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   187
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   188
        Create grid for "SyncManager"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   189
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   190
        # declare Table object
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   191
        self.SyncManagersTable = SyncManagersTable(self, [], GetSyncManagersTableColnames())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   192
        self.SyncManagersGrid.SetTable(self.SyncManagersTable)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   193
        # set grid alignment attr. (CENTER)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   194
        self.SyncManagersGridColAlignements = [wx.ALIGN_CENTRE, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE,
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   195
                                               wx.ALIGN_CENTRE, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   196
        # set grid size
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   197
        self.SyncManagersGridColSizes = [40, 150, 100, 100, 100, 100]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   198
        self.SyncManagersGrid.SetRowLabelSize(0)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   199
        for col in range(self.SyncManagersTable.GetNumberCols()):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   200
            attr = wx.grid.GridCellAttr()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   201
            attr.SetAlignment(self.SyncManagersGridColAlignements[col], wx.ALIGN_CENTRE)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   202
            self.SyncManagersGrid.SetColAttr(col, attr)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   203
            self.SyncManagersGrid.SetColMinimalWidth(col, self.SyncManagersGridColSizes[col])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   204
            self.SyncManagersGrid.AutoSizeColumn(col, False)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   205
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   206
        self.RefreshSlaveInfos()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   207
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   208
    def RefreshSlaveInfos(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   209
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   210
        Fill data in "Slave Information" and "SyncManager"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   211
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   212
        slave_infos = self.Controler.GetSlaveInfos()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   213
        sync_manager_section = ["vendor", "product_code", "revision_number", "physics"]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   214
        if slave_infos is not None:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   215
            # this method is same as "TextCtrl.SetValue"
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   216
            for textctrl_name in sync_manager_section:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   217
                self.TextCtrlDic[textctrl_name].SetValue(slave_infos[textctrl_name])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   218
            self.SyncManagersTable.SetData(slave_infos["sync_managers"])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   219
            self.SyncManagersTable.ResetView(self.SyncManagersGrid)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   220
        else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   221
            for textctrl_name in sync_manager_section:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   222
                self.TextCtrlDic[textctrl_name].SetValue("")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   223
            self.SyncManagersTable.SetData([])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   224
            self.SyncManagersTable.ResetView(self.SyncManagersGrid)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   225
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   226
    def OnButtonClick(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   227
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   228
        Event handler for slave state transition button click (Init, PreOP, SafeOP, OP button)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   229
        @param event : wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   230
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   231
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   232
        if check_connect_flag:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   233
            state_dic = ["INIT", "PREOP", "SAFEOP", "OP"]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   234
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   235
            # If target state is one of {INIT, PREOP, SAFEOP}, request slave state transition immediately.
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   236
            if event.GetId() < 3:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   237
                self.Controler.CommonMethod.RequestSlaveState(state_dic[event.GetId()])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   238
                self.TextCtrlDic["TargetState"].SetValue(state_dic[event.GetId()])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   239
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   240
            # If target state is OP, first check "PLC status".
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   241
            #  (1) If current PLC status is "Started", then request slave state transition
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   242
            #  (2) Otherwise, show error message and return
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   243
            else:
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   244
                status, _log_count = self.Controler.GetCTRoot()._connector.GetPLCstatus()
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   245
                if status == "Started":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   246
                    self.Controler.CommonMethod.RequestSlaveState("OP")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   247
                    self.TextCtrlDic["TargetState"].SetValue("OP")
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   248
                else:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   249
                    self.Controler.CommonMethod.CreateErrorDialog("PLC is Not Started")
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   250
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   251
    def GetCurrentState(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   252
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   253
        Timer event handler for periodic slave state monitoring (Default period: 1 sec = 1000 msec).
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   254
        @param event : wx.TIMER object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   255
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   256
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(True)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   257
        if check_connect_flag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   258
            returnVal = self.Controler.CommonMethod.GetSlaveStateFromSlave()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   259
            line = returnVal.split("\n")
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   260
            try:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   261
                self.SetCurrentState(line[self.Controler.GetSlavePos()])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   262
            except Exception:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   263
                pass
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 SetCurrentState(self, line):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   266
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   267
        Show current slave state using the executiob result of "ethercat slaves" command.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   268
        @param line : result of "ethercat slaves" command
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   269
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   270
        state_array = ["INIT", "PREOP", "SAFEOP", "OP"]
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   271
        try:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   272
            # parse the execution result of  "ethercat slaves" command
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   273
            # Result example : 0  0:0  PREOP  +  EL9800 (V4.30) (PIC24, SPI, ET1100)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   274
            token = line.split("  ")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   275
            if token[2] in state_array:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   276
                self.TextCtrlDic["CurrentState"].SetValue(token[2])
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   277
        except Exception:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   278
            pass
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   279
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   280
    def StartTimer(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   281
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   282
        Event handler for "Start State Monitoring" button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   283
          - start slave state monitoring thread
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   284
        @param event : wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   285
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   286
        self.SlaveStateThread = wx.Timer(self)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   287
        # set timer period (1000 ms)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   288
        self.SlaveStateThread.Start(1000)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   289
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   290
    def CurrentStateThreadStop(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   291
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   292
        Event handler for "Stop State Monitoring" button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   293
          - stop slave state monitoring thread
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   294
        @param event : wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   295
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   296
        try:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   297
            self.SlaveStateThread.Stop()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   298
        except Exception:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   299
            pass
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   300
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
   301
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   302
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   303
#                    For SDO Management Panel
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   304
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   305
class SDOPanelClass(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   306
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   307
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   308
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   309
        @param parent: Reference to the parent EtherCATManagementTreebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   310
        @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
   311
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   312
        wx.Panel.__init__(self, parent, -1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   313
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   314
        self.DatatypeDescription, self.CommunicationObject, self.ManufacturerSpecific, \
2384
d7d9f0e60bc9 clean etherlab: pep8, E122 continuation line missing indentation or outdented
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2383
diff changeset
   315
            self.ProfileSpecific, self.Reserved, self.AllSDOData = range(6)
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
        self.Controler = controler
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   318
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   319
        self.SDOManagementMainSizer = wx.BoxSizer(wx.VERTICAL)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   320
        self.SDOManagementInnerMainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   321
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   322
        self.SDOUpdate = wx.Button(self, label=_('update'))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   323
        self.SDOUpdate.Bind(wx.EVT_BUTTON, self.SDOInfoUpdate)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   324
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   325
        self.CallSDONoteBook = SDONoteBook(self, controler=self.Controler)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   326
        self.SDOManagementInnerMainSizer.Add(self.SDOUpdate)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   327
        self.SDOManagementInnerMainSizer.Add(self.CallSDONoteBook, wx.ALL | wx.EXPAND)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   328
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   329
        self.SDOManagementMainSizer.Add(self.SDOManagementInnerMainSizer)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   330
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   331
        self.SetSizer(self.SDOManagementMainSizer)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   332
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   333
    def SDOInfoUpdate(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   334
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   335
        Evenet handler for SDO "update" button.
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   336
          - Load SDO data from current slave
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   337
        @param event : wx.EVT_BUTTON object
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   338
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   339
        self.Controler.CommonMethod.SaveSDOData = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   340
        self.Controler.CommonMethod.ClearSDODataSet()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   341
        self.SDOFlag = False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   342
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   343
        # Check whether beremiz connected or not.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   344
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   345
        if check_connect_flag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   346
            self.SDOs = self.Controler.CommonMethod.GetSlaveSDOFromSlave()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   347
            # SDOFlag is "False", user click "Cancel" button
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   348
            self.SDOFlag = self.SDOParser()
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   349
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   350
            if self.SDOFlag:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   351
                self.CallSDONoteBook.CreateNoteBook()
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   352
                self.Refresh()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   353
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   354
    def SDOParser(self):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   355
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   356
        Parse SDO data set that obtain "SDOInfoUpdate" Method
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   357
        @return True or False
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   358
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   359
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   360
        slaveSDO_progress = wx.ProgressDialog("Slave SDO Monitoring", "Now Uploading...",
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   361
                                              maximum=len(self.SDOs.splitlines()),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   362
                                              parent=self,
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   363
                                              style=wx.PD_CAN_ABORT | wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME |
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   364
                                              wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME |
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   365
                                              wx.PD_AUTO_HIDE | wx.PD_SMOOTH)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   366
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   367
        # If keep_going flag is False, SDOParser method is stop and return "False".
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   368
        keep_going = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   369
        count = 0
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   370
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   371
        # SDO data example
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   372
        # SDO 0x1000, "Device type"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   373
        # 0x1000:00,r-r-r-,uint32,32 bit,"Device type",0x00020192, 131474
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   374
        for details_line in self.SDOs.splitlines():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   375
            count += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   376
            line_token = details_line.split("\"")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   377
            # len(line_token[2]) case : SDO 0x1000, "Device type"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   378
            if len(line_token[2]) == 0:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   379
                title_name = line_token[1]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   380
            # else case : 0x1000:00,r-r-r-,uint32,32 bit,"Device type",0x00020192, 131474
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   381
            else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   382
                # line_token = ['0x1000:00,r-r-r-,uint32,32 bit,', 'Device type', ',0x00020192, 131474']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   383
                token_head, name, token_tail = line_token
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   384
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   385
                # token_head = ['0x1000:00', 'r-r-r-', 'uint32', '32 bit', '']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   386
                token_head = token_head.split(",")
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   387
                ful_idx, access, type, size, _empty = token_head
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   388
                # ful_idx.split(":") = ['0x1000', '00']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   389
                idx, sub_idx = ful_idx.split(":")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   390
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   391
                # token_tail = ['', '0x00020192', '131474']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   392
                token_tail = token_tail.split(",")
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   393
                try:
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   394
                    _empty, hex_val, _dec_val = token_tail
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   395
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   396
                # SDO data is not return "dec value"
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   397
                # line example :
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   398
                # 0x1702:01,rwr-r-,uint32,32 bit," 1st mapping", ----
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   399
                except Exception:
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   400
                    _empty, hex_val = token_tail
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
                name_after_check = self.StringTest(name)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   403
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   404
                # convert hex type
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   405
                sub_idx = "0x" + sub_idx
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   406
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   407
                if type == "octet_string":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   408
                    hex_val = ' ---- '
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   409
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   410
                # SResult of SlaveSDO data parsing. (data type : dictionary)
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   411
                self.Data = {'idx': idx.strip(), 'subIdx': sub_idx.strip(), 'access': access.strip(),
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   412
                             'type': type.strip(), 'size': size.strip(),  'name': name_after_check.strip("\""),
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   413
                             'value': hex_val.strip(), "category": title_name.strip("\"")}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   414
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   415
                category_divide_value = [0x1000, 0x2000, 0x6000, 0xa000, 0xffff]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   416
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   417
                for count in range(len(category_divide_value)):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   418
                    if int(idx, 0) < category_divide_value[count]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   419
                        self.Controler.CommonMethod.SaveSDOData[count].append(self.Data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   420
                        break
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   421
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   422
                self.Controler.CommonMethod.SaveSDOData[self.AllSDOData].append(self.Data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   423
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   424
            if count >= len(self.SDOs.splitlines()) / 2:
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   425
                (keep_going, _skip) = slaveSDO_progress.Update(count, "Please waiting a moment!!")
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   426
            else:
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   427
                (keep_going, _skip) = slaveSDO_progress.Update(count)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   428
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   429
            # If user click "Cancel" loop suspend immediately
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
   430
            if not keep_going:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   431
                break
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   432
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   433
        slaveSDO_progress.Destroy()
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   434
        return keep_going
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   435
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   436
    def StringTest(self, check_string):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   437
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   438
        Test value 'name' is alphanumeric
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   439
        @param check_string : input data for check
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   440
        @return result : output data after check
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   441
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   442
        # string.printable is print this result
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   443
        # '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   444
        # !"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   445
        allow_range = string.printable
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   446
        result = check_string
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   447
        for i in range(0, len(check_string)):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   448
            # string.isalnum() is check whether string is alphanumeric or not
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   449
            if check_string[len(check_string)-1-i:len(check_string)-i] in allow_range:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   450
                result = check_string[:len(check_string) - i]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   451
                break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   452
        return result
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   453
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   454
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   455
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   456
#                    For SDO Notebook (divide category)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   457
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   458
class SDONoteBook(wx.Notebook):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   459
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   460
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   461
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   462
        @param parent: Reference to the parent SDOPanelClass class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   463
        @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
   464
        """
2366
d635680e4c2c cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2365
diff changeset
   465
        wx.Notebook.__init__(self, parent, id=-1, size=(850, 500))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   466
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   467
        self.parent = parent
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
        self.CreateNoteBook()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   470
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   471
    def CreateNoteBook(self):
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
        Create each NoteBook page, divided SDO index
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   474
        According to EtherCAT Communication(03/2011), 158p
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   475
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   476
        self.Data = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   477
        count = 1
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   478
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   479
        page_texts = [("all", self.parent.AllSDOData),
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   480
                      ("0x0000 - 0x0ff", self.parent.DatatypeDescription),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   481
                      ("0x1000 - 0x1fff", self.parent.CommunicationObject),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   482
                      ("0x2000 - 0x5fff", self.parent.ManufacturerSpecific),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   483
                      ("0x6000 - 0x9fff", self.parent.ProfileSpecific),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   484
                      ("0xa000 - 0xffff", self.parent.Reserved)]
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   485
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   486
        # page_tooltip_string = ["SDO Index 0x0000 - 0x0fff : Data Type Description",
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   487
        #                        "SDO Index 0x1000 - 0x1fff : Communication object",
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   488
        #                        "SDO Index 0x2000 - 0x5fff : Manufacturer specific",
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   489
        #                        "SDO Index 0x6000 - 0x9fff : Profile specific",
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   490
        #                        "SDO Index 0xa000 - 0xffff : Reserved",
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   491
        #                        "All SDO Object"]
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   492
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   493
        self.DeleteAllPages()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   494
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   495
        for txt, count in page_texts:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   496
            self.Data = self.Controler.CommonMethod.SaveSDOData[count]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   497
            self.Win = SlaveSDOTable(self, self.Data)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   498
            self.AddPage(self.Win, txt)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   499
2360
2a3d022a7dac cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2358
diff changeset
   500
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   501
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   502
#                    For SDO Grid (fill index, subindex, etc...)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   503
# -------------------------------------------------------------------------------
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   504
class SlaveSDOTable(wx.grid.Grid):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   505
    def __init__(self, parent, data):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   506
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   507
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   508
        @param parent: Reference to the parent SDOPanelClass class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   509
        @param data: SDO data after parsing "SDOParser" method
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   510
        """
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   511
        wx.grid.Grid.__init__(self, parent, -1, size=(830, 490),
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
   512
                              style=wx.EXPAND | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   513
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   514
        self.Controler = parent.Controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   515
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   516
        self.SDOFlag = True
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   517
        if data is None:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   518
            self.SDOs = []
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   519
        else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   520
            self.SDOs = data
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   521
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   522
        self.CreateGrid(len(self.SDOs), 8)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   523
        SDOCellSize = [(0, 65), (1, 65), (2, 50), (3, 55),
2380
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
   524
                       (4, 40), (5, 200), (6, 250), (7, 85)]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   525
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   526
        for (index, size) in SDOCellSize:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   527
            self.SetColSize(index, size)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   528
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   529
        self.SetRowLabelSize(0)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   530
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   531
        SDOTableLabel = [(0, "Index"), (1, "Subindex"), (2, "Access"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   532
                         (3, "Type"), (4, "Size"), (5, "Category"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   533
                         (6, "Name"), (7, "Value")]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   534
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   535
        for (index, label) in SDOTableLabel:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   536
            self.SetColLabelValue(index, label)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   537
            self.SetColLabelAlignment(index, wx.ALIGN_CENTRE)
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
        attr = wx.grid.GridCellAttr()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   540
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   541
        # for SDO download
2389
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
   542
        self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.SDOModifyDialog)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   543
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   544
        for i in range(7):
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   545
            self.SetColAttr(i, attr)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   546
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   547
        self.SetColLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   548
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   549
        self.SetTableValue()
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   550
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   551
    def SetTableValue(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   552
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   553
        Cell is filled by new parsing data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   554
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   555
        sdo_list = ['idx', 'subIdx', 'access', 'type', 'size', 'category', 'name', 'value']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   556
        for row_idx in range(len(self.SDOs)):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   557
            for col_idx in range(len(self.SDOs[row_idx])):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   558
                self.SetCellValue(row_idx, col_idx, self.SDOs[row_idx][sdo_list[col_idx]])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   559
                self.SetReadOnly(row_idx, col_idx, True)
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   560
                if col_idx < 5:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   561
                    self.SetCellAlignment(row_idx, col_idx, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   562
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   563
    def CheckSDODataAccess(self, row):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   564
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   565
        CheckSDODataAccess method is checking that access data has "w"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   566
        Access field consist 6 char, if mean
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   567
           rw      rw     rw
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   568
        (preop) (safeop) (op)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   569
        Example Access field : rwrwrw, rwrw--
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   570
        @param row : Selected cell by user
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   571
        @return Write_flag : If data has "w", flag is true
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
        write_flag = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   574
        check = self.SDOs[row]['access']
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   575
        if check[1:2] == 'w':
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   576
            self.Controler.CommonMethod.Check_PREOP = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   577
            write_flag = True
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   578
        if check[3:4] == 'w':
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   579
            self.Controler.CommonMethod.Check_SAFEOP = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   580
            write_flag = True
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   581
        if check[5:] == 'w':
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   582
            self.Controler.CommonMethod.Check_OP = True
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   583
            write_flag = True
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   584
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   585
        return write_flag
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   586
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   587
    def DecideSDODownload(self, state):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   588
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   589
        compare current state and "access" field,
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   590
        result notify SDOModifyDialog method
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   591
        @param state : current slave state
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   592
        @return True or False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   593
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   594
        # Example of 'state' parameter : "0  0:0  PREOP  +  EL9800 (V4.30) (PIC24, SPI, ET1100)"
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   595
        state = state[self.Controler.GetSlavePos()].split("  ")[2]
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   596
        if state == "PREOP" and self.Controler.CommonMethod.Check_PREOP:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   597
            return True
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   598
        elif state == "SAFEOP" and self.Controler.CommonMethod.Check_SAFEOP:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   599
            return True
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   600
        elif state == "OP" and self.Controler.CommonMethod.Check_OP:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   601
            return True
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   602
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   603
        return False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   604
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   605
    def ClearStateFlag(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   606
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   607
        Initialize StateFlag
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   608
        StateFlag is notice SDOData access each slave state
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   609
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   610
        self.Controler.CommonMethod.Check_PREOP = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   611
        self.Controler.CommonMethod.Check_SAFEOP = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   612
        self.Controler.CommonMethod.Check_OP = False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   613
2382
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   614
    def SDOModifyDialog(self, event):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   615
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   616
        Create dialog for SDO value modify
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   617
        if user enter data, perform command "ethercat download"
2389
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
   618
        @param event : wx.grid.EVT_GRID_CELL_LEFT_DCLICK object
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   619
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   620
        self.ClearStateFlag()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   621
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   622
        # CheckSDODataAccess is checking that OD(Object Dictionary) has "w"
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   623
        if event.GetCol() == 7 and self.CheckSDODataAccess(event.GetRow()):
2382
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   624
            dlg = wx.TextEntryDialog(
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   625
                self,
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   626
                _("Enter hex or dec value (if enter dec value, it automatically conversed hex value)"),
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   627
                "SDOModifyDialog",
e783c6beacf1 clean etherlab: pep8, E211 whitespace before '['
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2381
diff changeset
   628
                style=wx.OK | wx.CANCEL)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   629
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   630
            start_value = self.GetCellValue(event.GetRow(), event.GetCol())
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   631
            dlg.SetValue(start_value)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   632
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   633
            if dlg.ShowModal() == wx.ID_OK:
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   634
                try:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   635
                    int(dlg.GetValue(), 0)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   636
                    # check "Access" field
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   637
                    if self.DecideSDODownload(self.Controler.CommonMethod.SlaveState[self.Controler.GetSlavePos()]):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   638
                        # Request "SDODownload"
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   639
                        self.Controler.CommonMethod.SDODownload(
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   640
                            self.SDOs[event.GetRow()]['type'],
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   641
                            self.SDOs[event.GetRow()]['idx'],
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   642
                            self.SDOs[event.GetRow()]['subIdx'],
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   643
                            dlg.GetValue())
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
   644
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   645
                        self.SetCellValue(event.GetRow(), event.GetCol(), hex(int(dlg.GetValue(), 0)))
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   646
                    else:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   647
                        self.Controler.CommonMethod.CreateErrorDialog('You cannot SDO download this state')
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   648
                # Error occured process of "int(variable)"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   649
                # User input is not hex, dec value
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   650
                except ValueError:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   651
                    self.Controler.CommonMethod.CreateErrorDialog('You can input only hex, dec value')
2354
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
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   654
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   655
#                 For PDO Monitoring Panel
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   656
# PDO Class UI  : Panel -> Choicebook (RxPDO, TxPDO) ->
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   657
#                 Notebook (PDO Index) -> Grid (PDO entry)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   658
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   659
class PDOPanelClass(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   660
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   661
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   662
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   663
        @param parent: Reference to the parent EtherCATManagementTreebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   664
        @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
   665
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   666
        wx.Panel.__init__(self, parent, -1)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   667
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   668
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   669
        self.PDOMonitoringEditorMainSizer = wx.BoxSizer(wx.VERTICAL)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   670
        self.PDOMonitoringEditorInnerMainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   671
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   672
        self.CallPDOChoicebook = PDOChoicebook(self, controler=self.Controler)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   673
        self.PDOMonitoringEditorInnerMainSizer.Add(self.CallPDOChoicebook, wx.ALL)
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
        self.PDOMonitoringEditorMainSizer.Add(self.PDOMonitoringEditorInnerMainSizer)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   676
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   677
        self.SetSizer(self.PDOMonitoringEditorMainSizer)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   678
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   679
    def PDOInfoUpdate(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   680
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   681
        Call RequestPDOInfo method and create Choicebook
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   682
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   683
        self.Controler.CommonMethod.RequestPDOInfo()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   684
        self.CallPDOChoicebook.Destroy()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   685
        self.CallPDOChoicebook = PDOChoicebook(self, controler=self.Controler)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   686
        self.Refresh()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   687
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   688
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   689
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   690
#                    For PDO Choicebook (divide Tx, Rx PDO)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   691
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   692
class PDOChoicebook(wx.Choicebook):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   693
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   694
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   695
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   696
        @param parent: Reference to the parent PDOPanelClass class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   697
        @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
   698
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   699
        wx.Choicebook.__init__(self, parent, id=-1, size=(500, 500), style=wx.CHB_DEFAULT)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   700
        self.Controler = controler
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   701
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   702
        RxWin = PDONoteBook(self, controler=self.Controler, name="Rx")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   703
        TxWin = PDONoteBook(self, controler=self.Controler, name="Tx")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   704
        self.AddPage(RxWin, "RxPDO")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   705
        self.AddPage(TxWin, "TxPDO")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   706
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   707
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   708
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   709
#                    For PDO Notebook (divide PDO index)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   710
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   711
class PDONoteBook(wx.Notebook):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   712
    def __init__(self, parent, name, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   713
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   714
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   715
        @param parent: Reference to the parent PDOChoicebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   716
        @param name: identifier whether RxPDO or TxPDO
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   717
        @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
   718
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   719
        wx.Notebook.__init__(self, parent, id=-1, size=(640, 400))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   720
        self.Controler = controler
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
        count = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   723
        page_texts = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   724
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   725
        self.Controler.CommonMethod.RequestPDOInfo()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   726
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   727
        if name == "Tx":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   728
            # obtain pdo_info and pdo_entry
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   729
            # pdo_info include (PDO index, name, number of entry)
2373
73d35ba8f982 clean etherlab: pep8, E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2369
diff changeset
   730
            pdo_info = self.Controler.CommonMethod.GetTxPDOCategory()
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   731
            pdo_entry = self.Controler.CommonMethod.GetTxPDOInfo()
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   732
            for tmp in pdo_info:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   733
                title = str(hex(tmp['pdo_index']))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   734
                page_texts.append(title)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   735
        # RX PDO case
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   736
        else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   737
            pdo_info = self.Controler.CommonMethod.GetRxPDOCategory()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   738
            pdo_entry = self.Controler.CommonMethod.GetRxPDOInfo()
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   739
            for tmp in pdo_info:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   740
                title = str(hex(tmp['pdo_index']))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   741
                page_texts.append(title)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   742
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   743
        # Add page depending on the number of pdo_info
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   744
        for txt in page_texts:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   745
            win = PDOEntryTable(self, pdo_info, pdo_entry, count)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   746
            self.AddPage(win, txt)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   747
            count += 1
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   748
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   749
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   750
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   751
#                    For PDO Grid (fill entry index, subindex etc...)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   752
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   753
class PDOEntryTable(wx.grid.Grid):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   754
    def __init__(self, parent, info, entry, count):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   755
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   756
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   757
        @param parent: Reference to the parent PDONoteBook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   758
        @param info : data structure including 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
   759
        @param entry : data structure including index, name, entry number
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   760
        @param count : page number
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   761
        """
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   762
        wx.grid.Grid.__init__(self, parent, -1, size=(500, 400), pos=wx.Point(0, 0),
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
   763
                              style=wx.EXPAND | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   764
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   765
        self.Controler = parent.Controler
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   766
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   767
        self.PDOInfo = info
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   768
        self.PDOEntry = entry
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   769
        self.Count = count
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   770
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   771
        self.CreateGrid(self.PDOInfo[self.Count]['number_of_entry'], 5)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   772
        self.SetColLabelSize(25)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   773
        self.SetRowLabelSize(0)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   774
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   775
        PDOTableLabel = [(0, "Index"), (1, "Subindex"), (2, "Length"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   776
                         (3, "Type"), (4, "Name")]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   777
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   778
        for (index, label) in PDOTableLabel:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   779
            self.SetColLabelValue(index, label)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   780
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   781
        PDOCellSize = [(0, 45), (1, 65), (2, 55), (3, 40), (4, 300)]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   782
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   783
        for (index, size) in PDOCellSize:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   784
            self.SetColSize(index, size)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   785
            self.SetColLabelAlignment(index, wx.ALIGN_LEFT)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   786
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   787
        attr = wx.grid.GridCellAttr()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   788
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   789
        for i in range(5):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   790
            self.SetColAttr(i, attr)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   791
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   792
        self.SetTableValue()
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
    def SetTableValue(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   795
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   796
        Cell is filled by new parsing data in XML
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   797
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   798
        list_index = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   799
        # number of entry
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   800
        for i in range(self.Count + 1):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   801
            list_index += self.PDOInfo[i]['number_of_entry']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   802
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   803
        start_value = list_index - self.PDOInfo[self.Count]['number_of_entry']
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
        pdo_list = ['entry_index', 'subindex', 'bitlen', 'type', 'name']
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   806
        for row_idx in range(self.PDOInfo[self.Count]['number_of_entry']):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   807
            for col_idx in range(len(self.PDOEntry[row_idx])):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   808
                # entry index is converted hex value.
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   809
                if col_idx == 0:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   810
                    self.SetCellValue(row_idx, col_idx, hex(self.PDOEntry[start_value][pdo_list[col_idx]]))
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   811
                else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   812
                    self.SetCellValue(row_idx, col_idx, str(self.PDOEntry[start_value][pdo_list[col_idx]]))
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   813
                if col_idx != 4:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   814
                    self.SetCellAlignment(row_idx, col_idx, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   815
                else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   816
                    self.SetCellAlignment(row_idx, col_idx, wx.ALIGN_LEFT, wx.ALIGN_CENTRE)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   817
                self.SetReadOnly(row_idx, col_idx, True)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   818
                self.SetRowSize(row_idx, 25)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   819
            start_value += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   820
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   821
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   822
# -------------------------------------------------------------------------------
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   823
#                    For EEPROM Access Main Panel
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   824
#                 (This class explain EEPROM Access)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   825
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   826
class EEPROMAccessPanel(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   827
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   828
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   829
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   830
        @param parent: Reference to the parent EtherCATManagementTreebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   831
        @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
   832
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   833
        wx.Panel.__init__(self, parent, -1)
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   834
        sizer = wx.FlexGridSizer(cols=1, hgap=20, rows=3, vgap=20)
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
        line = wx.StaticText(self, -1, "\n  EEPROM Access is composed to SmartView and HexView. \
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   837
                                              \n\n   - SmartView shows Config Data, Device Identity, Mailbox settings, etc. \
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   838
                                              \n\n   - HexView shows EEPROM's contents.")
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
        sizer.Add(line)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   841
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   842
        self.SetSizer(sizer)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   843
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   844
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   845
# -------------------------------------------------------------------------------
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   846
#                    For Smart View Panel
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
   847
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   848
class SlaveSiiSmartView(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   849
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   850
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   851
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   852
        @param parent: Reference to the parent EtherCATManagementTreebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   853
        @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
   854
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   855
        wx.Panel.__init__(self, parent, -1)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   856
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   857
        self.Controler = controler
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   858
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   859
        self.PDIType = {
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   860
            0: ['none', '00000000'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   861
            4: ['Digital I/O', '00000100'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   862
            5: ['SPI Slave', '00000101'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   863
            7: ['EtherCAT Bridge (port3)', '00000111'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   864
            8: ['uC async. 16bit', '00001000'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   865
            9: ['uC async. 8bit', '00001001'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   866
            10: ['uC sync. 16bit', '00001010'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   867
            11: ['uC sync. 8bit', '00001011'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   868
            16: ['32 Digtal Input and 0 Digital Output', '00010000'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   869
            17: ['24 Digtal Input and 8 Digital Output', '00010001'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   870
            18: ['16 Digtal Input and 16 Digital Output', '00010010'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   871
            19: ['8 Digtal Input and 24 Digital Output', '00010011'],
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
   872
            20: ['0 Digtal Input and 32 Digital Output', '00010100'],
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   873
            128: ['On-chip bus', '11111111']
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   874
        }
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   875
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   876
        sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   877
        button_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=5)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   878
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   879
        for button, mapping_method in [("Write EEPROM", self.WriteToEEPROM),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   880
                                       ("Read EEPROM", self.ReadFromEEPROM)]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   881
            btn = wx.Button(self, -1, button, size=(150, 40))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   882
            button_sizer.Add(btn, border=10, flag=wx.ALL)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   883
            btn.Bind(wx.EVT_BUTTON, mapping_method)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   884
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   885
        self.TreeListCtrl = SmartViewTreeListCtrl(self, self.Controler)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   886
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   887
        sizer.Add(button_sizer, border=10, flag=wx.ALL)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   888
        sizer.Add(self.TreeListCtrl, border=10, flag=wx.ALL)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   889
        self.SetSizer(sizer)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   890
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   891
        self.Create_SmartView()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   892
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   893
    def Create_SmartView(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   894
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   895
        SmartView shows information based on XML as initial value.
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   896
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   897
        self.Controler.CommonMethod.SmartViewInfosFromXML = self.Controler.CommonMethod.GetSmartViewInfos()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   898
        self.SetXMLData()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   899
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   900
    def WriteToEEPROM(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   901
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   902
        Open binary file (user select) and write the selected binary data to EEPROM
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   903
        @param event : wx.EVT_BUTTON object
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   904
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   905
        # Check whether beremiz connected or not, and whether status is "Started" or not.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   906
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   907
        if check_connect_flag:
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
   908
            status, _log_count = self.Controler.GetCTRoot()._connector.GetPLCstatus()
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   909
            if status is not "Started":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   910
                dialog = wx.FileDialog(self, _("Choose a binary file"), os.getcwd(), "",  _("bin files (*.bin)|*.bin"), wx.OPEN)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   911
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   912
                if dialog.ShowModal() == wx.ID_OK:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   913
                    filepath = dialog.GetPath()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   914
                    try:
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   915
                        binfile = open(filepath, "rb")
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   916
                        self.SiiBinary = binfile.read()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   917
                        dialog.Destroy()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   918
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   919
                        self.Controler.CommonMethod.SiiWrite(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   920
                        # refresh data structure kept by master
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   921
                        self.Controler.CommonMethod.Rescan()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   922
                        # save binary data as inner global data of beremiz
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   923
                        # for fast loading when slave plugin node is reopened.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   924
                        self.Controler.CommonMethod.SiiData = self.SiiBinary
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   925
                        self.SetEEPROMData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   926
                    except Exception:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   927
                        self.Controler.CommonMethod.CreateErrorDialog('The file does not exist!')
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   928
                        dialog.Destroy()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   929
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   930
    def ReadFromEEPROM(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   931
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   932
        Refresh displayed data based on slave EEPROM and save binary file through dialog
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   933
        @param event : wx.EVT_BUTTON object
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   934
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   935
        # Check whether beremiz connected or not.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   936
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   937
        if check_connect_flag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   938
            self.SiiBinary = self.Controler.CommonMethod.LoadData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   939
            self.SetEEPROMData()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   940
            dialog = wx.FileDialog(self, _("Save as..."), os.getcwd(),
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   941
                                   "slave0.bin",  _("bin files (*.bin)|*.bin|All files|*.*"),
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
   942
                                   wx.SAVE | wx.OVERWRITE_PROMPT)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   943
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   944
            if dialog.ShowModal() == wx.ID_OK:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   945
                filepath = dialog.GetPath()
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
   946
                binfile = open(filepath, "wb")
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   947
                binfile.write(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   948
                binfile.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   949
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   950
            dialog.Destroy()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   951
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   952
    def SetXMLData(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   953
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   954
        Set data based on XML initially
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   955
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   956
        # Config Data: EEPROM Size, PDI Type, Device Emulation
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   957
        # Find PDI Type in pdiType dictionary
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   958
        cnt_pdi_type = self.Controler.CommonMethod.SmartViewInfosFromXML["pdi_type"]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   959
        for i in self.PDIType.keys():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   960
            if cnt_pdi_type == i:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   961
                cnt_pdi_type = self.PDIType[i][0]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   962
                break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   963
        #  Set Config Data
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   964
        for treelist, data in [("EEPROM Size (Bytes)",
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   965
                                str(self.Controler.CommonMethod.SmartViewInfosFromXML["eeprom_size"])),
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   966
                               ("PDI Type",
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   967
                                cnt_pdi_type),
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   968
                               ("Device Emulation",
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   969
                                self.Controler.CommonMethod.SmartViewInfosFromXML["device_emulation"])]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   970
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.ConfigData[treelist], data, 1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   971
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   972
        # Device Identity: Vendor ID, Product Code, Revision No., Serial No.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   973
        #  Set Device Identity
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   974
        for treelist, data in [("Vendor ID", self.Controler.CommonMethod.SmartViewInfosFromXML["vendor_id"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   975
                               ("Product Code", self.Controler.CommonMethod.SmartViewInfosFromXML["product_code"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   976
                               ("Revision No.", self.Controler.CommonMethod.SmartViewInfosFromXML["revision_no"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   977
                               ("Serial No.", self.Controler.CommonMethod.SmartViewInfosFromXML["serial_no"])]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   978
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.DeviceIdentity[treelist], data, 1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   979
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   980
        # Mailbox: Supported Mailbox, Bootstrap Configuration, Standard Configuration
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   981
        #  Set Mailbox
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   982
        for treelist, data in [("Supported Mailbox", self.Controler.CommonMethod.SmartViewInfosFromXML["supported_mailbox"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   983
                               ("Bootstrap Configuration", ""),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   984
                               ("Standard Configuration", "")]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   985
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.Mailbox[treelist], data, 1)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   986
        #  Set Bootstrap Configuration: Receive Offset, Receive Size, Send Offset, Send Size
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   987
        for treelist, data in [("Receive Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_outstart"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   988
                               ("Receive Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_outlength"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   989
                               ("Send Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_instart"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   990
                               ("Send Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_inlength"])]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   991
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.BootstrapConfig[treelist], data, 1)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   992
        #  Set Standard Configuration: Receive Offset, Receive Size, Send Offset, Send Size
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   993
        for treelist, data in [("Receive Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_outstart"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   994
                               ("Receive Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_outlength"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   995
                               ("Send Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_instart"]),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   996
                               ("Send Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_inlength"])]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   997
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.StandardConfig[treelist], data, 1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
   998
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
   999
    def SetEEPROMData(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1000
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1001
        Set data based on slave EEPROM.
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
        # sii_dict = { Parameter : (WordAddress, WordSize) }
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  1004
        sii_dict = {
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1005
            'PDIControl':                          ('0', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1006
            'PDIConfiguration':                    ('1', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1007
            'PulseLengthOfSYNCSignals':            ('2', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1008
            'ExtendedPDIConfiguration':            ('3', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1009
            'ConfiguredStationAlias':              ('4', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1010
            'Checksum':                            ('7', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1011
            'VendorID':                            ('8', 2),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1012
            'ProductCode':                         ('a', 2),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1013
            'RevisionNumber':                      ('c', 2),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1014
            'SerialNumber':                        ('e', 2),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1015
            'Execution Delay':                     ('10', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1016
            'Port0Delay':                          ('11', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1017
            'Port1Delay':                          ('12', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1018
            'BootstrapReceiveMailboxOffset':       ('14', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1019
            'BootstrapReceiveMailboxSize':         ('15', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1020
            'BootstrapSendMailboxOffset':          ('16', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1021
            'BootstrapSendMailboxSize':            ('17', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1022
            'StandardReceiveMailboxOffset':        ('18', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1023
            'StandardReceiveMailboxSize':          ('19', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1024
            'StandardSendMailboxOffset':           ('1a', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1025
            'StandardSendMailboxSize':             ('1b', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1026
            'MailboxProtocol':                     ('1c', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1027
            'Size':                                ('3e', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1028
            'Version':                             ('3f', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1029
            'First Category Type/Vendor Specific': ('40', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1030
            'Following Category Word Size':        ('41', 1),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1031
            'Category Data':                       ('42', 1),
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  1032
        }
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1033
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1034
        # Config Data: EEPROM Size, PDI Type, Device Emulation
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1035
        # EEPROM's data in address '0x003f' is Size of EEPROM in KBit-1
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1036
        eeprom_size = str((int(self.GetWordAddressData(sii_dict.get('Size'), 10))+1)/8*1024)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1037
        # Find PDI Type in pdiType dictionary
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1038
        cnt_pdi_type = int(self.GetWordAddressData(sii_dict.get('PDIControl'), 16).split('x')[1][2:4], 16)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1039
        for i in self.PDIType.keys():
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1040
            if cnt_pdi_type == i:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1041
                cnt_pdi_type = self.PDIType[i][0]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1042
                break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1043
        #  Get Device Emulation
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1044
        device_emulation = str(bool(int("{:0>16b}".format(int(self.GetWordAddressData(sii_dict.get('PDIControl'), 16), 16))[7])))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1045
        #  Set Config Data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1046
        for treelist, data in [("EEPROM Size (Bytes)", eeprom_size),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1047
                               ("PDI Type", cnt_pdi_type),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1048
                               ("Device Emulation", device_emulation)]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1049
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.ConfigData[treelist], data, 1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1050
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1051
        # Device Identity: Vendor ID, Product Code, Revision No., Serial No.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1052
        #  Set Device Identity
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1053
        for treelist, data in [
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1054
                ("Vendor ID", self.GetWordAddressData(sii_dict.get('VendorID'), 16)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1055
                ("Product Code", self.GetWordAddressData(sii_dict.get('ProductCode'), 16)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1056
                ("Revision No.", self.GetWordAddressData(sii_dict.get('RevisionNumber'), 16)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1057
                ("Serial No.", self.GetWordAddressData(sii_dict.get('SerialNumber'), 16))]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1058
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.DeviceIdentity[treelist], data, 1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1059
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1060
        # Mailbox
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1061
        # EEORPOM's word address '1c' indicates supported mailbox protocol.
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1062
        # each value of mailbox protocol :
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1063
        # VoE(0x0020), SoE(0x0010), FoE(0x0008), CoE(0x0004), EoE(0x0002), AoE(0x0001)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1064
        supported_mailbox = ""
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  1065
        mailbox_protocol = ["VoE,  ", "SoE,  ", "FoE,  ", "CoE,  ", "EoE,  ", "AoE,  "]
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1066
        mailbox_data = "{:0>8b}".format(int(self.GetWordAddressData(sii_dict.get('MailboxProtocol'), 16), 16))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1067
        for protocol in range(6):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1068
            if mailbox_data[protocol+2] == '1':
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1069
                supported_mailbox += mailbox_protocol[protocol]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1070
        supported_mailbox = supported_mailbox.strip(",  ")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1071
        #  Set Mailbox
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1072
        for treelist, data in [("Supported Mailbox", supported_mailbox),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1073
                               ("Bootstrap Configuration", ""),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1074
                               ("Standard Configuration", "")]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1075
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.Mailbox[treelist], data, 1)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1076
        #  Set Bootstrap Configuration: Receive Offset, Receive Size, Send Offset, Send Size
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1077
        for treelist, data in [
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1078
                ("Receive Offset", self.GetWordAddressData(sii_dict.get('BootstrapReceiveMailboxOffset'), 10)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1079
                ("Receive Size", self.GetWordAddressData(sii_dict.get('BootstrapReceiveMailboxSize'), 10)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1080
                ("Send Offset", self.GetWordAddressData(sii_dict.get('BootstrapSendMailboxOffset'), 10)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1081
                ("Send Size", self.GetWordAddressData(sii_dict.get('BootstrapSendMailboxSize'), 10))]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1082
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.BootstrapConfig[treelist], data, 1)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1083
        #  Set Standard Configuration: Receive Offset, Receive Size, Send Offset, Send Size
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1084
        for treelist, data in [
2369
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1085
                ("Receive Offset", self.GetWordAddressData(sii_dict.get('StandardReceiveMailboxOffset'), 10)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1086
                ("Receive Size", self.GetWordAddressData(sii_dict.get('StandardReceiveMailboxSize'), 10)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1087
                ("Send Offset", self.GetWordAddressData(sii_dict.get('StandardSendMailboxOffset'), 10)),
24db1e592e20 cleanup etherlab: pep8, E201 whitespace after '('
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2368
diff changeset
  1088
                ("Send Size", self.GetWordAddressData(sii_dict.get('StandardSendMailboxSize'), 10))]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1089
            self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.StandardConfig[treelist], data, 1)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1090
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1091
    def MakeStaticBoxSizer(self, boxlabel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1092
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1093
        Make StaticBoxSizer
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1094
        @param boxlabel : label of box sizer
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1095
        @return sizer : the StaticBoxSizer labeled 'boxlabel'
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1096
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1097
        box = wx.StaticBox(self, -1, boxlabel)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1098
        sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1099
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1100
        return sizer
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1101
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1102
    def GetWordAddressData(self, dict_tuple, format):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1103
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1104
        This method converts word address data from EEPROM binary.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1105
        @param dict_tuple : element of 'sii_dict' dictionary in SetEEPROMData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1106
        @param format : format of data. It can be 16(hex), 10(decimal) and 2(binary).
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1107
        @return formatted value
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1108
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1109
        offset = int(str(dict_tuple[0]), 16) * 2
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1110
        length = int(str(dict_tuple[1]), 16) * 2
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1111
        list = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1112
        data = ''
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1113
        for index in range(length):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1114
            hexdata = hex(ord(self.SiiBinary[offset + index]))[2:]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1115
            list.append(hexdata.zfill(2))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1116
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1117
        list.reverse()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1118
        data = list[0:length]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1119
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1120
        if format == 16:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1121
            return '0x' + ''.join(data)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1122
        elif format == 10:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1123
            return str(int(str(''.join(data)), 16))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1124
        elif format == 2:
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1125
            ''.join(data)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1126
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1127
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1128
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1129
#                    For Smart View TreeListCtrl
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1130
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1131
class SmartViewTreeListCtrl(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1132
    def __init__(self, parent, Controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1133
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1134
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1135
        @param parent: Reference to the parent SlaveSiiSmartView class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1136
        @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
  1137
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1138
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1139
        wx.Panel.__init__(self, parent, -1, size=(350, 500))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1140
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1141
        self.Tree = wx.gizmos.TreeListCtrl(self, -1, size=(350, 500),
2386
d00f1430d57a clean etherlab: pep8, W503 line break before binary operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2385
diff changeset
  1142
                                           style=(wx.TR_DEFAULT_STYLE |
d00f1430d57a clean etherlab: pep8, W503 line break before binary operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2385
diff changeset
  1143
                                                  wx.TR_FULL_ROW_HIGHLIGHT |
d00f1430d57a clean etherlab: pep8, W503 line break before binary operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2385
diff changeset
  1144
                                                  wx.TR_HIDE_ROOT |
d00f1430d57a clean etherlab: pep8, W503 line break before binary operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2385
diff changeset
  1145
                                                  wx.TR_COLUMN_LINES |
d00f1430d57a clean etherlab: pep8, W503 line break before binary operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2385
diff changeset
  1146
                                                  wx.TR_ROW_LINES))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1147
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1148
        self.Tree.AddColumn("Description", width=200)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1149
        self.Tree.AddColumn("Value", width=140)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1150
        self.Tree.SetMainColumn(0)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1151
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1152
        self.Root = self.Tree.AddRoot("")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1153
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1154
        # Add item
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1155
        #  Level 1 nodes
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1156
        self.Level1Nodes = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1157
        for lv1 in ["Config Data", "Device Identity", "Mailbox"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1158
            self.Level1Nodes[lv1] = self.Tree.AppendItem(self.Root, lv1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1159
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1160
        #  Level 2 nodes
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1161
        #   Config Data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1162
        self.ConfigData = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1163
        for lv2 in ["EEPROM Size (Bytes)", "PDI Type", "Device Emulation"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1164
            self.ConfigData[lv2] = self.Tree.AppendItem(self.Level1Nodes["Config Data"], lv2)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1165
        #   Device Identity
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1166
        self.DeviceIdentity = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1167
        for lv2 in ["Vendor ID", "Product Code", "Revision No.", "Serial No."]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1168
            self.DeviceIdentity[lv2] = self.Tree.AppendItem(self.Level1Nodes["Device Identity"], lv2)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1169
        #   Mailbox
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1170
        self.Mailbox = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1171
        for lv2 in ["Supported Mailbox", "Bootstrap Configuration", "Standard Configuration"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1172
            self.Mailbox[lv2] = self.Tree.AppendItem(self.Level1Nodes["Mailbox"], lv2)
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
        #  Level 3 nodes
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1175
        #   Children of Bootstrap Configuration
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1176
        self.BootstrapConfig = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1177
        for lv3 in ["Receive Offset", "Receive Size", "Send Offset", "Send Size"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1178
            self.BootstrapConfig[lv3] = self.Tree.AppendItem(self.Mailbox["Bootstrap Configuration"], lv3)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1179
        #   Children of Standard Configuration
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1180
        self.StandardConfig = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1181
        for lv3 in ["Receive Offset", "Receive Size", "Send Offset", "Send Size"]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1182
            self.StandardConfig[lv3] = self.Tree.AppendItem(self.Mailbox["Standard Configuration"], lv3)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1183
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1184
        # Expand Tree
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1185
        for tree in [self.Root,
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1186
                     self.Level1Nodes["Config Data"],
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1187
                     self.Level1Nodes["Device Identity"],
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1188
                     self.Level1Nodes["Mailbox"],
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1189
                     self.Mailbox["Bootstrap Configuration"],
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1190
                     self.Mailbox["Standard Configuration"]]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1191
            self.Tree.Expand(tree)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1192
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1193
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1194
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1195
#                         For Hex View Panel
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1196
#            shows EEPROM binary as hex data and characters.
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1197
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1198
class HexView(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1199
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1200
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1201
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1202
        @param parent: Reference to the parent EtherCATManagementTreebook class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1203
        @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
  1204
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1205
        wx.Panel.__init__(self, parent, -1)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1206
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1207
        self.Controler = controler
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
        self.HexRow = 8
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1210
        self.HexCol = 17
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1211
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1212
        self.HexViewSizer = {"view": wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10),
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1213
                             "siiButton": wx.BoxSizer()}
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1214
        self.HexViewButton = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1215
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1216
        for key, evt_handler in [
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1217
                ("Sii Upload", self.OnButtonSiiUpload),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1218
                ("Sii Download", self.OnButtonSiiDownload),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1219
                ("Write to File", self.OnButtonWriteToBinFile),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1220
                ("Read from File", self.OnButtonReadFromBinFile),
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1221
                ("XML to EEPROM Image", self.OnButtonXmlToEEPROMImg)]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1222
            self.HexViewButton[key] = wx.Button(self, -1, key)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1223
            self.HexViewButton[key].Bind(wx.EVT_BUTTON, evt_handler)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1224
            self.HexViewSizer["siiButton"].Add(self.HexViewButton[key])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1225
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1226
        self.SiiBinary = self.Controler.CommonMethod.XmlToEeprom()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1227
        self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1228
        self.SiiGrid = SiiGridTable(self, self.Controler, self.HexRow, self.HexCol)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1229
        self.HexViewSizer["view"].AddMany([self.HexViewSizer["siiButton"], self.SiiGrid])
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1230
        self.SiiGrid.CreateGrid(self.HexRow, self.HexCol)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1231
        self.SetSizer(self.HexViewSizer["view"])
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1232
        self.HexViewSizer["view"].FitInside(self.parent.parent)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1233
        self.parent.parent.FitInside()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1234
        self.SiiGrid.SetValue(self.HexCode)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1235
        self.SiiGrid.Update()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1236
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1237
    def UpdateSiiGridTable(self, row, col):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1238
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1239
        Destroy existing grid and recreate
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1240
        @param row, col : Hex View grid size
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1241
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1242
        self.HexViewSizer["view"].Detach(self.SiiGrid)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1243
        self.SiiGrid.Destroy()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1244
        self.SiiGrid = SiiGridTable(self, self.Controler, row, col)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1245
        self.HexViewSizer["view"].Add(self.SiiGrid)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1246
        self.SiiGrid.CreateGrid(row, col)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1247
        self.SetSizer(self.HexViewSizer["view"])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1248
        self.HexViewSizer["view"].FitInside(self.parent.parent)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1249
        self.parent.parent.FitInside()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1250
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1251
    def OnButtonSiiUpload(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1252
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1253
        Load EEPROM data from slave and refresh Hex View grid
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1254
        Binded to 'Sii Upload' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1255
        @param event : wx.EVT_BUTTON object
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1256
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1257
        # Check whether beremiz connected or not.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1258
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1259
        if check_connect_flag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1260
            # load from EEPROM data and parsing
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1261
            self.SiiBinary = self.Controler.CommonMethod.LoadData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1262
            self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1263
            self.UpdateSiiGridTable(self.HexRow, self.HexCol)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1264
            self.SiiGrid.SetValue(self.HexCode)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1265
            self.SiiGrid.Update()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1266
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1267
    def OnButtonSiiDownload(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1268
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1269
        Write current EEPROM data to slave and refresh data structure kept by master
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1270
        Binded to 'Sii Download' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1271
        @param event : wx.EVT_BUTTON object
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1272
        """
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1273
        # Check whether beremiz connected or not,
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1274
        # and whether status is "Started" or not.
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1275
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1276
        if check_connect_flag:
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1277
            status, _log_count = self.Controler.GetCTRoot()._connector.GetPLCstatus()
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1278
            if status is not "Started":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1279
                self.Controler.CommonMethod.SiiWrite(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1280
                self.Controler.CommonMethod.Rescan()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1281
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1282
    def OnButtonWriteToBinFile(self, event):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1283
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1284
        Save current EEPROM data to binary file through FileDialog
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1285
        Binded to 'Write to File' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1286
        @param event : wx.EVT_BUTTON object
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1287
        """
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1288
        dialog = wx.FileDialog(self, _("Save as..."), os.getcwd(), "slave0.bin",
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
  1289
                               _("bin files (*.bin)|*.bin|All files|*.*"), wx.SAVE | wx.OVERWRITE_PROMPT)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1290
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1291
        if dialog.ShowModal() == wx.ID_OK:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1292
            filepath = dialog.GetPath()
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1293
            binfile = open(filepath, "wb")
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1294
            binfile.write(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1295
            binfile.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1296
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1297
        dialog.Destroy()
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1298
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1299
    def OnButtonReadFromBinFile(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1300
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1301
        Load binary file through FileDialog
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1302
        Binded to 'Read from File' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1303
        @param event : wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1304
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1305
        dialog = wx.FileDialog(self, _("Choose a binary file"), os.getcwd(), "",
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1306
                               _("bin files (*.bin)|*.bin"), wx.OPEN)
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
        if dialog.ShowModal() == wx.ID_OK:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1309
            filepath = dialog.GetPath()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1310
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1311
            try:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1312
                binfile = open(filepath, "rb")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1313
                self.SiiBinary = binfile.read()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1314
                self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1315
                self.UpdateSiiGridTable(self.HexRow, self.HexCol)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1316
                self.SiiGrid.SetValue(self.HexCode)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1317
                self.SiiGrid.Update()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1318
            except Exception:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1319
                self.Controler.CommonMethod.CreateErrorDialog('The file does not exist!')
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1320
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1321
        dialog.Destroy()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1322
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1323
    def OnButtonXmlToEEPROMImg(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1324
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1325
        Create EEPROM data based XML data that current imported
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1326
        Binded to 'XML to EEPROM' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1327
        @param event : wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1328
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1329
        self.SiiBinary = self.Controler.CommonMethod.XmlToEeprom()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1330
        self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1331
        self.UpdateSiiGridTable(self.HexRow, self.HexCol)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1332
        self.SiiGrid.SetValue(self.HexCode)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1333
        self.SiiGrid.Update()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1334
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1335
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1336
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1337
#                    For Hex View grid (fill hex data)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1338
# -------------------------------------------------------------------------------
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1339
class SiiGridTable(wx.grid.Grid):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1340
    def __init__(self, parent, controler, row, col):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1341
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1342
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1343
        @param parent: Reference to the parent HexView class
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1344
        @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
  1345
        @param row, col: Hex View grid size
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
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1348
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1349
        self.Row = row
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1350
        self.Col = col
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1351
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1352
        wx.grid.Grid.__init__(self, parent, -1, size=(830, 450),
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
  1353
                              style=wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1355
    def SetValue(self, value):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1356
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1357
        Set data in the table
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1358
        @param value: EEPROM data list of which element is 1 Byte hex data
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1359
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1360
        # set label name and size
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1361
        self.SetRowLabelSize(100)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1362
        for col in range(self.Col):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1363
            if col == 16:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1364
                self.SetColLabelValue(16, "Text View")
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1365
                self.SetColSize(16, (self.GetSize().x-120)*4/20)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1366
            else:
2358
8e5a9830867e cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
  1367
                self.SetColLabelValue(col, '%s' % col)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1368
                self.SetColSize(col, (self.GetSize().x-120)/20)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1369
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1370
        # set data into table
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1371
        row = col = 0
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1372
        for row_idx in value:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1373
            col = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1374
            self.SetRowLabelValue(row, "0x"+"{:0>4x}".format(row*(self.Col-1)))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1375
            for hex in row_idx:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1376
                self.SetCellValue(row, col, hex)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1377
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1378
                if col == 16:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1379
                    self.SetCellAlignment(row, col, wx.ALIGN_LEFT, wx.ALIGN_CENTER)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1380
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1381
                    self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTER)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1382
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1383
                self.SetReadOnly(row, col, True)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1384
                col = col + 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1385
            row = row + 1
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1386
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1387
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1388
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1389
#                    For Register Access Panel
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1390
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1391
class RegisterAccessPanel(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1392
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1393
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1394
        Constructor
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1395
        @param parent: EEPROMAccessPanel object
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1396
        @param controler: _EthercatSlaveCTN class in EthercatSlave.py
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1397
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1398
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1399
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1400
        self.__init_data()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1401
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1402
        wx.Panel.__init__(self, parent, -1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1403
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1404
        sizer = wx.FlexGridSizer(cols=1, hgap=20, rows=2, vgap=5)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1405
        button_sizer = wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=10)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1406
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1407
        self.ReloadButton = wx.Button(self, -1, "Reload")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1408
        self.CompactViewCheckbox = wx.CheckBox(self, -1, "Compact View")
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1409
        self.RegisterNotebook = RegisterNotebook(self, self.Controler)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1410
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1411
        button_sizer.AddMany([self.ReloadButton, self.CompactViewCheckbox])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1412
        sizer.AddMany([button_sizer, self.RegisterNotebook])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1413
        self.SetSizer(sizer)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1414
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1415
        self.ReloadButton.Bind(wx.EVT_BUTTON, self.OnReloadButton)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1416
        self.CompactViewCheckbox.Bind(wx.EVT_CHECKBOX, self.ToggleCompactViewCheckbox)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1417
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1418
        for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1419
            self.RegisterNotebook.RegPage[index].MainTable.CreateGrid(self.MainRow[index], self.MainCol)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1420
            self.RegisterNotebook.RegPage[index].MainTable.SetValue(self, 0, index*512, (index+1)*512)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1421
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1422
        # data default setting
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1423
        if self.Controler.CommonMethod.RegData == "":
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1424
            self.CompactViewCheckbox.Disable()
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1425
            for index in range(4):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1426
                self.RegisterNotebook.RegPage[index].MainTable.SetValue(self, 0, index*512, (index+1)*512)
2361
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
  1427
        else:  # If data was saved,
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1428
            self.BasicSetData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1429
            self.ParseData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1430
            for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1431
                self.RegisterNotebook.RegPage[index].MainTable.SetValue(self, self.RegMonitorData, index*512, (index+1)*512)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1432
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1433
    def __init_data(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1434
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1435
        Declare initial data.
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1436
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1437
        # flag for compact view
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1438
        self.CompactFlag = False
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1439
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1440
        # main grid의 rows and cols
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1441
        self.MainRow = [512, 512, 512, 512]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1442
        self.MainCol = 4
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1443
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1444
        # main grids' data range
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1445
        self.PageRange = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1446
        for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1447
            self.PageRange.append([512*index, 512*(index+1)])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1448
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1449
        #  Previous value of register data for register description configuration
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1450
        self.PreRegSpec = {"ESCType": "",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1451
                           "FMMUNumber": "",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1452
                           "SMNumber": "",
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1453
                           "PDIType": ""}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1454
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1455
    def LoadData(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1456
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1457
        Get data from the register.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1458
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1459
        self.Controler.CommonMethod.RegData = ""
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1460
        # ethercat reg_read
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1461
        # ex : ethercat reg_read -p 0 0x0000 0x0001
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1462
        # return value : 0x11
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1463
        for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1464
            self.Controler.CommonMethod.RegData = self.Controler.CommonMethod.RegData + " " + self.Controler.CommonMethod.RegRead("0x"+"{:0>4x}".format(index*1024), "0x0400")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1465
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1466
        # store previous value
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1467
        # (ESC type, port number of FMMU, port number of SM, and PDI type))
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1468
        for reg_spec in ["ESCType", "FMMUNumber", "SMNumber", "PDIType"]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1469
            self.PreRegSpec[reg_spec] = self.Controler.CommonMethod.CrtRegSpec[reg_spec]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1470
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1471
        # update registers' description
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1472
        # (ESC type, port number of FMMU, port number of SM, and PDI type)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1473
        for reg_spec, address in [("ESCType", "0x0000"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1474
                                  ("FMMUNumber", "0x0004"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1475
                                  ("SMNumber", "0x0005"),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1476
                                  ("PDIType", "0x0140")]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1477
            self.Controler.CommonMethod.CrtRegSpec[reg_spec] = self.Controler.CommonMethod.RegRead(address, "0x0001")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1478
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1479
        # Enable compactView checkbox
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1480
        self.CompactViewCheckbox.Enable()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1481
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1482
    def BasicSetData(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1483
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1484
        Get and save the description of registers.
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1485
        It's done by parsing register_information.xml.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1486
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1487
        # parse the above register's value
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1488
        # If the value is 0x12, the result is 12
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1489
        self.ESCType = self.Controler.CommonMethod.CrtRegSpec["ESCType"].split('x')[1]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1490
        self.PDIType = self.Controler.CommonMethod.CrtRegSpec["PDIType"].split('x')[1]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1491
        # If the value is 0x12, the result is 18 (It's converted to decimal value)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1492
        self.FMMUNumber = int(self.Controler.CommonMethod.CrtRegSpec["FMMUNumber"], 16)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1493
        self.SMNumber = int(self.Controler.CommonMethod.CrtRegSpec["SMNumber"], 16)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1494
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1495
        # initialize description dictionary of register main table and register sub table.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1496
        self.RegisterDescriptionDict = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1497
        self.RegisterSubGridDict = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1498
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1499
        # ./EthercatMaster/register_information.xml contains register description.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1500
        if wx.Platform == '__WXMSW__':
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1501
            reg_info_file = open("../../EthercatMaster/register_information.xml", 'r')
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1502
        else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1503
            reg_info_file = open("./EthercatMaster/register_information.xml", 'r')
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1504
        reg_info_tree = minidom.parse(reg_info_file)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1505
        reg_info_file.close()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1506
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1507
        # parse register description
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1508
        for register_info in reg_info_tree.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1509
            for register in register_info.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1510
                if register.nodeType == reg_info_tree.ELEMENT_NODE and register.nodeName == "Register":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1511
                    # If it depends on the property(ESC type, PDI type, FMMU number, SM number)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1512
                    for property, type, value in [("esc", "type", self.ESCType),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1513
                                                  ("pdi", "type", self.PDIType),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1514
                                                  ("fmmu", "number", self.FMMUNumber),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1515
                                                  ("sm", "number", self.SMNumber)]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1516
                        if property in register.attributes.keys():
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1517
                            if type == "type":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1518
                                if register.attributes[property].value == value:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1519
                                    self.GetRegisterInfo(reg_info_tree, register)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1520
                                    break
2361
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
  1521
                            else:  # type == "number"
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1522
                                if register.attributes[property].value < value:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1523
                                    self.GetRegisterInfo(reg_info_tree, register)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1524
                                    break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1525
                        else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1526
                            self.GetRegisterInfo(reg_info_tree, register)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1527
                            break
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1528
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1529
    def GetRegisterInfo(self, reg_info_tree, register):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1530
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1531
        Save the register's description into the dictionary.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1532
        reg_info_tree is based on the register_information.xml.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1533
        @param reg_info_tree: XML tree
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1534
        @param register: register which you want to get the description
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1535
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1536
        # temporary variables for register main table idescription dictionary
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1537
        reg_index = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1538
        reg_main_description = ""
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1539
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1540
        for data in register.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1541
            if data.nodeType == reg_info_tree.ELEMENT_NODE and data.nodeName == "Index":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1542
                for index in data.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1543
                    reg_index = index.nodeValue
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1544
            if data.nodeType == reg_info_tree.ELEMENT_NODE and data.nodeName == "Description":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1545
                for description in data.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1546
                    reg_main_description = description.nodeValue
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1547
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1548
            # Add description for register main table
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1549
            if reg_index is not "" and reg_main_description is not "":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1550
                self.RegisterDescriptionDict[reg_index] = reg_main_description
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1551
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1552
            if data.nodeType == reg_info_tree.ELEMENT_NODE and data.nodeName == "Details":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1553
                # declare register sub table description dictionary about this index
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1554
                self.RegisterSubGridDict[reg_index] = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1555
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1556
                for detail in data.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1557
                    if detail.nodeType == reg_info_tree.ELEMENT_NODE and detail.nodeName == "Detail":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1558
                        # If it depends on the property(ESC type, PDI type, FMMU number, SM number)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1559
                        for property, type, value in [("esc", "type", self.ESCType),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1560
                                                      ("pdi", "type", self.PDIType),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1561
                                                      ("fmmu", "number", self.FMMUNumber),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1562
                                                      ("sm", "number", self.SMNumber)]:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1563
                            if property in detail.attributes.keys():
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1564
                                if type == "type":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1565
                                    if detail.attributes[property].value == value:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1566
                                        self.GetRegisterDetailInfo(reg_info_tree, reg_index, detail)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1567
                                        break
2361
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
  1568
                                else:  # type == "number"
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1569
                                    if detail.attributes[property].value < value:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1570
                                        self.GetRegisterDetailInfo(reg_info_tree, reg_index, detail)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1571
                                        break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1572
                            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1573
                                self.GetRegisterDetailInfo(reg_info_tree, reg_index, detail)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1574
                                break
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1575
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1576
    def GetRegisterDetailInfo(self, reg_info_tree, reg_index, detail):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1577
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1578
        Get the resgister's detailed description(for sub table) from the reg_info_tree.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1579
        @param reg_info_tree: XML tree (register_information.xml)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1580
        @param reg_index: index of the register
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1581
        @param detail: description of the register
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1582
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1583
        # temporary variables for register sub table description dictionary
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1584
        # - It is initialized in every sub description
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1585
        reg_bit_range = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1586
        reg_sub_description = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1587
        reg_enum_dictionary = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1588
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1589
        for detail_data in detail.childNodes:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1590
            if detail_data.nodeType == reg_info_tree.ELEMENT_NODE and detail_data.nodeName == "Range":
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1591
                for range in detail_data.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1592
                    reg_bit_range = range.nodeValue
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1593
            if detail_data.nodeType == reg_info_tree.ELEMENT_NODE and detail_data.nodeName == "Description":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1594
                for description in detail_data.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1595
                    reg_sub_description = description.nodeValue
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1596
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1597
            if detail_data.nodeType == reg_info_tree.ELEMENT_NODE and detail_data.nodeName == "Enum":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1598
                for enum in detail_data.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1599
                    if enum.nodeType == reg_info_tree.ELEMENT_NODE and enum.nodeName == "item":
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1600
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1601
                        # temporary variables for a description of each value
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1602
                        # For example, if the bit is 1, it is 'enabled'('On', 'True', etc.),
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1603
                        # otherwise 'disabled'('Off', 'False', etc.).
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1604
                        reg_sub_value = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1605
                        reg_sub_value_description = ""
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1606
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1607
                        for item in enum.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1608
                            if item.nodeType == reg_info_tree.ELEMENT_NODE and item.nodeName == "value":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1609
                                for value in item.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1610
                                    reg_sub_value = value.nodeValue
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1611
                            if item.nodeType == reg_info_tree.ELEMENT_NODE and item.nodeName == "Description":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1612
                                for description in item.childNodes:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1613
                                    reg_sub_value_description = description.nodeValue
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1614
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1615
                            # Add a description of each value to register enum dictionary
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1616
                            if reg_sub_value is not "" and reg_sub_value_description is not "":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1617
                                reg_enum_dictionary[reg_sub_value] = reg_sub_value_description
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1618
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1619
        # add a description to register sub table description dictionary
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1620
        if reg_bit_range is not "" and reg_sub_description is not "":
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1621
            self.RegisterSubGridDict[reg_index].append([reg_bit_range,
2380
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1622
                                                        reg_sub_description,
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1623
                                                        reg_enum_dictionary])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1624
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1625
    def ParseData(self):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1626
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1627
        Transform the data into dec, hex, string, and description
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1628
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1629
        row_data = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1630
        self.RegMonitorData = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1631
        reg_word = ""
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1632
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1633
        reg_data = self.Controler.CommonMethod.RegData.split()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1634
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1635
        # loop for register(0x0000:0x0fff)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1636
        for address in range(0x1000):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1637
            # arrange 2 Bytes of register data
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1638
            reg_word = reg_data[address].split('x')[1] + reg_word
2358
8e5a9830867e cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2356
diff changeset
  1639
            if (address % 2) == 1:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1640
                # append address
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1641
                hex_address = "{:0>4x}".format(address-1)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1642
                row_data.append(hex_address)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1643
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1644
                # append description
2377
88a9d64560d3 clean etherlab: pep8, W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2375
diff changeset
  1645
                if hex_address in self.RegisterDescriptionDict:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1646
                    row_data.append(self.RegisterDescriptionDict[hex_address])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1647
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1648
                    row_data.append("")
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1649
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1650
                # append Decimal value
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1651
                row_data.append(str(int(reg_word, 16)))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1652
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1653
                # append Hex value
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1654
                row_data.append('0x'+reg_word)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1655
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1656
                # append ASCII value
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1657
                char_data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1658
                for iter in range(2):
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  1659
                    if int(reg_word[iter*2:iter*2+2], 16) >= 32 and int(reg_word[iter*2:iter*2+2], 16) <= 126:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1660
                        char_data = char_data + chr(int(reg_word[iter*2:iter*2+2], 16))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1661
                    else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1662
                        char_data = char_data + "."
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1663
                row_data.append(char_data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1664
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1665
                self.RegMonitorData.append(row_data)
2361
5d6ce74f7835 cleanup etherlab: pep8, E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2360
diff changeset
  1666
                reg_word = ""  # initialize regWord
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1667
                row_data = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1668
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1669
    def OnReloadButton(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1670
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1671
        Handle the click event of the 'Reload' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1672
        Get the data from registers again, and update the table.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1673
        @param event: wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1674
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1675
        # Check whether beremiz connected or not.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1676
        check_connect_flag = self.Controler.CommonMethod.CheckConnect(False)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1677
        if check_connect_flag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1678
            self.LoadData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1679
            self.BasicSetData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1680
            self.ParseData()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1681
            # set data into UI
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1682
            if self.CompactFlag:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1683
                self.ToggleCompactViewCheckbox(True)
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  1684
            else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1685
                for index in range(4):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1686
                    self.RegisterNotebook.RegPage[index].UpdateMainTable(self.MainRow[index], self.MainCol,
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1687
                                                                         self.PageRange[index][0], self.PageRange[index][1],
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1688
                                                                         self.RegMonitorData)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1689
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1690
    def ToggleCompactViewCheckbox(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1691
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1692
        Handles the event of the 'Compact view' check box.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1693
        If it's checked, show only the registers that have a description.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1694
        If not, show all the registers.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1695
        @param event: wx.EVT_CHECKBOX object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1696
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1697
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1698
        # If "Compact View" Checkbox is True
2385
f2a53fa6e5d7 clean etherlab: pep8, E266 too many leading '#' for block comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2384
diff changeset
  1699
        # 'event' is argument of this method or event of checkbox.
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
  1700
        if event is True or event.GetEventObject().GetValue():
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1701
            self.CompactFlag = True
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1702
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1703
            reg_compact_data = []
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1704
            page_row = [0, 0, 0, 0]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1705
            for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1706
                self.PageRange[index] = [0, 0]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1707
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1708
            for reg_row_data in self.RegMonitorData:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1709
                if reg_row_data[1] is not "":
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1710
                    # data structure for "compact view"
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1711
                    reg_compact_data.append(reg_row_data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1712
                    # count for each register notebooks' row
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1713
                    # It compare with register's address.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1714
                    for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1715
                        if int('0x'+reg_row_data[0], 16) < (index+1)*1024:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1716
                            page_row[index] += 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1717
                            break
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1718
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1719
            # Setting tables' rows and cols, range for compact view
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1720
            for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1721
                self.MainRow[index] = page_row[index]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1722
                self.PageRange[index][1] = page_row[index]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1723
                for iter in range(index):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1724
                    self.PageRange[index][0] += page_row[iter]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1725
                    self.PageRange[index][1] += page_row[iter]
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1726
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1727
            # Update table
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1728
            for index in range(4):
2380
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1729
                self.RegisterNotebook.RegPage[index].UpdateMainTable(
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1730
                    self.MainRow[index],
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1731
                    self.MainCol,
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1732
                    self.PageRange[index][0],
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1733
                    self.PageRange[index][1],
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1734
                    reg_compact_data)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1735
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1736
        # Compact View Checkbox is False
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1737
        else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1738
            self.CompactFlag = False
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1739
            # Setting original rows, cols and range
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1740
            self.MainRow = [512, 512, 512, 512]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1741
            self.PageRange = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1742
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1743
            for index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1744
                self.PageRange.append([512*index, 512*(index+1)])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1745
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1746
            # Update table
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1747
            for index in range(4):
2380
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1748
                self.RegisterNotebook.RegPage[index].UpdateMainTable(
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1749
                    self.MainRow[index],
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1750
                    self.MainCol,
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1751
                    self.PageRange[index][0],
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1752
                    self.PageRange[index][1],
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  1753
                    self.RegMonitorData)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1754
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1755
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1756
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1757
#                    For Register Access Notebook (divide index range)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1758
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1759
class RegisterNotebook(wx.Notebook):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1760
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1761
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1762
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1763
        @param parent: RegisterAccessPanel object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1764
        @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
  1765
        """
2366
d635680e4c2c cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2365
diff changeset
  1766
        wx.Notebook.__init__(self, parent, id=-1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1767
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1768
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1769
        self.Controler = controler
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1770
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1771
        # Initialize pages
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1772
        self.RegPage = []
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1773
        pages = 4
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1774
        for dummy in range(pages):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1775
            self.RegPage.append(None)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1776
2406
ffd091b51cd0 clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2405
diff changeset
  1777
        for index in range(pages):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1778
            self.RegPage[index] = RegisterNotebookPanel(self, self.Controler,
2381
1c40e3976cc2 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2380
diff changeset
  1779
                                                        parent.MainRow[index], parent.MainCol)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1780
            self.AddPage(self.RegPage[index],
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1781
                         "0x"+"{:0>4x}".format(index*1024)+" - 0x"+"{:0>4x}".format((index+1)*1024-1))
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1782
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1783
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1784
# -------------------------------------------------------------------------------
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1785
#                    For Register Access Notebook Panel
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1786
#                  (Main UI : including main, sub table)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1787
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1788
class RegisterNotebookPanel(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1789
    def __init__(self, parent, controler, row, col):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1790
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1791
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1792
        @param parent: RegisterAccessPanel object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1793
        @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
  1794
        @param row, col: size of the table
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1795
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1796
        wx.Panel.__init__(self, parent, -1)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1797
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1798
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1799
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1800
        self.Row = row
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1801
        self.Col = col
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1802
        sub_row = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1803
        sub_col = 4
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1804
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1805
        self.Sizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=30)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1806
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1807
        self.MainTable = RegisterMainTable(self, self.Row, self.Col, self.Controler)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1808
        self.SubTable = RegisterSubTable(self, sub_row, sub_col)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1809
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1810
        self.SubTable.CreateGrid(sub_row, sub_col)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1811
        self.SubTable.SetValue(self, [])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1812
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1813
        self.Sizer.AddMany([self.MainTable, self.SubTable])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1814
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1815
        self.SetSizer(self.Sizer)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1816
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1817
    def UpdateMainTable(self, row, col, low_index, high_index, data):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1818
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1819
        Updates main table.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1820
        It's done by deleting the main table and creating it again.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1821
        @param row, col: size of the table
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1822
        @param low_index: the lowest index of the page
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1823
        @param high_index: the highest index of the page
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1824
        @param data: data
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1825
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1826
        self.MainTable.Destroy()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1827
        self.MainTable = RegisterMainTable(self, row, col, self.Controler)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1828
        self.Sizer.Detach(self.SubTable)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1829
        self.Sizer.AddMany([self.MainTable, self.SubTable])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1830
        self.SetSizer(self.Sizer)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1831
        self.MainTable.CreateGrid(row, col)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1832
        self.MainTable.SetValue(self, data, low_index, high_index)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1833
        self.MainTable.Update()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1834
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1835
    def UpdateSubTable(self, row, col, data):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1836
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1837
        Updates sub table.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1838
        It's done by deleting the sub table and creating it again.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1839
        @param row, col: size of the table
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1840
        @param data: data
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1841
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1842
        self.SubTable.Destroy()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1843
        self.SubTable = RegisterSubTable(self, row, col)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1844
        self.Sizer.Detach(self.MainTable)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1845
        self.Sizer.AddMany([self.MainTable, self.SubTable])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1846
        self.Sizer.Layout()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1847
        self.SetSizer(self.Sizer)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1848
        self.SubTable.CreateGrid(row, col)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1849
        self.SubTable.SetValue(self, data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1850
        self.SubTable.Update()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1851
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1852
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1853
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1854
#                    For Register Access Notebook Panel (Main Table)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  1855
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1856
class RegisterMainTable(wx.grid.Grid):
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1857
    def __init__(self, parent, row, col, controler):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1858
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1859
            Constructor
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1860
            @param parent: RegisterNotebook object
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1861
            @param row, col: size of the table
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1862
            @param controler: _EthercatSlaveCTN class in EthercatSlave.py
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1863
            """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1864
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1865
        self.Data = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1866
        self.Row = row
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1867
        self.Col = col
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1868
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1869
        self.RegisterAccessPanel = self.parent.parent.parent
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1870
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  1871
        wx.grid.Grid.__init__(self, parent, -1, size=(820, 300),
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
  1872
                              style=wx.EXPAND | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1873
2389
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
  1874
        for evt, mapping_method in [(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnSelectCell),
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
  1875
                                    (wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnSelectCell),
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
  1876
                                    (wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.OnRegModifyDialog)]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1877
            self.Bind(evt, mapping_method)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1878
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1879
    def SetValue(self, parent, reg_monitor_data, low_index, high_index):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1880
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1881
            Set the RegMonitorData into the main table.
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1882
            @param parent: RegisterNotebook object
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1883
            @param reg_monitor_data: data
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1884
            @param low_index: the lowest index of the page
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1885
            @param high_index: the highest index of the page
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1886
            """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1887
        self.RegMonitorData = reg_monitor_data
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1888
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1889
        # set label name and size
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1890
        register_maintable_label = [(0, "Description"), (1, "Dec"),
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1891
                                    (2, "Hex"), (3, "Char")]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1892
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1893
        for (index, label) in register_maintable_label:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1894
            self.SetColLabelValue(index, label)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1895
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1896
        self.SetColSize(0, 200)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1897
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1898
        # if reg_monitor_data is 0, it is initialization of register access.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1899
        if reg_monitor_data == 0:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1900
            return 0
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1901
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1902
        # set data into UI
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1903
        row = col = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1904
        for row_index in reg_monitor_data[low_index:high_index]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1905
            col = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1906
            self.SetRowLabelValue(row, row_index[0])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1907
            for data_index in range(4):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1908
                self.SetCellValue(row, col, row_index[data_index+1])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1909
                self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTER)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1910
                self.SetReadOnly(row, col, True)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1911
                col = col + 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1912
            row = row + 1
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1913
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1914
    def OnSelectCell(self, event):
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1915
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1916
            Handles the event of the cell of the main table.
2389
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
  1917
            @param event: wx.grid object (left click)
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1918
            """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1919
        # if reg_monitor_data is 0, it is initialization of register access.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1920
        if self.RegMonitorData == 0:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1921
            event.Skip()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1922
            return 0
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1923
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1924
        sub_row = 0
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1925
        sub_col = 4
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1926
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1927
        address = self.GetRowLabelValue(event.GetRow())
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1928
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1929
        reg_sub_grid_data = []
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1930
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1931
        BIT_RANGE, NAME, DESCRIPTIONS = range(3)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1932
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1933
        # Check if this register's detail description is exist or not,
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1934
        # and create data structure for the detail description table ; sub grid
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1935
        if address in self.RegisterAccessPanel.RegisterSubGridDict:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1936
            for element in self.RegisterAccessPanel.RegisterSubGridDict[address]:
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  1937
                row_data = []
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1938
                row_data.append(element[BIT_RANGE])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1939
                row_data.append(element[NAME])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1940
                bin_data = "{:0>16b}".format(int(self.GetCellValue(event.GetRow(), 1)))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1941
                value_range = element[BIT_RANGE].split('-')
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1942
                value = (bin_data[8:16][::-1]+bin_data[0:8][::-1])[int(value_range[0]):(int(value_range[-1])+1)][::-1]
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1943
                row_data.append(str(int(('0b'+str(value)), 2)))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1944
                if value in element[DESCRIPTIONS]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1945
                    row_data.append(element[DESCRIPTIONS][value])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1946
                else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1947
                    row_data.append('')
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1948
                reg_sub_grid_data.append(row_data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1949
                sub_row = sub_row + 1
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1950
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1951
        self.parent.UpdateSubTable(sub_row, sub_col, reg_sub_grid_data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1952
        # event.Skip() updates UI of selecting cell
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1953
        event.Skip()
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1954
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1955
    def OnRegModifyDialog(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1956
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1957
        Handle the event of the cell of the main table.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1958
        Display the window where the user modifies the value of the cell.
2389
f86eefc8d378 clean etherlab: pylint, W0404 # reimported module
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2386
diff changeset
  1959
        @param event: wx.grid object (double click)
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  1960
            """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1961
        # user can enter a value in case that user double-clicked 'Dec' or 'Hex' value.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1962
        if event.GetCol() == 1 or event.GetCol() == 2:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1963
            dlg = wx.TextEntryDialog(self, "Enter hex(0xnnnn) or dec(n) value",
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
  1964
                                     "Register Modify Dialog", style=wx.OK | wx.CANCEL)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1965
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1966
            # Setting value in initial dialog value
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1967
            start_value = self.GetCellValue(event.GetRow(), event.GetCol())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1968
            dlg.SetValue(start_value)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1969
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1970
            if dlg.ShowModal() == wx.ID_OK:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1971
                try:
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1972
                    # It int(input) success, this input is dev or hex value.
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1973
                    # Otherwise, it's error, so it goes except.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1974
                    int(dlg.GetValue(), 0)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1975
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1976
                    # reg_write
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1977
                    # ex) ethercat reg_write -p 0 -t uint16 0x0000 0x0000
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1978
                    return_val = self.Controler.CommonMethod.RegWrite('0x'+self.GetRowLabelValue(event.GetRow()), dlg.GetValue())
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1979
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  1980
                    if len(return_val) == 0:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1981
                        # set dec
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1982
                        self.SetCellValue(event.GetRow(), 1, str(int(dlg.GetValue(), 0)))
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1983
                        # set hex
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1984
                        hex_data = '0x'+"{:0>4x}".format(int(dlg.GetValue(), 0))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1985
                        self.SetCellValue(event.GetRow(), 2, hex_data)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1986
                        # set char
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1987
                        char_data = ""
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1988
                        # If hex_data is been able to convert to ascii code, append ascii code.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1989
                        for iter in range(2):
2365
bc07b9910cdb cleanup etherlab: pep8, E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2364
diff changeset
  1990
                            if int(hex_data[(iter+1)*2:(iter+2)*2], 16) >= 32 and int(hex_data[(iter+1)*2:(iter+2)*2], 16) <= 126:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1991
                                char_data = char_data + chr(int(hex_data[(iter+1)*2:(iter+2)*2], 16))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1992
                            else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1993
                                char_data = char_data + "."
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1994
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1995
                        self.SetCellValue(event.GetRow(), 3, char_data)
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1996
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1997
                    else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  1998
                        self.Controler.CommonMethod.CreateErrorDialog('You can\'t modify it. This register is read-only or it\'s not connected.')
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  1999
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2000
                except ValueError:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2001
                    self.Controler.CommonMethod.CreateErrorDialog('You entered wrong value. You can enter dec or hex value only.')
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2002
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2003
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  2004
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2005
#                    For Register Access Notebook Panel (Sub Table)
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  2006
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2007
class RegisterSubTable(wx.grid.Grid):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2008
    def __init__(self, parent, row, col):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2009
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2010
         Constructor
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2011
         @param parent: RegisterNotebook object
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2012
         @param row, col: size of the table
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2013
        """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2014
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2015
        self.Data = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2016
        self.Row = row
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2017
        self.Col = col
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2018
2363
9c7da6ff6a34 cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2361
diff changeset
  2019
        wx.grid.Grid.__init__(self, parent, -1, size=(820, 150),
2367
0fb54172a18b cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2366
diff changeset
  2020
                              style=wx.EXPAND | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2021
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2022
    def SetValue(self, parent, data):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2023
        """
2383
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2024
            Set the data into the subtable.
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2025
            @param parent: RegisterNotebook object
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2026
            @param data: data
6cc3460be285 clean etherlab: pep8, W191 indentation contains tabs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2382
diff changeset
  2027
            """
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2028
        # lset label name and size
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2029
        Register_SubTable_Label = [(0, "Bits"), (1, "Name"),
2380
b35bce45bc5a clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2379
diff changeset
  2030
                                   (2, "Value"), (3, "Enum")]
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2031
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2032
        for (index, label) in Register_SubTable_Label:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2033
            self.SetColLabelValue(index, label)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2034
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2035
        self.SetColSize(1, 200)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2036
        self.SetColSize(3, 200)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2037
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2038
        # set data into table
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2039
        row = col = 0
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2040
        for rowData in data:
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2041
            col = 0
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2042
            for element in rowData:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2043
                self.SetCellValue(row, col, element)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2044
                self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTER)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2045
                self.SetReadOnly(row, col, True)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2046
                col = col + 1
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2047
            row = row + 1
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2048
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2049
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  2050
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2051
#                    For Master State Panel
2356
c26e0c66d8d5 cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2355
diff changeset
  2052
# -------------------------------------------------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2053
class MasterStatePanelClass(wx.Panel):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2054
    def __init__(self, parent, controler):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2055
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2056
        Constructor
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2057
        @param parent: wx.ScrollWindow object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2058
        @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
  2059
        """
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2060
        wx.Panel.__init__(self, parent, -1, (0, 0),
2366
d635680e4c2c cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2365
diff changeset
  2061
                          size=wx.DefaultSize, style=wx.SUNKEN_BORDER)
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2062
        self.Controler = controler
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2063
        self.parent = parent
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2064
        self.StaticBox = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2065
        self.StaticText = {}
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2066
        self.TextCtrl = {}
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2067
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2068
        # ----------------------- Main Sizer and Update Button --------------------------------------------
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  2069
        self.MasterStateSizer = {"main": wx.BoxSizer(wx.VERTICAL)}
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2070
        for key, attr in [
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2071
                ("innerMain",           [1, 10, 2, 10]),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2072
                ("innerTopHalf",        [2, 10, 1, 10]),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2073
                ("innerBottomHalf",     [2, 10, 1, 10]),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2074
                ("innerMasterState",    [2, 10, 3, 10]),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2075
                ("innerDeviceInfo",     [4, 10, 3, 10]),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2076
                ("innerFrameInfo",      [4, 10, 5, 10])]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2077
            self.MasterStateSizer[key] = wx.FlexGridSizer(cols=attr[0], hgap=attr[1], rows=attr[2], vgap=attr[3])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2078
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2079
        self.UpdateButton = wx.Button(self, label=_('Update'))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2080
        self.UpdateButton.Bind(wx.EVT_BUTTON, self.OnButtonClick)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2081
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2082
        for key, label in [
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2083
                ('masterState', 'EtherCAT Master State'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2084
                ('deviceInfo', 'Ethernet Network Card Information'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2085
                ('frameInfo', 'Network Frame Information')]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2086
            self.StaticBox[key] = wx.StaticBox(self, label=_(label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2087
            self.MasterStateSizer[key] = wx.StaticBoxSizer(self.StaticBox[key])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2088
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2089
        # ----------------------- Master State -----------------------------------------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2090
        for key, label in [
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2091
                ('Phase', 'Phase:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2092
                ('Active', 'Active:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2093
                ('Slaves', 'Slave Count:')]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2094
            self.StaticText[key] = wx.StaticText(self, label=_(label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2095
            self.TextCtrl[key] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY)
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2096
            self.MasterStateSizer['innerMasterState'].AddMany([self.StaticText[key], self.TextCtrl[key]])
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2097
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2098
        self.MasterStateSizer['masterState'].AddSizer(self.MasterStateSizer['innerMasterState'])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2099
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2100
        # ----------------------- Ethernet Network Card Information ---------------------------------------
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2101
        for key, label in [
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2102
                ('Main', 'MAC Address:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2103
                ('Link', 'Link State:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2104
                ('Tx frames', 'Tx Frames:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2105
                ('Rx frames', 'Rx Frames:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2106
                ('Lost frames', 'Lost Frames:')]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2107
            self.StaticText[key] = wx.StaticText(self, label=_(label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2108
            self.TextCtrl[key] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2109
            self.MasterStateSizer['innerDeviceInfo'].AddMany([self.StaticText[key], self.TextCtrl[key]])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2110
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2111
        self.MasterStateSizer['deviceInfo'].AddSizer(self.MasterStateSizer['innerDeviceInfo'])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2112
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2113
        # ----------------------- Network Frame Information -----------------------------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2114
        for key, label in [
2379
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2115
                ('Tx frame rate [1/s]', 'Tx Frame Rate [1/s]:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2116
                ('Rx frame rate [1/s]', 'Tx Rate [kByte/s]:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2117
                ('Loss rate [1/s]', 'Loss Rate [1/s]:'),
015b724c30a5 clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2377
diff changeset
  2118
                ('Frame loss [%]', 'Frame Loss [%]:')]:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2119
            self.StaticText[key] = wx.StaticText(self, label=_(label))
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2120
            self.MasterStateSizer['innerFrameInfo'].Add(self.StaticText[key])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2121
            self.TextCtrl[key] = {}
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2122
            for index in ['0', '1', '2']:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2123
                self.TextCtrl[key][index] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2124
                self.MasterStateSizer['innerFrameInfo'].Add(self.TextCtrl[key][index])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2125
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2126
        self.MasterStateSizer['frameInfo'].AddSizer(self.MasterStateSizer['innerFrameInfo'])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2127
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2128
        # --------------------------------- Main Sizer ----------------------------------------------------
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2129
        for key, sub, in [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2130
            ('innerTopHalf', [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2131
                    'masterState', 'deviceInfo']),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2132
            ('innerBottomHalf', [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2133
                    'frameInfo']),
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2134
            ('innerMain', [
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2135
                    'innerTopHalf', 'innerBottomHalf'])]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2136
            for key2 in sub:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2137
                self.MasterStateSizer[key].AddSizer(self.MasterStateSizer[key2])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2138
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2139
        self.MasterStateSizer['main'].AddSizer(self.UpdateButton)
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2140
        self.MasterStateSizer['main'].AddSizer(self.MasterStateSizer['innerMain'])
2355
fec77f2b9e07 cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2354
diff changeset
  2141
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2142
        self.SetSizer(self.MasterStateSizer['main'])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2143
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2144
    def OnButtonClick(self, event):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2145
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2146
        Handle the event of the 'Update' button.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2147
        Update the data of the master state.
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2148
        @param event: wx.EVT_BUTTON object
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2149
        """
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2150
        if self.Controler.GetCTRoot()._connector is not None:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2151
            self.MasterState = self.Controler.CommonMethod.GetMasterState()
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2152
            # Update each TextCtrl
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2153
            if self.MasterState:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2154
                for key in self.TextCtrl:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2155
                    if isinstance(self.TextCtrl[key], dict):
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2156
                        for index in self.TextCtrl[key]:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2157
                            self.TextCtrl[key][index].SetValue(self.MasterState[key][int(index)])
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2158
                    else:
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2159
                        self.TextCtrl[key].SetValue(self.MasterState[key][0])
2375
cfa68a06a24d clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2374
diff changeset
  2160
        else:
2354
9460872f1440 convert some etherlab source files to unix format
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2353
diff changeset
  2161
            self.Controler.CommonMethod.CreateErrorDialog('PLC not connected!')