Edouard@2152: #!/usr/bin/env python Edouard@2152: # -*- coding: utf-8 -*- Edouard@2152: edouard@2165: # This file is part of Beremiz Edouard@2152: # edouard@2165: # Copyright (C) 2013: Real-Time & Embedded Systems (RTES) Lab., University of Seoul Edouard@2152: # edouard@2165: # See COPYING file for copyrights details. Edouard@2152: Edouard@2152: import os Edouard@2152: Edouard@2152: import wx Edouard@2152: import wx.grid Edouard@2152: import wx.gizmos Edouard@2152: import wx.lib.buttons Edouard@2152: Edouard@2152: # -------------------------------------------------------------------- Edouard@2152: from controls import CustomGrid, CustomTable Edouard@2152: # -------------------------------------------------------------------- Edouard@2152: Edouard@2152: # ------------ for SDO Management -------------------- Edouard@2152: import string Edouard@2152: import wx.grid as gridlib Edouard@2152: #------------------------------------------------------------- Edouard@2152: Edouard@2152: # ------------ for register management --------------- Edouard@2152: from xml.dom import minidom Edouard@2152: #------------------------------------------------------------- Edouard@2152: Edouard@2152: # ----------------------------- For Sync Manager Table ----------------------------------- Edouard@2152: def GetSyncManagersTableColnames(): Edouard@2152: """ Edouard@2152: Returns column names of SyncManager Table in Slave state panel. Edouard@2152: """ Edouard@2152: _ = lambda x : x Edouard@2152: return ["#", _("Name"), _("Start Address"), _("Default Size"), _("Control Byte"), _("Enable")] Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # Sync Managers Table Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class SyncManagersTable(CustomTable): Edouard@2152: def GetValue(self, row, col): Edouard@2152: if row < self.GetNumberRows(): Edouard@2152: if col == 0: Edouard@2152: return row Edouard@2152: return self.data[row].get(self.GetColLabelValue(col, False), "") Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # EtherCAT Management Treebook Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class EtherCATManagementTreebook(wx.Treebook): Edouard@2152: def __init__(self, parent, controler, node_editor): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent wx.ScrolledWindow object Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: @param node_editor: Reference to Beremiz frame Edouard@2152: """ Edouard@2152: wx.Treebook.__init__(self, parent, -1, size=wx.DefaultSize, style=wx.BK_DEFAULT) Edouard@2152: self.parent = parent Edouard@2152: self.Controler = controler Edouard@2152: self.NodeEditor = node_editor Edouard@2152: Edouard@2152: self.EtherCATManagementClassObject = {} Edouard@2152: Edouard@2152: # fill EtherCAT Management Treebook Edouard@2152: for pname, pclass, subs in [ Edouard@2152: ("Slave State", SlaveStatePanelClass, []), Edouard@2152: ("SDO Management", SDOPanelClass, []), Edouard@2152: ("PDO Monitoring", PDOPanelClass, []), Edouard@2152: ("ESC Management", EEPROMAccessPanel, [ Edouard@2152: ("Smart View", SlaveSiiSmartView), Edouard@2152: ("Hex View", HexView)]), Edouard@2152: ("Register Access", RegisterAccessPanel, [])]: Edouard@2152: self.AddPage(pclass(self, self.Controler), pname) Edouard@2152: for spname, spclass in subs: Edouard@2152: self.AddSubPage(spclass(self, self.Controler), spname) Edouard@2152: Edouard@2152: self.Bind(wx.EVT_TREEBOOK_PAGE_CHANGED, self.OnPageChanged) Edouard@2152: self.Bind(wx.EVT_TREEBOOK_PAGE_CHANGING, self.OnPageChanging) Edouard@2152: Edouard@2152: def OnPageChanged(self, event): Edouard@2152: old = event.GetOldSelection() Edouard@2152: new = event.GetSelection() Edouard@2152: sel = event.GetSelection() Edouard@2152: event.Skip() Edouard@2152: Edouard@2152: def OnPageChanging(self, event): Edouard@2152: old = event.GetOldSelection() Edouard@2152: new = event.GetSelection() Edouard@2152: sel = event.GetSelection() Edouard@2152: event.Skip() Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For SlaveState Panel Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class SlaveStatePanelClass(wx.Panel): Edouard@2152: def __init__(self, parent, controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent EtherCATManagementTreebook class Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: wx.Panel.__init__(self, parent, -1, (0, 0), size=wx.DefaultSize, style = wx.SUNKEN_BORDER) Edouard@2152: self.Controler = controler Edouard@2152: self.parent = parent Edouard@2152: Edouard@2152: # initialize SlaveStatePanel UI dictionaries Edouard@2152: self.StaticBoxDic = {} Edouard@2152: self.StaticTextDic = {} Edouard@2152: self.TextCtrlDic = {} Edouard@2152: self.ButtonDic = {} Edouard@2152: Edouard@2152: # iniitalize BoxSizer and FlexGridSizer Edouard@2152: self.SizerDic = { Edouard@2152: "SlaveState_main_sizer" : wx.BoxSizer(wx.VERTICAL), Edouard@2152: "SlaveState_inner_main_sizer" : wx.FlexGridSizer(cols=1, hgap=50, rows=3, vgap=10), Edouard@2152: "SlaveInfosDetailsInnerSizer" : wx.FlexGridSizer(cols=4, hgap=10, rows=2, vgap=10), Edouard@2152: "SyncManagerInnerSizer" : wx.FlexGridSizer(cols=1, hgap=5, rows=1, vgap=5), Edouard@2152: "SlaveState_sizer" : wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10), Edouard@2152: "SlaveState_up_sizer" : wx.FlexGridSizer(cols=4, hgap=10, rows=2, vgap=10), Edouard@2152: "SlaveState_down_sizer" : wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=10)} Edouard@2152: Edouard@2152: # initialize StaticBox and StaticBoxSizer Edouard@2152: for box_name, box_label in [ Edouard@2152: ("SlaveInfosDetailsBox", "Slave Informations"), Edouard@2152: ("SyncManagerBox", "Sync Manager"), Edouard@2152: ("SlaveStateBox", "Slave State Transition && Monitoring")]: Edouard@2152: self.StaticBoxDic[box_name] = wx.StaticBox(self, label=_(box_label)) Edouard@2152: self.SizerDic[box_name] = wx.StaticBoxSizer(self.StaticBoxDic[box_name]) Edouard@2152: Edouard@2152: for statictext_name, statictext_label, textctrl_name in [ Edouard@2152: ("VendorLabel", "Vendor:", "vendor"), Edouard@2152: ("ProductcodeLabel", "Product code:", "product_code"), Edouard@2152: ("RevisionnumberLabel", "Slave Count:", "revision_number"), Edouard@2152: ("PhysicsLabel", "Physics:", "physics")]: Edouard@2152: self.StaticTextDic[statictext_name] = wx.StaticText(self, label=_(statictext_label)) Edouard@2152: self.TextCtrlDic[textctrl_name] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY) Edouard@2152: self.SizerDic["SlaveInfosDetailsInnerSizer"].AddMany([self.StaticTextDic[statictext_name], Edouard@2152: self.TextCtrlDic[textctrl_name]]) Edouard@2152: Edouard@2152: self.SizerDic["SlaveInfosDetailsBox"].AddSizer(self.SizerDic["SlaveInfosDetailsInnerSizer"]) Edouard@2152: Edouard@2152: self.SyncManagersGrid = CustomGrid(self, size=wx.Size(605,155), style=wx.VSCROLL) Edouard@2152: Edouard@2152: self.SizerDic["SyncManagerInnerSizer"].Add(self.SyncManagersGrid) Edouard@2152: self.SizerDic["SyncManagerBox"].Add(self.SizerDic["SyncManagerInnerSizer"]) Edouard@2152: Edouard@2152: for button_name, button_id, button_label, button_tooltipstring, event_method, sub_item in [ Edouard@2152: ("InitButton", 0, "INIT", "State Transition to \"Init\" State", self.OnButtonClick, []), Edouard@2152: ("PreOPButton", 1, "PREOP", "State Transition to \"PreOP\" State", self.OnButtonClick, [ Edouard@2152: ("TargetStateLabel", "Target State:" , "TargetState")]), Edouard@2152: ("SafeOPButton", 2, "SAFEOP", "State Transition to \"SafeOP\" State", self.OnButtonClick, []), Edouard@2152: ("OPButton", 3, "OP", "State Transition to \"OP\" State", self.OnButtonClick, [ Edouard@2152: ("CurrentStateLabel", "Current State:", "CurrentState")])]: Edouard@2152: self.ButtonDic[button_name] = wx.Button(self, id=button_id ,label=_(button_label)) Edouard@2152: self.ButtonDic[button_name].Bind(wx.EVT_BUTTON, event_method) Edouard@2152: self.ButtonDic[button_name].SetToolTipString(button_tooltipstring) Edouard@2152: self.SizerDic["SlaveState_up_sizer"].Add(self.ButtonDic[button_name]) Edouard@2152: for statictext_name, statictext_label, textctrl_name in sub_item : Edouard@2152: self.StaticTextDic[statictext_name] = wx.StaticText(self, label=_(statictext_label)) Edouard@2152: self.TextCtrlDic[textctrl_name] = wx.TextCtrl(self, size=wx.DefaultSize, style=wx.TE_READONLY) Edouard@2152: self.SizerDic["SlaveState_up_sizer"].AddMany([self.StaticTextDic[statictext_name], Edouard@2152: self.TextCtrlDic[textctrl_name]]) Edouard@2152: Edouard@2152: for button_name, button_label, button_tooltipstring, event_method in [ Edouard@2152: ("StartTimerButton", "Start State Monitoring", "Slave State Update Restart", self.StartTimer), Edouard@2152: ("StopTimerButton", "Stop State Monitoring", "Slave State Update Stop", self.CurrentStateThreadStop)]: Edouard@2152: self.ButtonDic[button_name] = wx.Button(self, label=_(button_label)) Edouard@2152: self.ButtonDic[button_name].Bind(wx.EVT_BUTTON, event_method) Edouard@2152: self.ButtonDic[button_name].SetToolTipString(button_tooltipstring) Edouard@2152: self.SizerDic["SlaveState_down_sizer"].Add(self.ButtonDic[button_name]) Edouard@2152: Edouard@2152: self.SizerDic["SlaveState_sizer"].AddMany([self.SizerDic["SlaveState_up_sizer"], Edouard@2152: self.SizerDic["SlaveState_down_sizer"]]) Edouard@2152: Edouard@2152: self.SizerDic["SlaveStateBox"].Add(self.SizerDic["SlaveState_sizer"]) Edouard@2152: Edouard@2152: self.SizerDic["SlaveState_inner_main_sizer"].AddMany([ Edouard@2152: self.SizerDic["SlaveInfosDetailsBox"], self.SizerDic["SyncManagerBox"], Edouard@2152: self.SizerDic["SlaveStateBox"]]) Edouard@2152: Edouard@2152: self.SizerDic["SlaveState_main_sizer"].Add(self.SizerDic["SlaveState_inner_main_sizer"]) Edouard@2152: Edouard@2152: self.SetSizer(self.SizerDic["SlaveState_main_sizer"]) Edouard@2152: Edouard@2152: # register a timer for periodic exectuion of slave state update (period: 1000 ms) Edouard@2152: self.Bind(wx.EVT_TIMER, self.GetCurrentState) Edouard@2152: Edouard@2152: self.CreateSyncManagerTable() Edouard@2152: Edouard@2152: self.Centre() Edouard@2152: Edouard@2152: def CreateSyncManagerTable(self): Edouard@2152: """ Edouard@2152: Create grid for "SyncManager" Edouard@2152: """ Edouard@2152: # declare Table object Edouard@2152: self.SyncManagersTable = SyncManagersTable(self, [], GetSyncManagersTableColnames()) Edouard@2152: self.SyncManagersGrid.SetTable(self.SyncManagersTable) Edouard@2152: # set grid alignment attr. (CENTER) Edouard@2152: self.SyncManagersGridColAlignements = [wx.ALIGN_CENTRE, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE, Edouard@2152: wx.ALIGN_CENTRE, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE] Edouard@2152: # set grid size Edouard@2152: self.SyncManagersGridColSizes = [40, 150, 100, 100, 100, 100] Edouard@2152: self.SyncManagersGrid.SetRowLabelSize(0) Edouard@2152: for col in range(self.SyncManagersTable.GetNumberCols()): Edouard@2152: attr = wx.grid.GridCellAttr() Edouard@2152: attr.SetAlignment(self.SyncManagersGridColAlignements[col], wx.ALIGN_CENTRE) Edouard@2152: self.SyncManagersGrid.SetColAttr(col, attr) Edouard@2152: self.SyncManagersGrid.SetColMinimalWidth(col, self.SyncManagersGridColSizes[col]) Edouard@2152: self.SyncManagersGrid.AutoSizeColumn(col, False) Edouard@2152: Edouard@2152: self.RefreshSlaveInfos() Edouard@2152: Edouard@2152: def RefreshSlaveInfos(self): Edouard@2152: """ Edouard@2152: Fill data in "Slave Information" and "SyncManager" Edouard@2152: """ Edouard@2152: slave_infos = self.Controler.GetSlaveInfos() Edouard@2152: sync_manager_section = ["vendor", "product_code", "revision_number", "physics"] Edouard@2152: if slave_infos is not None: Edouard@2152: # this method is same as "TextCtrl.SetValue" Edouard@2152: for textctrl_name in sync_manager_section: Edouard@2152: self.TextCtrlDic[textctrl_name].SetValue(slave_infos[textctrl_name]) Edouard@2152: self.SyncManagersTable.SetData(slave_infos["sync_managers"]) Edouard@2152: self.SyncManagersTable.ResetView(self.SyncManagersGrid) Edouard@2152: else: Edouard@2152: for textctrl_name in sync_manager_section: Edouard@2152: self.TextCtrlDic[textctrl_name].SetValue("") Edouard@2152: self.SyncManagersTable.SetData([]) Edouard@2152: self.SyncManagersTable.ResetView(self.SyncManagersGrid) Edouard@2152: Edouard@2152: def OnButtonClick(self, event): Edouard@2152: """ Edouard@2152: Event handler for slave state transition button click (Init, PreOP, SafeOP, OP button) Edouard@2152: @param event : wx.EVT_BUTTON object Edouard@2152: """ Edouard@2152: check_connect_flag = self.Controler.CommonMethod.CheckConnect(False) Edouard@2152: if check_connect_flag : Edouard@2152: state_dic = ["INIT", "PREOP", "SAFEOP", "OP"] Edouard@2152: Edouard@2152: # If target state is one of {INIT, PREOP, SAFEOP}, request slave state transition immediately. Edouard@2152: if event.GetId() < 3 : Edouard@2152: self.Controler.CommonMethod.RequestSlaveState(state_dic[event.GetId()]) Edouard@2152: self.TextCtrlDic["TargetState"].SetValue(state_dic[event.GetId()]) Edouard@2152: Edouard@2152: # If target state is OP, first check "PLC status". Edouard@2152: # (1) If current PLC status is "Started", then request slave state transition Edouard@2152: # (2) Otherwise, show error message and return Edouard@2152: else : Edouard@2152: status, count = self.Controler.GetCTRoot()._connector.GetPLCstatus() Edouard@2152: if status == "Started" : Edouard@2152: self.Controler.CommonMethod.RequestSlaveState("OP") Edouard@2152: self.TextCtrlDic["TargetState"].SetValue("OP") Edouard@2152: else : Edouard@2152: self.Controler.CommonMethod.CreateErrorDialog("PLC is Not Started") Edouard@2152: Edouard@2152: def GetCurrentState(self, event): Edouard@2152: """ Edouard@2152: Timer event handler for periodic slave state monitoring (Default period: 1 sec = 1000 msec). Edouard@2152: @param event : wx.TIMER object Edouard@2152: """ Edouard@2152: check_connect_flag = self.Controler.CommonMethod.CheckConnect(True) Edouard@2152: if check_connect_flag: Edouard@2152: returnVal = self.Controler.CommonMethod.GetSlaveStateFromSlave() Edouard@2152: line = returnVal.split("\n") Edouard@2152: try : Edouard@2152: self.SetCurrentState(line[self.Controler.GetSlavePos()]) Edouard@2152: except : Edouard@2152: pass Edouard@2152: Edouard@2152: def SetCurrentState(self, line): Edouard@2152: """ Edouard@2152: Show current slave state using the executiob result of "ethercat slaves" command. Edouard@2152: @param line : result of "ethercat slaves" command Edouard@2152: """ Edouard@2152: state_array = ["INIT", "PREOP", "SAFEOP", "OP"] Edouard@2152: try : Edouard@2152: # parse the execution result of "ethercat slaves" command Edouard@2152: # Result example : 0 0:0 PREOP + EL9800 (V4.30) (PIC24, SPI, ET1100) Edouard@2152: token = line.split(" ") Edouard@2152: if token[2] in state_array: Edouard@2152: self.TextCtrlDic["CurrentState"].SetValue(token[2]) Edouard@2152: except : Edouard@2152: pass Edouard@2152: Edouard@2152: def StartTimer(self, event): Edouard@2152: """ Edouard@2152: Event handler for "Start State Monitoring" button. Edouard@2152: - start slave state monitoring thread Edouard@2152: @param event : wx.EVT_BUTTON object Edouard@2152: """ Edouard@2152: self.SlaveStateThread = wx.Timer(self) Edouard@2152: # set timer period (1000 ms) Edouard@2152: self.SlaveStateThread.Start(1000) Edouard@2152: Edouard@2152: def CurrentStateThreadStop(self, event): Edouard@2152: """ Edouard@2152: Event handler for "Stop State Monitoring" button. Edouard@2152: - stop slave state monitoring thread Edouard@2152: @param event : wx.EVT_BUTTON object Edouard@2152: """ Edouard@2152: try: Edouard@2152: self.SlaveStateThread.Stop() Edouard@2152: except: Edouard@2152: pass Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For SDO Management Panel Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class SDOPanelClass(wx.Panel): Edouard@2152: def __init__(self, parent, controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent EtherCATManagementTreebook class Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: wx.Panel.__init__(self, parent, -1) Edouard@2152: Edouard@2152: self.DatatypeDescription, self.CommunicationObject, self.ManufacturerSpecific, \ Edouard@2152: self.ProfileSpecific, self.Reserved, self.AllSDOData = range(6) Edouard@2152: Edouard@2152: self.Controler = controler Edouard@2152: Edouard@2152: self.SDOManagementMainSizer = wx.BoxSizer(wx.VERTICAL) Edouard@2152: self.SDOManagementInnerMainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10) Edouard@2152: Edouard@2152: self.SDOUpdate = wx.Button(self, label=_('update')) Edouard@2152: self.SDOUpdate.Bind(wx.EVT_BUTTON, self.SDOInfoUpdate) Edouard@2152: Edouard@2152: self.CallSDONoteBook = SDONoteBook(self, controler=self.Controler) Edouard@2152: self.SDOManagementInnerMainSizer.Add(self.SDOUpdate) Edouard@2152: self.SDOManagementInnerMainSizer.Add(self.CallSDONoteBook, wx.ALL | wx.EXPAND) Edouard@2152: Edouard@2152: self.SDOManagementMainSizer.Add(self.SDOManagementInnerMainSizer) Edouard@2152: Edouard@2152: self.SetSizer(self.SDOManagementMainSizer) Edouard@2152: Edouard@2152: def SDOInfoUpdate(self, event): Edouard@2152: """ Edouard@2152: Evenet handler for SDO "update" button. Edouard@2152: - Load SDO data from current slave Edouard@2152: @param event : wx.EVT_BUTTON object Edouard@2152: """ Edouard@2152: self.Controler.CommonMethod.SaveSDOData = [] Edouard@2152: self.Controler.CommonMethod.ClearSDODataSet() Edouard@2152: self.SDOFlag = False Edouard@2152: Edouard@2152: # Check whether beremiz connected or not. Edouard@2152: check_connect_flag = self.Controler.CommonMethod.CheckConnect(False) Edouard@2152: if check_connect_flag: Edouard@2152: self.SDOs = self.Controler.CommonMethod.GetSlaveSDOFromSlave() Edouard@2152: # SDOFlag is "False", user click "Cancel" button Edouard@2152: self.SDOFlag = self.SDOParser() Edouard@2152: Edouard@2152: if self.SDOFlag : Edouard@2152: self.CallSDONoteBook.CreateNoteBook() Edouard@2152: self.Refresh() Edouard@2152: Edouard@2152: def SDOParser(self): Edouard@2152: """ Edouard@2152: Parse SDO data set that obtain "SDOInfoUpdate" Method Edouard@2152: @return True or False Edouard@2152: """ Edouard@2152: Edouard@2152: slaveSDO_progress = wx.ProgressDialog("Slave SDO Monitoring", "Now Uploading...", Edouard@2152: maximum = len(self.SDOs.splitlines()), parent=self, Edouard@2152: style = wx.PD_CAN_ABORT | wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | Edouard@2152: wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME | Edouard@2152: wx.PD_AUTO_HIDE | wx.PD_SMOOTH) Edouard@2152: Edouard@2152: # If keep_going flag is False, SDOParser method is stop and return "False". Edouard@2152: keep_going = True Edouard@2152: count = 0 Edouard@2152: Edouard@2152: # SDO data example Edouard@2152: # SDO 0x1000, "Device type" Edouard@2152: # 0x1000:00,r-r-r-,uint32,32 bit,"Device type",0x00020192, 131474 Edouard@2152: for details_line in self.SDOs.splitlines(): Edouard@2152: count += 1 Edouard@2152: line_token = details_line.split("\"") Edouard@2152: # len(line_token[2]) case : SDO 0x1000, "Device type" Edouard@2152: if len(line_token[2]) == 0: Edouard@2152: title_name = line_token[1] Edouard@2152: # else case : 0x1000:00,r-r-r-,uint32,32 bit,"Device type",0x00020192, 131474 Edouard@2152: else : Edouard@2152: # line_token = ['0x1000:00,r-r-r-,uint32,32 bit,', 'Device type', ',0x00020192, 131474'] Edouard@2152: token_head, name, token_tail = line_token Edouard@2152: Edouard@2152: # token_head = ['0x1000:00', 'r-r-r-', 'uint32', '32 bit', ''] Edouard@2152: token_head = token_head.split(",") Edouard@2152: ful_idx, access, type, size, empty = token_head Edouard@2152: # ful_idx.split(":") = ['0x1000', '00'] Edouard@2152: idx, sub_idx = ful_idx.split(":") Edouard@2152: Edouard@2152: # token_tail = ['', '0x00020192', '131474'] Edouard@2152: token_tail = token_tail.split(",") Edouard@2152: try : Edouard@2152: empty, hex_val, dec_val = token_tail Edouard@2152: Edouard@2152: # SDO data is not return "dec value" Edouard@2152: # line example : Edouard@2152: # 0x1702:01,rwr-r-,uint32,32 bit," 1st mapping", ---- Edouard@2152: except : Edouard@2152: empty, hex_val = token_tail Edouard@2152: Edouard@2152: name_after_check = self.StringTest(name) Edouard@2152: Edouard@2152: # convert hex type Edouard@2152: sub_idx = "0x" + sub_idx Edouard@2152: Edouard@2152: if type == "octet_string": Edouard@2152: hex_val = ' ---- ' Edouard@2152: Edouard@2152: # SResult of SlaveSDO data parsing. (data type : dictionary) Edouard@2152: self.Data = {'idx':idx.strip(), 'subIdx':sub_idx.strip(), 'access':access.strip(), Edouard@2152: 'type':type.strip(), 'size':size.strip(), 'name':name_after_check.strip("\""), Edouard@2152: 'value':hex_val.strip(), "category":title_name.strip("\"")} Edouard@2152: Edouard@2152: category_divide_value = [0x1000, 0x2000, 0x6000, 0xa000, 0xffff] Edouard@2152: Edouard@2152: for count in range(len(category_divide_value)) : Edouard@2152: if int(idx, 0) < category_divide_value[count]: Edouard@2152: self.Controler.CommonMethod.SaveSDOData[count].append(self.Data) Edouard@2152: break Edouard@2152: Edouard@2152: self.Controler.CommonMethod.SaveSDOData[self.AllSDOData].append(self.Data) Edouard@2152: Edouard@2152: if count >= len(self.SDOs.splitlines()) / 2: Edouard@2152: (keep_going, skip) = slaveSDO_progress.Update(count, "Please waiting a moment!!") Edouard@2152: else: Edouard@2152: (keep_going, skip) = slaveSDO_progress.Update(count) Edouard@2152: Edouard@2152: # If user click "Cancel" loop suspend immediately Edouard@2152: if (keep_going == False): Edouard@2152: break Edouard@2152: Edouard@2152: slaveSDO_progress.Destroy() Edouard@2152: return keep_going Edouard@2152: Edouard@2152: def StringTest(self, check_string): Edouard@2152: """ Edouard@2152: Test value 'name' is alphanumeric Edouard@2152: @param check_string : input data for check Edouard@2152: @return result : output data after check Edouard@2152: """ Edouard@2152: # string.printable is print this result Edouard@2152: #'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ Edouard@2152: #!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c Edouard@2152: allow_range = string.printable Edouard@2152: result = check_string Edouard@2152: for i in range(0, len(check_string)): Edouard@2152: # string.isalnum() is check whether string is alphanumeric or not Edouard@2152: if check_string[len(check_string)-1-i:len(check_string)-i] in allow_range : Edouard@2152: result = check_string[:len(check_string) - i] Edouard@2152: break Edouard@2152: return result Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For SDO Notebook (divide category) Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class SDONoteBook(wx.Notebook): Edouard@2152: def __init__(self, parent, controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent SDOPanelClass class Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: wx.Notebook.__init__(self, parent, id = -1, size=(850,500)) Edouard@2152: self.Controler = controler Edouard@2152: self.parent = parent Edouard@2152: Edouard@2152: self.CreateNoteBook() Edouard@2152: Edouard@2152: self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGED, self.OnPageChanged) Edouard@2152: self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGING, self.OnPageChanging) Edouard@2152: Edouard@2152: def CreateNoteBook(self): Edouard@2152: """ Edouard@2152: Create each NoteBook page, divided SDO index Edouard@2152: According to EtherCAT Communication(03/2011), 158p Edouard@2152: """ Edouard@2152: self.Data = [] Edouard@2152: count = 1 Edouard@2152: Edouard@2152: page_texts = [("all", self.parent.AllSDOData), Edouard@2152: ("0x0000 - 0x0ff", self.parent.DatatypeDescription), Edouard@2152: ("0x1000 - 0x1fff", self.parent.CommunicationObject), Edouard@2152: ("0x2000 - 0x5fff", self.parent.ManufacturerSpecific), Edouard@2152: ("0x6000 - 0x9fff", self.parent.ProfileSpecific), Edouard@2152: ("0xa000 - 0xffff", self.parent.Reserved)] Edouard@2152: Edouard@2152: page_tooltip_string = ["SDO Index 0x0000 - 0x0fff : Data Type Description", Edouard@2152: "SDO Index 0x1000 - 0x1fff : Communication object", Edouard@2152: "SDO Index 0x2000 - 0x5fff : Manufacturer specific", Edouard@2152: "SDO Index 0x6000 - 0x9fff : Profile specific", Edouard@2152: "SDO Index 0xa000 - 0xffff : Reserved", Edouard@2152: "All SDO Object"] Edouard@2152: Edouard@2152: self.DeleteAllPages() Edouard@2152: Edouard@2152: for txt, count in page_texts: Edouard@2152: self.Data = self.Controler.CommonMethod.SaveSDOData[count] Edouard@2152: self.Win = SlaveSDOTable(self, self.Data) Edouard@2152: self.AddPage(self.Win, txt) Edouard@2152: Edouard@2152: def OnPageChanged(self, event): Edouard@2152: old = event.GetOldSelection() Edouard@2152: new = event.GetSelection() Edouard@2152: sel = self.GetSelection() Edouard@2152: event.Skip() Edouard@2152: Edouard@2152: def OnPageChanging(self, event): Edouard@2152: old = event.GetOldSelection() Edouard@2152: new = event.GetSelection() Edouard@2152: sel = self.GetSelection() Edouard@2152: event.Skip() Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For SDO Grid (fill index, subindex, etc...) Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class SlaveSDOTable(wx.grid.Grid): Edouard@2152: def __init__(self, parent, data): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent SDOPanelClass class Edouard@2152: @param data: SDO data after parsing "SDOParser" method Edouard@2152: """ Edouard@2152: wx.grid.Grid.__init__(self, parent, -1, size=(830,490), Edouard@2152: style=wx.EXPAND|wx.ALIGN_CENTRE_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL) Edouard@2152: Edouard@2152: self.Controler = parent.Controler Edouard@2152: self.parent = parent Edouard@2152: self.SDOFlag = True Edouard@2152: if data is None : Edouard@2152: self.SDOs = [] Edouard@2152: else : Edouard@2152: self.SDOs = data Edouard@2152: Edouard@2152: self.CreateGrid(len(self.SDOs), 8) Edouard@2152: SDOCellSize = [(0, 65), (1, 65), (2, 50), (3, 55), Edouard@2152: (4, 40), (5, 200), (6, 250), (7, 85)] Edouard@2152: Edouard@2152: for (index, size) in SDOCellSize: Edouard@2152: self.SetColSize(index, size) Edouard@2152: Edouard@2152: self.SetRowLabelSize(0) Edouard@2152: Edouard@2152: SDOTableLabel = [(0, "Index"), (1, "Subindex"), (2, "Access"), Edouard@2152: (3, "Type"), (4, "Size"), (5, "Category"), Edouard@2152: (6, "Name"), (7, "Value")] Edouard@2152: Edouard@2152: for (index, label) in SDOTableLabel: Edouard@2152: self.SetColLabelValue(index, label) Edouard@2152: self.SetColLabelAlignment(index, wx.ALIGN_CENTRE) Edouard@2152: Edouard@2152: attr = wx.grid.GridCellAttr() Edouard@2152: Edouard@2152: # for SDO download Edouard@2152: self.Bind(gridlib.EVT_GRID_CELL_LEFT_DCLICK, self.SDOModifyDialog) Edouard@2152: Edouard@2152: for i in range(7): Edouard@2152: self.SetColAttr(i,attr) Edouard@2152: Edouard@2152: self.SetColLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER) Edouard@2152: Edouard@2152: self.SetTableValue() Edouard@2152: Edouard@2152: def SetTableValue(self): Edouard@2152: """ Edouard@2152: Cell is filled by new parsing data Edouard@2152: """ Edouard@2152: sdo_list = ['idx', 'subIdx', 'access', 'type', 'size', 'category', 'name', 'value'] Edouard@2152: for row_idx in range(len(self.SDOs)): Edouard@2152: for col_idx in range(len(self.SDOs[row_idx])): Edouard@2152: self.SetCellValue(row_idx, col_idx, self.SDOs[row_idx][sdo_list[col_idx]]) Edouard@2152: self.SetReadOnly(row_idx, col_idx, True) Edouard@2152: if col_idx < 5 : Edouard@2152: self.SetCellAlignment(row_idx, col_idx, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) Edouard@2152: Edouard@2152: def CheckSDODataAccess(self, row): Edouard@2152: """ Edouard@2152: CheckSDODataAccess method is checking that access data has "w" Edouard@2152: Access field consist 6 char, if mean Edouard@2152: rw rw rw Edouard@2152: (preop) (safeop) (op) Edouard@2152: Example Access field : rwrwrw, rwrw-- Edouard@2152: @param row : Selected cell by user Edouard@2152: @return Write_flag : If data has "w", flag is true Edouard@2152: """ Edouard@2152: write_flag = False Edouard@2152: check = self.SDOs[row]['access'] Edouard@2152: if check[1:2] == 'w' : Edouard@2152: self.Controler.CommonMethod.Check_PREOP = True Edouard@2152: write_flag = True Edouard@2152: if check[3:4] == 'w' : Edouard@2152: self.Controler.CommonMethod.Check_SAFEOP = True Edouard@2152: write_flag = True Edouard@2152: if check[5:] =='w' : Edouard@2152: self.Controler.CommonMethod.Check_OP = True Edouard@2152: write_flag = True Edouard@2152: Edouard@2152: return write_flag Edouard@2152: Edouard@2152: def DecideSDODownload(self, state): Edouard@2152: """ Edouard@2152: compare current state and "access" field, Edouard@2152: result notify SDOModifyDialog method Edouard@2152: @param state : current slave state Edouard@2152: @return True or False Edouard@2152: """ Edouard@2152: # Example of 'state' parameter : "0 0:0 PREOP + EL9800 (V4.30) (PIC24, SPI, ET1100)" Edouard@2152: state = state[self.Controler.GetSlavePos()].split(" ")[2] Edouard@2152: if state == "PREOP" and self.Controler.CommonMethod.Check_PREOP : Edouard@2152: return True Edouard@2152: elif state == "SAFEOP" and self.Controler.CommonMethod.Check_SAFEOP : Edouard@2152: return True Edouard@2152: elif state == "OP" and self.Controler.CommonMethod.Check_OP : Edouard@2152: return True Edouard@2152: Edouard@2152: return False Edouard@2152: Edouard@2152: def ClearStateFlag(self): Edouard@2152: """ Edouard@2152: Initialize StateFlag Edouard@2152: StateFlag is notice SDOData access each slave state Edouard@2152: """ Edouard@2152: self.Controler.CommonMethod.Check_PREOP = False Edouard@2152: self.Controler.CommonMethod.Check_SAFEOP = False Edouard@2152: self.Controler.CommonMethod.Check_OP = False Edouard@2152: Edouard@2152: def SDOModifyDialog (self, event): Edouard@2152: """ Edouard@2152: Create dialog for SDO value modify Edouard@2152: if user enter data, perform command "ethercat download" Edouard@2152: @param event : gridlib.EVT_GRID_CELL_LEFT_DCLICK object Edouard@2152: """ Edouard@2152: self.ClearStateFlag() Edouard@2152: Edouard@2152: # CheckSDODataAccess is checking that OD(Object Dictionary) has "w" Edouard@2152: if event.GetCol() == 7 and self.CheckSDODataAccess(event.GetRow()) : Edouard@2152: dlg = wx.TextEntryDialog (self, "Enter hex or dec value (if enter dec value, it automatically conversed hex value)", Edouard@2152: "SDOModifyDialog", style = wx.OK | wx.CANCEL) Edouard@2152: Edouard@2152: start_value = self.GetCellValue(event.GetRow(), event.GetCol()) Edouard@2152: dlg.SetValue(start_value) Edouard@2152: Edouard@2152: if dlg.ShowModal() == wx.ID_OK: Edouard@2152: try : Edouard@2152: int(dlg.GetValue(), 0) Edouard@2152: # check "Access" field Edouard@2152: if self.DecideSDODownload(self.Controler.CommonMethod.SlaveState[self.Controler.GetSlavePos()]) : Edouard@2152: # Request "SDODownload" Edouard@2152: self.Controler.CommonMethod.SDODownload(self.SDOs[event.GetRow()]['type'], self.SDOs[event.GetRow()]['idx'], Edouard@2152: self.SDOs[event.GetRow()]['subIdx'], dlg.GetValue()) Edouard@2152: self.SetCellValue(event.GetRow(), event.GetCol(), hex(int(dlg.GetValue(), 0))) Edouard@2152: else : Edouard@2152: self.Controler.CommonMethod.CreateErrorDialog('You cannot SDO download this state') Edouard@2152: # Error occured process of "int(variable)" Edouard@2152: # User input is not hex, dec value Edouard@2152: except ValueError: Edouard@2152: self.Controler.CommonMethod.CreateErrorDialog('You can input only hex, dec value') Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For PDO Monitoring Panel Edouard@2152: # PDO Class UI : Panel -> Choicebook (RxPDO, TxPDO) -> Edouard@2152: # Notebook (PDO Index) -> Grid (PDO entry) Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class PDOPanelClass(wx.Panel): Edouard@2152: def __init__(self, parent, controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent EtherCATManagementTreebook class Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: wx.Panel.__init__(self, parent, -1) Edouard@2152: self.Controler = controler Edouard@2152: Edouard@2152: self.PDOMonitoringEditorMainSizer = wx.BoxSizer(wx.VERTICAL) Edouard@2152: self.PDOMonitoringEditorInnerMainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10) Edouard@2152: Edouard@2152: self.CallPDOChoicebook = PDOChoicebook(self, controler=self.Controler) Edouard@2152: self.PDOMonitoringEditorInnerMainSizer.Add(self.CallPDOChoicebook, wx.ALL) Edouard@2152: Edouard@2152: self.PDOMonitoringEditorMainSizer.Add(self.PDOMonitoringEditorInnerMainSizer) Edouard@2152: Edouard@2152: self.SetSizer(self.PDOMonitoringEditorMainSizer) Edouard@2152: Edouard@2152: def PDOInfoUpdate(self): Edouard@2152: """ Edouard@2152: Call RequestPDOInfo method and create Choicebook Edouard@2152: """ Edouard@2152: self.Controler.CommonMethod.RequestPDOInfo() Edouard@2152: self.CallPDOChoicebook.Destroy() Edouard@2152: self.CallPDOChoicebook = PDOChoicebook(self, controler=self.Controler) Edouard@2152: self.Refresh() Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For PDO Choicebook (divide Tx, Rx PDO) Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class PDOChoicebook(wx.Choicebook): Edouard@2152: def __init__(self, parent, controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent PDOPanelClass class Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: wx.Choicebook.__init__(self, parent, id=-1, size=(500, 500), style=wx.CHB_DEFAULT) Edouard@2152: self.Controler = controler Edouard@2152: Edouard@2152: RxWin = PDONoteBook(self, controler=self.Controler, name="Rx") Edouard@2152: TxWin = PDONoteBook(self, controler=self.Controler, name="Tx") Edouard@2152: self.AddPage(RxWin, "RxPDO") Edouard@2152: self.AddPage(TxWin, "TxPDO") Edouard@2152: Edouard@2152: self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGED, self.OnPageChanged) Edouard@2152: self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGING, self.OnPageChanging) Edouard@2152: Edouard@2152: def OnPageChanged(self, event): Edouard@2152: old = event.GetOldSelection() Edouard@2152: new = event.GetSelection() Edouard@2152: sel = self.GetSelection() Edouard@2152: event.Skip() Edouard@2152: Edouard@2152: def OnPageChanging(self, event): Edouard@2152: old = event.GetOldSelection() Edouard@2152: new = event.GetSelection() Edouard@2152: sel = self.GetSelection() Edouard@2152: event.Skip() Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For PDO Notebook (divide PDO index) Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class PDONoteBook(wx.Notebook): Edouard@2152: def __init__(self, parent, name, controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent PDOChoicebook class Edouard@2152: @param name: identifier whether RxPDO or TxPDO Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: wx.Notebook.__init__(self, parent, id=-1, size=(640, 400)) Edouard@2152: self.Controler = controler Edouard@2152: Edouard@2152: count = 0 Edouard@2152: page_texts = [] Edouard@2152: Edouard@2152: self.Controler.CommonMethod.RequestPDOInfo() Edouard@2152: Edouard@2152: if name == "Tx" : Edouard@2152: # obtain pdo_info and pdo_entry Edouard@2152: # pdo_info include (PDO index, name, number of entry) Edouard@2152: pdo_info = self.Controler.CommonMethod.GetTxPDOCategory() Edouard@2152: pdo_entry = self.Controler.CommonMethod.GetTxPDOInfo() Edouard@2152: for tmp in pdo_info : Edouard@2152: title = str(hex(tmp['pdo_index'])) Edouard@2152: page_texts.append(title) Edouard@2152: # RX PDO case Edouard@2152: else : Edouard@2152: pdo_info = self.Controler.CommonMethod.GetRxPDOCategory() Edouard@2152: pdo_entry = self.Controler.CommonMethod.GetRxPDOInfo() Edouard@2152: for tmp in pdo_info : Edouard@2152: title = str(hex(tmp['pdo_index'])) Edouard@2152: page_texts.append(title) Edouard@2152: Edouard@2152: # Add page depending on the number of pdo_info Edouard@2152: for txt in page_texts: Edouard@2152: win = PDOEntryTable(self, pdo_info, pdo_entry, count) Edouard@2152: self.AddPage(win, txt) Edouard@2152: count += 1 Edouard@2152: Edouard@2152: self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGED, self.OnPageChanged) Edouard@2152: self.Bind(wx.EVT_CHOICEBOOK_PAGE_CHANGING, self.OnPageChanging) Edouard@2152: Edouard@2152: def OnPageChanged(self, event): Edouard@2152: old = event.GetOldSelection() Edouard@2152: new = event.GetSelection() Edouard@2152: sel = self.GetSelection() Edouard@2152: event.Skip() Edouard@2152: Edouard@2152: def OnPageChanging(self, event): Edouard@2152: old = event.GetOldSelection() Edouard@2152: new = event.GetSelection() Edouard@2152: sel = self.GetSelection() Edouard@2152: event.Skip() Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For PDO Grid (fill entry index, subindex etc...) Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class PDOEntryTable(wx.grid.Grid): Edouard@2152: def __init__(self, parent, info, entry, count): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent PDONoteBook class Edouard@2152: @param info : data structure including entry index, sub index, name, length, type Edouard@2152: @param entry : data structure including index, name, entry number Edouard@2152: @param count : page number Edouard@2152: """ Edouard@2152: wx.grid.Grid.__init__(self, parent, -1, size=(500, 400), pos=wx.Point(0,0), Edouard@2152: style=wx.EXPAND|wx.ALIGN_CENTRE_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL) Edouard@2152: Edouard@2152: self.Controler = parent.Controler Edouard@2152: Edouard@2152: self.PDOInfo = info Edouard@2152: self.PDOEntry = entry Edouard@2152: self.Count = count Edouard@2152: Edouard@2152: self.CreateGrid(self.PDOInfo[self.Count]['number_of_entry'], 5) Edouard@2152: self.SetColLabelSize(25) Edouard@2152: self.SetRowLabelSize(0) Edouard@2152: Edouard@2152: PDOTableLabel = [(0, "Index"), (1, "Subindex"), (2, "Length"), Edouard@2152: (3, "Type"), (4, "Name")] Edouard@2152: Edouard@2152: for (index, label) in PDOTableLabel: Edouard@2152: self.SetColLabelValue(index, label) Edouard@2152: Edouard@2152: PDOCellSize = [(0, 45), (1, 65), (2, 55), (3, 40), (4, 300)] Edouard@2152: Edouard@2152: for (index, size) in PDOCellSize: Edouard@2152: self.SetColSize(index, size) Edouard@2152: self.SetColLabelAlignment(index, wx.ALIGN_LEFT) Edouard@2152: Edouard@2152: attr = wx.grid.GridCellAttr() Edouard@2152: Edouard@2152: for i in range(5): Edouard@2152: self.SetColAttr(i, attr) Edouard@2152: Edouard@2152: self.SetTableValue() Edouard@2152: Edouard@2152: def SetTableValue(self): Edouard@2152: """ Edouard@2152: Cell is filled by new parsing data in XML Edouard@2152: """ Edouard@2152: list_index = 0 Edouard@2152: # number of entry Edouard@2152: for i in range(self.Count + 1) : Edouard@2152: list_index += self.PDOInfo[i]['number_of_entry'] Edouard@2152: Edouard@2152: start_value = list_index - self.PDOInfo[self.Count]['number_of_entry'] Edouard@2152: Edouard@2152: pdo_list = ['entry_index', 'subindex', 'bitlen', 'type', 'name'] Edouard@2152: for row_idx in range(self.PDOInfo[self.Count]['number_of_entry']): Edouard@2152: for col_idx in range(len(self.PDOEntry[row_idx])): Edouard@2152: # entry index is converted hex value. Edouard@2152: if col_idx == 0 : Edouard@2152: self.SetCellValue(row_idx, col_idx, hex(self.PDOEntry[start_value][pdo_list[col_idx]])) Edouard@2152: else : Edouard@2152: self.SetCellValue(row_idx, col_idx, str(self.PDOEntry[start_value][pdo_list[col_idx]])) Edouard@2152: if col_idx != 4 : Edouard@2152: self.SetCellAlignment(row_idx, col_idx, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) Edouard@2152: else : Edouard@2152: self.SetCellAlignment(row_idx, col_idx, wx.ALIGN_LEFT, wx.ALIGN_CENTRE) Edouard@2152: self.SetReadOnly(row_idx, col_idx, True) Edouard@2152: self.SetRowSize(row_idx, 25) Edouard@2152: start_value += 1 Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For EEPROM Access Main Panel Edouard@2152: # (This class explain EEPROM Access) Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class EEPROMAccessPanel(wx.Panel): Edouard@2152: def __init__(self, parent, controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent EtherCATManagementTreebook class Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: wx.Panel.__init__(self, parent, -1) Edouard@2152: sizer = wx.FlexGridSizer(cols=1, hgap=20,rows=3, vgap=20) Edouard@2152: Edouard@2152: line = wx.StaticText(self, -1, "\n EEPROM Access is composed to SmartView and HexView. \ Edouard@2152: \n\n - SmartView shows Config Data, Device Identity, Mailbox settings, etc. \ Edouard@2152: \n\n - HexView shows EEPROM's contents.") Edouard@2152: Edouard@2152: sizer.Add(line) Edouard@2152: Edouard@2152: self.SetSizer(sizer) Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For Smart View Panel Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class SlaveSiiSmartView(wx.Panel): Edouard@2152: def __init__(self, parent, controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent EtherCATManagementTreebook class Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: wx.Panel.__init__(self, parent, -1) Edouard@2152: self.parent = parent Edouard@2152: self.Controler = controler Edouard@2152: Edouard@2152: self.PDIType = {0 :['none', '00000000'], Edouard@2152: 4 :['Digital I/O', '00000100'], Edouard@2152: 5 :['SPI Slave', '00000101'], Edouard@2152: 7 :['EtherCAT Bridge (port3)', '00000111'], Edouard@2152: 8 :['uC async. 16bit', '00001000'], Edouard@2152: 9 :['uC async. 8bit', '00001001'], Edouard@2152: 10 :['uC sync. 16bit', '00001010'], Edouard@2152: 11 :['uC sync. 8bit', '00001011'], Edouard@2152: 16 :['32 Digtal Input and 0 Digital Output', '00010000'], Edouard@2152: 17 :['24 Digtal Input and 8 Digital Output', '00010001'], Edouard@2152: 18 :['16 Digtal Input and 16 Digital Output','00010010'], Edouard@2152: 19 :['8 Digtal Input and 24 Digital Output', '00010011'], Edouard@2152: 20 :['0 Digtal Input and 32 Digital Output', '00010100'], Edouard@2152: 128:['On-chip bus', '11111111'] Edouard@2152: } Edouard@2152: Edouard@2152: sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5) Edouard@2152: button_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=5) Edouard@2152: Edouard@2152: for button, mapping_method in [("Write EEPROM", self.WriteToEEPROM), Edouard@2152: ("Read EEPROM", self.ReadFromEEPROM)]: Edouard@2152: btn = wx.Button(self, -1, button, size=(150, 40)) Edouard@2152: button_sizer.Add(btn, border=10, flag=wx.ALL) Edouard@2152: btn.Bind(wx.EVT_BUTTON, mapping_method) Edouard@2152: Edouard@2152: self.TreeListCtrl = SmartViewTreeListCtrl(self, self.Controler) Edouard@2152: Edouard@2152: sizer.Add(button_sizer, border=10, flag=wx.ALL) Edouard@2152: sizer.Add(self.TreeListCtrl, border=10, flag=wx.ALL) Edouard@2152: self.SetSizer(sizer) Edouard@2152: Edouard@2152: self.Create_SmartView() Edouard@2152: Edouard@2152: def Create_SmartView(self): Edouard@2152: """ Edouard@2152: SmartView shows information based on XML as initial value. Edouard@2152: """ Edouard@2152: self.Controler.CommonMethod.SmartViewInfosFromXML = self.Controler.CommonMethod.GetSmartViewInfos() Edouard@2152: self.SetXMLData() Edouard@2152: Edouard@2152: def WriteToEEPROM(self, event): Edouard@2152: """ Edouard@2152: Open binary file (user select) and write the selected binary data to EEPROM Edouard@2152: @param event : wx.EVT_BUTTON object Edouard@2152: """ Edouard@2152: # Check whether beremiz connected or not, and whether status is "Started" or not. Edouard@2152: check_connect_flag = self.Controler.CommonMethod.CheckConnect(False) Edouard@2152: if check_connect_flag: Edouard@2152: status, count = self.Controler.GetCTRoot()._connector.GetPLCstatus() Edouard@2152: if status is not "Started": Edouard@2152: dialog = wx.FileDialog(self, _("Choose a binary file"), os.getcwd(), "", _("bin files (*.bin)|*.bin"), wx.OPEN) Edouard@2152: Edouard@2152: if dialog.ShowModal() == wx.ID_OK: Edouard@2152: filepath = dialog.GetPath() Edouard@2152: try: Edouard@2152: binfile = open(filepath,"rb") Edouard@2152: self.SiiBinary = binfile.read() Edouard@2152: dialog.Destroy() Edouard@2152: Edouard@2152: self.Controler.CommonMethod.SiiWrite(self.SiiBinary) Edouard@2152: # refresh data structure kept by master Edouard@2152: self.Controler.CommonMethod.Rescan() Edouard@2152: # save binary data as inner global data of beremiz Edouard@2152: # for fast loading when slave plugin node is reopened. Edouard@2152: self.Controler.CommonMethod.SiiData = self.SiiBinary Edouard@2152: self.SetEEPROMData() Edouard@2152: except: Edouard@2152: self.Controler.CommonMethod.CreateErrorDialog('The file does not exist!') Edouard@2152: dialog.Destroy() Edouard@2152: Edouard@2152: def ReadFromEEPROM(self, event): Edouard@2152: """ Edouard@2152: Refresh displayed data based on slave EEPROM and save binary file through dialog Edouard@2152: @param event : wx.EVT_BUTTON object Edouard@2152: """ Edouard@2152: # Check whether beremiz connected or not. Edouard@2152: check_connect_flag = self.Controler.CommonMethod.CheckConnect(False) Edouard@2152: if check_connect_flag: Edouard@2152: self.SiiBinary = self.Controler.CommonMethod.LoadData() Edouard@2152: self.SetEEPROMData() Edouard@2152: dialog = wx.FileDialog(self, _("Save as..."), os.getcwd(), Edouard@2152: "slave0.bin", _("bin files (*.bin)|*.bin|All files|*.*"), Edouard@2152: wx.SAVE|wx.OVERWRITE_PROMPT) Edouard@2152: Edouard@2152: if dialog.ShowModal() == wx.ID_OK: Edouard@2152: filepath = dialog.GetPath() Edouard@2152: binfile = open(filepath,"wb") Edouard@2152: binfile.write(self.SiiBinary) Edouard@2152: binfile.close() Edouard@2152: Edouard@2152: dialog.Destroy() Edouard@2152: Edouard@2152: def SetXMLData(self): Edouard@2152: """ Edouard@2152: Set data based on XML initially Edouard@2152: """ Edouard@2152: # Config Data: EEPROM Size, PDI Type, Device Emulation Edouard@2152: # Find PDI Type in pdiType dictionary Edouard@2152: cnt_pdi_type = self.Controler.CommonMethod.SmartViewInfosFromXML["pdi_type"] Edouard@2152: for i in self.PDIType.keys(): Edouard@2152: if cnt_pdi_type == i: Edouard@2152: cnt_pdi_type = self.PDIType[i][0] Edouard@2152: break Edouard@2152: # Set Config Data Edouard@2152: for treelist, data in [("EEPROM Size (Bytes)", Edouard@2152: str(self.Controler.CommonMethod.SmartViewInfosFromXML["eeprom_size"])), Edouard@2152: ("PDI Type", Edouard@2152: cnt_pdi_type), Edouard@2152: ("Device Emulation", Edouard@2152: self.Controler.CommonMethod.SmartViewInfosFromXML["device_emulation"])]: Edouard@2152: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.ConfigData[treelist], data, 1) Edouard@2152: Edouard@2152: # Device Identity: Vendor ID, Product Code, Revision No., Serial No. Edouard@2152: # Set Device Identity Edouard@2152: for treelist, data in [("Vendor ID", self.Controler.CommonMethod.SmartViewInfosFromXML["vendor_id"]), Edouard@2152: ("Product Code", self.Controler.CommonMethod.SmartViewInfosFromXML["product_code"]), Edouard@2152: ("Revision No.", self.Controler.CommonMethod.SmartViewInfosFromXML["revision_no"]), Edouard@2152: ("Serial No.", self.Controler.CommonMethod.SmartViewInfosFromXML["serial_no"])]: Edouard@2152: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.DeviceIdentity[treelist], data, 1) Edouard@2152: Edouard@2152: # Mailbox: Supported Mailbox, Bootstrap Configuration, Standard Configuration Edouard@2152: # Set Mailbox Edouard@2152: for treelist, data in [("Supported Mailbox", self.Controler.CommonMethod.SmartViewInfosFromXML["supported_mailbox"]), Edouard@2152: ("Bootstrap Configuration", ""), Edouard@2152: ("Standard Configuration", "")]: Edouard@2152: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.Mailbox[treelist], data, 1) Edouard@2152: # Set Bootstrap Configuration: Receive Offset, Receive Size, Send Offset, Send Size Edouard@2152: for treelist, data in [("Receive Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_outstart"]), Edouard@2152: ("Receive Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_outlength"]), Edouard@2152: ("Send Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_instart"]), Edouard@2152: ("Send Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_inlength"])]: Edouard@2152: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.BootstrapConfig[treelist], data, 1) Edouard@2152: # Set Standard Configuration: Receive Offset, Receive Size, Send Offset, Send Size Edouard@2152: for treelist, data in [("Receive Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_outstart"]), Edouard@2152: ("Receive Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_outlength"]), Edouard@2152: ("Send Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_instart"]), Edouard@2152: ("Send Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_inlength"])]: Edouard@2152: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.StandardConfig[treelist], data, 1) Edouard@2152: Edouard@2152: def SetEEPROMData(self): Edouard@2152: """ Edouard@2152: Set data based on slave EEPROM. Edouard@2152: """ Edouard@2152: # sii_dict = { Parameter : (WordAddress, WordSize) } Edouard@2152: sii_dict= { 'PDIControl' : ( '0', 1), Edouard@2152: 'PDIConfiguration' : ( '1', 1), Edouard@2152: 'PulseLengthOfSYNCSignals' : ( '2', 1), Edouard@2152: 'ExtendedPDIConfiguration' : ( '3', 1), Edouard@2152: 'ConfiguredStationAlias' : ( '4', 1), Edouard@2152: 'Checksum' : ( '7', 1), Edouard@2152: 'VendorID' : ( '8', 2), Edouard@2152: 'ProductCode' : ( 'a', 2), Edouard@2152: 'RevisionNumber' : ( 'c', 2), Edouard@2152: 'SerialNumber' : ( 'e', 2), Edouard@2152: 'Execution Delay' : ('10', 1), Edouard@2152: 'Port0Delay' : ('11', 1), Edouard@2152: 'Port1Delay' : ('12', 1), Edouard@2152: 'BootstrapReceiveMailboxOffset' : ('14', 1), Edouard@2152: 'BootstrapReceiveMailboxSize' : ('15', 1), Edouard@2152: 'BootstrapSendMailboxOffset' : ('16', 1), Edouard@2152: 'BootstrapSendMailboxSize' : ('17', 1), Edouard@2152: 'StandardReceiveMailboxOffset' : ('18', 1), Edouard@2152: 'StandardReceiveMailboxSize' : ('19', 1), Edouard@2152: 'StandardSendMailboxOffset' : ('1a', 1), Edouard@2152: 'StandardSendMailboxSize' : ('1b', 1), Edouard@2152: 'MailboxProtocol' : ('1c', 1), Edouard@2152: 'Size' : ('3e', 1), Edouard@2152: 'Version' : ('3f', 1), Edouard@2152: 'First Category Type/Vendor Specific' : ('40', 1), Edouard@2152: 'Following Category Word Size' : ('41', 1), Edouard@2152: 'Category Data' : ('42', 1), Edouard@2152: } Edouard@2152: Edouard@2152: # Config Data: EEPROM Size, PDI Type, Device Emulation Edouard@2152: # EEPROM's data in address '0x003f' is Size of EEPROM in KBit-1 Edouard@2152: eeprom_size = str((int(self.GetWordAddressData( sii_dict.get('Size'),10 ))+1)/8*1024) Edouard@2152: # Find PDI Type in pdiType dictionary Edouard@2152: cnt_pdi_type = int(self.GetWordAddressData( sii_dict.get('PDIControl'),16 ).split('x')[1][2:4], 16) Edouard@2152: for i in self.PDIType.keys(): Edouard@2152: if cnt_pdi_type == i: Edouard@2152: cnt_pdi_type = self.PDIType[i][0] Edouard@2152: break Edouard@2152: # Get Device Emulation Edouard@2152: device_emulation = str(bool(int("{:0>16b}".format(int(self.GetWordAddressData( sii_dict.get('PDIControl'),16 ), 16))[7]))) Edouard@2152: # Set Config Data Edouard@2152: for treelist, data in [("EEPROM Size (Bytes)", eeprom_size), Edouard@2152: ("PDI Type", cnt_pdi_type), Edouard@2152: ("Device Emulation", device_emulation)]: Edouard@2152: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.ConfigData[treelist], data, 1) Edouard@2152: Edouard@2152: # Device Identity: Vendor ID, Product Code, Revision No., Serial No. Edouard@2152: # Set Device Identity Edouard@2152: for treelist, data in [("Vendor ID", self.GetWordAddressData( sii_dict.get('VendorID'),16 )), Edouard@2152: ("Product Code", self.GetWordAddressData( sii_dict.get('ProductCode'),16 )), Edouard@2152: ("Revision No.", self.GetWordAddressData( sii_dict.get('RevisionNumber'),16 )), Edouard@2152: ("Serial No.", self.GetWordAddressData( sii_dict.get('SerialNumber'),16 ))]: Edouard@2152: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.DeviceIdentity[treelist], data, 1) Edouard@2152: Edouard@2152: # Mailbox Edouard@2152: # EEORPOM's word address '1c' indicates supported mailbox protocol. Edouard@2152: # each value of mailbox protocol : Edouard@2152: # VoE(0x0020), SoE(0x0010), FoE(0x0008), CoE(0x0004), EoE(0x0002), AoE(0x0001) Edouard@2152: supported_mailbox = "" Edouard@2152: mailbox_protocol=["VoE, ", "SoE, ", "FoE, ", "CoE, ", "EoE, ", "AoE, "] Edouard@2152: mailbox_data = "{:0>8b}".format(int(self.GetWordAddressData( sii_dict.get('MailboxProtocol'),16 ), 16)) Edouard@2152: for protocol in range(6): Edouard@2152: if mailbox_data[protocol+2] == '1': Edouard@2152: supported_mailbox += mailbox_protocol[protocol] Edouard@2152: supported_mailbox = supported_mailbox.strip(", ") Edouard@2152: # Set Mailbox Edouard@2152: for treelist, data in [("Supported Mailbox", supported_mailbox), Edouard@2152: ("Bootstrap Configuration", ""), Edouard@2152: ("Standard Configuration", "")]: Edouard@2152: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.Mailbox[treelist], data, 1) Edouard@2152: # Set Bootstrap Configuration: Receive Offset, Receive Size, Send Offset, Send Size Edouard@2152: for treelist, data in [("Receive Offset", self.GetWordAddressData( sii_dict.get('BootstrapReceiveMailboxOffset'),10 )), Edouard@2152: ("Receive Size", self.GetWordAddressData( sii_dict.get('BootstrapReceiveMailboxSize'),10 )), Edouard@2152: ("Send Offset", self.GetWordAddressData( sii_dict.get('BootstrapSendMailboxOffset'),10 )), Edouard@2152: ("Send Size", self.GetWordAddressData( sii_dict.get('BootstrapSendMailboxSize'),10 ))]: Edouard@2152: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.BootstrapConfig[treelist], data, 1) Edouard@2152: # Set Standard Configuration: Receive Offset, Receive Size, Send Offset, Send Size Edouard@2152: for treelist, data in [("Receive Offset", self.GetWordAddressData( sii_dict.get('StandardReceiveMailboxOffset'),10 )), Edouard@2152: ("Receive Size", self.GetWordAddressData( sii_dict.get('StandardReceiveMailboxSize'),10 )), Edouard@2152: ("Send Offset", self.GetWordAddressData( sii_dict.get('StandardSendMailboxOffset'),10 )), Edouard@2152: ("Send Size", self.GetWordAddressData( sii_dict.get('StandardSendMailboxSize'),10 ))]: Edouard@2152: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.StandardConfig[treelist], data, 1) Edouard@2152: Edouard@2152: def MakeStaticBoxSizer(self, boxlabel): Edouard@2152: """ Edouard@2152: Make StaticBoxSizer Edouard@2152: @param boxlabel : label of box sizer Edouard@2152: @return sizer : the StaticBoxSizer labeled 'boxlabel' Edouard@2152: """ Edouard@2152: box = wx.StaticBox(self, -1, boxlabel) Edouard@2152: sizer = wx.StaticBoxSizer(box, wx.VERTICAL) Edouard@2152: Edouard@2152: return sizer Edouard@2152: Edouard@2152: def GetWordAddressData(self, dict_tuple, format): Edouard@2152: """ Edouard@2152: This method converts word address data from EEPROM binary. Edouard@2152: @param dict_tuple : element of 'sii_dict' dictionary in SetEEPROMData() Edouard@2152: @param format : format of data. It can be 16(hex), 10(decimal) and 2(binary). Edouard@2152: @return formatted value Edouard@2152: """ Edouard@2152: offset = int(str(dict_tuple[0]), 16) * 2 Edouard@2152: length = int(str(dict_tuple[1]), 16) * 2 Edouard@2152: list = [] Edouard@2152: data = '' Edouard@2152: for index in range(length): Edouard@2152: hexdata = hex(ord(self.SiiBinary[offset + index]))[2:] Edouard@2152: list.append(hexdata.zfill(2)) Edouard@2152: Edouard@2152: list.reverse() Edouard@2152: data = list[0:length] Edouard@2152: Edouard@2152: if format == 16: Edouard@2152: return '0x' + ''.join(data) Edouard@2152: elif format == 10: Edouard@2152: return str(int(str(''.join(data)), 16)) Edouard@2152: elif format == 2: Edouard@2152: ''.join(data) Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For Smart View TreeListCtrl Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class SmartViewTreeListCtrl(wx.Panel): Edouard@2152: def __init__(self, parent, Controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent SlaveSiiSmartView class Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: Edouard@2152: wx.Panel.__init__(self, parent, -1, size=(350, 500)) Edouard@2152: Edouard@2152: self.Tree = wx.gizmos.TreeListCtrl(self, -1, size=(350, 500), Edouard@2152: style=wx.TR_DEFAULT_STYLE Edouard@2152: |wx.TR_FULL_ROW_HIGHLIGHT Edouard@2152: |wx.TR_HIDE_ROOT Edouard@2152: |wx.TR_COLUMN_LINES Edouard@2152: |wx.TR_ROW_LINES) Edouard@2152: Edouard@2152: self.Tree.AddColumn("Description", width=200) Edouard@2152: self.Tree.AddColumn("Value", width=140) Edouard@2152: self.Tree.SetMainColumn(0) Edouard@2152: Edouard@2152: self.Root = self.Tree.AddRoot("") Edouard@2152: Edouard@2152: # Add item Edouard@2152: # Level 1 nodes Edouard@2152: self.Level1Nodes = {} Edouard@2152: for lv1 in ["Config Data", "Device Identity", "Mailbox"]: Edouard@2152: self.Level1Nodes[lv1] = self.Tree.AppendItem(self.Root, lv1) Edouard@2152: Edouard@2152: # Level 2 nodes Edouard@2152: # Config Data Edouard@2152: self.ConfigData = {} Edouard@2152: for lv2 in ["EEPROM Size (Bytes)", "PDI Type", "Device Emulation"]: Edouard@2152: self.ConfigData[lv2] = self.Tree.AppendItem(self.Level1Nodes["Config Data"], lv2) Edouard@2152: # Device Identity Edouard@2152: self.DeviceIdentity = {} Edouard@2152: for lv2 in ["Vendor ID", "Product Code", "Revision No.", "Serial No."]: Edouard@2152: self.DeviceIdentity[lv2] = self.Tree.AppendItem(self.Level1Nodes["Device Identity"], lv2) Edouard@2152: # Mailbox Edouard@2152: self.Mailbox = {} Edouard@2152: for lv2 in ["Supported Mailbox", "Bootstrap Configuration", "Standard Configuration"]: Edouard@2152: self.Mailbox[lv2] = self.Tree.AppendItem(self.Level1Nodes["Mailbox"], lv2) Edouard@2152: Edouard@2152: # Level 3 nodes Edouard@2152: # Children of Bootstrap Configuration Edouard@2152: self.BootstrapConfig = {} Edouard@2152: for lv3 in ["Receive Offset", "Receive Size", "Send Offset", "Send Size"]: Edouard@2152: self.BootstrapConfig[lv3] = self.Tree.AppendItem(self.Mailbox["Bootstrap Configuration"], lv3) Edouard@2152: # Children of Standard Configuration Edouard@2152: self.StandardConfig = {} Edouard@2152: for lv3 in ["Receive Offset", "Receive Size", "Send Offset", "Send Size"]: Edouard@2152: self.StandardConfig[lv3] = self.Tree.AppendItem(self.Mailbox["Standard Configuration"], lv3) Edouard@2152: Edouard@2152: # Expand Tree Edouard@2152: for tree in [self.Root, Edouard@2152: self.Level1Nodes["Config Data"], Edouard@2152: self.Level1Nodes["Device Identity"], Edouard@2152: self.Level1Nodes["Mailbox"], Edouard@2152: self.Mailbox["Bootstrap Configuration"], Edouard@2152: self.Mailbox["Standard Configuration"]]: Edouard@2152: self.Tree.Expand(tree) Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For Hex View Panel Edouard@2152: # shows EEPROM binary as hex data and characters. Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class HexView(wx.Panel): Edouard@2152: def __init__(self, parent, controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent EtherCATManagementTreebook class Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: wx.Panel.__init__(self, parent, -1) Edouard@2152: self.parent = parent Edouard@2152: self.Controler = controler Edouard@2152: Edouard@2152: self.HexRow = 8 Edouard@2152: self.HexCol = 17 Edouard@2152: Edouard@2152: self.HexViewSizer = {"view" : wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10), Edouard@2152: "siiButton" : wx.BoxSizer()} Edouard@2152: self.HexViewButton = {} Edouard@2152: Edouard@2152: for key, evt_handler in [("Sii Upload", self.OnButtonSiiUpload), Edouard@2152: ("Sii Download", self.OnButtonSiiDownload), Edouard@2152: ("Write to File", self.OnButtonWriteToBinFile), Edouard@2152: ("Read from File", self.OnButtonReadFromBinFile), Edouard@2152: ("XML to EEPROM Image", self.OnButtonXmlToEEPROMImg)]: Edouard@2152: self.HexViewButton[key] = wx.Button(self, -1, key) Edouard@2152: self.HexViewButton[key].Bind(wx.EVT_BUTTON, evt_handler) Edouard@2152: self.HexViewSizer["siiButton"].Add(self.HexViewButton[key]) Edouard@2152: Edouard@2152: self.SiiBinary = self.Controler.CommonMethod.XmlToEeprom() Edouard@2152: self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary) Edouard@2152: self.SiiGrid = SiiGridTable(self, self.Controler, self.HexRow, self.HexCol) Edouard@2152: self.HexViewSizer["view"].AddMany([self.HexViewSizer["siiButton"], self.SiiGrid]) Edouard@2152: self.SiiGrid.CreateGrid(self.HexRow, self.HexCol) Edouard@2152: self.SetSizer(self.HexViewSizer["view"]) Edouard@2152: self.HexViewSizer["view"].FitInside(self.parent.parent) Edouard@2152: self.parent.parent.FitInside() Edouard@2152: self.SiiGrid.SetValue(self.HexCode) Edouard@2152: self.SiiGrid.Update() Edouard@2152: Edouard@2152: def UpdateSiiGridTable(self, row, col): Edouard@2152: """ Edouard@2152: Destroy existing grid and recreate Edouard@2152: @param row, col : Hex View grid size Edouard@2152: """ Edouard@2152: self.HexViewSizer["view"].Detach(self.SiiGrid) Edouard@2152: self.SiiGrid.Destroy() Edouard@2152: self.SiiGrid = SiiGridTable(self, self.Controler, row, col) Edouard@2152: self.HexViewSizer["view"].Add(self.SiiGrid) Edouard@2152: self.SiiGrid.CreateGrid(row, col) Edouard@2152: self.SetSizer(self.HexViewSizer["view"]) Edouard@2152: self.HexViewSizer["view"].FitInside(self.parent.parent) Edouard@2152: self.parent.parent.FitInside() Edouard@2152: Edouard@2152: def OnButtonSiiUpload(self, event): Edouard@2152: """ Edouard@2152: Load EEPROM data from slave and refresh Hex View grid Edouard@2152: Binded to 'Sii Upload' button. Edouard@2152: @param event : wx.EVT_BUTTON object Edouard@2152: """ Edouard@2152: # Check whether beremiz connected or not. Edouard@2152: check_connect_flag = self.Controler.CommonMethod.CheckConnect(False) Edouard@2152: if check_connect_flag: Edouard@2152: # load from EEPROM data and parsing Edouard@2152: self.SiiBinary = self.Controler.CommonMethod.LoadData() Edouard@2152: self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary) Edouard@2152: self.UpdateSiiGridTable(self.HexRow, self.HexCol) Edouard@2152: self.SiiGrid.SetValue(self.HexCode) Edouard@2152: self.SiiGrid.Update() Edouard@2152: Edouard@2152: def OnButtonSiiDownload(self, event): Edouard@2152: """ Edouard@2152: Write current EEPROM data to slave and refresh data structure kept by master Edouard@2152: Binded to 'Sii Download' button. Edouard@2152: @param event : wx.EVT_BUTTON object Edouard@2152: """ Edouard@2152: # Check whether beremiz connected or not, Edouard@2152: # and whether status is "Started" or not. Edouard@2152: check_connect_flag = self.Controler.CommonMethod.CheckConnect(False) Edouard@2152: if check_connect_flag: Edouard@2152: status, count = self.Controler.GetCTRoot()._connector.GetPLCstatus() Edouard@2152: if status is not "Started": Edouard@2152: self.Controler.CommonMethod.SiiWrite(self.SiiBinary) Edouard@2152: self.Controler.CommonMethod.Rescan() Edouard@2152: Edouard@2152: def OnButtonWriteToBinFile(self, event): Edouard@2152: """ Edouard@2152: Save current EEPROM data to binary file through FileDialog Edouard@2152: Binded to 'Write to File' button. Edouard@2152: @param event : wx.EVT_BUTTON object Edouard@2152: """ Edouard@2152: dialog = wx.FileDialog(self, _("Save as..."), os.getcwd(), "slave0.bin", Edouard@2152: _("bin files (*.bin)|*.bin|All files|*.*"), wx.SAVE|wx.OVERWRITE_PROMPT) Edouard@2152: Edouard@2152: if dialog.ShowModal() == wx.ID_OK: Edouard@2152: filepath = dialog.GetPath() Edouard@2152: binfile = open(filepath,"wb") Edouard@2152: binfile.write(self.SiiBinary) Edouard@2152: binfile.close() Edouard@2152: Edouard@2152: dialog.Destroy() Edouard@2152: Edouard@2152: def OnButtonReadFromBinFile(self, event): Edouard@2152: """ Edouard@2152: Load binary file through FileDialog Edouard@2152: Binded to 'Read from File' button. Edouard@2152: @param event : wx.EVT_BUTTON object Edouard@2152: """ Edouard@2152: dialog = wx.FileDialog(self, _("Choose a binary file"), os.getcwd(), "", Edouard@2152: _("bin files (*.bin)|*.bin"), wx.OPEN) Edouard@2152: Edouard@2152: if dialog.ShowModal() == wx.ID_OK: Edouard@2152: filepath = dialog.GetPath() Edouard@2152: Edouard@2152: try: Edouard@2152: binfile = open(filepath, "rb") Edouard@2152: self.SiiBinary = binfile.read() Edouard@2152: self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary) Edouard@2152: self.UpdateSiiGridTable(self.HexRow, self.HexCol) Edouard@2152: self.SiiGrid.SetValue(self.HexCode) Edouard@2152: self.SiiGrid.Update() Edouard@2152: except: Edouard@2152: self.Controler.CommonMethod.CreateErrorDialog('The file does not exist!') Edouard@2152: Edouard@2152: dialog.Destroy() Edouard@2152: Edouard@2152: def OnButtonXmlToEEPROMImg(self, event): Edouard@2152: """ Edouard@2152: Create EEPROM data based XML data that current imported Edouard@2152: Binded to 'XML to EEPROM' button. Edouard@2152: @param event : wx.EVT_BUTTON object Edouard@2152: """ Edouard@2152: self.SiiBinary = self.Controler.CommonMethod.XmlToEeprom() Edouard@2152: self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary) Edouard@2152: self.UpdateSiiGridTable(self.HexRow, self.HexCol) Edouard@2152: self.SiiGrid.SetValue(self.HexCode) Edouard@2152: self.SiiGrid.Update() Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For Hex View grid (fill hex data) Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class SiiGridTable(wx.grid.Grid): Edouard@2152: def __init__(self, parent, controler, row, col): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: Reference to the parent HexView class Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: @param row, col: Hex View grid size Edouard@2152: """ Edouard@2152: self.parent = parent Edouard@2152: self.Controler = controler Edouard@2152: self.Row = row Edouard@2152: self.Col = col Edouard@2152: Edouard@2152: wx.grid.Grid.__init__(self, parent, -1, size=(830,450), Edouard@2152: style=wx.ALIGN_CENTRE_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL) Edouard@2152: Edouard@2152: def SetValue(self, value): Edouard@2152: """ Edouard@2152: Set data in the table Edouard@2152: @param value: EEPROM data list of which element is 1 Byte hex data Edouard@2152: """ Edouard@2152: # set label name and size Edouard@2152: self.SetRowLabelSize(100) Edouard@2152: for col in range(self.Col): Edouard@2152: if col == 16: Edouard@2152: self.SetColLabelValue(16, "Text View") Edouard@2152: self.SetColSize(16, (self.GetSize().x-120)*4/20) Edouard@2152: else: Edouard@2152: self.SetColLabelValue(col, '%s'%col) Edouard@2152: self.SetColSize(col, (self.GetSize().x-120)/20) Edouard@2152: Edouard@2152: # set data into table Edouard@2152: row = col = 0 Edouard@2152: for row_idx in value: Edouard@2152: col = 0 Edouard@2152: self.SetRowLabelValue(row, "0x"+"{:0>4x}".format(row*(self.Col-1))) Edouard@2152: for hex in row_idx: Edouard@2152: self.SetCellValue(row, col, hex) Edouard@2152: Edouard@2152: if col == 16: Edouard@2152: self.SetCellAlignment(row, col, wx.ALIGN_LEFT, wx.ALIGN_CENTER) Edouard@2152: else: Edouard@2152: self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTER) Edouard@2152: Edouard@2152: self.SetReadOnly(row, col, True) Edouard@2152: col = col + 1 Edouard@2152: row = row + 1 Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For Register Access Panel Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class RegisterAccessPanel(wx.Panel): Edouard@2152: def __init__(self, parent, controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: EEPROMAccessPanel object Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: self.parent = parent Edouard@2152: self.Controler = controler Edouard@2152: self.__init_data() Edouard@2152: Edouard@2152: wx.Panel.__init__(self, parent, -1) Edouard@2152: Edouard@2152: sizer = wx.FlexGridSizer(cols=1, hgap=20, rows=2, vgap=5) Edouard@2152: button_sizer = wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=10) Edouard@2152: Edouard@2152: self.ReloadButton = wx.Button(self, -1, "Reload") Edouard@2152: self.CompactViewCheckbox = wx.CheckBox(self, -1, "Compact View") Edouard@2152: self.RegisterNotebook = RegisterNotebook(self, self.Controler) Edouard@2152: Edouard@2152: button_sizer.AddMany([self.ReloadButton, self.CompactViewCheckbox]) Edouard@2152: sizer.AddMany([button_sizer, self.RegisterNotebook]) Edouard@2152: self.SetSizer(sizer) Edouard@2152: Edouard@2152: self.ReloadButton.Bind(wx.EVT_BUTTON, self.OnReloadButton) Edouard@2152: self.CompactViewCheckbox.Bind(wx.EVT_CHECKBOX, self.ToggleCompactViewCheckbox) Edouard@2152: Edouard@2152: for index in range(4): Edouard@2152: self.RegisterNotebook.RegPage[index].MainTable.CreateGrid(self.MainRow[index], self.MainCol) Edouard@2152: self.RegisterNotebook.RegPage[index].MainTable.SetValue(self, 0, index*512, (index+1)*512) Edouard@2152: Edouard@2152: # data default setting Edouard@2152: if self.Controler.CommonMethod.RegData == "": Edouard@2152: self.CompactViewCheckbox.Disable() Edouard@2152: for index in range(4): Edouard@2152: self.RegisterNotebook.RegPage[index].MainTable.SetValue(self, 0, index*512, (index+1)*512) Edouard@2152: else: # If data was saved, Edouard@2152: self.BasicSetData() Edouard@2152: self.ParseData() Edouard@2152: for index in range(4): Edouard@2152: self.RegisterNotebook.RegPage[index].MainTable.SetValue(self, self.RegMonitorData, index*512, (index+1)*512) Edouard@2152: Edouard@2152: def __init_data(self): Edouard@2152: """ Edouard@2152: Declare initial data. Edouard@2152: """ Edouard@2152: # flag for compact view Edouard@2152: self.CompactFlag = False Edouard@2152: Edouard@2152: # main grid의 rows and cols Edouard@2152: self.MainRow = [512, 512, 512, 512] Edouard@2152: self.MainCol = 4 Edouard@2152: Edouard@2152: # main grids' data range Edouard@2152: self.PageRange = [] Edouard@2152: for index in range(4): Edouard@2152: self.PageRange.append([512*index, 512*(index+1)]) Edouard@2152: Edouard@2152: # Previous value of register data for register description configuration Edouard@2152: self.PreRegSpec = {"ESCType": "", Edouard@2152: "FMMUNumber": "", Edouard@2152: "SMNumber": "", Edouard@2152: "PDIType": ""} Edouard@2152: Edouard@2152: def LoadData(self): Edouard@2152: """ Edouard@2152: Get data from the register. Edouard@2152: """ Edouard@2152: self.Controler.CommonMethod.RegData = "" Edouard@2152: #ethercat reg_read Edouard@2152: #ex : ethercat reg_read -p 0 0x0000 0x0001 Edouard@2152: #return value : 0x11 Edouard@2152: for index in range(4): Edouard@2152: self.Controler.CommonMethod.RegData = self.Controler.CommonMethod.RegData + " " + self.Controler.CommonMethod.RegRead("0x"+"{:0>4x}".format(index*1024), "0x0400") Edouard@2152: Edouard@2152: # store previous value Edouard@2152: # (ESC type, port number of FMMU, port number of SM, and PDI type)) Edouard@2152: for reg_spec in ["ESCType","FMMUNumber","SMNumber", "PDIType"]: Edouard@2152: self.PreRegSpec[reg_spec] = self.Controler.CommonMethod.CrtRegSpec[reg_spec] Edouard@2152: Edouard@2152: # update registers' description Edouard@2152: # (ESC type, port number of FMMU, port number of SM, and PDI type) Edouard@2152: for reg_spec, address in [("ESCType", "0x0000"), Edouard@2152: ("FMMUNumber", "0x0004"), Edouard@2152: ("SMNumber", "0x0005"), Edouard@2152: ("PDIType", "0x0140")]: Edouard@2152: self.Controler.CommonMethod.CrtRegSpec[reg_spec] = self.Controler.CommonMethod.RegRead(address, "0x0001") Edouard@2152: Edouard@2152: # Enable compactView checkbox Edouard@2152: self.CompactViewCheckbox.Enable() Edouard@2152: Edouard@2152: def BasicSetData(self): Edouard@2152: """ Edouard@2152: Get and save the description of registers. Edouard@2152: It's done by parsing register_information.xml. Edouard@2152: """ Edouard@2152: # parse the above register's value Edouard@2152: # If the value is 0x12, the result is 12 Edouard@2152: self.ESCType = self.Controler.CommonMethod.CrtRegSpec["ESCType"].split('x')[1] Edouard@2152: self.PDIType = self.Controler.CommonMethod.CrtRegSpec["PDIType"].split('x')[1] Edouard@2152: # If the value is 0x12, the result is 18 (It's converted to decimal value) Edouard@2152: self.FMMUNumber = int(self.Controler.CommonMethod.CrtRegSpec["FMMUNumber"], 16) Edouard@2152: self.SMNumber = int(self.Controler.CommonMethod.CrtRegSpec["SMNumber"], 16) Edouard@2152: Edouard@2152: # initialize description dictionary of register main table and register sub table. Edouard@2152: self.RegisterDescriptionDict = {} Edouard@2152: self.RegisterSubGridDict = {} Edouard@2152: Edouard@2152: # ./EthercatMaster/register_information.xml contains register description. Edouard@2152: if wx.Platform == '__WXMSW__': Edouard@2152: reg_info_file = open("../../EthercatMaster/register_information.xml", 'r') Edouard@2152: else: Edouard@2152: reg_info_file = open("./EthercatMaster/register_information.xml", 'r') Edouard@2152: reg_info_tree = minidom.parse(reg_info_file) Edouard@2152: reg_info_file.close() Edouard@2152: Edouard@2152: # parse register description Edouard@2152: for register_info in reg_info_tree.childNodes: Edouard@2152: for register in register_info.childNodes: Edouard@2152: if register.nodeType == reg_info_tree.ELEMENT_NODE and register.nodeName == "Register": Edouard@2152: # If it depends on the property(ESC type, PDI type, FMMU number, SM number) Edouard@2152: for property, type, value in [("esc", "type", self.ESCType), Edouard@2152: ("pdi", "type", self.PDIType), Edouard@2152: ("fmmu", "number", self.FMMUNumber), Edouard@2152: ("sm", "number", self.SMNumber)]: Edouard@2152: if property in register.attributes.keys(): Edouard@2152: if type == "type": Edouard@2152: if register.attributes[property].value == value: Edouard@2152: self.GetRegisterInfo(reg_info_tree, register) Edouard@2152: break Edouard@2152: else: # type == "number" Edouard@2152: if register.attributes[property].value < value: Edouard@2152: self.GetRegisterInfo(reg_info_tree, register) Edouard@2152: break Edouard@2152: else: Edouard@2152: self.GetRegisterInfo(reg_info_tree, register) Edouard@2152: break Edouard@2152: Edouard@2152: def GetRegisterInfo(self, reg_info_tree, register): Edouard@2152: """ Edouard@2152: Save the register's description into the dictionary. Edouard@2152: reg_info_tree is based on the register_information.xml. Edouard@2152: @param reg_info_tree: XML tree Edouard@2152: @param register: register which you want to get the description Edouard@2152: """ Edouard@2152: # temporary variables for register main table idescription dictionary Edouard@2152: reg_index = "" Edouard@2152: reg_main_description = "" Edouard@2152: Edouard@2152: for data in register.childNodes: Edouard@2152: if data.nodeType == reg_info_tree.ELEMENT_NODE and data.nodeName == "Index": Edouard@2152: for index in data.childNodes: Edouard@2152: reg_index = index.nodeValue Edouard@2152: if data.nodeType == reg_info_tree.ELEMENT_NODE and data.nodeName == "Description": Edouard@2152: for description in data.childNodes: Edouard@2152: reg_main_description = description.nodeValue Edouard@2152: Edouard@2152: # Add description for register main table Edouard@2152: if reg_index is not "" and reg_main_description is not "": Edouard@2152: self.RegisterDescriptionDict[reg_index] = reg_main_description Edouard@2152: Edouard@2152: if data.nodeType == reg_info_tree.ELEMENT_NODE and data.nodeName == "Details": Edouard@2152: # declare register sub table description dictionary about this index Edouard@2152: self.RegisterSubGridDict[reg_index] = [] Edouard@2152: Edouard@2152: for detail in data.childNodes: Edouard@2152: if detail.nodeType == reg_info_tree.ELEMENT_NODE and detail.nodeName == "Detail": Edouard@2152: # If it depends on the property(ESC type, PDI type, FMMU number, SM number) Edouard@2152: for property, type, value in [("esc", "type", self.ESCType), Edouard@2152: ("pdi", "type", self.PDIType), Edouard@2152: ("fmmu", "number", self.FMMUNumber), Edouard@2152: ("sm", "number", self.SMNumber)]: Edouard@2152: if property in detail.attributes.keys(): Edouard@2152: if type == "type": Edouard@2152: if detail.attributes[property].value == value: Edouard@2152: self.GetRegisterDetailInfo(reg_info_tree, reg_index, detail) Edouard@2152: break Edouard@2152: else: # type == "number" Edouard@2152: if detail.attributes[property].value < value: Edouard@2152: self.GetRegisterDetailInfo(reg_info_tree, reg_index, detail) Edouard@2152: break Edouard@2152: else: Edouard@2152: self.GetRegisterDetailInfo(reg_info_tree, reg_index, detail) Edouard@2152: break Edouard@2152: Edouard@2152: def GetRegisterDetailInfo(self, reg_info_tree, reg_index, detail): Edouard@2152: """ Edouard@2152: Get the resgister's detailed description(for sub table) from the reg_info_tree. Edouard@2152: @param reg_info_tree: XML tree (register_information.xml) Edouard@2152: @param reg_index: index of the register Edouard@2152: @param detail: description of the register Edouard@2152: """ Edouard@2152: # temporary variables for register sub table description dictionary Edouard@2152: # - It is initialized in every sub description Edouard@2152: reg_bit_range = "" Edouard@2152: reg_sub_description = "" Edouard@2152: reg_enum_dictionary = {} Edouard@2152: Edouard@2152: for detail_data in detail.childNodes: Edouard@2152: if detail_data.nodeType == reg_info_tree.ELEMENT_NODE and detail_data.nodeName == "Range": Edouard@2152: for range in detail_data.childNodes: Edouard@2152: reg_bit_range = range.nodeValue Edouard@2152: if detail_data.nodeType == reg_info_tree.ELEMENT_NODE and detail_data.nodeName == "Description": Edouard@2152: for description in detail_data.childNodes: Edouard@2152: reg_sub_description = description.nodeValue Edouard@2152: Edouard@2152: if detail_data.nodeType == reg_info_tree.ELEMENT_NODE and detail_data.nodeName == "Enum": Edouard@2152: for enum in detail_data.childNodes: Edouard@2152: if enum.nodeType == reg_info_tree.ELEMENT_NODE and enum.nodeName == "item": Edouard@2152: Edouard@2152: # temporary variables for a description of each value Edouard@2152: # For example, if the bit is 1, it is 'enabled'('On', 'True', etc.), Edouard@2152: # otherwise 'disabled'('Off', 'False', etc.). Edouard@2152: reg_sub_value = "" Edouard@2152: reg_sub_value_description = "" Edouard@2152: Edouard@2152: for item in enum.childNodes: Edouard@2152: if item.nodeType == reg_info_tree.ELEMENT_NODE and item.nodeName == "value": Edouard@2152: for value in item.childNodes: Edouard@2152: reg_sub_value = value.nodeValue Edouard@2152: if item.nodeType == reg_info_tree.ELEMENT_NODE and item.nodeName == "Description": Edouard@2152: for description in item.childNodes: Edouard@2152: reg_sub_value_description = description.nodeValue Edouard@2152: Edouard@2152: # Add a description of each value to register enum dictionary Edouard@2152: if reg_sub_value is not "" and reg_sub_value_description is not "": Edouard@2152: reg_enum_dictionary[reg_sub_value] = reg_sub_value_description Edouard@2152: Edouard@2152: # add a description to register sub table description dictionary Edouard@2152: if reg_bit_range is not "" and reg_sub_description is not "": Edouard@2152: self.RegisterSubGridDict[reg_index].append([reg_bit_range, Edouard@2152: reg_sub_description, reg_enum_dictionary]) Edouard@2152: Edouard@2152: def ParseData(self): Edouard@2152: """ Edouard@2152: Transform the data into dec, hex, string, and description Edouard@2152: """ Edouard@2152: row_data = [] Edouard@2152: self.RegMonitorData = [] Edouard@2152: reg_word = "" Edouard@2152: Edouard@2152: reg_data = self.Controler.CommonMethod.RegData.split() Edouard@2152: Edouard@2152: # loop for register(0x0000:0x0fff) Edouard@2152: for address in range(0x1000): Edouard@2152: # arrange 2 Bytes of register data Edouard@2152: reg_word = reg_data[address].split('x')[1] + reg_word Edouard@2152: if (address%2) == 1: Edouard@2152: # append address Edouard@2152: hex_address = "{:0>4x}".format(address-1) Edouard@2152: row_data.append(hex_address) Edouard@2152: Edouard@2152: # append description Edouard@2152: if self.RegisterDescriptionDict.has_key(hex_address): Edouard@2152: row_data.append(self.RegisterDescriptionDict[hex_address]) Edouard@2152: else: Edouard@2152: row_data.append("") Edouard@2152: Edouard@2152: # append Decimal value Edouard@2152: row_data.append(str(int(reg_word, 16))) Edouard@2152: Edouard@2152: # append Hex value Edouard@2152: row_data.append('0x'+reg_word) Edouard@2152: Edouard@2152: # append ASCII value Edouard@2152: char_data = "" Edouard@2152: for iter in range(2): Edouard@2152: if int(reg_word[iter*2:iter*2+2], 16)>=32 and int(reg_word[iter*2:iter*2+2], 16)<=126: Edouard@2152: char_data = char_data + chr(int(reg_word[iter*2:iter*2+2], 16)) Edouard@2152: else: Edouard@2152: char_data = char_data + "." Edouard@2152: row_data.append(char_data) Edouard@2152: Edouard@2152: self.RegMonitorData.append(row_data) Edouard@2152: reg_word = "" # initialize regWord Edouard@2152: row_data = [] Edouard@2152: Edouard@2152: def OnReloadButton(self, event): Edouard@2152: """ Edouard@2152: Handle the click event of the 'Reload' button. Edouard@2152: Get the data from registers again, and update the table. Edouard@2152: @param event: wx.EVT_BUTTON object Edouard@2152: """ Edouard@2152: # Check whether beremiz connected or not. Edouard@2152: check_connect_flag = self.Controler.CommonMethod.CheckConnect(False) Edouard@2152: if check_connect_flag: Edouard@2152: self.LoadData() Edouard@2152: self.BasicSetData() Edouard@2152: self.ParseData() Edouard@2152: # set data into UI Edouard@2152: if self.CompactFlag: Edouard@2152: self.ToggleCompactViewCheckbox(True) Edouard@2152: else : Edouard@2152: for index in range(4): Edouard@2152: self.RegisterNotebook.RegPage[index].UpdateMainTable(self.MainRow[index], self.MainCol, Edouard@2152: self.PageRange[index][0], self.PageRange[index][1], Edouard@2152: self.RegMonitorData) Edouard@2152: Edouard@2152: def ToggleCompactViewCheckbox(self, event): Edouard@2152: """ Edouard@2152: Handles the event of the 'Compact view' check box. Edouard@2152: If it's checked, show only the registers that have a description. Edouard@2152: If not, show all the registers. Edouard@2152: @param event: wx.EVT_CHECKBOX object Edouard@2152: """ Edouard@2152: Edouard@2152: # If "Compact View" Checkbox is True Edouard@2152: ## 'event' is argument of this method or event of checkbox. Edouard@2152: if event==True or event.GetEventObject().GetValue(): Edouard@2152: self.CompactFlag = True Edouard@2152: Edouard@2152: reg_compact_data = [] Edouard@2152: page_row = [0, 0, 0, 0] Edouard@2152: for index in range(4): Edouard@2152: self.PageRange[index] = [0, 0] Edouard@2152: Edouard@2152: for reg_row_data in self.RegMonitorData: Edouard@2152: if reg_row_data[1] is not "": Edouard@2152: # data structure for "compact view" Edouard@2152: reg_compact_data.append(reg_row_data) Edouard@2152: # count for each register notebooks' row Edouard@2152: # It compare with register's address. Edouard@2152: for index in range(4): Edouard@2152: if int('0x'+reg_row_data[0], 16) < (index+1)*1024: Edouard@2152: page_row[index] += 1 Edouard@2152: break Edouard@2152: Edouard@2152: # Setting tables' rows and cols, range for compact view Edouard@2152: for index in range(4): Edouard@2152: self.MainRow[index] = page_row[index] Edouard@2152: self.PageRange[index][1] = page_row[index] Edouard@2152: for iter in range(index): Edouard@2152: self.PageRange[index][0] += page_row[iter] Edouard@2152: self.PageRange[index][1] += page_row[iter] Edouard@2152: Edouard@2152: # Update table Edouard@2152: for index in range(4): Edouard@2152: self.RegisterNotebook.RegPage[index].UpdateMainTable(self.MainRow[index], self.MainCol, Edouard@2152: self.PageRange[index][0], self.PageRange[index][1], Edouard@2152: reg_compact_data) Edouard@2152: Edouard@2152: # Compact View Checkbox is False Edouard@2152: else: Edouard@2152: self.CompactFlag = False Edouard@2152: # Setting original rows, cols and range Edouard@2152: self.MainRow = [512, 512, 512, 512] Edouard@2152: self.PageRange = [] Edouard@2152: Edouard@2152: for index in range(4): Edouard@2152: self.PageRange.append([512*index, 512*(index+1)]) Edouard@2152: Edouard@2152: # Update table Edouard@2152: for index in range(4): Edouard@2152: self.RegisterNotebook.RegPage[index].UpdateMainTable(self.MainRow[index], self.MainCol, Edouard@2152: self.PageRange[index][0], self.PageRange[index][1], Edouard@2152: self.RegMonitorData) Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For Register Access Notebook (divide index range) Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class RegisterNotebook(wx.Notebook): Edouard@2152: def __init__(self, parent, controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: RegisterAccessPanel object Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: wx.Notebook.__init__(self, parent, id = -1) Edouard@2152: Edouard@2152: self.parent = parent Edouard@2152: self.Controler = controler Edouard@2152: Edouard@2152: # Initialize pages Edouard@2152: self.RegPage = [] Edouard@2152: for iter in range(4): Edouard@2152: self.RegPage.append(None) Edouard@2152: Edouard@2152: for index in range(4): Edouard@2152: self.RegPage[index] = RegisterNotebookPanel(self, self.Controler, Edouard@2152: parent.MainRow[index], parent.MainCol) Edouard@2152: self.AddPage(self.RegPage[index], Edouard@2152: "0x"+"{:0>4x}".format(index*1024)+" - 0x"+"{:0>4x}".format((index+1)*1024-1)) Edouard@2152: Edouard@2152: self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged) Edouard@2152: self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging) Edouard@2152: Edouard@2152: def OnPageChanged(self, event): Edouard@2152: old = event.GetOldSelection() Edouard@2152: new = event.GetSelection() Edouard@2152: sel = self.GetSelection() Edouard@2152: event.Skip() Edouard@2152: Edouard@2152: def OnPageChanging(self, event): Edouard@2152: old = event.GetOldSelection() Edouard@2152: new = event.GetSelection() Edouard@2152: sel = self.GetSelection() Edouard@2152: event.Skip() Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For Register Access Notebook Panel Edouard@2152: # (Main UI : including main, sub table) Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class RegisterNotebookPanel(wx.Panel): Edouard@2152: def __init__(self, parent, controler, row, col): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: RegisterAccessPanel object Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: @param row, col: size of the table Edouard@2152: """ Edouard@2152: wx.Panel.__init__(self, parent, -1) Edouard@2152: Edouard@2152: self.parent = parent Edouard@2152: self.Controler = controler Edouard@2152: self.Row = row Edouard@2152: self.Col = col Edouard@2152: sub_row = 0 Edouard@2152: sub_col = 4 Edouard@2152: Edouard@2152: self.Sizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=30) Edouard@2152: Edouard@2152: self.MainTable = RegisterMainTable(self, self.Row, self.Col, self.Controler) Edouard@2152: self.SubTable = RegisterSubTable(self, sub_row, sub_col) Edouard@2152: Edouard@2152: self.SubTable.CreateGrid(sub_row, sub_col) Edouard@2152: self.SubTable.SetValue(self, []) Edouard@2152: Edouard@2152: self.Sizer.AddMany([self.MainTable, self.SubTable]) Edouard@2152: Edouard@2152: self.SetSizer(self.Sizer) Edouard@2152: Edouard@2152: def UpdateMainTable(self, row, col, low_index, high_index, data): Edouard@2152: """ Edouard@2152: Updates main table. Edouard@2152: It's done by deleting the main table and creating it again. Edouard@2152: @param row, col: size of the table Edouard@2152: @param low_index: the lowest index of the page Edouard@2152: @param high_index: the highest index of the page Edouard@2152: @param data: data Edouard@2152: """ Edouard@2152: self.MainTable.Destroy() Edouard@2152: self.MainTable = RegisterMainTable(self, row, col, self.Controler) Edouard@2152: self.Sizer.Detach(self.SubTable) Edouard@2152: self.Sizer.AddMany([self.MainTable, self.SubTable]) Edouard@2152: self.SetSizer(self.Sizer) Edouard@2152: self.MainTable.CreateGrid(row, col) Edouard@2152: self.MainTable.SetValue(self, data, low_index, high_index) Edouard@2152: self.MainTable.Update() Edouard@2152: Edouard@2152: def UpdateSubTable(self, row, col, data): Edouard@2152: """ Edouard@2152: Updates sub table. Edouard@2152: It's done by deleting the sub table and creating it again. Edouard@2152: @param row, col: size of the table Edouard@2152: @param data: data Edouard@2152: """ Edouard@2152: self.SubTable.Destroy() Edouard@2152: self.SubTable = RegisterSubTable(self, row, col) Edouard@2152: self.Sizer.Detach(self.MainTable) Edouard@2152: self.Sizer.AddMany([self.MainTable, self.SubTable]) Edouard@2152: self.Sizer.Layout() Edouard@2152: self.SetSizer(self.Sizer) Edouard@2152: self.SubTable.CreateGrid(row, col) Edouard@2152: self.SubTable.SetValue(self, data) Edouard@2152: self.SubTable.Update() Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For Register Access Notebook Panel (Main Table) Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class RegisterMainTable(wx.grid.Grid): Edouard@2152: def __init__(self, parent, row, col, controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: RegisterNotebook object Edouard@2152: @param row, col: size of the table Edouard@2152: @param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: self.parent = parent Edouard@2152: self.Data = {} Edouard@2152: self.Row = row Edouard@2152: self.Col = col Edouard@2152: self.Controler = controler Edouard@2152: self.RegisterAccessPanel = self.parent.parent.parent Edouard@2152: Edouard@2152: wx.grid.Grid.__init__(self, parent, -1, size=(820,300), Edouard@2152: style=wx.EXPAND|wx.ALIGN_CENTRE_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL) Edouard@2152: Edouard@2152: for evt, mapping_method in [(gridlib.EVT_GRID_CELL_LEFT_CLICK, self.OnSelectCell), Edouard@2152: (gridlib.EVT_GRID_CELL_LEFT_CLICK, self.OnSelectCell), Edouard@2152: (gridlib.EVT_GRID_CELL_LEFT_DCLICK, self.OnRegModifyDialog)]: Edouard@2152: self.Bind(evt, mapping_method) Edouard@2152: Edouard@2152: def SetValue(self, parent, reg_monitor_data, low_index, high_index): Edouard@2152: """ Edouard@2152: Set the RegMonitorData into the main table. Edouard@2152: @param parent: RegisterNotebook object Edouard@2152: @param reg_monitor_data: data Edouard@2152: @param low_index: the lowest index of the page Edouard@2152: @param high_index: the highest index of the page Edouard@2152: """ Edouard@2152: self.RegMonitorData = reg_monitor_data Edouard@2152: Edouard@2152: # set label name and size Edouard@2152: register_maintable_label = [(0, "Description"), (1, "Dec"), Edouard@2152: (2, "Hex"), (3, "Char")] Edouard@2152: Edouard@2152: for (index, label) in register_maintable_label: Edouard@2152: self.SetColLabelValue(index, label) Edouard@2152: Edouard@2152: self.SetColSize(0, 200) Edouard@2152: Edouard@2152: # if reg_monitor_data is 0, it is initialization of register access. Edouard@2152: if reg_monitor_data == 0: Edouard@2152: return 0 Edouard@2152: Edouard@2152: # set data into UI Edouard@2152: row = col = 0 Edouard@2152: for row_index in reg_monitor_data[low_index:high_index]: Edouard@2152: col = 0 Edouard@2152: self.SetRowLabelValue(row, row_index[0]) Edouard@2152: for data_index in range(4): Edouard@2152: self.SetCellValue(row, col, row_index[data_index+1]) Edouard@2152: self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTER) Edouard@2152: self.SetReadOnly(row, col, True) Edouard@2152: col = col + 1 Edouard@2152: row = row + 1 Edouard@2152: Edouard@2152: def OnSelectCell(self, event): Edouard@2152: """ Edouard@2152: Handles the event of the cell of the main table. Edouard@2152: @param event: gridlib object (left click) Edouard@2152: """ Edouard@2152: # if reg_monitor_data is 0, it is initialization of register access. Edouard@2152: if self.RegMonitorData == 0: Edouard@2152: event.Skip() Edouard@2152: return 0 Edouard@2152: Edouard@2152: sub_row = 0 Edouard@2152: sub_col = 4 Edouard@2152: Edouard@2152: address = self.GetRowLabelValue(event.GetRow()) Edouard@2152: Edouard@2152: reg_sub_grid_data = [] Edouard@2152: Edouard@2152: BIT_RANGE, NAME, DESCRIPTIONS = range(3) Edouard@2152: Edouard@2152: # Check if this register's detail description is exist or not, Edouard@2152: # and create data structure for the detail description table ; sub grid Edouard@2152: if address in self.RegisterAccessPanel.RegisterSubGridDict: Edouard@2152: for element in self.RegisterAccessPanel.RegisterSubGridDict[address]: Edouard@2152: row_data =[] Edouard@2152: row_data.append(element[BIT_RANGE]) Edouard@2152: row_data.append(element[NAME]) Edouard@2152: bin_data = "{:0>16b}".format(int(self.GetCellValue(event.GetRow(), 1))) Edouard@2152: value_range = element[BIT_RANGE].split('-') Edouard@2152: value = (bin_data[8:16][::-1]+bin_data[0:8][::-1])[int(value_range[0]):(int(value_range[-1])+1)][::-1] Edouard@2152: row_data.append(str(int(('0b'+str(value)), 2))) Edouard@2152: if value in element[DESCRIPTIONS]: Edouard@2152: row_data.append(element[DESCRIPTIONS][value]) Edouard@2152: else: Edouard@2152: row_data.append('') Edouard@2152: reg_sub_grid_data.append(row_data) Edouard@2152: sub_row = sub_row + 1 Edouard@2152: Edouard@2152: self.parent.UpdateSubTable(sub_row, sub_col, reg_sub_grid_data) Edouard@2152: # event.Skip() updates UI of selecting cell Edouard@2152: event.Skip() Edouard@2152: Edouard@2152: def OnRegModifyDialog(self, event): Edouard@2152: """ Edouard@2152: Handle the event of the cell of the main table. Edouard@2152: Display the window where the user modifies the value of the cell. Edouard@2152: @param event: gridlib object (double click) Edouard@2152: """ Edouard@2152: # user can enter a value in case that user double-clicked 'Dec' or 'Hex' value. Edouard@2152: if event.GetCol() == 1 or event.GetCol() == 2: Edouard@2152: dlg = wx.TextEntryDialog(self, "Enter hex(0xnnnn) or dec(n) value", Edouard@2152: "Register Modify Dialog", style = wx.OK|wx.CANCEL) Edouard@2152: Edouard@2152: # Setting value in initial dialog value Edouard@2152: start_value = self.GetCellValue(event.GetRow(), event.GetCol()) Edouard@2152: dlg.SetValue(start_value) Edouard@2152: Edouard@2152: if dlg.ShowModal() == wx.ID_OK: Edouard@2152: try: Edouard@2152: # It int(input) success, this input is dev or hex value. Edouard@2152: # Otherwise, it's error, so it goes except. Edouard@2152: int(dlg.GetValue(), 0) Edouard@2152: Edouard@2152: # reg_write Edouard@2152: # ex) ethercat reg_write -p 0 -t uint16 0x0000 0x0000 Edouard@2152: return_val = self.Controler.CommonMethod.RegWrite('0x'+self.GetRowLabelValue(event.GetRow()), dlg.GetValue()) Edouard@2152: Edouard@2152: if len(return_val)==0: Edouard@2152: # set dec Edouard@2152: self.SetCellValue(event.GetRow(), 1, str(int(dlg.GetValue(), 0))) Edouard@2152: # set hex Edouard@2152: hex_data = '0x'+"{:0>4x}".format(int(dlg.GetValue(), 0)) Edouard@2152: self.SetCellValue(event.GetRow(), 2, hex_data) Edouard@2152: # set char Edouard@2152: char_data = "" Edouard@2152: # If hex_data is been able to convert to ascii code, append ascii code. Edouard@2152: for iter in range(2): Edouard@2152: if int(hex_data[(iter+1)*2:(iter+2)*2], 16)>=32 and int(hex_data[(iter+1)*2:(iter+2)*2], 16)<=126: Edouard@2152: char_data = char_data + chr(int(hex_data[(iter+1)*2:(iter+2)*2], 16)) Edouard@2152: else: Edouard@2152: char_data = char_data + "." Edouard@2152: Edouard@2152: self.SetCellValue(event.GetRow(), 3, char_data) Edouard@2152: Edouard@2152: else: Edouard@2152: self.Controler.CommonMethod.CreateErrorDialog('You can\'t modify it. This register is read-only or it\'s not connected.') Edouard@2152: Edouard@2152: except ValueError: Edouard@2152: self.Controler.CommonMethod.CreateErrorDialog('You entered wrong value. You can enter dec or hex value only.') Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For Register Access Notebook Panel (Sub Table) Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class RegisterSubTable(wx.grid.Grid): Edouard@2152: def __init__(self, parent, row, col): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: RegisterNotebook object Edouard@2152: @param row, col: size of the table Edouard@2152: """ Edouard@2152: self.parent = parent Edouard@2152: self.Data = {} Edouard@2152: self.Row = row Edouard@2152: self.Col = col Edouard@2152: Edouard@2152: wx.grid.Grid.__init__(self, parent, -1, size=(820,150), Edouard@2152: style=wx.EXPAND|wx.ALIGN_CENTRE_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL) Edouard@2152: Edouard@2152: def SetValue(self, parent, data): Edouard@2152: """ Edouard@2152: Set the data into the subtable. Edouard@2152: @param parent: RegisterNotebook object Edouard@2152: @param data: data Edouard@2152: """ Edouard@2152: # lset label name and size Edouard@2152: Register_SubTable_Label = [(0, "Bits"), (1, "Name"), Edouard@2152: (2, "Value"), (3, "Enum")] Edouard@2152: Edouard@2152: for (index, label) in Register_SubTable_Label: Edouard@2152: self.SetColLabelValue(index, label) Edouard@2152: Edouard@2152: self.SetColSize(1, 200) Edouard@2152: self.SetColSize(3, 200) Edouard@2152: Edouard@2152: # set data into table Edouard@2152: row = col = 0 Edouard@2152: for rowData in data: Edouard@2152: col = 0 Edouard@2152: for element in rowData: Edouard@2152: self.SetCellValue(row, col, element) Edouard@2152: self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTER) Edouard@2152: self.SetReadOnly(row, col, True) Edouard@2152: col = col + 1 Edouard@2152: row = row + 1 Edouard@2152: Edouard@2152: Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: # For Master State Panel Edouard@2152: #------------------------------------------------------------------------------- Edouard@2152: class MasterStatePanelClass(wx.Panel): Edouard@2152: def __init__(self, parent, controler): Edouard@2152: """ Edouard@2152: Constructor Edouard@2152: @param parent: wx.ScrollWindow object Edouard@2152: @Param controler: _EthercatSlaveCTN class in EthercatSlave.py Edouard@2152: """ Edouard@2152: wx.Panel.__init__(self, parent, -1, (0, 0), Edouard@2152: size=wx.DefaultSize, style = wx.SUNKEN_BORDER) Edouard@2152: self.Controler = controler Edouard@2152: self.parent = parent Edouard@2152: self.StaticBox = {} Edouard@2152: self.StaticText = {} Edouard@2152: self.TextCtrl = {} Edouard@2152: Edouard@2152: # ----------------------- Main Sizer and Update Button -------------------------------------------- Edouard@2152: self.MasterStateSizer = {"main" : wx.BoxSizer(wx.VERTICAL)} Edouard@2152: for key, attr in [ Edouard@2152: ("innerMain", [1, 10, 2, 10]), Edouard@2152: ("innerTopHalf", [2, 10, 1, 10]), Edouard@2152: ("innerBottomHalf", [2, 10, 1, 10]), Edouard@2152: ("innerMasterState", [2, 10, 3, 10]), Edouard@2152: ("innerDeviceInfo", [4, 10, 3, 10]), Edouard@2152: ("innerFrameInfo", [4, 10, 5, 10])]: Edouard@2152: self.MasterStateSizer[key] = wx.FlexGridSizer(cols=attr[0], hgap=attr[1], rows=attr[2], vgap=attr[3]) Edouard@2152: Edouard@2152: Edouard@2152: self.UpdateButton = wx.Button(self, label=_('Update')) Edouard@2152: self.UpdateButton.Bind(wx.EVT_BUTTON, self.OnButtonClick) Edouard@2152: Edouard@2152: for key, label in [ Edouard@2152: ('masterState', 'EtherCAT Master State'), Edouard@2152: ('deviceInfo', 'Ethernet Network Card Information'), Edouard@2152: ('frameInfo', 'Network Frame Information')]: Edouard@2152: self.StaticBox[key] = wx.StaticBox(self, label=_(label)) Edouard@2152: self.MasterStateSizer[key] = wx.StaticBoxSizer(self.StaticBox[key]) Edouard@2152: Edouard@2152: Edouard@2152: # ----------------------- Master State ----------------------------------------------------------- Edouard@2152: for key, label in [ Edouard@2152: ('Phase', 'Phase:'), Edouard@2152: ('Active', 'Active:'), Edouard@2152: ('Slaves', 'Slave Count:')]: Edouard@2152: self.StaticText[key] = wx.StaticText(self, label=_(label)) Edouard@2152: self.TextCtrl[key] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY) Edouard@2152: self.MasterStateSizer['innerMasterState'].AddMany([self.StaticText[key], self.TextCtrl[key]]) Edouard@2152: Edouard@2152: self.MasterStateSizer['masterState'].AddSizer(self.MasterStateSizer['innerMasterState']) Edouard@2152: Edouard@2152: # ----------------------- Ethernet Network Card Information --------------------------------------- Edouard@2152: for key, label in [ Edouard@2152: ('Main', 'MAC Address:'), Edouard@2152: ('Link', 'Link State:'), Edouard@2152: ('Tx frames', 'Tx Frames:'), Edouard@2152: ('Rx frames', 'Rx Frames:'), Edouard@2152: ('Lost frames', 'Lost Frames:')]: Edouard@2152: self.StaticText[key] = wx.StaticText(self, label=_(label)) Edouard@2152: self.TextCtrl[key] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY) Edouard@2152: self.MasterStateSizer['innerDeviceInfo'].AddMany([self.StaticText[key], self.TextCtrl[key]]) Edouard@2152: Edouard@2152: self.MasterStateSizer['deviceInfo'].AddSizer(self.MasterStateSizer['innerDeviceInfo']) Edouard@2152: Edouard@2152: # ----------------------- Network Frame Information ----------------------------------------------- Edouard@2152: for key, label in [ Edouard@2152: ('Tx frame rate [1/s]', 'Tx Frame Rate [1/s]:'), Edouard@2152: ('Rx frame rate [1/s]', 'Tx Rate [kByte/s]:'), Edouard@2152: ('Loss rate [1/s]', 'Loss Rate [1/s]:'), Edouard@2152: ('Frame loss [%]', 'Frame Loss [%]:')]: Edouard@2152: self.StaticText[key] = wx.StaticText(self, label=_(label)) Edouard@2152: self.MasterStateSizer['innerFrameInfo'].Add(self.StaticText[key]) Edouard@2152: self.TextCtrl[key] = {} Edouard@2152: for index in ['0', '1', '2']: Edouard@2152: self.TextCtrl[key][index] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY) Edouard@2152: self.MasterStateSizer['innerFrameInfo'].Add(self.TextCtrl[key][index]) Edouard@2152: Edouard@2152: self.MasterStateSizer['frameInfo'].AddSizer(self.MasterStateSizer['innerFrameInfo']) Edouard@2152: Edouard@2152: # --------------------------------- Main Sizer ---------------------------------------------------- Edouard@2152: for key, sub, in [ Edouard@2152: ('innerTopHalf', [ Edouard@2152: 'masterState', 'deviceInfo']), Edouard@2152: ('innerBottomHalf', [ Edouard@2152: 'frameInfo']), Edouard@2152: ('innerMain', [ Edouard@2152: 'innerTopHalf', 'innerBottomHalf'])]: Edouard@2152: for key2 in sub: Edouard@2152: self.MasterStateSizer[key].AddSizer(self.MasterStateSizer[key2]) Edouard@2152: Edouard@2152: self.MasterStateSizer['main'].AddSizer(self.UpdateButton) Edouard@2152: self.MasterStateSizer['main'].AddSizer(self.MasterStateSizer['innerMain']) Edouard@2152: Edouard@2152: self.SetSizer(self.MasterStateSizer['main']) Edouard@2152: Edouard@2152: def OnButtonClick(self, event): Edouard@2152: """ Edouard@2152: Handle the event of the 'Update' button. Edouard@2152: Update the data of the master state. Edouard@2152: @param event: wx.EVT_BUTTON object Edouard@2152: """ Edouard@2152: if self.Controler.GetCTRoot()._connector is not None: Edouard@2152: self.MasterState = self.Controler.CommonMethod.GetMasterState() Edouard@2152: # Update each TextCtrl Edouard@2152: if self.MasterState: Edouard@2152: for key in self.TextCtrl: Edouard@2152: if isinstance(self.TextCtrl[key], dict): Edouard@2152: for index in self.TextCtrl[key]: Edouard@2152: self.TextCtrl[key][index].SetValue(self.MasterState[key][int(index)]) Edouard@2152: else: Edouard@2152: self.TextCtrl[key].SetValue(self.MasterState[key][0]) Edouard@2152: else : Edouard@2152: self.Controler.CommonMethod.CreateErrorDialog('PLC not connected!')