andrej@2354: #!/usr/bin/env python andrej@2354: # -*- coding: utf-8 -*- andrej@2354: andrej@2354: # This file is part of Beremiz andrej@2354: # andrej@2354: # Copyright (C) 2013: Real-Time & Embedded Systems (RTES) Lab., University of Seoul andrej@2354: # andrej@2354: # See COPYING file for copyrights details. andrej@2354: kinsamanka@3750: kinsamanka@3750: andrej@2354: import os andrej@2390: import string andrej@2390: from xml.dom import minidom andrej@2354: andrej@2354: import wx andrej@2354: import wx.grid edouard@3303: import wx.adv andrej@2354: import wx.lib.buttons andrej@2354: andrej@2354: # -------------------------------------------------------------------- andrej@2354: from controls import CustomGrid, CustomTable andrej@2416: from runtime import PlcStatus andrej@2354: # -------------------------------------------------------------------- andrej@2354: andrej@2355: # ------------ for register management --------------- andrej@2390: andrej@2375: from util.TranslationCatalogs import NoTranslate andrej@2356: # ------------------------------------------------------------- andrej@2354: andrej@2360: andrej@2354: # ----------------------------- For Sync Manager Table ----------------------------------- andrej@2354: def GetSyncManagersTableColnames(): andrej@2354: """ andrej@2354: Returns column names of SyncManager Table in Slave state panel. andrej@2354: """ andrej@2375: _ = NoTranslate andrej@2354: return ["#", _("Name"), _("Start Address"), _("Default Size"), _("Control Byte"), _("Enable")] andrej@2354: andrej@2360: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # Sync Managers Table andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class SyncManagersTable(CustomTable): andrej@2355: def GetValue(self, row, col): andrej@2354: if row < self.GetNumberRows(): andrej@2354: if col == 0: andrej@2354: return row andrej@2354: return self.data[row].get(self.GetColLabelValue(col, False), "") andrej@2354: andrej@2360: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # EtherCAT Management Treebook andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class EtherCATManagementTreebook(wx.Treebook): andrej@2354: def __init__(self, parent, controler, node_editor): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: Reference to the parent wx.ScrolledWindow object andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: @param node_editor: Reference to Beremiz frame andrej@2354: """ andrej@2354: wx.Treebook.__init__(self, parent, -1, size=wx.DefaultSize, style=wx.BK_DEFAULT) andrej@2354: self.parent = parent andrej@2354: self.Controler = controler andrej@2354: self.NodeEditor = node_editor andrej@2355: andrej@2354: self.EtherCATManagementClassObject = {} andrej@2355: andrej@2354: # fill EtherCAT Management Treebook andrej@2379: panels = [ andrej@2354: ("Slave State", SlaveStatePanelClass, []), andrej@2354: ("SDO Management", SDOPanelClass, []), edouard@2643: ("PDO Mapping", PDOPanelClass, [ edouard@2643: ("Rx PDO", RxPDOPanelClass), edouard@2643: ("Tx PDO", TxPDOPanelClass)]), edouard@2643: ("MDP Setting", MDPPanel, []), andrej@2355: ("ESC Management", EEPROMAccessPanel, [ edouard@2643: ("Smart View", SlaveSiiSmartView), edouard@2643: ("Hex View", HexView)]), edouard@2643: ("Register Access", RegisterAccessPanel, []), edouard@2643: ("DC Configuration", DCConfigPanel, []) andrej@2379: ] andrej@2379: for pname, pclass, subs in panels: andrej@2379: self.AddPage(pclass(self, self.Controler), pname) andrej@2379: for spname, spclass in subs: andrej@2379: self.AddSubPage(spclass(self, self.Controler), spname) andrej@2354: andrej@2360: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # For SlaveState Panel andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class SlaveStatePanelClass(wx.Panel): andrej@2354: def __init__(self, parent, controler): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: Reference to the parent EtherCATManagementTreebook class andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: """ andrej@2366: wx.Panel.__init__(self, parent, -1, (0, 0), size=wx.DefaultSize, style=wx.SUNKEN_BORDER) andrej@2354: self.Controler = controler andrej@2354: self.parent = parent andrej@2355: andrej@2354: # initialize SlaveStatePanel UI dictionaries andrej@2354: self.StaticBoxDic = {} andrej@2354: self.StaticTextDic = {} andrej@2354: self.TextCtrlDic = {} andrej@2354: self.ButtonDic = {} andrej@2355: andrej@2354: # iniitalize BoxSizer and FlexGridSizer andrej@2354: self.SizerDic = { andrej@2375: "SlaveState_main_sizer": wx.BoxSizer(wx.VERTICAL), andrej@2375: "SlaveState_inner_main_sizer": wx.FlexGridSizer(cols=1, hgap=50, rows=3, vgap=10), andrej@2375: "SlaveInfosDetailsInnerSizer": wx.FlexGridSizer(cols=4, hgap=10, rows=2, vgap=10), andrej@2375: "SyncManagerInnerSizer": wx.FlexGridSizer(cols=1, hgap=5, rows=1, vgap=5), andrej@2375: "SlaveState_sizer": wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10), andrej@2375: "SlaveState_up_sizer": wx.FlexGridSizer(cols=4, hgap=10, rows=2, vgap=10), andrej@2375: "SlaveState_down_sizer": wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=10)} andrej@2355: andrej@2354: # initialize StaticBox and StaticBoxSizer andrej@2354: for box_name, box_label in [ andrej@2354: ("SlaveInfosDetailsBox", "Slave Informations"), andrej@2354: ("SyncManagerBox", "Sync Manager"), andrej@2354: ("SlaveStateBox", "Slave State Transition && Monitoring")]: andrej@2354: self.StaticBoxDic[box_name] = wx.StaticBox(self, label=_(box_label)) andrej@2355: self.SizerDic[box_name] = wx.StaticBoxSizer(self.StaticBoxDic[box_name]) andrej@2355: andrej@2354: for statictext_name, statictext_label, textctrl_name in [ andrej@2354: ("VendorLabel", "Vendor:", "vendor"), andrej@2354: ("ProductcodeLabel", "Product code:", "product_code"), andrej@2354: ("RevisionnumberLabel", "Slave Count:", "revision_number"), andrej@2354: ("PhysicsLabel", "Physics:", "physics")]: andrej@2354: self.StaticTextDic[statictext_name] = wx.StaticText(self, label=_(statictext_label)) andrej@2354: self.TextCtrlDic[textctrl_name] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY) andrej@2355: self.SizerDic["SlaveInfosDetailsInnerSizer"].AddMany([self.StaticTextDic[statictext_name], andrej@2381: self.TextCtrlDic[textctrl_name]]) andrej@2355: edouard@3303: self.SizerDic["SlaveInfosDetailsBox"].Add(self.SizerDic["SlaveInfosDetailsInnerSizer"]) andrej@2355: andrej@2363: self.SyncManagersGrid = CustomGrid(self, size=wx.Size(605, 155), style=wx.VSCROLL) andrej@2355: andrej@2355: self.SizerDic["SyncManagerInnerSizer"].Add(self.SyncManagersGrid) andrej@2354: self.SizerDic["SyncManagerBox"].Add(self.SizerDic["SyncManagerInnerSizer"]) andrej@2355: andrej@2375: buttons = [ andrej@2375: ("InitButton", 0, "INIT", "State Transition to \"Init\" State", self.OnButtonClick, []), andrej@2375: ("PreOPButton", 1, "PREOP", "State Transition to \"PreOP\" State", self.OnButtonClick, [ andrej@2375: ("TargetStateLabel", "Target State:", "TargetState")]), andrej@2375: ("SafeOPButton", 2, "SAFEOP", "State Transition to \"SafeOP\" State", self.OnButtonClick, []), andrej@2375: ("OPButton", 3, "OP", "State Transition to \"OP\" State", self.OnButtonClick, [ andrej@2375: ("CurrentStateLabel", "Current State:", "CurrentState")]) andrej@2375: ] andrej@2375: for button_name, button_id, button_label, button_tooltipstring, event_method, sub_item in buttons: andrej@2363: self.ButtonDic[button_name] = wx.Button(self, id=button_id, label=_(button_label)) andrej@2354: self.ButtonDic[button_name].Bind(wx.EVT_BUTTON, event_method) edouard@3303: self.ButtonDic[button_name].SetToolTip(button_tooltipstring) andrej@2354: self.SizerDic["SlaveState_up_sizer"].Add(self.ButtonDic[button_name]) andrej@2375: for statictext_name, statictext_label, textctrl_name in sub_item: andrej@2354: self.StaticTextDic[statictext_name] = wx.StaticText(self, label=_(statictext_label)) andrej@2354: self.TextCtrlDic[textctrl_name] = wx.TextCtrl(self, size=wx.DefaultSize, style=wx.TE_READONLY) andrej@2355: self.SizerDic["SlaveState_up_sizer"].AddMany([self.StaticTextDic[statictext_name], andrej@2380: self.TextCtrlDic[textctrl_name]]) andrej@2355: andrej@2354: for button_name, button_label, button_tooltipstring, event_method in [ andrej@2354: ("StartTimerButton", "Start State Monitoring", "Slave State Update Restart", self.StartTimer), andrej@2354: ("StopTimerButton", "Stop State Monitoring", "Slave State Update Stop", self.CurrentStateThreadStop)]: andrej@2354: self.ButtonDic[button_name] = wx.Button(self, label=_(button_label)) andrej@2354: self.ButtonDic[button_name].Bind(wx.EVT_BUTTON, event_method) edouard@3303: self.ButtonDic[button_name].SetToolTip(button_tooltipstring) andrej@2355: self.SizerDic["SlaveState_down_sizer"].Add(self.ButtonDic[button_name]) andrej@2355: andrej@2355: self.SizerDic["SlaveState_sizer"].AddMany([self.SizerDic["SlaveState_up_sizer"], andrej@2381: self.SizerDic["SlaveState_down_sizer"]]) andrej@2355: andrej@2354: self.SizerDic["SlaveStateBox"].Add(self.SizerDic["SlaveState_sizer"]) andrej@2355: andrej@2354: self.SizerDic["SlaveState_inner_main_sizer"].AddMany([ andrej@2354: self.SizerDic["SlaveInfosDetailsBox"], self.SizerDic["SyncManagerBox"], andrej@2354: self.SizerDic["SlaveStateBox"]]) andrej@2355: andrej@2354: self.SizerDic["SlaveState_main_sizer"].Add(self.SizerDic["SlaveState_inner_main_sizer"]) andrej@2355: andrej@2354: self.SetSizer(self.SizerDic["SlaveState_main_sizer"]) andrej@2355: andrej@2354: # register a timer for periodic exectuion of slave state update (period: 1000 ms) andrej@2354: self.Bind(wx.EVT_TIMER, self.GetCurrentState) andrej@2355: andrej@2354: self.CreateSyncManagerTable() andrej@2355: andrej@2354: self.Centre() andrej@2355: andrej@2354: def CreateSyncManagerTable(self): andrej@2354: """ andrej@2354: Create grid for "SyncManager" andrej@2354: """ andrej@2355: # declare Table object andrej@2354: self.SyncManagersTable = SyncManagersTable(self, [], GetSyncManagersTableColnames()) andrej@2354: self.SyncManagersGrid.SetTable(self.SyncManagersTable) andrej@2354: # set grid alignment attr. (CENTER) andrej@2355: self.SyncManagersGridColAlignements = [wx.ALIGN_CENTRE, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE, andrej@2354: wx.ALIGN_CENTRE, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE] andrej@2354: # set grid size andrej@2354: self.SyncManagersGridColSizes = [40, 150, 100, 100, 100, 100] andrej@2354: self.SyncManagersGrid.SetRowLabelSize(0) andrej@2354: for col in range(self.SyncManagersTable.GetNumberCols()): andrej@2354: attr = wx.grid.GridCellAttr() andrej@2354: attr.SetAlignment(self.SyncManagersGridColAlignements[col], wx.ALIGN_CENTRE) andrej@2354: self.SyncManagersGrid.SetColAttr(col, attr) andrej@2354: self.SyncManagersGrid.SetColMinimalWidth(col, self.SyncManagersGridColSizes[col]) andrej@2355: self.SyncManagersGrid.AutoSizeColumn(col, False) andrej@2355: andrej@2354: self.RefreshSlaveInfos() andrej@2355: andrej@2354: def RefreshSlaveInfos(self): andrej@2354: """ andrej@2354: Fill data in "Slave Information" and "SyncManager" andrej@2354: """ andrej@2354: slave_infos = self.Controler.GetSlaveInfos() andrej@2354: sync_manager_section = ["vendor", "product_code", "revision_number", "physics"] andrej@2354: if slave_infos is not None: andrej@2355: # this method is same as "TextCtrl.SetValue" andrej@2354: for textctrl_name in sync_manager_section: andrej@2354: self.TextCtrlDic[textctrl_name].SetValue(slave_infos[textctrl_name]) andrej@2354: self.SyncManagersTable.SetData(slave_infos["sync_managers"]) andrej@2354: self.SyncManagersTable.ResetView(self.SyncManagersGrid) andrej@2354: else: andrej@2354: for textctrl_name in sync_manager_section: andrej@2354: self.TextCtrlDic[textctrl_name].SetValue("") andrej@2354: self.SyncManagersTable.SetData([]) andrej@2354: self.SyncManagersTable.ResetView(self.SyncManagersGrid) andrej@2355: andrej@2354: def OnButtonClick(self, event): andrej@2354: """ andrej@2354: Event handler for slave state transition button click (Init, PreOP, SafeOP, OP button) andrej@2354: @param event : wx.EVT_BUTTON object andrej@2354: """ edouard@2643: # Check whether beremiz connected or not. edouard@2643: # If this method is called cyclically, set the cyclic flag true edouard@2643: check_connect_flag = self.Controler.CommonMethod.CheckConnect(cyclic_flag = False) andrej@2375: if check_connect_flag: andrej@2354: state_dic = ["INIT", "PREOP", "SAFEOP", "OP"] andrej@2355: andrej@2354: # If target state is one of {INIT, PREOP, SAFEOP}, request slave state transition immediately. andrej@2375: if event.GetId() < 3: andrej@2354: self.Controler.CommonMethod.RequestSlaveState(state_dic[event.GetId()]) andrej@2354: self.TextCtrlDic["TargetState"].SetValue(state_dic[event.GetId()]) andrej@2354: andrej@2354: # If target state is OP, first check "PLC status". andrej@2354: # (1) If current PLC status is "Started", then request slave state transition andrej@2354: # (2) Otherwise, show error message and return andrej@2375: else: andrej@2406: status, _log_count = self.Controler.GetCTRoot()._connector.GetPLCstatus() andrej@2416: if status == PlcStatus.Started: andrej@2354: self.Controler.CommonMethod.RequestSlaveState("OP") andrej@2354: self.TextCtrlDic["TargetState"].SetValue("OP") andrej@2375: else: andrej@2423: self.Controler.CommonMethod.CreateErrorDialog(_("PLC is Not Started")) andrej@2355: andrej@2354: def GetCurrentState(self, event): andrej@2354: """ andrej@2354: Timer event handler for periodic slave state monitoring (Default period: 1 sec = 1000 msec). andrej@2354: @param event : wx.TIMER object andrej@2354: """ edouard@2643: if self.IsShownOnScreen() is False: edouard@2643: return edouard@2643: edouard@2643: # Check whether beremiz connected or not. edouard@2643: # If this method is called cyclically, set the cyclic flag true edouard@2643: check_connect_flag = self.Controler.CommonMethod.CheckConnect(cyclic_flag = True) andrej@2354: if check_connect_flag: andrej@2354: returnVal = self.Controler.CommonMethod.GetSlaveStateFromSlave() andrej@2354: line = returnVal.split("\n") andrej@2375: try: andrej@2354: self.SetCurrentState(line[self.Controler.GetSlavePos()]) andrej@2354: except Exception: andrej@2355: pass andrej@2355: andrej@2354: def SetCurrentState(self, line): andrej@2354: """ andrej@2354: Show current slave state using the executiob result of "ethercat slaves" command. andrej@2354: @param line : result of "ethercat slaves" command andrej@2354: """ andrej@2354: state_array = ["INIT", "PREOP", "SAFEOP", "OP"] andrej@2375: try: andrej@2354: # parse the execution result of "ethercat slaves" command andrej@2354: # Result example : 0 0:0 PREOP + EL9800 (V4.30) (PIC24, SPI, ET1100) andrej@2354: token = line.split(" ") andrej@2354: if token[2] in state_array: andrej@2355: self.TextCtrlDic["CurrentState"].SetValue(token[2]) andrej@2354: except Exception: andrej@2355: pass andrej@2355: andrej@2354: def StartTimer(self, event): andrej@2354: """ andrej@2354: Event handler for "Start State Monitoring" button. andrej@2354: - start slave state monitoring thread andrej@2354: @param event : wx.EVT_BUTTON object andrej@2354: """ edouard@2643: # Check whether beremiz connected or not. edouard@2643: # If this method is called cyclically, set the cyclic flag true edouard@2643: check_connect_flag = self.Controler.CommonMethod.CheckConnect(cyclic_flag = False) edouard@2643: if check_connect_flag: edouard@2643: self.SlaveStateThread = wx.Timer(self) edouard@2643: # set timer period (2000 ms) edouard@2643: self.SlaveStateThread.Start(2000) edouard@2643: else: edouard@2643: pass andrej@2355: andrej@2354: def CurrentStateThreadStop(self, event): andrej@2354: """ andrej@2354: Event handler for "Stop State Monitoring" button. andrej@2354: - stop slave state monitoring thread andrej@2354: @param event : wx.EVT_BUTTON object andrej@2354: """ andrej@2354: try: andrej@2354: self.SlaveStateThread.Stop() andrej@2354: except Exception: andrej@2354: pass andrej@2355: andrej@2360: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # For SDO Management Panel andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class SDOPanelClass(wx.Panel): andrej@2354: def __init__(self, parent, controler): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: Reference to the parent EtherCATManagementTreebook class andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: """ andrej@2354: wx.Panel.__init__(self, parent, -1) andrej@2355: andrej@2354: self.DatatypeDescription, self.CommunicationObject, self.ManufacturerSpecific, \ kinsamanka@3750: self.ProfileSpecific, self.Reserved, self.AllSDOData = list(range(6)) andrej@2355: andrej@2354: self.Controler = controler andrej@2355: edouard@2643: self.SDOMonitorEntries = {} edouard@2643: #----------------------------- SDO Monitor -------------------------------# edouard@2643: self.RBList = ["ON","OFF"] edouard@2643: edouard@2643: self.SDOMonitorRB = wx.RadioBox(self, label=_("monitoring"), edouard@2643: choices=self.RBList, majorDimension=2) edouard@2643: edouard@2643: self.SDOMonitorRB.SetSelection(1) edouard@2643: self.Bind(wx.EVT_RADIOBOX, self.OnRadioBox, self.SDOMonitorRB) edouard@2643: edouard@2643: self.SDOMonitorGrid = wx.grid.Grid(self,size=wx.Size(850,150),style=wx.EXPAND edouard@2643: |wx.ALIGN_CENTER_HORIZONTAL edouard@2643: |wx.ALIGN_CENTER_VERTICAL) edouard@2643: self.SDOMonitorGrid.Bind(gridlib.EVT_GRID_CELL_LEFT_DCLICK, edouard@2643: self.onMonitorGridDoubleClick) edouard@2643: edouard@2643: #----------------------------- SDO Entries ----------------------------# edouard@2643: self.SDOUpdateBtn = wx.Button(self, label=_("update")) edouard@2643: self.SDOUpdateBtn.Bind(wx.EVT_BUTTON, self.OnSDOUpdate) edouard@2643: edouard@2643: self.SDOTraceThread = None edouard@2643: self.SDOMonitoringFlag = False edouard@2643: self.SDOValuesList = [] edouard@2643: # Default SDO Page Number edouard@2643: self.SDOPageNum = 2 edouard@2643: edouard@2643: #----------------------------- Sizer --------------------------------------# andrej@2354: self.SDOManagementMainSizer = wx.BoxSizer(wx.VERTICAL) edouard@2643: self.SDOInfoBox = wx.StaticBox(self, label=_("SDO Entries")) edouard@2643: self.SDOMonitorBox = wx.StaticBox(self, label=_("SDO Monitor")) edouard@2643: edouard@2643: self.SDONoteBook = SDONoteBook(self, controler=self.Controler) edouard@2643: self.SDOInfoBoxSizer = wx.StaticBoxSizer(self.SDOInfoBox, orient=wx.VERTICAL) edouard@2643: self.SDOMonitorBoxSizer = wx.StaticBoxSizer(self.SDOMonitorBox, edouard@2643: orient=wx.VERTICAL) edouard@2643: self.SDOInfoBoxSizer.Add(self.SDOUpdateBtn) edouard@2643: edouard@2643: self.SDOInfoBoxSizer.Add(self.SDONoteBook, wx.ALL|wx.EXPAND) edouard@2643: self.SDOMonitorBoxSizer.Add(self.SDOMonitorRB) edouard@2643: self.SDOMonitorBoxSizer.Add(self.SDOMonitorGrid) edouard@2643: self.SDOManagementMainSizer.AddMany([self.SDOInfoBoxSizer, edouard@2643: self.SDOMonitorBoxSizer]) andrej@2354: self.SetSizer(self.SDOManagementMainSizer) edouard@2643: edouard@2643: #----------------------------- fill the contents --------------------------# edouard@2643: #self.entries = self.Controler.CTNParent.CTNParent.GetEntriesList() edouard@2643: edouard@2643: slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos()) edouard@2643: type_infos = slave.getType() edouard@2643: device, alignment = self.Controler.CTNParent.GetModuleInfos(type_infos) edouard@2643: self.entries = device.GetEntriesList() edouard@2643: edouard@2643: self.Controler.CommonMethod.SDOVariables = [] edouard@2643: self.Controler.CommonMethod.SDOSubEntryData = [] andrej@2354: self.Controler.CommonMethod.ClearSDODataSet() edouard@2643: self.SDOParserXML(self.entries) edouard@2643: self.SDONoteBook.CreateNoteBook() edouard@2643: self.CreateSDOMonitorGrid() edouard@2643: self.Refresh() edouard@2643: edouard@2643: def OnSDOUpdate(self, event): edouard@2643: SlavePos = self.Controler.GetSlavePos() edouard@2643: num = self.SDOPageNum - 1 edouard@2643: if num < 0: edouard@2643: for i in range(len(self.Controler.CommonMethod.SDOVariables)): edouard@2643: data = self.Controler.GetCTRoot()._connector.GetSDOEntriesData( edouard@2643: self.Controler.CommonMethod.SDOVariables[i], SlavePos) edouard@2643: self.Controler.CommonMethod.SDOVariables[i] = data edouard@2643: else : edouard@2643: SDOUploadEntries = self.Controler.CommonMethod.SDOVariables[num] edouard@2643: data = self.Controler.GetCTRoot()._connector.GetSDOEntriesData(SDOUploadEntries, SlavePos) edouard@2643: self.Controler.CommonMethod.SDOVariables[num] = data edouard@2643: edouard@2643: self.SDONoteBook.CreateNoteBook() edouard@2643: self.Refresh() edouard@2643: edouard@2643: def OnRadioBox(self, event): edouard@2643: """ edouard@2643: There are two selections that are on and off. edouard@2643: If the on is selected, the monitor thread begins to run. edouard@2643: If the off is selected, the monitor thread gets off. edouard@2643: @param event: wx.EVT_RADIOBOX object edouard@2643: """ kinsamanka@3750: on, off = list(range(2)) edouard@2643: edouard@2643: if event.GetInt() == on: edouard@2643: CheckThreadFlag = self.SDOMonitoringThreadOn() edouard@2643: if not CheckThreadFlag: edouard@2643: self.SDOMonitorRB.SetSelection(off) edouard@2643: elif event.GetInt() == off: edouard@2643: self.SDOMonitoringThreadOff() edouard@2643: edouard@2643: def SDOMonitoringThreadOn(self): edouard@2643: check_connect_flag = self.Controler.CommonMethod.CheckConnect(cyclic_flag = False) andrej@2354: if check_connect_flag: edouard@2643: self.SetSDOTraceValues(self.SDOMonitorEntries) edouard@2643: self.Controler.GetCTRoot()._connector.GetSDOData() edouard@2643: self.SDOTraceThread = Thread(target=self.SDOMonitorThreadProc) edouard@2643: self.SDOMonitoringFlag = True edouard@2643: self.SDOTraceThread.start() edouard@2643: return check_connect_flag edouard@2643: edouard@2643: def SDOMonitoringThreadOff(self): edouard@2643: check_connect_flag = self.Controler.CommonMethod.CheckConnect(cyclic_flag = False) edouard@2643: if check_connect_flag: edouard@2643: self.SDOMonitoringFlag = False edouard@2643: if self.SDOTraceThread is not None: edouard@2643: self.SDOTraceThread.join() edouard@2643: self.SDOTraceThread = None edouard@2643: self.Controler.GetCTRoot()._connector.StopSDOThread() edouard@2643: edouard@2643: def SetSDOTraceValues(self, SDOMonitorEntries): edouard@2643: SlavePos = self.Controler.GetSlavePos() edouard@2643: check_connect_flag = self.Controler.CommonMethod.CheckConnect(cyclic_flag = True) edouard@2643: if check_connect_flag: edouard@2643: self.Controler.GetCTRoot()._connector.SetSDOTraceValues(SDOMonitorEntries, SlavePos) edouard@2643: edouard@2643: def SDOMonitorThreadProc(self): edouard@2643: while self.SDOMonitoringFlag and self.Controler.GetCTRoot()._connector.PLCStatus != "Started": edouard@2643: self.SDOValuesList = self.Controler.GetCTRoot()._connector.GetSDOData() kinsamanka@3750: LocalData = list(self.SDOValuesList[0].items()) edouard@2643: LocalData.sort() edouard@2643: if self.SDOValuesList[1] != self.Controler.GetSlavePos(): edouard@2643: continue edouard@2643: row = 0 edouard@2643: for (idx, subidx), data in LocalData: edouard@2643: self.SDOMonitorGrid.SetCellValue(row, 6, str(data["value"])) edouard@2643: row += 1 edouard@2643: time.sleep(0.5) edouard@2643: edouard@2643: def CreateSDOMonitorGrid(self): edouard@2643: """ edouard@2643: It creates SDO Monitor table and specifies cell size and labels. edouard@2643: """ edouard@2643: self.SDOMonitorGrid.CreateGrid(0,7) edouard@2643: SDOCellSize = [(0, 65), (1, 65), (2, 50), (3, 70), edouard@2643: (4, 40), (5, 450), (6, 85)] edouard@2643: edouard@2643: for (index, size) in SDOCellSize: edouard@2643: self.SDOMonitorGrid.SetColSize(index, size) edouard@2643: edouard@2643: self.SDOMonitorGrid.SetRowLabelSize(0) edouard@2643: edouard@2643: SDOTableLabel = [(0, "Index"), (1, "Subindex"), (2, "Access"), edouard@2643: (3, "Type"), (4, "Size"), (5, "Name"), (6, "Value")] edouard@2643: edouard@2643: for (index, label) in SDOTableLabel: edouard@2643: self.SDOMonitorGrid.SetColLabelValue(index, label) edouard@2643: self.SDOMonitorGrid.SetColLabelAlignment(index, wx.ALIGN_CENTER) edouard@2643: edouard@2643: def onMonitorGridDoubleClick(self, event): edouard@2643: """ edouard@2643: Event Handler for double click on the SDO entries table. edouard@2643: It adds the entry into the SDO monitor table. edouard@2643: If the entry is already in the SDO monitor table, edouard@2643: then it's removed from the SDO monitor table. edouard@2643: @pram event: gridlib.EVT_GRID_CELL_LEFT_DCLICK object edouard@2643: """ edouard@2643: row = event.GetRow() edouard@2643: idx = self.SDOMonitorGrid.GetCellValue(row, 0) edouard@2643: subIdx = self.SDOMonitorGrid.GetCellValue(row, 1) edouard@2643: edouard@2643: del self.SDOMonitorEntries[(idx, subIdx)] edouard@2643: self.SDOMonitorGrid.DeleteRows(row, 1) edouard@2643: # add jblee edouard@2643: self.SetSDOTraceValues(self.SDOMonitorEntries) edouard@2643: self.SDOMonitorGrid.Refresh() edouard@2643: edouard@2643: def SDOParserXML(self, entries): edouard@2643: """ edouard@2643: Parse SDO data set that obtain "ESI file" edouard@2643: @param entries: SDO entry list edouard@2643: """ kinsamanka@3750: entries_list = list(entries.items()) edouard@2643: entries_list.sort() edouard@2643: self.ForDefaultValueFlag = False edouard@2643: self.CompareValue = "" edouard@2643: self.sub_entry_value_list = [] edouard@2643: edouard@2643: for (index, subidx), entry in entries_list: edouard@2643: # exclude entry that isn't in the objects edouard@2643: check_mapping = entry["PDOMapping"] edouard@2643: if check_mapping is "T" or check_mapping is "R": kinsamanka@3750: if "PDO index" not in list(entry.keys()): edouard@2643: continue edouard@2643: edouard@2643: idx = "0" + entry["Index"].strip("#") edouard@2643: #subidx = hex(int(entry["SubIndex"], 0)) edouard@2643: try : edouard@2643: subidx = "0x" + entry["SubIndex"] edouard@2643: except : edouard@2643: subidx = "0x0" edouard@2643: datatype = entry["Type"] edouard@2643: edouard@2643: try : edouard@2643: default_value = entry["DefaultData"] edouard@2643: except : edouard@2643: default_value = " --- " edouard@2643: # Result of SlaveSDO data parsing. (data type : dictionary) edouard@2643: self.Data = {'idx':idx, 'subIdx':subidx, 'access':entry["Access"], edouard@2643: 'type':datatype, 'size': str(entry["BitSize"]), edouard@2643: 'name':entry["Name"], 'value':default_value} edouard@2643: category_divide_value = [0x1000, 0x2000, 0x6000, 0xa000, 0xffff] edouard@2643: edouard@2643: for count in range(len(category_divide_value)) : edouard@2643: if int(idx, 0) < category_divide_value[count]: edouard@2643: self.Controler.CommonMethod.SDOVariables[count].append(self.Data) edouard@2643: break edouard@2643: edouard@2643: self.Controler.CommonMethod.SDOSubEntryData = self.sub_entry_value_list edouard@2643: edouard@2643: #------------------------------------------------------------------------------- andrej@2354: # For SDO Notebook (divide category) andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class SDONoteBook(wx.Notebook): andrej@2354: def __init__(self, parent, controler): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: Reference to the parent SDOPanelClass class andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: """ andrej@2366: wx.Notebook.__init__(self, parent, id=-1, size=(850, 500)) andrej@2354: self.Controler = controler andrej@2354: self.parent = parent andrej@2355: andrej@2354: self.CreateNoteBook() andrej@2355: andrej@2355: def CreateNoteBook(self): andrej@2354: """ andrej@2354: Create each NoteBook page, divided SDO index andrej@2354: According to EtherCAT Communication(03/2011), 158p andrej@2355: """ andrej@2354: self.Data = [] andrej@2354: count = 1 andrej@2355: andrej@2354: page_texts = [("all", self.parent.AllSDOData), andrej@2381: ("0x0000 - 0x0ff", self.parent.DatatypeDescription), andrej@2381: ("0x1000 - 0x1fff", self.parent.CommunicationObject), andrej@2381: ("0x2000 - 0x5fff", self.parent.ManufacturerSpecific), andrej@2381: ("0x6000 - 0x9fff", self.parent.ProfileSpecific), andrej@2381: ("0xa000 - 0xffff", self.parent.Reserved)] andrej@2354: andrej@2406: # page_tooltip_string = ["SDO Index 0x0000 - 0x0fff : Data Type Description", andrej@2406: # "SDO Index 0x1000 - 0x1fff : Communication object", andrej@2406: # "SDO Index 0x2000 - 0x5fff : Manufacturer specific", andrej@2406: # "SDO Index 0x6000 - 0x9fff : Profile specific", andrej@2406: # "SDO Index 0xa000 - 0xffff : Reserved", andrej@2406: # "All SDO Object"] andrej@2354: andrej@2354: self.DeleteAllPages() andrej@2355: edouard@2643: self.Controler.CommonMethod.SDOVariables[5] = [] edouard@2643: for i in range(4): edouard@2643: self.Controler.CommonMethod.SDOVariables[5] += self.Controler.CommonMethod.SDOVariables[i] edouard@2643: andrej@2354: for txt, count in page_texts: edouard@2643: self.Data = self.Controler.CommonMethod.SDOVariables[count] edouard@2643: self.SubEntryData = self.Controler.CommonMethod.SDOSubEntryData edouard@2643: self.Win = SlaveSDOTable(self, self.Data, self.SubEntryData) andrej@2354: self.AddPage(self.Win, txt) andrej@2355: edouard@2643: # add jblee edouard@2643: def OnPageChanged(self, event): edouard@2643: old = event.GetOldSelection() edouard@2643: new = event.GetSelection() edouard@2643: sel = self.GetSelection() edouard@2643: self.parent.SDOPageNum = new edouard@2643: event.Skip() edouard@2643: edouard@2643: def OnPageChanging(self, event): edouard@2643: old = event.GetOldSelection() edouard@2643: new = event.GetSelection() edouard@2643: sel = self.GetSelection() edouard@2643: event.Skip() andrej@2360: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # For SDO Grid (fill index, subindex, etc...) andrej@2356: # ------------------------------------------------------------------------------- andrej@2355: class SlaveSDOTable(wx.grid.Grid): edouard@2643: def __init__(self, parent, data, fixed_value): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: Reference to the parent SDOPanelClass class andrej@2354: @param data: SDO data after parsing "SDOParser" method andrej@2354: """ andrej@2363: wx.grid.Grid.__init__(self, parent, -1, size=(830, 490), andrej@2367: style=wx.EXPAND | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL) andrej@2355: andrej@2354: self.Controler = parent.Controler andrej@2354: self.parent = parent andrej@2354: self.SDOFlag = True andrej@2375: if data is None: andrej@2354: self.SDOs = [] edouard@2643: self.sub_entry_value = [] edouard@2643: else : andrej@2354: self.SDOs = data edouard@2643: self.sub_entry_value = fixed_value edouard@2643: edouard@2643: self.CreateGrid(len(self.SDOs), 7) edouard@2643: SDOCellSize = [(0, 65), (1, 65), (2, 50), (3, 70), edouard@2643: (4, 40), (5, 400), (6, 135)] edouard@2643: andrej@2354: for (index, size) in SDOCellSize: andrej@2354: self.SetColSize(index, size) andrej@2355: andrej@2354: self.SetRowLabelSize(0) andrej@2355: andrej@2354: SDOTableLabel = [(0, "Index"), (1, "Subindex"), (2, "Access"), edouard@2643: (3, "Type"), (4, "Size"), (5, "Name"), (6, "Value")] andrej@2355: andrej@2354: for (index, label) in SDOTableLabel: andrej@2354: self.SetColLabelValue(index, label) edouard@2643: self.SetColLabelAlignment(index, wx.ALIGN_CENTER) andrej@2355: andrej@2354: attr = wx.grid.GridCellAttr() andrej@2354: edouard@2643: # for SDO download and monitoring edouard@2643: self.Bind(gridlib.EVT_GRID_CELL_LEFT_DCLICK, self.onGridDoubleClick) andrej@2355: andrej@2355: for i in range(7): andrej@2363: self.SetColAttr(i, attr) andrej@2355: andrej@2354: self.SetColLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER) andrej@2355: andrej@2355: self.SetTableValue() andrej@2355: andrej@2354: def SetTableValue(self): andrej@2354: """ andrej@2354: Cell is filled by new parsing data andrej@2354: """ edouard@2643: sdo_list = ['idx', 'subIdx', 'access', 'type', 'size', 'name', 'value'] edouard@2643: count = 0 andrej@2354: for row_idx in range(len(self.SDOs)): andrej@2355: for col_idx in range(len(self.SDOs[row_idx])): edouard@2643: edouard@2643: # the top entries that have sub index is shaded. edouard@2643: if int(self.SDOs[row_idx]['subIdx'], 16) == 0x00: edouard@2643: try: edouard@2643: if int(self.SDOs[row_idx + 1]['subIdx'], 16) is not 0x00: edouard@2643: self.SetCellBackgroundColour(row_idx, col_idx, \ edouard@2643: wx.LIGHT_GREY) edouard@2643: except: edouard@2643: pass edouard@2643: edouard@2643: if self.SDOs[row_idx][sdo_list[col_idx]] == "modifying": edouard@2643: if len(self.sub_entry_value) == count: edouard@2643: continue edouard@2643: self.SetCellValue(row_idx, col_idx, self.sub_entry_value[count]) edouard@2643: count += 1 edouard@2643: else : edouard@2643: self.SetCellValue(row_idx, col_idx, \ edouard@2643: self.SDOs[row_idx][sdo_list[col_idx]]) edouard@2643: andrej@2354: self.SetReadOnly(row_idx, col_idx, True) andrej@2375: if col_idx < 5: andrej@2354: self.SetCellAlignment(row_idx, col_idx, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) andrej@2355: andrej@2354: def CheckSDODataAccess(self, row): andrej@2354: """ edouard@2643: check that access field has "rw" andrej@2354: @param row : Selected cell by user andrej@2354: @return Write_flag : If data has "w", flag is true andrej@2354: """ andrej@2354: check = self.SDOs[row]['access'] edouard@2643: if check == "rw": andrej@2354: return True edouard@2643: else: edouard@2643: return False edouard@2643: andrej@2354: def ClearStateFlag(self): andrej@2354: """ andrej@2354: Initialize StateFlag andrej@2354: StateFlag is notice SDOData access each slave state andrej@2354: """ andrej@2354: self.Controler.CommonMethod.Check_PREOP = False andrej@2354: self.Controler.CommonMethod.Check_SAFEOP = False andrej@2354: self.Controler.CommonMethod.Check_OP = False andrej@2355: edouard@2643: def onGridDoubleClick (self, event): andrej@2354: """ andrej@2354: Create dialog for SDO value modify edouard@2643: if user enter data, perform command "ethercat download" edouard@2643: @param event : gridlib.EVT_GRID_CELL_LEFT_DCLICK object andrej@2354: """ andrej@2354: self.ClearStateFlag() edouard@2643: edouard@2643: # CheckSDODataAccess is checking that OD(Object Dictionary) has "w" edouard@2643: if event.GetCol() == 6 and self.CheckSDODataAccess(event.GetRow()) : edouard@2643: dlg = wx.TextEntryDialog (self, edouard@2643: "Enter hex or dec value (if enter dec value, " \ edouard@2643: + "it automatically conversed hex value)", edouard@2643: "SDOModifyDialog", style = wx.OK | wx.CANCEL) edouard@2643: edouard@2643: start_value = self.GetCellValue(event.GetRow(), event.GetCol()) andrej@2354: dlg.SetValue(start_value) edouard@2643: andrej@2354: if dlg.ShowModal() == wx.ID_OK: edouard@2643: # Check whether beremiz connected or not. edouard@2643: # If this method is called cyclically, set the cyclic flag true edouard@2643: check_connect_flag = self.Controler.CommonMethod.CheckConnect(cyclic_flag = False) edouard@2643: if check_connect_flag: edouard@2643: try : edouard@2643: input_val = hex(int(dlg.GetValue(), 0)) andrej@2354: # Request "SDODownload" edouard@2643: return_val = self.Controler.CommonMethod.SDODownload( edouard@2643: self.SDOs[event.GetRow()]["type"], edouard@2643: self.SDOs[event.GetRow()]["idx"], edouard@2643: self.SDOs[event.GetRow()]["subIdx"], edouard@2643: dlg.GetValue()) edouard@2643: if return_val is "": edouard@2643: SDOUploadEntry = {"idx" : self.SDOs[event.GetRow()]["idx"], edouard@2643: "subIdx" : self.SDOs[event.GetRow()]["subIdx"], edouard@2643: "size" : self.SDOs[event.GetRow()]["size"] edouard@2643: } edouard@2643: data = self.Controler.GetCTRoot()._connector.GetSDOEntryData( edouard@2643: SDOUploadEntry, self.Controler.GetSlavePos()) edouard@2643: hex_val = hex(data)[:-1] edouard@2643: edouard@2643: # download data check edouard@2643: if input_val == hex_val: edouard@2643: display_val = "%s(%d)" % (hex_val, data) edouard@2643: self.SetCellValue(event.GetRow(), event.GetCol(), edouard@2643: display_val) edouard@2643: else : edouard@2643: self.Controler.CommonMethod.CreateErrorDialog(\ edouard@2643: 'SDO Value not completely download, please try again') edouard@2643: else: edouard@2643: self.Controler.GetCTRoot().logger.write_error(return_val) edouard@2643: edouard@2643: # Error occured process of "int(variable)" edouard@2643: # User input is not hex, dec value edouard@2643: except ValueError: edouard@2643: self.Controler.CommonMethod.CreateErrorDialog(\ edouard@2643: 'You can input only hex, dec value') edouard@2643: else: edouard@2643: SDOPanel = self.parent.parent edouard@2643: row = event.GetRow() edouard@2643: edouard@2643: idx = self.SDOs[row]["idx"] edouard@2643: subIdx = self.SDOs[row]["subIdx"] edouard@2643: SDOPanel.SDOMonitorEntries[(idx, subIdx)] = { edouard@2643: "access": self.SDOs[row]["access"], edouard@2643: "type": self.SDOs[row]["type"], edouard@2643: "size": self.SDOs[row]["size"], edouard@2643: "name": self.SDOs[row]["name"], edouard@2643: # add jblee edouard@2643: "value": ""} edouard@2643: edouard@2643: del_rows = SDOPanel.SDOMonitorGrid.GetNumberRows() edouard@2643: edouard@2643: try: edouard@2643: SDOPanel.SDOMonitorGrid.DeleteRows(0, del_rows) edouard@2643: except: edouard@2643: pass edouard@2643: edouard@2643: SDOPanel.SDOMonitorGrid.AppendRows(len(SDOPanel.SDOMonitorEntries)) edouard@2643: SDOPanel.SetSDOTraceValues(SDOPanel.SDOMonitorEntries) edouard@2643: kinsamanka@3750: SME_list = list(SDOPanel.SDOMonitorEntries.items()) edouard@2643: SME_list.sort() edouard@2643: edouard@2643: gridRow = 0 edouard@2643: for (idx, subIdx), entry in SME_list: edouard@2643: SDOPanel.SDOMonitorGrid.SetCellValue(gridRow, 0, str(idx)) edouard@2643: SDOPanel.SDOMonitorGrid.SetCellValue(gridRow, 1, str(subIdx)) edouard@2643: for col, key in [(2, "access"), edouard@2643: (3, "type"), edouard@2643: (4, "size"), edouard@2643: (5, "name")]: edouard@2643: SDOPanel.SDOMonitorGrid.SetCellValue(gridRow, col, entry[key]) edouard@2643: for col in range(7): edouard@2643: SDOPanel.SDOMonitorGrid.SetReadOnly(gridRow, col, True) edouard@2643: if col < 5 : edouard@2643: SDOPanel.SDOMonitorGrid.SetCellAlignment(\ edouard@2643: gridRow, col, wx.ALIGN_CENTER, wx.ALIGN_CENTER) edouard@2643: gridRow += 1 edouard@2643: edouard@2643: SDOPanel.SDOMonitorGrid.Refresh() edouard@2643: edouard@2643: #------------------------------------------------------------------------------- edouard@2643: # For PDO Mapping Panel andrej@2355: # PDO Class UI : Panel -> Choicebook (RxPDO, TxPDO) -> andrej@2354: # Notebook (PDO Index) -> Grid (PDO entry) edouard@2643: #------------------------------------------------------------------------------- andrej@2354: class PDOPanelClass(wx.Panel): andrej@2354: def __init__(self, parent, controler): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: Reference to the parent EtherCATManagementTreebook class andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: """ andrej@2354: wx.Panel.__init__(self, parent, -1) andrej@2354: self.Controler = controler edouard@2643: sizer = wx.FlexGridSizer(cols=1, hgap=20,rows=3, vgap=20) edouard@2643: line = wx.StaticText(self, -1, "\n In order to control Ethercat device, user must select proper PDO set.\ edouard@2643: \n Each PDO sets describe operation modes (CSP, CSV, CST) supported by Ethercat devices.\ edouard@2643: \n\n PDOs have two types, RxPDO and TxPDO.\ edouard@2643: \n - RxPDO refers to the Receive Process Data Object. It means the control parameters which sent from controller to the EtherCAT Slave device.\ edouard@2643: \n In general, ControlWord (0x6040), Modes of Operations (0x6060), and TargetPosition (0x607A) are regarded as RxPDO.\ edouard@2643: \n - TxPDO refers to the Transmit Process Data Object. It used to report status of EtherCAT Slave device to the controller in order to calibrate their next actuation.\ edouard@2643: \n StatusWord (0x6041), Modes of Operation Display (0x6061), and ActualPosition (0x607A) include in TxPDO.\ edouard@2643: \n\n PDO Mapping feature provides available RxPDO and TxPDO sets which defined in Ethercat slave description XML.\ edouard@2643: \n If there is no selection of PDO set, first set (0x1600, 0x1A00) will be chosen as default configuration.") edouard@2643: edouard@2643: sizer.Add(line) edouard@2643: self.SetSizer(sizer) edouard@2643: edouard@2643: class RxPDOPanelClass(wx.Panel): edouard@2643: def __init__(self, parent, controler): edouard@2643: """ edouard@2643: Constructor edouard@2643: @param parent: Reference to the parent EtherCATManagementTreebook class edouard@2643: @param controler: _EthercatSlaveCTN class in EthercatSlave.py edouard@2643: """ edouard@2643: wx.Panel.__init__(self, parent, -1) edouard@2643: self.Controler = controler edouard@2643: edouard@2643: # add jblee edouard@2643: #self.PDOIndexList = ["RxPDO"] edouard@2643: self.PDOIndexList = [] edouard@2643: self.LoadPDOSelectData() edouard@2643: edouard@2643: #HSAHN ADD. 2015.7.26 PDO Select Function ADD edouard@2643: self.Controler.CommonMethod.RequestPDOInfo() edouard@2643: self.PDOcheckBox = [] edouard@2643: self.rx_pdo_entries = self.Controler.CommonMethod.GetRxPDOCategory() edouard@2643: if len(self.rx_pdo_entries): edouard@2643: for i in range(len(self.rx_pdo_entries)): edouard@2643: self.PDOcheckBox.append(wx.CheckBox(self, label=str(hex(self.rx_pdo_entries[i]['pdo_index'])), size=(120,15))) edouard@2643: if not self.Controler.SelectedRxPDOIndex and self.rx_pdo_entries[i]['sm'] is not None: edouard@2643: self.PDOcheckBox[-1].SetValue(True) edouard@2643: self.Controler.SelectedRxPDOIndex.append(int(self.PDOcheckBox[-1].GetLabel(), 0)) edouard@2643: self.InitSavePDO() edouard@2643: elif self.rx_pdo_entries[i]['pdo_index'] in self.Controler.SelectedRxPDOIndex: edouard@2643: self.PDOIndexList.append(str(hex(self.rx_pdo_entries[i]['pdo_index']))) edouard@2643: self.PDOcheckBox[-1].SetValue(True) edouard@2643: edouard@2643: for cb in self.PDOcheckBox: edouard@2643: self.Bind(wx.EVT_CHECKBOX, self.PDOSelectCheck, cb) edouard@2643: edouard@2643: self.PDOListBox = wx.StaticBox(self, label=_("PDO Mapping Select")) edouard@2643: self.PDOListBoxSizer = wx.StaticBoxSizer(self.PDOListBox, orient=wx.HORIZONTAL) edouard@2643: self.RxPDOListBox = wx.StaticBox(self, label=_("RxPDO")) edouard@2643: self.RxPDOListBoxSizer = wx.StaticBoxSizer(self.RxPDOListBox, orient=wx.VERTICAL) edouard@2643: self.RxPDOListBoxInnerSizer = wx.FlexGridSizer(cols=3, hgap=5, rows=10, vgap=5) edouard@2643: self.RxPDOListBoxInnerSizer.AddMany(self.PDOcheckBox[0:len(self.rx_pdo_entries)]) edouard@2643: self.RxPDOListBoxSizer.Add(self.RxPDOListBoxInnerSizer) edouard@2643: self.PDOListBoxSizer.Add(self.RxPDOListBoxSizer) edouard@2643: self.PDOWarningText = wx.StaticText(self, -1, edouard@2643: " *Warning*\n\n By default configuration, \n\n first mapping set is selected. \n\n Choose the PDO mapping!", edouard@2643: size=(220, -1)) edouard@2643: self.PDOListBoxSizer.Add(self.PDOWarningText) edouard@2643: edouard@2643: self.PDOMonitoringEditorMainSizer = wx.BoxSizer(wx.VERTICAL) edouard@2643: self.PDOMonitoringEditorInnerMainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10) edouard@2643: edouard@2643: edouard@2643: self.CallPDOChoicebook = PDONoteBook(self, controler=self.Controler, name="Rx") edouard@2643: self.PDOMonitoringEditorInnerMainSizer.Add(self.CallPDOChoicebook, wx.ALL) edouard@2643: edouard@2643: self.PDOInformationBox = wx.StaticBox(self, label=_("RxPDO Mapping List")) edouard@2643: self.PDOInformationBoxSizer = wx.StaticBoxSizer(self.PDOInformationBox, orient=wx.VERTICAL) edouard@2643: self.PDOInformationBoxSizer.Add(self.PDOMonitoringEditorInnerMainSizer) edouard@2643: edouard@2643: self.PDOMonitoringEditorMainSizer.Add(self.PDOListBoxSizer) edouard@2643: self.PDOMonitoringEditorMainSizer.Add(self.PDOInformationBoxSizer) edouard@2643: self.SetSizer(self.PDOMonitoringEditorMainSizer) edouard@2643: edouard@2643: # add jblee edouard@2643: self.PDOExcludeCheck() edouard@2643: else: edouard@2643: sizer = wx.FlexGridSizer(cols=1, hgap=20,rows=3, vgap=20) edouard@2643: line = wx.StaticText(self, -1, "\n This device does not support RxPDO.") edouard@2643: edouard@2643: sizer.Add(line) edouard@2643: self.SetSizer(sizer) edouard@2643: edouard@2643: def LoadPDOSelectData(self): edouard@2643: RxPDOData = self.Controler.BaseParams.getRxPDO() edouard@2643: RxPDOs = [] edouard@2643: if RxPDOData != "None": edouard@2643: RxPDOs = RxPDOData.split() edouard@2643: if RxPDOs : edouard@2643: for RxPDO in RxPDOs : edouard@2643: self.Controler.SelectedRxPDOIndex.append(int(RxPDO, 0)) edouard@2643: edouard@2643: def PDOSelectCheck(self, event): edouard@2643: # add jblee for Save User Select edouard@2643: cb = event.GetEventObject() edouard@2643: # prevent duplicated check edouard@2643: if cb.GetValue() and int(cb.GetLabel(), 0) not in self.Controler.SelectedRxPDOIndex: edouard@2643: self.Controler.SelectedRxPDOIndex.append(int(cb.GetLabel(), 0)) edouard@2643: self.PDOIndexList.append(cb.GetLabel()) edouard@2643: else: edouard@2643: self.Controler.SelectedRxPDOIndex.remove(int(cb.GetLabel(), 0)) edouard@2643: self.PDOIndexList.remove(cb.GetLabel()) edouard@2643: edouard@2643: data = "" edouard@2643: for PDOIndex in self.PDOIndexList: edouard@2643: data = data + " " + PDOIndex edouard@2643: edouard@2643: self.Controler.BaseParams.setRxPDO(data) edouard@2643: self.Controler.GetCTRoot().CTNRequestSave() edouard@2643: edouard@2643: self.PDOExcludeCheck() edouard@2643: edouard@2643: def InitSavePDO(self): edouard@2643: for PDOIndex in self.Controler.SelectedRxPDOIndex: edouard@2643: self.PDOIndexList.append(str(hex(PDOIndex))) edouard@2643: edouard@2643: data = "" edouard@2643: for PDOIndex in self.PDOIndexList: edouard@2643: data = data + " " + PDOIndex edouard@2643: edouard@2643: self.Controler.BaseParams.setRxPDO(data) edouard@2643: edouard@2643: # 2016.06.21 edouard@2643: # add jblee for check exclude pdo list edouard@2643: def PDOExcludeCheck(self): edouard@2643: #files = os.listdir(self.Controler.CTNPath()) edouard@2643: #filepath = os.path.join(self.Controler.CTNPath(), "DataForPDO.txt") edouard@2643: CurIndexs = self.Controler.SelectedRxPDOIndex edouard@2643: for CB in self.PDOcheckBox: edouard@2643: if len(CB.GetLabel().split()) > 1: edouard@2643: CB.Enable() edouard@2643: CB.SetLabel(CB.GetLabel().split()[0]) edouard@2643: edouard@2643: for pdo in self.rx_pdo_entries: edouard@2643: for CurIndex in CurIndexs: edouard@2643: if pdo["pdo_index"] == CurIndex: edouard@2643: ex_list = pdo["exclude_list"] edouard@2643: for ex_item in ex_list: edouard@2643: for CB in self.PDOcheckBox: edouard@2643: if CB.GetLabel() == hex(ex_item): edouard@2643: CB.SetLabel(CB.GetLabel() + " (Excluded)") edouard@2643: CB.Disable() edouard@2643: edouard@2643: def RefreshPDOInfo(self): edouard@2643: pass andrej@2354: andrej@2354: def PDOInfoUpdate(self): andrej@2354: """ andrej@2354: Call RequestPDOInfo method and create Choicebook andrej@2354: """ andrej@2354: self.Controler.CommonMethod.RequestPDOInfo() andrej@2354: self.CallPDOChoicebook.Destroy() edouard@2643: self.CallPDOChoicebook = PDOChoicebook(self, controler=self.Controler, name="Rx") andrej@2354: self.Refresh() andrej@2354: edouard@2643: class TxPDOPanelClass(wx.Panel): andrej@2354: def __init__(self, parent, controler): andrej@2354: """ andrej@2354: Constructor edouard@2643: @param parent: Reference to the parent EtherCATManagementTreebook class andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: """ edouard@2643: wx.Panel.__init__(self, parent, -1) andrej@2354: self.Controler = controler andrej@2355: edouard@2643: # add jblee edouard@2643: self.PDOIndexList = [] edouard@2643: self.LoadPDOSelectData() edouard@2643: edouard@2643: #HSAHN ADD. 2015.7.26 PDO Select Function ADD edouard@2643: self.Controler.CommonMethod.RequestPDOInfo() edouard@2643: self.PDOcheckBox = [] edouard@2643: self.tx_pdo_entries = self.Controler.CommonMethod.GetTxPDOCategory() edouard@2643: if len(self.tx_pdo_entries): edouard@2643: for i in range(len(self.tx_pdo_entries)): edouard@2643: self.PDOcheckBox.append(wx.CheckBox(self, label=str(hex(self.tx_pdo_entries[i]['pdo_index'])), size=(120,15))) edouard@2643: if not self.Controler.SelectedTxPDOIndex and self.tx_pdo_entries[i]['sm'] is not None: edouard@2643: self.PDOcheckBox[-1].SetValue(True) edouard@2643: self.Controler.SelectedTxPDOIndex.append(int(self.PDOcheckBox[-1].GetLabel(), 0)) edouard@2643: self.InitSavePDO() edouard@2643: elif self.tx_pdo_entries[i]['pdo_index'] in self.Controler.SelectedTxPDOIndex: edouard@2643: self.PDOIndexList.append(str(hex(self.tx_pdo_entries[i]['pdo_index']))) edouard@2643: self.PDOcheckBox[-1].SetValue(True) edouard@2643: for cb in self.PDOcheckBox: edouard@2643: self.Bind(wx.EVT_CHECKBOX, self.PDOSelectCheck, cb) edouard@2643: edouard@2643: self.PDOListBox = wx.StaticBox(self, label=_("PDO Mapping Select")) edouard@2643: self.PDOListBoxSizer = wx.StaticBoxSizer(self.PDOListBox, orient=wx.HORIZONTAL) edouard@2643: self.TxPDOListBox = wx.StaticBox(self, label=_("TxPDO")) edouard@2643: self.TxPDOListBoxSizer = wx.StaticBoxSizer(self.TxPDOListBox, orient=wx.VERTICAL) edouard@2643: self.TxPDOListBoxInnerSizer = wx.FlexGridSizer(cols=3, hgap=5, rows=10, vgap=5) edouard@2643: self.TxPDOListBoxInnerSizer.AddMany(self.PDOcheckBox[0:len(self.tx_pdo_entries)]) edouard@2643: self.TxPDOListBoxSizer.Add(self.TxPDOListBoxInnerSizer) edouard@2643: self.PDOListBoxSizer.Add(self.TxPDOListBoxSizer) edouard@2643: self.PDOWarningText = wx.StaticText(self, -1, edouard@2643: " *Warning*\n\n By default configuration, \n\n first mapping set is selected. \n\n Choose the PDO mapping!", edouard@2643: size=(220, -1)) edouard@2643: self.PDOListBoxSizer.Add(self.PDOWarningText) edouard@2643: edouard@2643: self.PDOMonitoringEditorMainSizer = wx.BoxSizer(wx.VERTICAL) edouard@2643: self.PDOMonitoringEditorInnerMainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10) edouard@2643: edouard@2643: self.CallPDOChoicebook = PDONoteBook(self, controler=self.Controler, name="Tx") edouard@2643: self.PDOMonitoringEditorInnerMainSizer.Add(self.CallPDOChoicebook, wx.ALL) edouard@2643: edouard@2643: self.PDOInformationBox = wx.StaticBox(self, label=_("TxPDO Mapping List")) edouard@2643: self.PDOInformationBoxSizer = wx.StaticBoxSizer(self.PDOInformationBox, orient=wx.VERTICAL) edouard@2643: self.PDOInformationBoxSizer.Add(self.PDOMonitoringEditorInnerMainSizer) edouard@2643: edouard@2643: self.PDOMonitoringEditorMainSizer.Add(self.PDOListBoxSizer) edouard@2643: self.PDOMonitoringEditorMainSizer.Add(self.PDOInformationBoxSizer) edouard@2643: self.SetSizer(self.PDOMonitoringEditorMainSizer) edouard@2643: edouard@2643: # add jblee edouard@2643: self.PDOExcludeCheck() edouard@2643: else: edouard@2643: sizer = wx.FlexGridSizer(cols=1, hgap=20,rows=3, vgap=20) edouard@2643: line = wx.StaticText(self, -1, "\n This device does not support TxPDO.") edouard@2643: edouard@2643: sizer.Add(line) edouard@2643: self.SetSizer(sizer) edouard@2643: edouard@2643: def LoadPDOSelectData(self): edouard@2643: TxPDOData = self.Controler.BaseParams.getTxPDO() edouard@2643: TxPDOs = [] edouard@2643: if TxPDOData != "None": edouard@2643: TxPDOs = TxPDOData.split() edouard@2643: if TxPDOs : edouard@2643: for TxPDO in TxPDOs : edouard@2643: self.Controler.SelectedTxPDOIndex.append(int(TxPDO, 0)) edouard@2643: edouard@2643: def PDOSelectCheck(self, event): edouard@2643: # add jblee for Save User Select edouard@2643: cb = event.GetEventObject() edouard@2643: # prevent duplicated check edouard@2643: if cb.GetValue() and int(cb.GetLabel(), 0) not in self.Controler.SelectedTxPDOIndex: edouard@2643: self.Controler.SelectedTxPDOIndex.append(int(cb.GetLabel(), 0)) edouard@2643: self.PDOIndexList.append(cb.GetLabel()) edouard@2643: else: edouard@2643: self.Controler.SelectedTxPDOIndex.remove(int(cb.GetLabel(), 0)) edouard@2643: self.PDOIndexList.remove(cb.GetLabel()) edouard@2643: edouard@2643: data = "" edouard@2643: for PDOIndex in self.PDOIndexList: edouard@2643: data = data + " " + PDOIndex edouard@2643: edouard@2643: self.Controler.BaseParams.setTxPDO(data) edouard@2643: self.Controler.GetCTRoot().CTNRequestSave() edouard@2643: edouard@2643: self.PDOExcludeCheck() edouard@2643: edouard@2643: def InitSavePDO(self): edouard@2643: for PDOIndex in self.Controler.SelectedTxPDOIndex: edouard@2643: self.PDOIndexList.append(str(hex(PDOIndex))) edouard@2643: edouard@2643: data = "" edouard@2643: for PDOIndex in self.PDOIndexList: edouard@2643: data = data + " " + PDOIndex edouard@2643: edouard@2643: self.Controler.BaseParams.setTxPDO(data) edouard@2643: edouard@2643: # 2016.06.21 edouard@2643: # add jblee for check exclude pdo list edouard@2643: def PDOExcludeCheck(self): edouard@2643: CurIndexs = self.Controler.SelectedTxPDOIndex edouard@2643: for CB in self.PDOcheckBox: edouard@2643: if len(CB.GetLabel().split()) > 1: edouard@2643: CB.Enable() edouard@2643: CB.SetLabel(CB.GetLabel().split()[0]) edouard@2643: edouard@2643: for pdo in self.tx_pdo_entries: edouard@2643: for CurIndex in CurIndexs: edouard@2643: if pdo["pdo_index"] == CurIndex: edouard@2643: ex_list = pdo["exclude_list"] edouard@2643: for ex_item in ex_list: edouard@2643: for CB in self.PDOcheckBox: edouard@2643: if CB.GetLabel() == hex(ex_item): edouard@2643: CB.SetLabel(CB.GetLabel() + " (Excluded)") edouard@2643: CB.Disable() edouard@2643: edouard@2643: def PDOInfoUpdate(self): edouard@2643: """ edouard@2643: Call RequestPDOInfo method and create Choicebook edouard@2643: """ edouard@2643: self.Controler.CommonMethod.RequestPDOInfo() edouard@2643: self.CallPDOChoicebook.Destroy() edouard@2643: self.CallPDOChoicebook = PDOChoicebook(self, controler=self.Controler, name="Tx") edouard@2643: self.Refresh() andrej@2354: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # For PDO Notebook (divide PDO index) andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class PDONoteBook(wx.Notebook): andrej@2354: def __init__(self, parent, name, controler): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: Reference to the parent PDOChoicebook class andrej@2354: @param name: identifier whether RxPDO or TxPDO andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: """ edouard@2643: wx.Notebook.__init__(self, parent, id=-1, size=(600, 400)) andrej@2354: self.Controler = controler andrej@2355: andrej@2354: count = 0 andrej@2354: page_texts = [] andrej@2355: andrej@2375: if name == "Tx": andrej@2354: # obtain pdo_info and pdo_entry andrej@2354: # pdo_info include (PDO index, name, number of entry) andrej@2373: pdo_info = self.Controler.CommonMethod.GetTxPDOCategory() andrej@2354: pdo_entry = self.Controler.CommonMethod.GetTxPDOInfo() andrej@2375: for tmp in pdo_info: andrej@2354: title = str(hex(tmp['pdo_index'])) andrej@2354: page_texts.append(title) andrej@2354: # RX PDO case andrej@2375: else: andrej@2354: pdo_info = self.Controler.CommonMethod.GetRxPDOCategory() andrej@2354: pdo_entry = self.Controler.CommonMethod.GetRxPDOInfo() andrej@2375: for tmp in pdo_info: andrej@2354: title = str(hex(tmp['pdo_index'])) andrej@2354: page_texts.append(title) andrej@2355: andrej@2354: # Add page depending on the number of pdo_info andrej@2354: for txt in page_texts: andrej@2354: win = PDOEntryTable(self, pdo_info, pdo_entry, count) andrej@2354: self.AddPage(win, txt) andrej@2355: count += 1 andrej@2354: andrej@2354: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # For PDO Grid (fill entry index, subindex etc...) andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class PDOEntryTable(wx.grid.Grid): andrej@2354: def __init__(self, parent, info, entry, count): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: Reference to the parent PDONoteBook class andrej@2354: @param info : data structure including entry index, sub index, name, length, type andrej@2354: @param entry : data structure including index, name, entry number andrej@2354: @param count : page number andrej@2354: """ andrej@2363: wx.grid.Grid.__init__(self, parent, -1, size=(500, 400), pos=wx.Point(0, 0), andrej@2367: style=wx.EXPAND | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL) andrej@2355: andrej@2354: self.Controler = parent.Controler andrej@2355: andrej@2354: self.PDOInfo = info andrej@2354: self.PDOEntry = entry andrej@2354: self.Count = count andrej@2355: andrej@2354: self.CreateGrid(self.PDOInfo[self.Count]['number_of_entry'], 5) andrej@2355: self.SetColLabelSize(25) andrej@2354: self.SetRowLabelSize(0) andrej@2355: andrej@2354: PDOTableLabel = [(0, "Index"), (1, "Subindex"), (2, "Length"), andrej@2354: (3, "Type"), (4, "Name")] andrej@2355: andrej@2354: for (index, label) in PDOTableLabel: andrej@2354: self.SetColLabelValue(index, label) andrej@2355: andrej@2354: PDOCellSize = [(0, 45), (1, 65), (2, 55), (3, 40), (4, 300)] andrej@2355: andrej@2354: for (index, size) in PDOCellSize: andrej@2354: self.SetColSize(index, size) andrej@2354: self.SetColLabelAlignment(index, wx.ALIGN_LEFT) andrej@2355: andrej@2354: attr = wx.grid.GridCellAttr() andrej@2355: andrej@2354: for i in range(5): andrej@2354: self.SetColAttr(i, attr) andrej@2355: andrej@2354: self.SetTableValue() andrej@2355: andrej@2354: def SetTableValue(self): andrej@2354: """ andrej@2354: Cell is filled by new parsing data in XML andrej@2354: """ andrej@2354: list_index = 0 andrej@2354: # number of entry andrej@2375: for i in range(self.Count + 1): andrej@2354: list_index += self.PDOInfo[i]['number_of_entry'] andrej@2354: andrej@2354: start_value = list_index - self.PDOInfo[self.Count]['number_of_entry'] andrej@2355: andrej@2354: pdo_list = ['entry_index', 'subindex', 'bitlen', 'type', 'name'] andrej@2354: for row_idx in range(self.PDOInfo[self.Count]['number_of_entry']): andrej@2354: for col_idx in range(len(self.PDOEntry[row_idx])): andrej@2354: # entry index is converted hex value. andrej@2375: if col_idx == 0: andrej@2354: self.SetCellValue(row_idx, col_idx, hex(self.PDOEntry[start_value][pdo_list[col_idx]])) andrej@2375: else: andrej@2354: self.SetCellValue(row_idx, col_idx, str(self.PDOEntry[start_value][pdo_list[col_idx]])) andrej@2375: if col_idx != 4: andrej@2354: self.SetCellAlignment(row_idx, col_idx, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) andrej@2375: else: andrej@2354: self.SetCellAlignment(row_idx, col_idx, wx.ALIGN_LEFT, wx.ALIGN_CENTRE) andrej@2354: self.SetReadOnly(row_idx, col_idx, True) andrej@2354: self.SetRowSize(row_idx, 25) andrej@2354: start_value += 1 andrej@2354: edouard@2643: #------------------------------------------------------------------------------- edouard@2643: # For MDP Main Panel edouard@2643: #------------------------------------------------------------------------------- edouard@2643: class MDPPanel(wx.Panel): andrej@2354: def __init__(self, parent, controler): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: Reference to the parent EtherCATManagementTreebook class andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: """ andrej@2354: wx.Panel.__init__(self, parent, -1) edouard@2643: self.parent = parent edouard@2643: self.Controler = controler edouard@2643: edouard@2643: sizer = wx.FlexGridSizer(cols=3, hgap=20, rows=1, vgap=20) edouard@2643: edouard@2643: # Include Module ListBox edouard@2643: leftInnerSizer = wx.FlexGridSizer(cols=1, hgap=10,rows=2, vgap=10) edouard@2643: # Include Add, Delete Button edouard@2643: middleInnerSizer = wx.FlexGridSizer(cols=1, hgap=10,rows=2, vgap=10) edouard@2643: # Include Slot ListBox edouard@2643: rightInnerSizer = wx.FlexGridSizer(cols=1, hgap=10,rows=2, vgap=10) edouard@2643: edouard@2643: # Get Module Name as Array edouard@2643: # MDPArray = {SlaveName, [data0, data1, ...], SlotIndexIncrement, SlotPdoIncrement} edouard@2643: # data = [ModuleName, ModuleInfo, [PDOInfo1, PDOInfo2, ...]] edouard@2643: # PDOInfo = {Index, Name, BitSize, Access, PDOMapping, SubIndex, Type} edouard@2643: slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos()) edouard@2643: type_infos = slave.getType() edouard@2643: MDPArray = self.Controler.CTNParent.CTNParent.GetMDPInfos(type_infos) edouard@2643: edouard@2643: NameSet = [] edouard@2643: if MDPArray: edouard@2643: for info in MDPArray[0][1]: edouard@2643: NameSet.append(info[0]) edouard@2643: edouard@2643: # Module ListBox edouard@2643: self.ModuleLabel = wx.StaticText(self, -1, "Module") edouard@2643: self.ModuleListBox = wx.ListBox(self, size = (150, 200), choices = NameSet) edouard@2643: #self.ModuleListBox = wx.ListBox(self, size = (150, 200), choices = []) edouard@2643: self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnModuleListBoxDCClick, self.ModuleListBox) edouard@2643: edouard@2643: # Button edouard@2643: self.AddButton = wx.Button(self, label=_(" Add Module ")) edouard@2643: self.DeleteButton = wx.Button(self, label=_("Delete Module")) edouard@2643: edouard@2643: # Button Event Mapping edouard@2643: self.AddButton.Bind(wx.EVT_BUTTON, self.OnAddButton) edouard@2643: self.DeleteButton.Bind(wx.EVT_BUTTON, self.OnDeleteButton) edouard@2643: edouard@2643: # Slot ListBox edouard@2643: self.SlotLabel = wx.StaticText(self, -1, "Slot") edouard@2643: self.SlotListBox = wx.ListBox(self, size = (150, 200)) edouard@2643: self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnSlotListBoxDCClick, self.SlotListBox) edouard@2643: self.SelectModule = [] edouard@2643: edouard@2643: # Add Object Each Sizer edouard@2643: leftInnerSizer.AddMany([self.ModuleLabel, self.ModuleListBox]) edouard@2643: middleInnerSizer.Add(self.AddButton, 0, wx.TOP, 100) edouard@2643: middleInnerSizer.Add(self.DeleteButton, 0, wx.BOTTOM, 120) edouard@2643: rightInnerSizer.AddMany([self.SlotLabel, self.SlotListBox]) edouard@2643: edouard@2643: sizer.AddMany([leftInnerSizer, middleInnerSizer, rightInnerSizer]) edouard@2643: edouard@2643: self.SetSizer(sizer) edouard@2643: edouard@2643: self.InitMDPSet() edouard@2643: edouard@2643: def InitMDPSet(self): edouard@2643: files = os.listdir(self.Controler.CTNPath()) edouard@2643: filepath = os.path.join(self.Controler.CTNPath(), "DataForMDP.txt") edouard@2643: try: edouard@2643: moduleDataFile = open(filepath, 'r') edouard@2643: lines = moduleDataFile.readlines() edouard@2643: edouard@2643: for line in lines: edouard@2643: if line == "\n": edouard@2643: continue edouard@2643: module_pos = line.split()[-1] edouard@2643: name_len_limit = len(line) - len(module_pos) - 2 edouard@2643: module_name = line[0:name_len_limit] edouard@2643: edouard@2643: self.SelectModule.append((module_name, int(module_pos))) edouard@2643: edouard@2643: localModuleInfo = [] edouard@2643: count = 1 edouard@2643: for (item, pos) in self.SelectModule: edouard@2643: slotString = "Slot %d %s : " % (count, item.split()[1]) + item.split()[0] edouard@2643: localModuleInfo.append(slotString) edouard@2643: count += 1 edouard@2643: self.SlotListBox.SetItems(localModuleInfo) edouard@2643: edouard@2643: except: edouard@2643: moduleDataFile = open(filepath, 'w') edouard@2643: edouard@2643: moduleDataFile.close() edouard@2643: edouard@2643: def OnAddButton(self, event): edouard@2643: files = os.listdir(self.Controler.CTNPath()) edouard@2643: filepath = os.path.join(self.Controler.CTNPath(), "DataForMDP.txt") edouard@2643: moduleDataFile = open(filepath, 'w') edouard@2643: edouard@2643: selectNum = self.ModuleListBox.GetSelection() edouard@2643: if selectNum >= 0: edouard@2643: selectStr = self.ModuleListBox.GetString(selectNum) edouard@2643: self.SelectModule.append((selectStr, selectNum)) edouard@2643: localModuleInfo = [] edouard@2643: count = 1 edouard@2643: for (item, pos) in self.SelectModule: edouard@2643: slotString = "Slot %d %s : " % (count, item.split()[1]) + item.split()[0] edouard@2643: localModuleInfo.append(slotString) edouard@2643: count += 1 edouard@2643: self.SlotListBox.SetItems(localModuleInfo) edouard@2643: edouard@2643: moduleDataFile.close() edouard@2643: edouard@2643: def OnDeleteButton(self, event): edouard@2643: files = os.listdir(self.Controler.CTNPath()) edouard@2643: filepath = os.path.join(self.Controler.CTNPath(), "DataForMDP.txt") edouard@2643: moduleDataFile = open(filepath, 'w') edouard@2643: edouard@2643: selectNum = self.SlotListBox.GetSelection() edouard@2643: if selectNum >= 0: edouard@2643: selectStr = self.SlotListBox.GetString(selectNum) edouard@2643: self.SelectModule.pop(selectNum) edouard@2643: localModuleInfo = [] edouard@2643: count = 1 edouard@2643: for (item, pos) in self.SelectModule: edouard@2643: moduleDataFile.write(item + " " + str(pos) + "\n") edouard@2643: slotString = "Slot %d %s : " % (count, item.split()[1]) + item.split()[0] edouard@2643: localModuleInfo.append(slotString) edouard@2643: count += 1 edouard@2643: self.SlotListBox.SetItems(localModuleInfo) edouard@2643: edouard@2643: moduleDataFile.close() edouard@2643: edouard@2643: def OnModuleListBoxDCClick(self, event): edouard@2643: files = os.listdir(self.Controler.CTNPath()) edouard@2643: filepath = os.path.join(self.Controler.CTNPath(), "DataForMDP.txt") edouard@2643: moduleDataFile = open(filepath, 'w') edouard@2643: edouard@2643: selectNum = self.ModuleListBox.GetSelection() edouard@2643: if selectNum >= 0: edouard@2643: selectStr = self.ModuleListBox.GetString(selectNum) edouard@2643: self.SelectModule.append((selectStr, selectNum)) edouard@2643: localModuleInfo = [] edouard@2643: count = 1 edouard@2643: for (item, pos) in self.SelectModule: edouard@2643: moduleDataFile.write(item + " " + str(pos) + "\n") edouard@2643: slotString = "Slot %d %s : " % (count, item.split()[1]) + item.split()[0] edouard@2643: localModuleInfo.append(slotString) edouard@2643: module = self.Controler.CTNParent.CTNParent.GetSelectModule(pos) edouard@2643: self.Controler.CommonMethod.SavePDOData(module) edouard@2643: count += 1 edouard@2643: self.SlotListBox.SetItems(localModuleInfo) edouard@2643: edouard@2643: moduleDataFile.close() edouard@2643: edouard@2643: def OnSlotListBoxDCClick(self, event): edouard@2643: files = os.listdir(self.Controler.CTNPath()) edouard@2643: filepath = os.path.join(self.Controler.CTNPath(), "DataForMDP.txt") edouard@2643: moduleDataFile = open(filepath, 'w') edouard@2643: edouard@2643: selectNum = self.SlotListBox.GetSelection() edouard@2643: if selectNum >= 0: edouard@2643: selectStr = self.SlotListBox.GetString(selectNum) edouard@2643: self.SelectModule.pop(selectNum) edouard@2643: localModuleInfo = [] edouard@2643: count = 1 edouard@2643: for (item, pos) in self.SelectModule: edouard@2643: moduleDataFile.write(item + " " + str(pos) + "\n") edouard@2643: slotString = "Slot %d %s : " % (count, item.split()[1]) + item.split()[0] edouard@2643: localModuleInfo.append(slotString) edouard@2643: count += 1 edouard@2643: self.SlotListBox.SetItems(localModuleInfo) edouard@2643: edouard@2643: moduleDataFile.close() edouard@2643: edouard@2643: # ------------------------------------------------------------------------------- edouard@2643: # For EEPROM Access Main Panel edouard@2643: # (This class explain EEPROM Access) edouard@2643: # ------------------------------------------------------------------------------- edouard@2643: class EEPROMAccessPanel(wx.Panel): edouard@2643: def __init__(self, parent, controler): edouard@2643: """ edouard@2643: Constructor edouard@2643: @param parent: Reference to the parent EtherCATManagementTreebook class edouard@2643: @param controler: _EthercatSlaveCTN class in EthercatSlave.py edouard@2643: """ edouard@2643: wx.Panel.__init__(self, parent, -1) andrej@2363: sizer = wx.FlexGridSizer(cols=1, hgap=20, rows=3, vgap=20) andrej@2355: andrej@2354: line = wx.StaticText(self, -1, "\n EEPROM Access is composed to SmartView and HexView. \ andrej@2354: \n\n - SmartView shows Config Data, Device Identity, Mailbox settings, etc. \ andrej@2354: \n\n - HexView shows EEPROM's contents.") andrej@2355: andrej@2354: sizer.Add(line) andrej@2355: andrej@2354: self.SetSizer(sizer) andrej@2354: andrej@2354: andrej@2356: # ------------------------------------------------------------------------------- andrej@2355: # For Smart View Panel andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class SlaveSiiSmartView(wx.Panel): andrej@2354: def __init__(self, parent, controler): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: Reference to the parent EtherCATManagementTreebook class andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: """ andrej@2354: wx.Panel.__init__(self, parent, -1) andrej@2354: self.parent = parent andrej@2354: self.Controler = controler andrej@2355: edouard@2643: # PDI Type 1, 13 unknown Type, Fix Future edouard@2643: self.PDIType = {0 :['none', '00000000'], edouard@2643: 1 :['unknown', '00000000'], edouard@2643: 4 :['Digital I/O', '00000100'], edouard@2643: 5 :['SPI Slave', '00000101'], edouard@2643: 7 :['EtherCAT Bridge (port3)', '00000111'], edouard@2643: 8 :['uC async. 16bit', '00001000'], edouard@2643: 9 :['uC async. 8bit', '00001001'], edouard@2643: 10 :['uC sync. 16bit', '00001010'], edouard@2643: 11 :['uC sync. 8bit', '00001011'], edouard@2643: 13 :['unknown', '00000000'], edouard@2643: 16 :['32 Digtal Input and 0 Digital Output', '00010000'], edouard@2643: 17 :['24 Digtal Input and 8 Digital Output', '00010001'], edouard@2643: 18 :['16 Digtal Input and 16 Digital Output','00010010'], edouard@2643: 19 :['8 Digtal Input and 24 Digital Output', '00010011'], edouard@2643: 20 :['0 Digtal Input and 32 Digital Output', '00010100'], edouard@2643: 128:['On-chip bus', '11111111'] edouard@2643: } andrej@2355: andrej@2354: sizer = wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5) andrej@2354: button_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=5) andrej@2354: andrej@2354: for button, mapping_method in [("Write EEPROM", self.WriteToEEPROM), andrej@2354: ("Read EEPROM", self.ReadFromEEPROM)]: andrej@2354: btn = wx.Button(self, -1, button, size=(150, 40)) andrej@2354: button_sizer.Add(btn, border=10, flag=wx.ALL) andrej@2354: btn.Bind(wx.EVT_BUTTON, mapping_method) andrej@2355: andrej@2354: self.TreeListCtrl = SmartViewTreeListCtrl(self, self.Controler) andrej@2355: andrej@2354: sizer.Add(button_sizer, border=10, flag=wx.ALL) andrej@2354: sizer.Add(self.TreeListCtrl, border=10, flag=wx.ALL) andrej@2354: self.SetSizer(sizer) andrej@2355: andrej@2354: self.Create_SmartView() andrej@2355: andrej@2354: def Create_SmartView(self): andrej@2354: """ andrej@2354: SmartView shows information based on XML as initial value. andrej@2355: """ andrej@2354: self.Controler.CommonMethod.SmartViewInfosFromXML = self.Controler.CommonMethod.GetSmartViewInfos() andrej@2354: self.SetXMLData() andrej@2355: andrej@2354: def WriteToEEPROM(self, event): andrej@2354: """ andrej@2354: Open binary file (user select) and write the selected binary data to EEPROM andrej@2354: @param event : wx.EVT_BUTTON object andrej@2355: """ andrej@2354: # Check whether beremiz connected or not, and whether status is "Started" or not. andrej@2354: check_connect_flag = self.Controler.CommonMethod.CheckConnect(False) andrej@2354: if check_connect_flag: andrej@2406: status, _log_count = self.Controler.GetCTRoot()._connector.GetPLCstatus() andrej@2416: if status is not PlcStatus.Started: edouard@3572: dialog = wx.FileDialog(self, _("Choose a binary file"), os.getcwd(), "", _("bin files (*.bin)|*.bin"), wx.FD_OPEN) andrej@2355: andrej@2354: if dialog.ShowModal() == wx.ID_OK: andrej@2354: filepath = dialog.GetPath() andrej@2354: try: andrej@2363: binfile = open(filepath, "rb") andrej@2354: self.SiiBinary = binfile.read() andrej@2354: dialog.Destroy() andrej@2355: andrej@2354: self.Controler.CommonMethod.SiiWrite(self.SiiBinary) andrej@2354: # refresh data structure kept by master andrej@2354: self.Controler.CommonMethod.Rescan() andrej@2355: # save binary data as inner global data of beremiz andrej@2354: # for fast loading when slave plugin node is reopened. andrej@2354: self.Controler.CommonMethod.SiiData = self.SiiBinary andrej@2354: self.SetEEPROMData() andrej@2354: except Exception: andrej@2423: self.Controler.CommonMethod.CreateErrorDialog(_('The file does not exist!')) andrej@2354: dialog.Destroy() andrej@2355: andrej@2354: def ReadFromEEPROM(self, event): andrej@2354: """ andrej@2354: Refresh displayed data based on slave EEPROM and save binary file through dialog andrej@2354: @param event : wx.EVT_BUTTON object andrej@2355: """ andrej@2354: # Check whether beremiz connected or not. edouard@2643: # If this method is called cyclically, set the cyclic flag true edouard@2643: check_connect_flag = self.Controler.CommonMethod.CheckConnect(cyclic_flag = False) andrej@2354: if check_connect_flag: andrej@2354: self.SiiBinary = self.Controler.CommonMethod.LoadData() andrej@2354: self.SetEEPROMData() andrej@2355: dialog = wx.FileDialog(self, _("Save as..."), os.getcwd(), andrej@2355: "slave0.bin", _("bin files (*.bin)|*.bin|All files|*.*"), andrej@2367: wx.SAVE | wx.OVERWRITE_PROMPT) andrej@2355: andrej@2354: if dialog.ShowModal() == wx.ID_OK: andrej@2354: filepath = dialog.GetPath() andrej@2363: binfile = open(filepath, "wb") andrej@2354: binfile.write(self.SiiBinary) andrej@2354: binfile.close() andrej@2355: andrej@2354: dialog.Destroy() andrej@2355: andrej@2354: def SetXMLData(self): andrej@2354: """ andrej@2354: Set data based on XML initially andrej@2355: """ andrej@2354: # Config Data: EEPROM Size, PDI Type, Device Emulation andrej@2354: # Find PDI Type in pdiType dictionary andrej@2354: cnt_pdi_type = self.Controler.CommonMethod.SmartViewInfosFromXML["pdi_type"] kinsamanka@3750: for i in list(self.PDIType.keys()): andrej@2354: if cnt_pdi_type == i: andrej@2354: cnt_pdi_type = self.PDIType[i][0] andrej@2354: break andrej@2354: # Set Config Data andrej@2355: for treelist, data in [("EEPROM Size (Bytes)", andrej@2354: str(self.Controler.CommonMethod.SmartViewInfosFromXML["eeprom_size"])), andrej@2355: ("PDI Type", andrej@2354: cnt_pdi_type), andrej@2355: ("Device Emulation", andrej@2354: self.Controler.CommonMethod.SmartViewInfosFromXML["device_emulation"])]: andrej@2354: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.ConfigData[treelist], data, 1) andrej@2355: andrej@2354: # Device Identity: Vendor ID, Product Code, Revision No., Serial No. andrej@2354: # Set Device Identity andrej@2354: for treelist, data in [("Vendor ID", self.Controler.CommonMethod.SmartViewInfosFromXML["vendor_id"]), andrej@2354: ("Product Code", self.Controler.CommonMethod.SmartViewInfosFromXML["product_code"]), andrej@2354: ("Revision No.", self.Controler.CommonMethod.SmartViewInfosFromXML["revision_no"]), andrej@2354: ("Serial No.", self.Controler.CommonMethod.SmartViewInfosFromXML["serial_no"])]: andrej@2354: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.DeviceIdentity[treelist], data, 1) andrej@2355: andrej@2354: # Mailbox: Supported Mailbox, Bootstrap Configuration, Standard Configuration andrej@2354: # Set Mailbox andrej@2354: for treelist, data in [("Supported Mailbox", self.Controler.CommonMethod.SmartViewInfosFromXML["supported_mailbox"]), andrej@2354: ("Bootstrap Configuration", ""), andrej@2354: ("Standard Configuration", "")]: andrej@2355: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.Mailbox[treelist], data, 1) andrej@2354: # Set Bootstrap Configuration: Receive Offset, Receive Size, Send Offset, Send Size andrej@2354: for treelist, data in [("Receive Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_outstart"]), andrej@2354: ("Receive Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_outlength"]), andrej@2354: ("Send Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_instart"]), andrej@2354: ("Send Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_bootstrapconf_inlength"])]: andrej@2355: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.BootstrapConfig[treelist], data, 1) andrej@2354: # Set Standard Configuration: Receive Offset, Receive Size, Send Offset, Send Size andrej@2354: for treelist, data in [("Receive Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_outstart"]), andrej@2354: ("Receive Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_outlength"]), andrej@2354: ("Send Offset", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_instart"]), andrej@2354: ("Send Size", self.Controler.CommonMethod.SmartViewInfosFromXML["mailbox_standardconf_inlength"])]: andrej@2354: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.StandardConfig[treelist], data, 1) andrej@2355: andrej@2354: def SetEEPROMData(self): andrej@2354: """ andrej@2354: Set data based on slave EEPROM. andrej@2355: """ andrej@2354: # sii_dict = { Parameter : (WordAddress, WordSize) } andrej@2365: sii_dict = { andrej@2375: 'PDIControl': ('0', 1), andrej@2375: 'PDIConfiguration': ('1', 1), andrej@2375: 'PulseLengthOfSYNCSignals': ('2', 1), andrej@2375: 'ExtendedPDIConfiguration': ('3', 1), andrej@2375: 'ConfiguredStationAlias': ('4', 1), andrej@2375: 'Checksum': ('7', 1), andrej@2375: 'VendorID': ('8', 2), andrej@2375: 'ProductCode': ('a', 2), andrej@2375: 'RevisionNumber': ('c', 2), andrej@2375: 'SerialNumber': ('e', 2), andrej@2375: 'Execution Delay': ('10', 1), andrej@2375: 'Port0Delay': ('11', 1), andrej@2375: 'Port1Delay': ('12', 1), andrej@2375: 'BootstrapReceiveMailboxOffset': ('14', 1), andrej@2375: 'BootstrapReceiveMailboxSize': ('15', 1), andrej@2375: 'BootstrapSendMailboxOffset': ('16', 1), andrej@2375: 'BootstrapSendMailboxSize': ('17', 1), andrej@2375: 'StandardReceiveMailboxOffset': ('18', 1), andrej@2375: 'StandardReceiveMailboxSize': ('19', 1), andrej@2375: 'StandardSendMailboxOffset': ('1a', 1), andrej@2375: 'StandardSendMailboxSize': ('1b', 1), andrej@2375: 'MailboxProtocol': ('1c', 1), andrej@2375: 'Size': ('3e', 1), andrej@2375: 'Version': ('3f', 1), andrej@2375: 'First Category Type/Vendor Specific': ('40', 1), andrej@2375: 'Following Category Word Size': ('41', 1), andrej@2375: 'Category Data': ('42', 1), andrej@2365: } andrej@2355: andrej@2354: # Config Data: EEPROM Size, PDI Type, Device Emulation andrej@2354: # EEPROM's data in address '0x003f' is Size of EEPROM in KBit-1 andrej@2437: eeprom_size = str((int(self.GetWordAddressData(sii_dict.get('Size'), 10))+1)//8*1024) andrej@2354: # Find PDI Type in pdiType dictionary andrej@2369: cnt_pdi_type = int(self.GetWordAddressData(sii_dict.get('PDIControl'), 16).split('x')[1][2:4], 16) kinsamanka@3750: for i in list(self.PDIType.keys()): andrej@2354: if cnt_pdi_type == i: andrej@2354: cnt_pdi_type = self.PDIType[i][0] andrej@2354: break andrej@2354: # Get Device Emulation andrej@2369: device_emulation = str(bool(int("{:0>16b}".format(int(self.GetWordAddressData(sii_dict.get('PDIControl'), 16), 16))[7]))) andrej@2354: # Set Config Data andrej@2354: for treelist, data in [("EEPROM Size (Bytes)", eeprom_size), andrej@2354: ("PDI Type", cnt_pdi_type), andrej@2354: ("Device Emulation", device_emulation)]: andrej@2354: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.ConfigData[treelist], data, 1) andrej@2355: andrej@2354: # Device Identity: Vendor ID, Product Code, Revision No., Serial No. andrej@2354: # Set Device Identity andrej@2363: for treelist, data in [ andrej@2369: ("Vendor ID", self.GetWordAddressData(sii_dict.get('VendorID'), 16)), andrej@2369: ("Product Code", self.GetWordAddressData(sii_dict.get('ProductCode'), 16)), andrej@2369: ("Revision No.", self.GetWordAddressData(sii_dict.get('RevisionNumber'), 16)), andrej@2369: ("Serial No.", self.GetWordAddressData(sii_dict.get('SerialNumber'), 16))]: andrej@2354: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.DeviceIdentity[treelist], data, 1) andrej@2355: andrej@2354: # Mailbox andrej@2354: # EEORPOM's word address '1c' indicates supported mailbox protocol. andrej@2355: # each value of mailbox protocol : andrej@2354: # VoE(0x0020), SoE(0x0010), FoE(0x0008), CoE(0x0004), EoE(0x0002), AoE(0x0001) andrej@2354: supported_mailbox = "" andrej@2365: mailbox_protocol = ["VoE, ", "SoE, ", "FoE, ", "CoE, ", "EoE, ", "AoE, "] andrej@2369: mailbox_data = "{:0>8b}".format(int(self.GetWordAddressData(sii_dict.get('MailboxProtocol'), 16), 16)) andrej@2354: for protocol in range(6): andrej@2354: if mailbox_data[protocol+2] == '1': andrej@2354: supported_mailbox += mailbox_protocol[protocol] andrej@2354: supported_mailbox = supported_mailbox.strip(", ") andrej@2354: # Set Mailbox andrej@2354: for treelist, data in [("Supported Mailbox", supported_mailbox), andrej@2354: ("Bootstrap Configuration", ""), andrej@2354: ("Standard Configuration", "")]: andrej@2355: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.Mailbox[treelist], data, 1) andrej@2354: # Set Bootstrap Configuration: Receive Offset, Receive Size, Send Offset, Send Size andrej@2363: for treelist, data in [ andrej@2369: ("Receive Offset", self.GetWordAddressData(sii_dict.get('BootstrapReceiveMailboxOffset'), 10)), andrej@2369: ("Receive Size", self.GetWordAddressData(sii_dict.get('BootstrapReceiveMailboxSize'), 10)), andrej@2369: ("Send Offset", self.GetWordAddressData(sii_dict.get('BootstrapSendMailboxOffset'), 10)), andrej@2369: ("Send Size", self.GetWordAddressData(sii_dict.get('BootstrapSendMailboxSize'), 10))]: andrej@2355: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.BootstrapConfig[treelist], data, 1) andrej@2354: # Set Standard Configuration: Receive Offset, Receive Size, Send Offset, Send Size andrej@2363: for treelist, data in [ andrej@2369: ("Receive Offset", self.GetWordAddressData(sii_dict.get('StandardReceiveMailboxOffset'), 10)), andrej@2369: ("Receive Size", self.GetWordAddressData(sii_dict.get('StandardReceiveMailboxSize'), 10)), andrej@2369: ("Send Offset", self.GetWordAddressData(sii_dict.get('StandardSendMailboxOffset'), 10)), andrej@2369: ("Send Size", self.GetWordAddressData(sii_dict.get('StandardSendMailboxSize'), 10))]: andrej@2355: self.TreeListCtrl.Tree.SetItemText(self.TreeListCtrl.StandardConfig[treelist], data, 1) andrej@2355: andrej@2354: def MakeStaticBoxSizer(self, boxlabel): andrej@2354: """ andrej@2354: Make StaticBoxSizer andrej@2354: @param boxlabel : label of box sizer andrej@2354: @return sizer : the StaticBoxSizer labeled 'boxlabel' andrej@2354: """ andrej@2354: box = wx.StaticBox(self, -1, boxlabel) andrej@2354: sizer = wx.StaticBoxSizer(box, wx.VERTICAL) andrej@2354: andrej@2354: return sizer andrej@2355: andrej@2354: def GetWordAddressData(self, dict_tuple, format): andrej@2354: """ andrej@2354: This method converts word address data from EEPROM binary. andrej@2354: @param dict_tuple : element of 'sii_dict' dictionary in SetEEPROMData() andrej@2354: @param format : format of data. It can be 16(hex), 10(decimal) and 2(binary). andrej@2354: @return formatted value andrej@2355: """ andrej@2354: offset = int(str(dict_tuple[0]), 16) * 2 andrej@2354: length = int(str(dict_tuple[1]), 16) * 2 andrej@2354: list = [] andrej@2354: data = '' andrej@2354: for index in range(length): andrej@2354: hexdata = hex(ord(self.SiiBinary[offset + index]))[2:] andrej@2354: list.append(hexdata.zfill(2)) andrej@2355: andrej@2354: list.reverse() andrej@2354: data = list[0:length] andrej@2354: andrej@2354: if format == 16: andrej@2355: return '0x' + ''.join(data) andrej@2354: elif format == 10: andrej@2354: return str(int(str(''.join(data)), 16)) andrej@2355: elif format == 2: andrej@2355: ''.join(data) andrej@2354: andrej@2354: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # For Smart View TreeListCtrl andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class SmartViewTreeListCtrl(wx.Panel): andrej@2354: def __init__(self, parent, Controler): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: Reference to the parent SlaveSiiSmartView class andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: """ andrej@2354: andrej@2354: wx.Panel.__init__(self, parent, -1, size=(350, 500)) andrej@2355: edouard@3303: self.Tree = wx.adv.TreeListCtrl(self, -1, size=(350, 500), andrej@2386: style=(wx.TR_DEFAULT_STYLE | andrej@2386: wx.TR_FULL_ROW_HIGHLIGHT | andrej@2386: wx.TR_HIDE_ROOT | andrej@2386: wx.TR_COLUMN_LINES | andrej@2386: wx.TR_ROW_LINES)) andrej@2355: andrej@2354: self.Tree.AddColumn("Description", width=200) andrej@2354: self.Tree.AddColumn("Value", width=140) andrej@2354: self.Tree.SetMainColumn(0) andrej@2355: andrej@2354: self.Root = self.Tree.AddRoot("") andrej@2355: andrej@2354: # Add item andrej@2354: # Level 1 nodes andrej@2354: self.Level1Nodes = {} andrej@2354: for lv1 in ["Config Data", "Device Identity", "Mailbox"]: andrej@2354: self.Level1Nodes[lv1] = self.Tree.AppendItem(self.Root, lv1) andrej@2355: andrej@2354: # Level 2 nodes andrej@2354: # Config Data andrej@2354: self.ConfigData = {} andrej@2354: for lv2 in ["EEPROM Size (Bytes)", "PDI Type", "Device Emulation"]: andrej@2354: self.ConfigData[lv2] = self.Tree.AppendItem(self.Level1Nodes["Config Data"], lv2) andrej@2354: # Device Identity andrej@2354: self.DeviceIdentity = {} andrej@2354: for lv2 in ["Vendor ID", "Product Code", "Revision No.", "Serial No."]: andrej@2354: self.DeviceIdentity[lv2] = self.Tree.AppendItem(self.Level1Nodes["Device Identity"], lv2) andrej@2354: # Mailbox andrej@2354: self.Mailbox = {} andrej@2354: for lv2 in ["Supported Mailbox", "Bootstrap Configuration", "Standard Configuration"]: andrej@2354: self.Mailbox[lv2] = self.Tree.AppendItem(self.Level1Nodes["Mailbox"], lv2) andrej@2355: andrej@2354: # Level 3 nodes andrej@2354: # Children of Bootstrap Configuration andrej@2354: self.BootstrapConfig = {} andrej@2354: for lv3 in ["Receive Offset", "Receive Size", "Send Offset", "Send Size"]: andrej@2354: self.BootstrapConfig[lv3] = self.Tree.AppendItem(self.Mailbox["Bootstrap Configuration"], lv3) andrej@2354: # Children of Standard Configuration andrej@2354: self.StandardConfig = {} andrej@2354: for lv3 in ["Receive Offset", "Receive Size", "Send Offset", "Send Size"]: andrej@2354: self.StandardConfig[lv3] = self.Tree.AppendItem(self.Mailbox["Standard Configuration"], lv3) andrej@2355: andrej@2354: # Expand Tree andrej@2355: for tree in [self.Root, andrej@2355: self.Level1Nodes["Config Data"], andrej@2355: self.Level1Nodes["Device Identity"], andrej@2354: self.Level1Nodes["Mailbox"], andrej@2355: self.Mailbox["Bootstrap Configuration"], andrej@2354: self.Mailbox["Standard Configuration"]]: andrej@2354: self.Tree.Expand(tree) andrej@2354: andrej@2354: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # For Hex View Panel andrej@2354: # shows EEPROM binary as hex data and characters. andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class HexView(wx.Panel): andrej@2354: def __init__(self, parent, controler): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: Reference to the parent EtherCATManagementTreebook class andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: """ andrej@2354: wx.Panel.__init__(self, parent, -1) andrej@2354: self.parent = parent andrej@2354: self.Controler = controler andrej@2355: andrej@2354: self.HexRow = 8 andrej@2354: self.HexCol = 17 andrej@2355: andrej@2375: self.HexViewSizer = {"view": wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=10), andrej@2375: "siiButton": wx.BoxSizer()} andrej@2354: self.HexViewButton = {} andrej@2354: andrej@2381: for key, evt_handler in [ andrej@2381: ("Sii Upload", self.OnButtonSiiUpload), andrej@2381: ("Sii Download", self.OnButtonSiiDownload), andrej@2381: ("Write to File", self.OnButtonWriteToBinFile), andrej@2381: ("Read from File", self.OnButtonReadFromBinFile), andrej@2381: ("XML to EEPROM Image", self.OnButtonXmlToEEPROMImg)]: andrej@2355: self.HexViewButton[key] = wx.Button(self, -1, key) andrej@2354: self.HexViewButton[key].Bind(wx.EVT_BUTTON, evt_handler) andrej@2354: self.HexViewSizer["siiButton"].Add(self.HexViewButton[key]) andrej@2354: andrej@2354: self.SiiBinary = self.Controler.CommonMethod.XmlToEeprom() andrej@2354: self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary) andrej@2354: self.SiiGrid = SiiGridTable(self, self.Controler, self.HexRow, self.HexCol) andrej@2355: self.HexViewSizer["view"].AddMany([self.HexViewSizer["siiButton"], self.SiiGrid]) andrej@2354: self.SiiGrid.CreateGrid(self.HexRow, self.HexCol) andrej@2355: self.SetSizer(self.HexViewSizer["view"]) andrej@2354: self.HexViewSizer["view"].FitInside(self.parent.parent) andrej@2354: self.parent.parent.FitInside() andrej@2354: self.SiiGrid.SetValue(self.HexCode) andrej@2354: self.SiiGrid.Update() andrej@2354: andrej@2354: def UpdateSiiGridTable(self, row, col): andrej@2354: """ andrej@2354: Destroy existing grid and recreate andrej@2354: @param row, col : Hex View grid size andrej@2355: """ andrej@2354: self.HexViewSizer["view"].Detach(self.SiiGrid) andrej@2354: self.SiiGrid.Destroy() andrej@2354: self.SiiGrid = SiiGridTable(self, self.Controler, row, col) andrej@2354: self.HexViewSizer["view"].Add(self.SiiGrid) andrej@2354: self.SiiGrid.CreateGrid(row, col) andrej@2354: self.SetSizer(self.HexViewSizer["view"]) andrej@2354: self.HexViewSizer["view"].FitInside(self.parent.parent) andrej@2354: self.parent.parent.FitInside() andrej@2354: andrej@2354: def OnButtonSiiUpload(self, event): andrej@2354: """ andrej@2354: Load EEPROM data from slave and refresh Hex View grid andrej@2354: Binded to 'Sii Upload' button. andrej@2354: @param event : wx.EVT_BUTTON object andrej@2355: """ andrej@2354: # Check whether beremiz connected or not. edouard@2643: # If this method is called cyclically, set the cyclic flag true edouard@2643: check_connect_flag = self.Controler.CommonMethod.CheckConnect(cyclic_flag = False) andrej@2354: if check_connect_flag: andrej@2354: # load from EEPROM data and parsing andrej@2354: self.SiiBinary = self.Controler.CommonMethod.LoadData() andrej@2354: self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary) andrej@2354: self.UpdateSiiGridTable(self.HexRow, self.HexCol) andrej@2354: self.SiiGrid.SetValue(self.HexCode) andrej@2354: self.SiiGrid.Update() andrej@2355: andrej@2354: def OnButtonSiiDownload(self, event): andrej@2354: """ andrej@2355: Write current EEPROM data to slave and refresh data structure kept by master andrej@2354: Binded to 'Sii Download' button. andrej@2354: @param event : wx.EVT_BUTTON object andrej@2355: """ andrej@2355: # Check whether beremiz connected or not, andrej@2355: # and whether status is "Started" or not. edouard@2643: # If this method is called cyclically, set the cyclic flag true edouard@2643: check_connect_flag = self.Controler.CommonMethod.CheckConnect(cyclic_flag = False) andrej@2354: if check_connect_flag: andrej@2406: status, _log_count = self.Controler.GetCTRoot()._connector.GetPLCstatus() andrej@2416: if status is not PlcStatus.Started: andrej@2354: self.Controler.CommonMethod.SiiWrite(self.SiiBinary) andrej@2354: self.Controler.CommonMethod.Rescan() andrej@2355: andrej@2354: def OnButtonWriteToBinFile(self, event): andrej@2355: """ andrej@2354: Save current EEPROM data to binary file through FileDialog andrej@2354: Binded to 'Write to File' button. andrej@2354: @param event : wx.EVT_BUTTON object andrej@2355: """ andrej@2355: dialog = wx.FileDialog(self, _("Save as..."), os.getcwd(), "slave0.bin", andrej@2367: _("bin files (*.bin)|*.bin|All files|*.*"), wx.SAVE | wx.OVERWRITE_PROMPT) andrej@2354: andrej@2354: if dialog.ShowModal() == wx.ID_OK: andrej@2354: filepath = dialog.GetPath() andrej@2363: binfile = open(filepath, "wb") andrej@2354: binfile.write(self.SiiBinary) andrej@2354: binfile.close() andrej@2355: andrej@2355: dialog.Destroy() andrej@2355: andrej@2354: def OnButtonReadFromBinFile(self, event): andrej@2354: """ andrej@2354: Load binary file through FileDialog andrej@2354: Binded to 'Read from File' button. andrej@2354: @param event : wx.EVT_BUTTON object andrej@2354: """ andrej@2355: dialog = wx.FileDialog(self, _("Choose a binary file"), os.getcwd(), "", edouard@3572: _("bin files (*.bin)|*.bin"), wx.FD_OPEN) andrej@2355: andrej@2354: if dialog.ShowModal() == wx.ID_OK: andrej@2354: filepath = dialog.GetPath() andrej@2355: andrej@2354: try: andrej@2354: binfile = open(filepath, "rb") andrej@2354: self.SiiBinary = binfile.read() andrej@2354: self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary) andrej@2355: self.UpdateSiiGridTable(self.HexRow, self.HexCol) andrej@2354: self.SiiGrid.SetValue(self.HexCode) andrej@2354: self.SiiGrid.Update() andrej@2354: except Exception: andrej@2423: self.Controler.CommonMethod.CreateErrorDialog(_('The file does not exist!')) andrej@2355: andrej@2354: dialog.Destroy() andrej@2355: andrej@2354: def OnButtonXmlToEEPROMImg(self, event): andrej@2354: """ andrej@2354: Create EEPROM data based XML data that current imported andrej@2354: Binded to 'XML to EEPROM' button. andrej@2354: @param event : wx.EVT_BUTTON object andrej@2354: """ andrej@2354: self.SiiBinary = self.Controler.CommonMethod.XmlToEeprom() andrej@2354: self.HexCode, self.HexRow, self.HexCol = self.Controler.CommonMethod.HexRead(self.SiiBinary) andrej@2354: self.UpdateSiiGridTable(self.HexRow, self.HexCol) andrej@2354: self.SiiGrid.SetValue(self.HexCode) andrej@2354: self.SiiGrid.Update() andrej@2354: andrej@2354: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # For Hex View grid (fill hex data) andrej@2356: # ------------------------------------------------------------------------------- andrej@2355: class SiiGridTable(wx.grid.Grid): andrej@2354: def __init__(self, parent, controler, row, col): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: Reference to the parent HexView class andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: @param row, col: Hex View grid size andrej@2354: """ andrej@2354: self.parent = parent andrej@2354: self.Controler = controler andrej@2354: self.Row = row andrej@2355: self.Col = col andrej@2355: andrej@2363: wx.grid.Grid.__init__(self, parent, -1, size=(830, 450), andrej@2367: style=wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL) andrej@2354: andrej@2354: def SetValue(self, value): andrej@2354: """ andrej@2354: Set data in the table andrej@2354: @param value: EEPROM data list of which element is 1 Byte hex data andrej@2354: """ andrej@2354: # set label name and size andrej@2354: self.SetRowLabelSize(100) andrej@2354: for col in range(self.Col): andrej@2354: if col == 16: andrej@2354: self.SetColLabelValue(16, "Text View") andrej@2437: self.SetColSize(16, (self.GetSize().x-120)*4//20) andrej@2354: else: andrej@2358: self.SetColLabelValue(col, '%s' % col) andrej@2437: self.SetColSize(col, (self.GetSize().x-120)//20) andrej@2355: andrej@2354: # set data into table andrej@2354: row = col = 0 andrej@2355: for row_idx in value: andrej@2354: col = 0 andrej@2354: self.SetRowLabelValue(row, "0x"+"{:0>4x}".format(row*(self.Col-1))) andrej@2354: for hex in row_idx: andrej@2354: self.SetCellValue(row, col, hex) andrej@2355: andrej@2355: if col == 16: andrej@2354: self.SetCellAlignment(row, col, wx.ALIGN_LEFT, wx.ALIGN_CENTER) andrej@2354: else: andrej@2354: self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTER) andrej@2355: andrej@2354: self.SetReadOnly(row, col, True) andrej@2354: col = col + 1 andrej@2354: row = row + 1 andrej@2355: andrej@2354: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # For Register Access Panel andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class RegisterAccessPanel(wx.Panel): andrej@2354: def __init__(self, parent, controler): andrej@2354: """ andrej@2383: Constructor andrej@2383: @param parent: EEPROMAccessPanel object andrej@2383: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2383: """ andrej@2354: self.parent = parent andrej@2354: self.Controler = controler andrej@2354: self.__init_data() andrej@2355: andrej@2354: wx.Panel.__init__(self, parent, -1) andrej@2355: andrej@2354: sizer = wx.FlexGridSizer(cols=1, hgap=20, rows=2, vgap=5) andrej@2354: button_sizer = wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=10) andrej@2355: andrej@2354: self.ReloadButton = wx.Button(self, -1, "Reload") andrej@2355: self.CompactViewCheckbox = wx.CheckBox(self, -1, "Compact View") andrej@2354: self.RegisterNotebook = RegisterNotebook(self, self.Controler) andrej@2355: andrej@2354: button_sizer.AddMany([self.ReloadButton, self.CompactViewCheckbox]) andrej@2354: sizer.AddMany([button_sizer, self.RegisterNotebook]) andrej@2354: self.SetSizer(sizer) andrej@2355: andrej@2354: self.ReloadButton.Bind(wx.EVT_BUTTON, self.OnReloadButton) andrej@2354: self.CompactViewCheckbox.Bind(wx.EVT_CHECKBOX, self.ToggleCompactViewCheckbox) andrej@2355: andrej@2354: for index in range(4): andrej@2354: self.RegisterNotebook.RegPage[index].MainTable.CreateGrid(self.MainRow[index], self.MainCol) andrej@2354: self.RegisterNotebook.RegPage[index].MainTable.SetValue(self, 0, index*512, (index+1)*512) andrej@2355: andrej@2354: # data default setting andrej@2355: if self.Controler.CommonMethod.RegData == "": andrej@2355: self.CompactViewCheckbox.Disable() andrej@2355: for index in range(4): andrej@2354: self.RegisterNotebook.RegPage[index].MainTable.SetValue(self, 0, index*512, (index+1)*512) andrej@2361: else: # If data was saved, andrej@2354: self.BasicSetData() andrej@2354: self.ParseData() andrej@2354: for index in range(4): andrej@2354: self.RegisterNotebook.RegPage[index].MainTable.SetValue(self, self.RegMonitorData, index*512, (index+1)*512) andrej@2354: andrej@2354: def __init_data(self): andrej@2354: """ andrej@2383: Declare initial data. andrej@2383: """ andrej@2354: # flag for compact view andrej@2354: self.CompactFlag = False andrej@2355: edouard@2643: # main grid rows and cols andrej@2354: self.MainRow = [512, 512, 512, 512] andrej@2354: self.MainCol = 4 andrej@2355: andrej@2354: # main grids' data range andrej@2354: self.PageRange = [] andrej@2354: for index in range(4): andrej@2354: self.PageRange.append([512*index, 512*(index+1)]) andrej@2355: andrej@2354: # Previous value of register data for register description configuration andrej@2354: self.PreRegSpec = {"ESCType": "", andrej@2354: "FMMUNumber": "", andrej@2354: "SMNumber": "", andrej@2354: "PDIType": ""} andrej@2355: andrej@2354: def LoadData(self): andrej@2354: """ andrej@2354: Get data from the register. andrej@2354: """ andrej@2354: self.Controler.CommonMethod.RegData = "" andrej@2356: # ethercat reg_read andrej@2356: # ex : ethercat reg_read -p 0 0x0000 0x0001 andrej@2356: # return value : 0x11 andrej@2354: for index in range(4): andrej@2354: self.Controler.CommonMethod.RegData = self.Controler.CommonMethod.RegData + " " + self.Controler.CommonMethod.RegRead("0x"+"{:0>4x}".format(index*1024), "0x0400") andrej@2355: andrej@2355: # store previous value andrej@2354: # (ESC type, port number of FMMU, port number of SM, and PDI type)) andrej@2363: for reg_spec in ["ESCType", "FMMUNumber", "SMNumber", "PDIType"]: andrej@2354: self.PreRegSpec[reg_spec] = self.Controler.CommonMethod.CrtRegSpec[reg_spec] andrej@2355: andrej@2355: # update registers' description andrej@2354: # (ESC type, port number of FMMU, port number of SM, and PDI type) andrej@2354: for reg_spec, address in [("ESCType", "0x0000"), andrej@2354: ("FMMUNumber", "0x0004"), andrej@2354: ("SMNumber", "0x0005"), andrej@2354: ("PDIType", "0x0140")]: andrej@2354: self.Controler.CommonMethod.CrtRegSpec[reg_spec] = self.Controler.CommonMethod.RegRead(address, "0x0001") andrej@2355: andrej@2354: # Enable compactView checkbox andrej@2354: self.CompactViewCheckbox.Enable() andrej@2355: andrej@2354: def BasicSetData(self): andrej@2354: """ andrej@2355: Get and save the description of registers. andrej@2354: It's done by parsing register_information.xml. andrej@2354: """ andrej@2354: # parse the above register's value andrej@2354: # If the value is 0x12, the result is 12 andrej@2354: self.ESCType = self.Controler.CommonMethod.CrtRegSpec["ESCType"].split('x')[1] andrej@2354: self.PDIType = self.Controler.CommonMethod.CrtRegSpec["PDIType"].split('x')[1] andrej@2354: # If the value is 0x12, the result is 18 (It's converted to decimal value) andrej@2354: self.FMMUNumber = int(self.Controler.CommonMethod.CrtRegSpec["FMMUNumber"], 16) andrej@2354: self.SMNumber = int(self.Controler.CommonMethod.CrtRegSpec["SMNumber"], 16) andrej@2355: andrej@2354: # initialize description dictionary of register main table and register sub table. andrej@2354: self.RegisterDescriptionDict = {} andrej@2354: self.RegisterSubGridDict = {} andrej@2355: andrej@2354: # ./EthercatMaster/register_information.xml contains register description. andrej@2354: if wx.Platform == '__WXMSW__': andrej@2354: reg_info_file = open("../../EthercatMaster/register_information.xml", 'r') andrej@2354: else: andrej@2354: reg_info_file = open("./EthercatMaster/register_information.xml", 'r') andrej@2354: reg_info_tree = minidom.parse(reg_info_file) andrej@2354: reg_info_file.close() andrej@2355: andrej@2354: # parse register description andrej@2354: for register_info in reg_info_tree.childNodes: andrej@2354: for register in register_info.childNodes: andrej@2354: if register.nodeType == reg_info_tree.ELEMENT_NODE and register.nodeName == "Register": andrej@2354: # If it depends on the property(ESC type, PDI type, FMMU number, SM number) andrej@2354: for property, type, value in [("esc", "type", self.ESCType), andrej@2354: ("pdi", "type", self.PDIType), andrej@2354: ("fmmu", "number", self.FMMUNumber), andrej@2354: ("sm", "number", self.SMNumber)]: kinsamanka@3750: if property in list(register.attributes.keys()): andrej@2354: if type == "type": andrej@2354: if register.attributes[property].value == value: andrej@2354: self.GetRegisterInfo(reg_info_tree, register) andrej@2354: break andrej@2361: else: # type == "number" andrej@2354: if register.attributes[property].value < value: andrej@2354: self.GetRegisterInfo(reg_info_tree, register) andrej@2354: break andrej@2354: else: andrej@2354: self.GetRegisterInfo(reg_info_tree, register) andrej@2354: break andrej@2355: andrej@2354: def GetRegisterInfo(self, reg_info_tree, register): andrej@2354: """ andrej@2354: Save the register's description into the dictionary. andrej@2354: reg_info_tree is based on the register_information.xml. andrej@2354: @param reg_info_tree: XML tree andrej@2354: @param register: register which you want to get the description andrej@2354: """ andrej@2354: # temporary variables for register main table idescription dictionary andrej@2354: reg_index = "" andrej@2354: reg_main_description = "" andrej@2355: andrej@2354: for data in register.childNodes: andrej@2354: if data.nodeType == reg_info_tree.ELEMENT_NODE and data.nodeName == "Index": andrej@2354: for index in data.childNodes: andrej@2354: reg_index = index.nodeValue andrej@2354: if data.nodeType == reg_info_tree.ELEMENT_NODE and data.nodeName == "Description": andrej@2354: for description in data.childNodes: andrej@2354: reg_main_description = description.nodeValue andrej@2355: andrej@2355: # Add description for register main table andrej@2417: if reg_index != "" and reg_main_description != "": andrej@2354: self.RegisterDescriptionDict[reg_index] = reg_main_description andrej@2355: andrej@2354: if data.nodeType == reg_info_tree.ELEMENT_NODE and data.nodeName == "Details": andrej@2354: # declare register sub table description dictionary about this index andrej@2354: self.RegisterSubGridDict[reg_index] = [] andrej@2355: andrej@2354: for detail in data.childNodes: andrej@2354: if detail.nodeType == reg_info_tree.ELEMENT_NODE and detail.nodeName == "Detail": andrej@2354: # If it depends on the property(ESC type, PDI type, FMMU number, SM number) andrej@2354: for property, type, value in [("esc", "type", self.ESCType), andrej@2354: ("pdi", "type", self.PDIType), andrej@2354: ("fmmu", "number", self.FMMUNumber), andrej@2354: ("sm", "number", self.SMNumber)]: kinsamanka@3750: if property in list(detail.attributes.keys()): andrej@2354: if type == "type": andrej@2354: if detail.attributes[property].value == value: andrej@2354: self.GetRegisterDetailInfo(reg_info_tree, reg_index, detail) andrej@2354: break andrej@2361: else: # type == "number" andrej@2354: if detail.attributes[property].value < value: andrej@2354: self.GetRegisterDetailInfo(reg_info_tree, reg_index, detail) andrej@2354: break andrej@2354: else: andrej@2354: self.GetRegisterDetailInfo(reg_info_tree, reg_index, detail) andrej@2354: break andrej@2355: andrej@2354: def GetRegisterDetailInfo(self, reg_info_tree, reg_index, detail): andrej@2354: """ andrej@2354: Get the resgister's detailed description(for sub table) from the reg_info_tree. andrej@2354: @param reg_info_tree: XML tree (register_information.xml) andrej@2354: @param reg_index: index of the register andrej@2354: @param detail: description of the register andrej@2354: """ andrej@2355: # temporary variables for register sub table description dictionary andrej@2355: # - It is initialized in every sub description andrej@2354: reg_bit_range = "" andrej@2354: reg_sub_description = "" andrej@2354: reg_enum_dictionary = {} andrej@2355: andrej@2354: for detail_data in detail.childNodes: andrej@2355: if detail_data.nodeType == reg_info_tree.ELEMENT_NODE and detail_data.nodeName == "Range": andrej@2354: for range in detail_data.childNodes: andrej@2354: reg_bit_range = range.nodeValue andrej@2354: if detail_data.nodeType == reg_info_tree.ELEMENT_NODE and detail_data.nodeName == "Description": andrej@2354: for description in detail_data.childNodes: andrej@2354: reg_sub_description = description.nodeValue andrej@2355: andrej@2354: if detail_data.nodeType == reg_info_tree.ELEMENT_NODE and detail_data.nodeName == "Enum": andrej@2354: for enum in detail_data.childNodes: andrej@2354: if enum.nodeType == reg_info_tree.ELEMENT_NODE and enum.nodeName == "item": andrej@2355: andrej@2355: # temporary variables for a description of each value andrej@2355: # For example, if the bit is 1, it is 'enabled'('On', 'True', etc.), andrej@2355: # otherwise 'disabled'('Off', 'False', etc.). andrej@2354: reg_sub_value = "" andrej@2354: reg_sub_value_description = "" andrej@2355: andrej@2354: for item in enum.childNodes: andrej@2354: if item.nodeType == reg_info_tree.ELEMENT_NODE and item.nodeName == "value": andrej@2354: for value in item.childNodes: andrej@2354: reg_sub_value = value.nodeValue andrej@2354: if item.nodeType == reg_info_tree.ELEMENT_NODE and item.nodeName == "Description": andrej@2354: for description in item.childNodes: andrej@2354: reg_sub_value_description = description.nodeValue andrej@2355: andrej@2354: # Add a description of each value to register enum dictionary andrej@2417: if reg_sub_value != "" and reg_sub_value_description != "": andrej@2354: reg_enum_dictionary[reg_sub_value] = reg_sub_value_description andrej@2355: andrej@2354: # add a description to register sub table description dictionary andrej@2417: if reg_bit_range != "" and reg_sub_description != "": andrej@2355: self.RegisterSubGridDict[reg_index].append([reg_bit_range, andrej@2380: reg_sub_description, andrej@2380: reg_enum_dictionary]) andrej@2355: andrej@2354: def ParseData(self): andrej@2354: """ andrej@2354: Transform the data into dec, hex, string, and description andrej@2354: """ andrej@2354: row_data = [] andrej@2354: self.RegMonitorData = [] andrej@2354: reg_word = "" andrej@2355: andrej@2354: reg_data = self.Controler.CommonMethod.RegData.split() andrej@2355: andrej@2354: # loop for register(0x0000:0x0fff) andrej@2354: for address in range(0x1000): andrej@2355: # arrange 2 Bytes of register data andrej@2354: reg_word = reg_data[address].split('x')[1] + reg_word andrej@2358: if (address % 2) == 1: andrej@2354: # append address andrej@2354: hex_address = "{:0>4x}".format(address-1) andrej@2354: row_data.append(hex_address) andrej@2355: andrej@2354: # append description andrej@2377: if hex_address in self.RegisterDescriptionDict: andrej@2354: row_data.append(self.RegisterDescriptionDict[hex_address]) andrej@2354: else: andrej@2354: row_data.append("") andrej@2355: andrej@2354: # append Decimal value andrej@2354: row_data.append(str(int(reg_word, 16))) andrej@2355: andrej@2354: # append Hex value andrej@2354: row_data.append('0x'+reg_word) andrej@2355: andrej@2354: # append ASCII value andrej@2354: char_data = "" andrej@2354: for iter in range(2): andrej@2365: if int(reg_word[iter*2:iter*2+2], 16) >= 32 and int(reg_word[iter*2:iter*2+2], 16) <= 126: andrej@2354: char_data = char_data + chr(int(reg_word[iter*2:iter*2+2], 16)) andrej@2354: else: andrej@2354: char_data = char_data + "." andrej@2354: row_data.append(char_data) andrej@2355: andrej@2354: self.RegMonitorData.append(row_data) andrej@2361: reg_word = "" # initialize regWord andrej@2354: row_data = [] andrej@2355: andrej@2354: def OnReloadButton(self, event): andrej@2354: """ andrej@2354: Handle the click event of the 'Reload' button. andrej@2354: Get the data from registers again, and update the table. andrej@2354: @param event: wx.EVT_BUTTON object andrej@2354: """ andrej@2354: # Check whether beremiz connected or not. edouard@2643: # If this method is called cyclically, set the cyclic flag true edouard@2643: check_connect_flag = self.Controler.CommonMethod.CheckConnect(cyclic_flag = False) andrej@2354: if check_connect_flag: andrej@2354: self.LoadData() andrej@2354: self.BasicSetData() andrej@2354: self.ParseData() andrej@2354: # set data into UI andrej@2354: if self.CompactFlag: andrej@2354: self.ToggleCompactViewCheckbox(True) andrej@2375: else: andrej@2354: for index in range(4): andrej@2355: self.RegisterNotebook.RegPage[index].UpdateMainTable(self.MainRow[index], self.MainCol, andrej@2355: self.PageRange[index][0], self.PageRange[index][1], andrej@2354: self.RegMonitorData) andrej@2354: andrej@2354: def ToggleCompactViewCheckbox(self, event): andrej@2354: """ andrej@2354: Handles the event of the 'Compact view' check box. andrej@2354: If it's checked, show only the registers that have a description. andrej@2354: If not, show all the registers. andrej@2354: @param event: wx.EVT_CHECKBOX object andrej@2354: """ andrej@2355: andrej@2354: # If "Compact View" Checkbox is True andrej@2385: # 'event' is argument of this method or event of checkbox. andrej@2374: if event is True or event.GetEventObject().GetValue(): andrej@2354: self.CompactFlag = True andrej@2355: andrej@2354: reg_compact_data = [] andrej@2354: page_row = [0, 0, 0, 0] andrej@2354: for index in range(4): andrej@2354: self.PageRange[index] = [0, 0] andrej@2354: andrej@2354: for reg_row_data in self.RegMonitorData: andrej@2417: if reg_row_data[1] != "": andrej@2354: # data structure for "compact view" andrej@2354: reg_compact_data.append(reg_row_data) andrej@2354: # count for each register notebooks' row andrej@2354: # It compare with register's address. andrej@2354: for index in range(4): andrej@2354: if int('0x'+reg_row_data[0], 16) < (index+1)*1024: andrej@2354: page_row[index] += 1 andrej@2354: break andrej@2354: andrej@2354: # Setting tables' rows and cols, range for compact view andrej@2354: for index in range(4): andrej@2354: self.MainRow[index] = page_row[index] andrej@2354: self.PageRange[index][1] = page_row[index] andrej@2354: for iter in range(index): andrej@2354: self.PageRange[index][0] += page_row[iter] andrej@2355: self.PageRange[index][1] += page_row[iter] andrej@2355: andrej@2354: # Update table andrej@2354: for index in range(4): andrej@2380: self.RegisterNotebook.RegPage[index].UpdateMainTable( andrej@2380: self.MainRow[index], andrej@2380: self.MainCol, andrej@2380: self.PageRange[index][0], andrej@2380: self.PageRange[index][1], andrej@2380: reg_compact_data) andrej@2355: andrej@2355: # Compact View Checkbox is False andrej@2354: else: andrej@2354: self.CompactFlag = False andrej@2354: # Setting original rows, cols and range andrej@2354: self.MainRow = [512, 512, 512, 512] andrej@2354: self.PageRange = [] andrej@2355: andrej@2354: for index in range(4): andrej@2354: self.PageRange.append([512*index, 512*(index+1)]) andrej@2355: andrej@2355: # Update table andrej@2354: for index in range(4): andrej@2380: self.RegisterNotebook.RegPage[index].UpdateMainTable( andrej@2380: self.MainRow[index], andrej@2380: self.MainCol, andrej@2380: self.PageRange[index][0], andrej@2380: self.PageRange[index][1], andrej@2380: self.RegMonitorData) andrej@2355: andrej@2354: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # For Register Access Notebook (divide index range) andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class RegisterNotebook(wx.Notebook): andrej@2354: def __init__(self, parent, controler): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: RegisterAccessPanel object andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: """ andrej@2366: wx.Notebook.__init__(self, parent, id=-1) andrej@2355: andrej@2354: self.parent = parent andrej@2354: self.Controler = controler andrej@2355: andrej@2354: # Initialize pages andrej@2354: self.RegPage = [] andrej@2406: pages = 4 andrej@2406: for dummy in range(pages): andrej@2354: self.RegPage.append(None) andrej@2355: andrej@2406: for index in range(pages): andrej@2355: self.RegPage[index] = RegisterNotebookPanel(self, self.Controler, andrej@2381: parent.MainRow[index], parent.MainCol) andrej@2355: self.AddPage(self.RegPage[index], andrej@2354: "0x"+"{:0>4x}".format(index*1024)+" - 0x"+"{:0>4x}".format((index+1)*1024-1)) andrej@2355: andrej@2354: andrej@2356: # ------------------------------------------------------------------------------- andrej@2355: # For Register Access Notebook Panel andrej@2354: # (Main UI : including main, sub table) andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class RegisterNotebookPanel(wx.Panel): andrej@2354: def __init__(self, parent, controler, row, col): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: RegisterAccessPanel object andrej@2354: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: @param row, col: size of the table andrej@2383: """ andrej@2354: wx.Panel.__init__(self, parent, -1) andrej@2355: andrej@2354: self.parent = parent andrej@2354: self.Controler = controler andrej@2354: self.Row = row andrej@2354: self.Col = col andrej@2354: sub_row = 0 andrej@2354: sub_col = 4 andrej@2355: andrej@2354: self.Sizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=30) andrej@2355: andrej@2354: self.MainTable = RegisterMainTable(self, self.Row, self.Col, self.Controler) andrej@2354: self.SubTable = RegisterSubTable(self, sub_row, sub_col) andrej@2355: andrej@2354: self.SubTable.CreateGrid(sub_row, sub_col) andrej@2354: self.SubTable.SetValue(self, []) andrej@2355: andrej@2354: self.Sizer.AddMany([self.MainTable, self.SubTable]) andrej@2355: andrej@2354: self.SetSizer(self.Sizer) andrej@2355: andrej@2354: def UpdateMainTable(self, row, col, low_index, high_index, data): andrej@2354: """ andrej@2354: Updates main table. andrej@2354: It's done by deleting the main table and creating it again. andrej@2354: @param row, col: size of the table andrej@2354: @param low_index: the lowest index of the page andrej@2354: @param high_index: the highest index of the page andrej@2354: @param data: data andrej@2383: """ andrej@2354: self.MainTable.Destroy() andrej@2354: self.MainTable = RegisterMainTable(self, row, col, self.Controler) andrej@2354: self.Sizer.Detach(self.SubTable) andrej@2354: self.Sizer.AddMany([self.MainTable, self.SubTable]) andrej@2354: self.SetSizer(self.Sizer) andrej@2354: self.MainTable.CreateGrid(row, col) andrej@2354: self.MainTable.SetValue(self, data, low_index, high_index) andrej@2354: self.MainTable.Update() andrej@2354: andrej@2354: def UpdateSubTable(self, row, col, data): andrej@2354: """ andrej@2354: Updates sub table. andrej@2354: It's done by deleting the sub table and creating it again. andrej@2354: @param row, col: size of the table andrej@2354: @param data: data andrej@2383: """ andrej@2354: self.SubTable.Destroy() andrej@2354: self.SubTable = RegisterSubTable(self, row, col) andrej@2354: self.Sizer.Detach(self.MainTable) andrej@2354: self.Sizer.AddMany([self.MainTable, self.SubTable]) andrej@2354: self.Sizer.Layout() andrej@2354: self.SetSizer(self.Sizer) andrej@2354: self.SubTable.CreateGrid(row, col) andrej@2354: self.SubTable.SetValue(self, data) andrej@2354: self.SubTable.Update() andrej@2355: andrej@2354: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # For Register Access Notebook Panel (Main Table) andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class RegisterMainTable(wx.grid.Grid): andrej@2355: def __init__(self, parent, row, col, controler): andrej@2354: """ andrej@2383: Constructor andrej@2383: @param parent: RegisterNotebook object andrej@2383: @param row, col: size of the table andrej@2383: @param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2383: """ andrej@2354: self.parent = parent andrej@2354: self.Data = {} andrej@2354: self.Row = row andrej@2354: self.Col = col andrej@2354: self.Controler = controler andrej@2354: self.RegisterAccessPanel = self.parent.parent.parent andrej@2355: andrej@2363: wx.grid.Grid.__init__(self, parent, -1, size=(820, 300), andrej@2367: style=wx.EXPAND | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL) andrej@2355: andrej@2389: for evt, mapping_method in [(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnSelectCell), andrej@2389: (wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnSelectCell), andrej@2389: (wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.OnRegModifyDialog)]: andrej@2354: self.Bind(evt, mapping_method) andrej@2355: andrej@2355: def SetValue(self, parent, reg_monitor_data, low_index, high_index): andrej@2354: """ andrej@2383: Set the RegMonitorData into the main table. andrej@2383: @param parent: RegisterNotebook object andrej@2383: @param reg_monitor_data: data andrej@2383: @param low_index: the lowest index of the page andrej@2383: @param high_index: the highest index of the page andrej@2383: """ andrej@2354: self.RegMonitorData = reg_monitor_data andrej@2355: andrej@2354: # set label name and size andrej@2355: register_maintable_label = [(0, "Description"), (1, "Dec"), andrej@2354: (2, "Hex"), (3, "Char")] andrej@2355: andrej@2354: for (index, label) in register_maintable_label: andrej@2354: self.SetColLabelValue(index, label) andrej@2355: andrej@2354: self.SetColSize(0, 200) andrej@2355: andrej@2354: # if reg_monitor_data is 0, it is initialization of register access. andrej@2354: if reg_monitor_data == 0: andrej@2354: return 0 andrej@2355: andrej@2355: # set data into UI andrej@2354: row = col = 0 andrej@2354: for row_index in reg_monitor_data[low_index:high_index]: andrej@2354: col = 0 andrej@2354: self.SetRowLabelValue(row, row_index[0]) andrej@2354: for data_index in range(4): andrej@2354: self.SetCellValue(row, col, row_index[data_index+1]) andrej@2354: self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTER) andrej@2354: self.SetReadOnly(row, col, True) andrej@2354: col = col + 1 andrej@2354: row = row + 1 andrej@2355: andrej@2355: def OnSelectCell(self, event): andrej@2354: """ andrej@2383: Handles the event of the cell of the main table. andrej@2389: @param event: wx.grid object (left click) andrej@2383: """ andrej@2354: # if reg_monitor_data is 0, it is initialization of register access. andrej@2354: if self.RegMonitorData == 0: andrej@2354: event.Skip() andrej@2354: return 0 andrej@2355: andrej@2354: sub_row = 0 andrej@2354: sub_col = 4 andrej@2355: andrej@2354: address = self.GetRowLabelValue(event.GetRow()) andrej@2355: andrej@2354: reg_sub_grid_data = [] andrej@2355: kinsamanka@3750: BIT_RANGE, NAME, DESCRIPTIONS = list(range(3)) andrej@2355: andrej@2355: # Check if this register's detail description is exist or not, andrej@2354: # and create data structure for the detail description table ; sub grid andrej@2354: if address in self.RegisterAccessPanel.RegisterSubGridDict: andrej@2354: for element in self.RegisterAccessPanel.RegisterSubGridDict[address]: andrej@2365: row_data = [] andrej@2354: row_data.append(element[BIT_RANGE]) andrej@2354: row_data.append(element[NAME]) andrej@2354: bin_data = "{:0>16b}".format(int(self.GetCellValue(event.GetRow(), 1))) andrej@2354: value_range = element[BIT_RANGE].split('-') andrej@2354: value = (bin_data[8:16][::-1]+bin_data[0:8][::-1])[int(value_range[0]):(int(value_range[-1])+1)][::-1] andrej@2354: row_data.append(str(int(('0b'+str(value)), 2))) andrej@2354: if value in element[DESCRIPTIONS]: andrej@2354: row_data.append(element[DESCRIPTIONS][value]) andrej@2354: else: andrej@2354: row_data.append('') andrej@2354: reg_sub_grid_data.append(row_data) andrej@2354: sub_row = sub_row + 1 andrej@2355: andrej@2354: self.parent.UpdateSubTable(sub_row, sub_col, reg_sub_grid_data) andrej@2354: # event.Skip() updates UI of selecting cell andrej@2354: event.Skip() andrej@2355: andrej@2354: def OnRegModifyDialog(self, event): andrej@2354: """ andrej@2354: Handle the event of the cell of the main table. andrej@2354: Display the window where the user modifies the value of the cell. andrej@2389: @param event: wx.grid object (double click) andrej@2383: """ andrej@2354: # user can enter a value in case that user double-clicked 'Dec' or 'Hex' value. andrej@2354: if event.GetCol() == 1 or event.GetCol() == 2: andrej@2423: dlg = wx.TextEntryDialog(self, _("Enter hex(0xnnnn) or dec(n) value"), andrej@2423: _("Register Modify Dialog"), style=wx.OK | wx.CANCEL) andrej@2355: andrej@2354: # Setting value in initial dialog value andrej@2354: start_value = self.GetCellValue(event.GetRow(), event.GetCol()) andrej@2354: dlg.SetValue(start_value) andrej@2355: andrej@2354: if dlg.ShowModal() == wx.ID_OK: andrej@2354: try: andrej@2355: # It int(input) success, this input is dev or hex value. andrej@2354: # Otherwise, it's error, so it goes except. andrej@2354: int(dlg.GetValue(), 0) andrej@2354: andrej@2354: # reg_write andrej@2354: # ex) ethercat reg_write -p 0 -t uint16 0x0000 0x0000 andrej@2354: return_val = self.Controler.CommonMethod.RegWrite('0x'+self.GetRowLabelValue(event.GetRow()), dlg.GetValue()) andrej@2354: andrej@2365: if len(return_val) == 0: andrej@2354: # set dec andrej@2355: self.SetCellValue(event.GetRow(), 1, str(int(dlg.GetValue(), 0))) andrej@2354: # set hex andrej@2354: hex_data = '0x'+"{:0>4x}".format(int(dlg.GetValue(), 0)) andrej@2354: self.SetCellValue(event.GetRow(), 2, hex_data) andrej@2354: # set char andrej@2354: char_data = "" andrej@2354: # If hex_data is been able to convert to ascii code, append ascii code. andrej@2354: for iter in range(2): andrej@2365: if int(hex_data[(iter+1)*2:(iter+2)*2], 16) >= 32 and int(hex_data[(iter+1)*2:(iter+2)*2], 16) <= 126: andrej@2354: char_data = char_data + chr(int(hex_data[(iter+1)*2:(iter+2)*2], 16)) andrej@2354: else: andrej@2354: char_data = char_data + "." andrej@2355: andrej@2355: self.SetCellValue(event.GetRow(), 3, char_data) andrej@2355: andrej@2354: else: andrej@2423: self.Controler.CommonMethod.CreateErrorDialog(_('You can\'t modify it. This register is read-only or it\'s not connected.')) andrej@2355: andrej@2354: except ValueError: andrej@2423: self.Controler.CommonMethod.CreateErrorDialog(_('You entered wrong value. You can enter dec or hex value only.')) andrej@2355: andrej@2355: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # For Register Access Notebook Panel (Sub Table) andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class RegisterSubTable(wx.grid.Grid): andrej@2354: def __init__(self, parent, row, col): andrej@2354: """ andrej@2383: Constructor andrej@2383: @param parent: RegisterNotebook object andrej@2383: @param row, col: size of the table andrej@2383: """ andrej@2354: self.parent = parent andrej@2354: self.Data = {} andrej@2354: self.Row = row andrej@2354: self.Col = col andrej@2354: andrej@2363: wx.grid.Grid.__init__(self, parent, -1, size=(820, 150), andrej@2367: style=wx.EXPAND | wx.ALIGN_CENTRE_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL) andrej@2354: andrej@2354: def SetValue(self, parent, data): andrej@2354: """ andrej@2383: Set the data into the subtable. andrej@2383: @param parent: RegisterNotebook object andrej@2383: @param data: data andrej@2383: """ andrej@2354: # lset label name and size andrej@2355: Register_SubTable_Label = [(0, "Bits"), (1, "Name"), andrej@2380: (2, "Value"), (3, "Enum")] andrej@2355: andrej@2354: for (index, label) in Register_SubTable_Label: andrej@2354: self.SetColLabelValue(index, label) andrej@2355: andrej@2354: self.SetColSize(1, 200) andrej@2354: self.SetColSize(3, 200) andrej@2355: andrej@2354: # set data into table andrej@2354: row = col = 0 andrej@2355: for rowData in data: andrej@2355: col = 0 andrej@2354: for element in rowData: andrej@2354: self.SetCellValue(row, col, element) andrej@2354: self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTER) andrej@2354: self.SetReadOnly(row, col, True) andrej@2354: col = col + 1 andrej@2354: row = row + 1 andrej@2355: andrej@2354: andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: # For Master State Panel andrej@2356: # ------------------------------------------------------------------------------- andrej@2354: class MasterStatePanelClass(wx.Panel): andrej@2354: def __init__(self, parent, controler): andrej@2354: """ andrej@2354: Constructor andrej@2354: @param parent: wx.ScrollWindow object andrej@2354: @Param controler: _EthercatSlaveCTN class in EthercatSlave.py andrej@2354: """ edouard@2643: wx.Panel.__init__(self, parent) andrej@2354: self.Controler = controler andrej@2354: self.parent = parent andrej@2354: self.StaticBox = {} andrej@2354: self.StaticText = {} andrej@2354: self.TextCtrl = {} andrej@2355: andrej@2354: # ----------------------- Main Sizer and Update Button -------------------------------------------- andrej@2375: self.MasterStateSizer = {"main": wx.BoxSizer(wx.VERTICAL)} andrej@2354: for key, attr in [ edouard@2643: ("innerTop", [2, 10, 1, 10]), edouard@2643: ("innerMiddle", [1, 10, 1, 10]), edouard@2643: ("innerBottom", [1, 10, 1, 10]), edouard@2643: ("innerMasterState", [2, 10, 3, 10]), edouard@2643: ("innerDeviceInfo", [4, 10, 3, 10]), edouard@2643: ("innerFrameInfo", [4, 10, 5, 10]), edouard@2643: ("innerSlaveInfo", [1, 10, 2, 10])]: andrej@2354: self.MasterStateSizer[key] = wx.FlexGridSizer(cols=attr[0], hgap=attr[1], rows=attr[2], vgap=attr[3]) andrej@2354: edouard@2643: self.MSUpdateButton = wx.Button(self, label=_("Update")) edouard@2643: self.MSUpdateButton.Bind(wx.EVT_BUTTON, self.OnMSUpdateButtonClick) edouard@2643: self.SIUpdateButton = wx.Button(self, label=_("Update")) edouard@2643: self.SIUpdateButton.Bind(wx.EVT_BUTTON, self.OnSIUpdateButtonClick) edouard@2643: edouard@2643: for key, label in [ edouard@2643: ("masterState", "EtherCAT Master State"), edouard@2643: ("deviceInfo", "Ethernet Network Card Information"), edouard@2643: ("frameInfo", "Network Frame Information"), edouard@2643: ("slaveInfo", "Slave Information")]: andrej@2354: self.StaticBox[key] = wx.StaticBox(self, label=_(label)) andrej@2354: self.MasterStateSizer[key] = wx.StaticBoxSizer(self.StaticBox[key]) andrej@2355: andrej@2354: # ----------------------- Master State ----------------------------------------------------------- andrej@2354: for key, label in [ andrej@2379: ('Phase', 'Phase:'), andrej@2379: ('Active', 'Active:'), andrej@2379: ('Slaves', 'Slave Count:')]: andrej@2354: self.StaticText[key] = wx.StaticText(self, label=_(label)) andrej@2354: self.TextCtrl[key] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY) andrej@2355: self.MasterStateSizer['innerMasterState'].AddMany([self.StaticText[key], self.TextCtrl[key]]) andrej@2355: edouard@3303: self.MasterStateSizer['masterState'].Add(self.MasterStateSizer['innerMasterState']) andrej@2355: andrej@2355: # ----------------------- Ethernet Network Card Information --------------------------------------- andrej@2354: for key, label in [ andrej@2379: ('Main', 'MAC Address:'), andrej@2379: ('Link', 'Link State:'), andrej@2379: ('Tx frames', 'Tx Frames:'), andrej@2379: ('Rx frames', 'Rx Frames:'), andrej@2379: ('Lost frames', 'Lost Frames:')]: andrej@2354: self.StaticText[key] = wx.StaticText(self, label=_(label)) andrej@2354: self.TextCtrl[key] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY) andrej@2354: self.MasterStateSizer['innerDeviceInfo'].AddMany([self.StaticText[key], self.TextCtrl[key]]) andrej@2355: edouard@3303: self.MasterStateSizer['deviceInfo'].Add(self.MasterStateSizer['innerDeviceInfo']) andrej@2355: andrej@2354: # ----------------------- Network Frame Information ----------------------------------------------- andrej@2354: for key, label in [ edouard@2643: ("Tx frame rate [1/s]", "Tx Frame Rate [1/s]:"), edouard@2643: ("Tx rate [KByte/s]", "Tx Rate [KByte/s]:"), edouard@2643: ("Rx frame rate [1/s]", "Rx Frame Rate [1/s]:"), edouard@2643: ("Rx rate [KByte/s]", "Rx Rate [KByte/s]:"), edouard@2643: ("Loss rate [1/s]", "Loss Rate [1/s]:"), edouard@2643: ("Frame loss [%]", "Frame Loss [%]:")]: andrej@2354: self.StaticText[key] = wx.StaticText(self, label=_(label)) andrej@2354: self.MasterStateSizer['innerFrameInfo'].Add(self.StaticText[key]) andrej@2355: self.TextCtrl[key] = {} andrej@2355: for index in ['0', '1', '2']: andrej@2354: self.TextCtrl[key][index] = wx.TextCtrl(self, size=wx.Size(130, 24), style=wx.TE_READONLY) andrej@2354: self.MasterStateSizer['innerFrameInfo'].Add(self.TextCtrl[key][index]) andrej@2355: edouard@3303: self.MasterStateSizer['frameInfo'].Add(self.MasterStateSizer['innerFrameInfo']) andrej@2355: edouard@2643: # ------------------------------- Slave Information ----------------------------------------------- edouard@2643: self.SITreeListCtrl = SITreeListCtrl(self, self.Controler) edouard@2643: self.MasterStateSizer["innerSlaveInfo"].AddMany([self.SIUpdateButton, edouard@2643: self.SITreeListCtrl]) edouard@3303: self.MasterStateSizer["slaveInfo"].Add( edouard@2643: self.MasterStateSizer["innerSlaveInfo"]) edouard@2643: andrej@2354: # --------------------------------- Main Sizer ---------------------------------------------------- edouard@2643: self.MasterStateSizer["main"].Add(self.MSUpdateButton) andrej@2354: for key, sub, in [ edouard@2643: ("innerTop", [ edouard@2643: "masterState", "deviceInfo"]), edouard@2643: ("innerMiddle", [ edouard@2643: "frameInfo"]), edouard@2643: ("innerBottom", [ edouard@2643: "slaveInfo"]), edouard@2643: ("main", [ edouard@2643: "innerTop", "innerMiddle", "innerBottom"])]: andrej@2354: for key2 in sub: edouard@3303: self.MasterStateSizer[key].Add(self.MasterStateSizer[key2]) andrej@2354: edouard@2643: self.SetSizer(self.MasterStateSizer["main"]) edouard@2643: edouard@2643: def OnMSUpdateButtonClick(self, event): andrej@2354: """ andrej@2354: Handle the event of the 'Update' button. andrej@2354: Update the data of the master state. andrej@2354: @param event: wx.EVT_BUTTON object andrej@2354: """ andrej@2354: if self.Controler.GetCTRoot()._connector is not None: andrej@2354: self.MasterState = self.Controler.CommonMethod.GetMasterState() andrej@2354: # Update each TextCtrl andrej@2354: if self.MasterState: andrej@2354: for key in self.TextCtrl: andrej@2354: if isinstance(self.TextCtrl[key], dict): andrej@2354: for index in self.TextCtrl[key]: andrej@2354: self.TextCtrl[key][index].SetValue(self.MasterState[key][int(index)]) andrej@2354: else: andrej@2354: self.TextCtrl[key].SetValue(self.MasterState[key][0]) andrej@2375: else: andrej@2423: self.Controler.CommonMethod.CreateErrorDialog(_('PLC not connected!')) edouard@2643: edouard@2643: def OnSIUpdateButtonClick(self, event): edouard@2643: """ edouard@2643: Handle the event of the radio box in the slave information edouard@2643: @param event: wx.EVT_RADIOBOX object edouard@2643: """ edouard@2643: if self.Controler.GetCTRoot()._connector is not None: edouard@2643: self.SITreeListCtrl.UpdateSI() edouard@2643: edouard@2643: else : edouard@2643: self.Controler.CommonMethod.CreateErrorDialog('PLC not connected!') edouard@2643: edouard@2643: edouard@2643: #------------------------------------------------------------------------------- edouard@2643: # For Slave Information Panel edouard@2643: #------------------------------------------------------------------------------- edouard@2643: class SITreeListCtrl(wx.Panel): edouard@2643: edouard@2643: EC_Addrs = ["0x0300", "0x0302", "0x0304", "0x0306", "0x0301", "0x0303", "0x0305", edouard@2643: "0x0307", "0x0308", "0x0309", "0x030A", "0x030B", "0x030C", "0x030D", edouard@2643: "0x0310", "0x0311", "0x0312", "0x0313", "0x0442", "0x0443"] edouard@2643: edouard@2643: def __init__(self, parent, controler): edouard@2643: """ edouard@2643: Constructor edouard@2643: @param parent: Reference to the MasterStatePanel class edouard@2643: @param Controler: _EthercatCTN class in EthercatMaster.py edouard@2643: """ edouard@2643: edouard@2643: wx.Panel.__init__(self, parent, -1, size=wx.Size(750, 350)) edouard@2643: edouard@2643: self.Controler=controler edouard@2643: edouard@3303: self.Tree = wx.adv.TreeListCtrl(self, -1, size=wx.Size(750,350), edouard@2643: style=wx.TR_HAS_BUTTONS edouard@2643: |wx.TR_HIDE_ROOT edouard@2643: |wx.TR_ROW_LINES edouard@2643: |wx.TR_COLUMN_LINES edouard@2643: |wx.TR_FULL_ROW_HIGHLIGHT) edouard@2643: for label, width in [ edouard@2643: ("name", 400), edouard@2643: ("position", 100), edouard@2643: ("state", 100), edouard@2643: ("error", 100)]: edouard@2643: self.Tree.AddColumn(label, width=width) edouard@2643: edouard@2643: self.Tree.SetMainColumn(0) edouard@2643: edouard@2643: def UpdateSI(self): edouard@2643: """ edouard@2643: Update the data of the slave information. edouard@2643: """ kinsamanka@3750: position, not_used, state, not_used, name = list(range(5)) edouard@2643: edouard@2643: slave_node = [] edouard@2643: slave_info_list = [] edouard@2643: error_counter= [] edouard@2643: edouard@2643: # get slave informations (name, position, state) edouard@2643: slaves_infos = self.Controler.CommonMethod.GetSlaveStateFromSlave() edouard@2643: slave_info_lines = slaves_infos.splitlines() edouard@2643: edouard@2643: for line in slave_info_lines: edouard@2643: slave_info_list.append(line.split(None,4)) edouard@2643: edouard@2643: slave_num = len(slave_info_lines) edouard@2643: edouard@2643: reg_info = [] edouard@2643: for ec in self.EC_Addrs: edouard@2643: reg_info.append(ec + ",0x001") edouard@2643: edouard@2643: # get error counts of slaves edouard@2643: err_count_list = self.Controler.CommonMethod.MultiRegRead(slave_num, reg_info) edouard@2643: edouard@2643: self.Tree.DeleteAllItems() edouard@2643: edouard@2643: root = self.Tree.AddRoot("") edouard@2643: ec_list_idx = 0 edouard@2643: edouard@2643: for slave_idx in range(slave_num): edouard@2643: slave_node = self.Tree.AppendItem(root, "") edouard@2643: edouard@2643: # set name, postion, state edouard@2643: col_num = 0 edouard@2643: for info_idx in [name, position, state]: edouard@2643: self.Tree.SetItemText(slave_node, edouard@2643: slave_info_list[slave_idx][info_idx], col_num) edouard@2643: col_num += 1 edouard@2643: edouard@2643: error_counter = {} edouard@2643: ec_idx = 0 edouard@2643: edouard@2643: # set error counter's name and default value edouard@2643: for ec, sub_ecs in [("Port Error Counters 0/1/2/3",[ edouard@2643: "Invaild Frame Counter 0/1/2/3", edouard@2643: "RX Error Counter 0/1/2/3"]), edouard@2643: ("Forward RX Error Counter 0/1/2/3", []), edouard@2643: ("ECAT Processing Unit Error Counter", []), edouard@2643: ("PDI Error Counter", []), edouard@2643: ("Lost Link Counter 0/1/2/3", []), edouard@2643: ("Watchdog Counter Process Data", []), edouard@2643: ("Watchdog Counter PDI", [])]: edouard@2643: ec_sub_idx = 0 edouard@2643: ec_name = ec edouard@2643: tree_node = self.Tree.AppendItem(slave_node, "%s" % ec) edouard@2643: edouard@2643: if ec_name.find("0/1/2/3") > 0: edouard@2643: num_ports = 4 edouard@2643: err_count = [0, 0, 0, 0] edouard@2643: else: edouard@2643: num_ports = 1 edouard@2643: err_count = [0] edouard@2643: edouard@2643: error_counter[(ec_idx, ec_sub_idx)] = { edouard@2643: "name": ec_name, edouard@2643: "tree_node": tree_node, edouard@2643: "num_ports": num_ports, edouard@2643: "err_count": err_count} edouard@2643: edouard@2643: for sub_ec in sub_ecs: edouard@2643: ec_sub_idx += 1 edouard@2643: ec_name = sub_ec edouard@2643: tree_node = self.Tree.AppendItem(\ edouard@2643: error_counter[(ec_idx, 0)]["tree_node"], edouard@2643: "%s" % sub_ec) edouard@2643: edouard@2643: if ec_name.find("0/1/2/3") > 0: edouard@2643: num_ports = 4 edouard@2643: err_count = [0, 0, 0, 0] edouard@2643: else: edouard@2643: num_ports = 1 edouard@2643: err_count = [0] edouard@2643: edouard@2643: error_counter[(ec_idx, ec_sub_idx)] = { edouard@2643: "name": ec_name, edouard@2643: "tree_node": tree_node, edouard@2643: "num_ports": num_ports, edouard@2643: "err_count": err_count} edouard@2643: edouard@2643: for port_num in range(num_ports): edouard@2643: try: edouard@2643: error_counter[(ec_idx, ec_sub_idx)]["err_count"][port_num] += \ edouard@2643: int(err_count_list[ec_list_idx].split(",")[2], 16) edouard@2643: except: edouard@2643: error_counter[(ec_idx, ec_sub_idx)]["err_count"][port_num] = -1 edouard@2643: edouard@2643: ec_list_idx += 1 edouard@2643: edouard@2643: if ec_sub_idx > 0: edouard@2643: for port_num in range(num_ports): edouard@2643: err_sum = 0 edouard@2643: for sub_idx in range(1, ec_sub_idx+1): edouard@2643: err_sum += error_counter[(ec_idx, sub_idx)]\ edouard@2643: ["err_count"][port_num] edouard@2643: error_counter[(ec_idx, 0)]["err_count"][port_num] = err_sum edouard@2643: edouard@2643: else: edouard@2643: for port_num in range(num_ports): edouard@2643: try: edouard@2643: error_counter[(ec_idx, ec_sub_idx)]["err_count"][port_num] += \ edouard@2643: int(err_count_list[ec_list_idx].split(",")[2], 16) edouard@2643: except: edouard@2643: error_counter[(ec_idx, ec_sub_idx)]["err_count"][port_num] = -1 edouard@2643: ec_list_idx += 1 edouard@2643: edouard@2643: ec_idx += 1 edouard@2643: edouard@2643: # set texts in "error" column. kinsamanka@3750: ec_info_list = list(error_counter.items()) edouard@2643: ec_info_list.sort() edouard@2643: edouard@2643: err_checker = "none" edouard@2643: edouard@2643: for (idx, sub_idx), ec_info in ec_info_list: edouard@2643: ec_text = "" edouard@2643: for port_num in range(ec_info["num_ports"]): edouard@2643: if ec_info["err_count"][port_num] != 0: edouard@2643: err_checker = "occurred" edouard@2643: edouard@2643: if ec_info["err_count"][port_num] < 0: edouard@2643: ec_text = "reg I/O error" edouard@2643: else: edouard@2643: ec_text = ec_text + "%d/" % ec_info["err_count"][port_num] edouard@2643: edouard@2643: ec_text = ec_text.strip("/") edouard@2643: edouard@2643: self.Tree.SetItemText(ec_info["tree_node"], ec_text, col_num) edouard@2643: edouard@2643: self.Tree.SetItemText(slave_node, err_checker, col_num) edouard@2643: edouard@2643: class DCConfigPanel(wx.Panel): edouard@2643: def __init__(self, parent, controler): edouard@2643: """ edouard@2643: Constructor edouard@2643: @param parent: Reference to the MasterStatePanel class edouard@2643: @param Controler: _EthercatCTN class in EthercatMaster.py edouard@2643: """ edouard@2643: edouard@2643: wx.Panel.__init__(self, parent, -1, size=wx.Size(750, 350)) edouard@2643: edouard@2643: self.Controler = controler edouard@2643: self.parent = parent edouard@2643: edouard@2643: self.ESI_DC_Data = self.Controler.CommonMethod.LoadESIData() edouard@2643: edouard@2643: # initialize SlaveStatePanel UI dictionaries edouard@2643: self.StaticBoxDic = {} edouard@2643: self.StaticTextDic = {} edouard@2643: self.TextCtrlDic = {} edouard@2643: self.ComboBoxDic = {} edouard@2643: self.CheckBoxDic = {} edouard@2643: self.RadioButtonDic = {} edouard@2643: OperationModeComboList = [] edouard@2643: Sync1CycleComboList = [] edouard@2643: edouard@2643: for ESI_Data in self.ESI_DC_Data: edouard@2643: OperationModeComboList.append(ESI_Data["desc"]) edouard@2643: edouard@2643: UnitComboList = [ "/100", "/ 50", "/ 40", "/ 30", "/ 25", "/ 20", "/16", edouard@2643: "/ 10", "/ 8", "/ 5", "/ 4", "/ 3", "/ 2", "x 1", "x 2", "x 3", "x 4", edouard@2643: "x 5", "x 8", "x 10", "x 16", "x 20", "x 25", "x 30", "x 40", "x 50", edouard@2643: "x 100" edouard@2643: ] edouard@2643: edouard@2643: UnitComboListPlus = [ "/100", "/ 50", "/ 40", "/ 30", "/ 25", "/ 20", "/16", edouard@2643: "/ 10", "/ 8", "/ 5", "/ 4", "/ 3", "/ 2", "x 0", "x 1", "x 2", "x 3", edouard@2643: "x 4", "x 5", "x 8", "x 10", "x 16", "x 20", "x 25", "x 30", "x 40", edouard@2643: "x 50", "x 100" edouard@2643: ] edouard@2643: edouard@2643: for i in range(1024): edouard@2643: Sync1CycleComboList.append("x " + str(i + 1)) edouard@2643: edouard@2643: # iniitalize BoxSizer and FlexGridSizer edouard@2643: self.SizerDic = { edouard@2643: "DCConfig_main_sizer" : wx.BoxSizer(wx.VERTICAL), edouard@2643: "DCConfig_inner_main_sizer" : wx.FlexGridSizer(cols=1, hgap=50, rows=2, vgap=10), edouard@2643: "CyclicMode_InnerSizer" : wx.FlexGridSizer(cols=1, hgap=5, rows=2, vgap=5), edouard@2643: "SyncMode_InnerSizer" : wx.FlexGridSizer(cols=2, hgap=5, rows=1, vgap=5), edouard@2643: "OperationMode_InnerSizer" : wx.FlexGridSizer(cols=2, hgap=100, rows=2, vgap=10), edouard@2643: "CheckEnable_InnerSizer" : wx.FlexGridSizer(cols=2, hgap=10, rows=1, vgap=10), edouard@2643: "Sync0_InnerSizer" : wx.FlexGridSizer(cols=1, hgap=15, rows=3, vgap=10), edouard@2643: "Sync0_CycleTimeSizer" : wx.FlexGridSizer(cols=2, hgap=10, rows=2, vgap=5), edouard@2643: "Sync0_ShiftTimeSizer" : wx.FlexGridSizer(cols=2, hgap=20, rows=2, vgap=5), edouard@2643: "Sync1_InnerSizer" : wx.FlexGridSizer(cols=1, hgap=15, rows=3, vgap=10), edouard@2643: "Sync1_CycleTimeSizer" : wx.FlexGridSizer(cols=2, hgap=10, rows=2, vgap=5), edouard@2643: "Sync1_ShiftTimeSizer" : wx.FlexGridSizer(cols=2, hgap=20, rows=2, vgap=5) edouard@2643: } edouard@2643: edouard@2643: # initialize StaticBox and StaticBoxSizer edouard@2643: for box_name, box_label in [ edouard@2643: ("CyclicModeBox", "Cyclic Mode"), edouard@2643: ("Sync0Box", "Sync0"), edouard@2643: ("Sync0CycleTimeBox", "Cycle Time (us):"), edouard@2643: ("Sync0ShiftTimeBox", "Shift Time (us):"), edouard@2643: ("Sync1Box", "Sync1"), edouard@2643: ("Sync1CycleTimeBox", "Cycle Time (us):"), edouard@2643: ("Sync1ShiftTimeBox", "Shift Time (us):") edouard@2643: ]: edouard@2643: self.StaticBoxDic[box_name] = wx.StaticBox(self, label=_(box_label)) edouard@2643: self.SizerDic[box_name] = wx.StaticBoxSizer(self.StaticBoxDic[box_name]) edouard@2643: edouard@2643: for statictext_name, statictext_label in [ edouard@2643: ("MainLabel", "Distributed Clock"), edouard@2643: ("OperationModeLabel", "Operation Mode:"), edouard@2643: ("SyncUnitCycleLabel", "Sync Unit Cycle (us)"), edouard@2643: ("Sync0ShiftTimeUserDefinedLabel", "User Defined"), edouard@2643: ("Sync1ShiftTimeUserDefinedLabel", "User Defined"), edouard@2643: ("BlankObject", ""), edouard@2643: ("BlankObject1", "") edouard@2643: ]: edouard@2643: self.StaticTextDic[statictext_name] = wx.StaticText(self, label=_(statictext_label)) edouard@2643: edouard@2643: for textctl_name in [ edouard@2643: ("SyncUnitCycle_Ctl"), edouard@2643: ("Sync0CycleTimeUserDefined_Ctl"), edouard@2643: ("Sync0ShiftTimeUserDefined_Ctl"), edouard@2643: ("Sync1CycleTimeUserDefined_Ctl"), edouard@2643: ("Sync1ShiftTimeUserDefined_Ctl"), edouard@2643: ]: edouard@2643: self.TextCtrlDic[textctl_name] = wx.TextCtrl( edouard@2643: self, size=wx.Size(130, 24), style=wx.TE_READONLY) edouard@2643: edouard@2643: for checkbox_name, checkbox_label in [ edouard@2643: ("DCEnable", "Enable"), edouard@2643: ("Sync0Enable", "Enable Sync0"), edouard@2643: ("Sync1Enable", "Enable Sync1") edouard@2643: ]: edouard@2643: self.CheckBoxDic[checkbox_name] = wx.CheckBox(self, -1, checkbox_label) edouard@2643: edouard@2643: for combobox_name, combobox_list, size in [ edouard@2643: ("OperationModeChoice", OperationModeComboList, 250), edouard@2643: ("Sync0UnitCycleChoice", UnitComboList, 130), edouard@2643: ("Sync1UnitCycleChoice", UnitComboList, 130) edouard@2643: ]: edouard@2643: self.ComboBoxDic[combobox_name] = wx.ComboBox(self, size=wx.Size(size, 24), edouard@2643: choices = combobox_list, style = wx.CB_DROPDOWN | wx.CB_READONLY) edouard@2643: edouard@2643: for radiobutton_name, radiobutton_label in [ edouard@2643: ("Sync0CycleTimeUnitRadioButton", "Sync Unit Cycle"), edouard@2643: ("Sync0CycleTimeUserDefinedRadioButton", "User Defined"), edouard@2643: ("Sync1CycleTimeUnitRadioButton", "Sync Unit Cycle"), edouard@2643: ("Sync1CycleTimeUserDefinedRadioButton", "User Defined") edouard@2643: ]: edouard@2643: self.RadioButtonDic[radiobutton_name] = wx.RadioButton( edouard@2643: self, label = radiobutton_label, style = wx.RB_SINGLE) edouard@2643: edouard@2643: edouard@2643: self.ApplyButton = wx.Button(self, label="Apply") edouard@2643: edouard@2643: # binding event edouard@2643: self.Bind(wx.EVT_CHECKBOX, self.CheckDCEnable, self.CheckBoxDic["DCEnable"]) edouard@2643: #self.Bind(wx.EVT_COMBOBOX, self.SelectOperationMode, self.ComboBoxDic["OperationModeChoice"]) edouard@2643: #self.Bind(wx.EVT_COMBOBOX, self.SelectUnitCycle, self.ComboBoxDic["Sync0UnitChoice"]) edouard@2643: self.Bind(wx.EVT_RADIOBUTTON, self.SelectSync0CycleTime, edouard@2643: self.RadioButtonDic["Sync0CycleTimeUnitRadioButton"]) edouard@2643: self.Bind(wx.EVT_RADIOBUTTON, self.SelectSync0CycleTime, edouard@2643: self.RadioButtonDic["Sync0CycleTimeUserDefinedRadioButton"]) edouard@2643: self.Bind(wx.EVT_RADIOBUTTON, self.SelectSync1CycleTime, edouard@2643: self.RadioButtonDic["Sync1CycleTimeUnitRadioButton"]) edouard@2643: self.Bind(wx.EVT_RADIOBUTTON, self.SelectSync1CycleTime, edouard@2643: self.RadioButtonDic["Sync1CycleTimeUserDefinedRadioButton"]) edouard@2643: self.Bind(wx.EVT_CHECKBOX, self.CheckSync0Enable, self.CheckBoxDic["Sync0Enable"]) edouard@2643: self.Bind(wx.EVT_CHECKBOX, self.CheckSync1Enable, self.CheckBoxDic["Sync1Enable"]) edouard@2643: self.Bind(wx.EVT_BUTTON, self.OnClickApplyButton, self.ApplyButton) edouard@2643: edouard@2643: # sync1 shifttime box contents edouard@2643: self.SizerDic["Sync1_ShiftTimeSizer"].AddMany([ edouard@2643: self.StaticTextDic["Sync1ShiftTimeUserDefinedLabel"], edouard@2643: self.TextCtrlDic["Sync1ShiftTimeUserDefined_Ctl"] edouard@2643: ]) edouard@2643: edouard@2643: # sync1 shifttime box edouard@2643: self.SizerDic["Sync1ShiftTimeBox"].Add(self.SizerDic["Sync1_ShiftTimeSizer"]) edouard@2643: edouard@2643: # sync1 cycletime box contents edouard@2643: self.SizerDic["Sync1_CycleTimeSizer"].AddMany([ edouard@2643: self.RadioButtonDic["Sync1CycleTimeUnitRadioButton"], edouard@2643: self.ComboBoxDic["Sync1UnitCycleChoice"], edouard@2643: self.RadioButtonDic["Sync1CycleTimeUserDefinedRadioButton"], edouard@2643: self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"] edouard@2643: ]) edouard@2643: edouard@2643: # sync0 cycletime box edouard@2643: self.SizerDic["Sync1CycleTimeBox"].Add(self.SizerDic["Sync1_CycleTimeSizer"]) edouard@2643: edouard@2643: self.SizerDic["Sync1_InnerSizer"].AddMany([ edouard@2643: self.CheckBoxDic["Sync1Enable"], self.SizerDic["Sync1CycleTimeBox"], edouard@2643: self.SizerDic["Sync1ShiftTimeBox"] edouard@2643: ]) edouard@2643: edouard@2643: # sync1 box edouard@2643: self.SizerDic["Sync1Box"].Add(self.SizerDic["Sync1_InnerSizer"]) edouard@2643: edouard@2643: # sync0 shifttime box contents edouard@2643: self.SizerDic["Sync0_ShiftTimeSizer"].AddMany([ edouard@2643: self.StaticTextDic["Sync0ShiftTimeUserDefinedLabel"], edouard@2643: self.TextCtrlDic["Sync0ShiftTimeUserDefined_Ctl"] edouard@2643: ]) edouard@2643: edouard@2643: # sync0 shifttime box edouard@2643: self.SizerDic["Sync0ShiftTimeBox"].Add(self.SizerDic["Sync0_ShiftTimeSizer"]) edouard@2643: edouard@2643: # sync0 cycletime box contents edouard@2643: self.SizerDic["Sync0_CycleTimeSizer"].AddMany([ edouard@2643: self.RadioButtonDic["Sync0CycleTimeUnitRadioButton"], edouard@2643: self.ComboBoxDic["Sync0UnitCycleChoice"], edouard@2643: self.RadioButtonDic["Sync0CycleTimeUserDefinedRadioButton"], edouard@2643: self.TextCtrlDic["Sync0CycleTimeUserDefined_Ctl"] edouard@2643: ]) edouard@2643: edouard@2643: # sync0 cycletime box edouard@2643: self.SizerDic["Sync0CycleTimeBox"].Add(self.SizerDic["Sync0_CycleTimeSizer"]) edouard@2643: edouard@2643: self.SizerDic["Sync0_InnerSizer"].AddMany([ edouard@2643: self.CheckBoxDic["Sync0Enable"], self.SizerDic["Sync0CycleTimeBox"], edouard@2643: self.SizerDic["Sync0ShiftTimeBox"] edouard@2643: ]) edouard@2643: edouard@2643: # sync0 box edouard@2643: self.SizerDic["Sync0Box"].Add(self.SizerDic["Sync0_InnerSizer"]) edouard@2643: edouard@2643: # sync0, sync1 box edouard@2643: self.SizerDic["SyncMode_InnerSizer"].AddMany([ edouard@2643: self.SizerDic["Sync0Box"], self.SizerDic["Sync1Box"] edouard@2643: ]) edouard@2643: edouard@2643: # CyclicMode Box edouard@2643: self.SizerDic["CheckEnable_InnerSizer"].AddMany([ edouard@2643: self.StaticTextDic["SyncUnitCycleLabel"], edouard@2643: self.TextCtrlDic["SyncUnitCycle_Ctl"] edouard@2643: ]) edouard@2643: edouard@2643: self.SizerDic["OperationMode_InnerSizer"].AddMany([ edouard@2643: self.StaticTextDic["OperationModeLabel"], edouard@2643: self.ComboBoxDic["OperationModeChoice"], edouard@2643: self.CheckBoxDic["DCEnable"], self.SizerDic["CheckEnable_InnerSizer"] edouard@2643: ]) edouard@2643: edouard@2643: self.SizerDic["CyclicMode_InnerSizer"].AddMany([ edouard@2643: self.SizerDic["OperationMode_InnerSizer"], edouard@2643: self.SizerDic["SyncMode_InnerSizer"] edouard@2643: ]) edouard@2643: edouard@2643: self.SizerDic["CyclicModeBox"].Add(self.SizerDic["CyclicMode_InnerSizer"]) edouard@2643: edouard@2643: # Main Sizer edouard@2643: self.SizerDic["DCConfig_inner_main_sizer"].AddMany([ edouard@2643: self.StaticTextDic["MainLabel"], self.ApplyButton, edouard@2643: self.SizerDic["CyclicModeBox"] edouard@2643: ]) edouard@2643: edouard@2643: self.SizerDic["DCConfig_main_sizer"].Add(self.SizerDic["DCConfig_inner_main_sizer"]) edouard@2643: edouard@2643: self.SetSizer(self.SizerDic["DCConfig_main_sizer"]) edouard@2643: edouard@2643: self.Centre() edouard@2643: edouard@2643: self.UIOnOffSet(False) edouard@2643: self.LoadProjectDCData() edouard@2643: edouard@2643: def UIOnOffSet(self, activate): edouard@2643: if activate : edouard@2643: for object in self.RadioButtonDic: edouard@2643: self.RadioButtonDic[object].Enable() edouard@2643: edouard@2643: for object in self.ComboBoxDic: edouard@2643: if object == "OperationModeChoice": edouard@2643: continue edouard@2643: self.ComboBoxDic[object].Enable() edouard@2643: edouard@2643: for object in self.TextCtrlDic: edouard@2643: if object in ["SyncUnitCycle_Ctl", "InputReference_Ctl"]: edouard@2643: continue edouard@2643: self.TextCtrlDic[object].Enable() edouard@2643: edouard@2643: for object in self.CheckBoxDic: edouard@2643: if object == "DCEnable": edouard@2643: continue edouard@2643: self.CheckBoxDic[object].Enable() edouard@2643: edouard@2643: # initial set or DC enable uncheck edouard@2643: else : edouard@2643: for object in self.RadioButtonDic: edouard@2643: self.RadioButtonDic[object].Disable() edouard@2643: edouard@2643: for object in self.ComboBoxDic: edouard@2643: if object == "OperationModeChoice": edouard@2643: continue edouard@2643: self.ComboBoxDic[object].Disable() edouard@2643: edouard@2643: for object in self.TextCtrlDic: edouard@2643: if object == "SyncUnitCycle_Ctl": edouard@2643: continue edouard@2643: self.TextCtrlDic[object].Disable() edouard@2643: edouard@2643: for object in self.CheckBoxDic: edouard@2643: if object == "DCEnable": edouard@2643: continue edouard@2643: self.CheckBoxDic[object].Disable() edouard@2643: edouard@2643: for data in self.ESI_DC_Data: edouard@2643: index = self.Controler.ExtractHexDecValue(data["assign_activate"]) edouard@2643: if index == 0: edouard@2643: config_name = data["desc"] edouard@2643: self.ComboBoxDic["OperationModeChoice"].SetStringSelection(config_name) edouard@2643: edouard@2643: def CheckSync0Enable(self, evt): edouard@2643: if evt.GetInt(): edouard@2643: self.ComboBoxDic["Sync0UnitCycleChoice"].Enable() edouard@2643: self.RadioButtonDic["Sync0CycleTimeUnitRadioButton"].Enable() edouard@2643: self.RadioButtonDic["Sync0CycleTimeUserDefinedRadioButton"].Enable() edouard@2643: self.TextCtrlDic["Sync0CycleTimeUserDefined_Ctl"].Enable() edouard@2643: self.TextCtrlDic["Sync0ShiftTimeUserDefined_Ctl"].Enable() edouard@2643: else : edouard@2643: self.ComboBoxDic["Sync0UnitCycleChoice"].Disable() edouard@2643: self.RadioButtonDic["Sync0CycleTimeUnitRadioButton"].Disable() edouard@2643: self.RadioButtonDic["Sync0CycleTimeUserDefinedRadioButton"].Disable() edouard@2643: self.TextCtrlDic["Sync0CycleTimeUserDefined_Ctl"].Disable() edouard@2643: self.TextCtrlDic["Sync0ShiftTimeUserDefined_Ctl"].Disable() edouard@2643: self.RadioButtonDic["Sync0CycleTimeUnitRadioButton"].SetValue(False) edouard@2643: self.RadioButtonDic["Sync0CycleTimeUserDefinedRadioButton"].SetValue(False) edouard@2643: self.TextCtrlDic["Sync0CycleTimeUserDefined_Ctl"].SetValue("") edouard@2643: self.TextCtrlDic["Sync0ShiftTimeUserDefined_Ctl"].SetValue("") edouard@2643: edouard@2643: def CheckSync1Enable(self, evt): edouard@2643: if evt.GetInt(): edouard@2643: self.ComboBoxDic["Sync1UnitCycleChoice"].Enable() edouard@2643: self.RadioButtonDic["Sync1CycleTimeUnitRadioButton"].Enable() edouard@2643: self.RadioButtonDic["Sync1CycleTimeUserDefinedRadioButton"].Enable() edouard@2643: self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"].Enable() edouard@2643: self.TextCtrlDic["Sync1ShiftTimeUserDefined_Ctl"].Enable() edouard@2643: else : edouard@2643: self.ComboBoxDic["Sync1UnitCycleChoice"].Disable() edouard@2643: self.RadioButtonDic["Sync1CycleTimeUnitRadioButton"].Disable() edouard@2643: self.RadioButtonDic["Sync1CycleTimeUserDefinedRadioButton"].Disable() edouard@2643: self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"].Disable() edouard@2643: self.TextCtrlDic["Sync1ShiftTimeUserDefined_Ctl"].Disable() edouard@2643: self.RadioButtonDic["Sync1CycleTimeUnitRadioButton"].SetValue(False) edouard@2643: self.RadioButtonDic["Sync1CycleTimeUserDefinedRadioButton"].SetValue(False) edouard@2643: self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"].SetValue("") edouard@2643: self.TextCtrlDic["Sync1ShiftTimeUserDefined_Ctl"].SetValue("") edouard@2643: edouard@2643: def CheckDCEnable(self, evt): edouard@2643: ns_mode = 1 edouard@2643: task_cycle_ns = self.GetInterval(ns_mode) edouard@2643: sync0_cycle_factor = None edouard@2643: sync1_cycle_factor = None edouard@2643: edouard@2643: #task_cycle_ns = self.Controler.GetCTRoot()._Ticktime edouard@2643: if (task_cycle_ns > 0): edouard@2643: self.UIOnOffSet(evt.GetInt()) edouard@2643: edouard@2643: if evt.GetInt(): edouard@2643: # default select DC enable sync0 edouard@2643: default_list_num = 0 edouard@2643: config_name = self.ESI_DC_Data[default_list_num]["desc"] edouard@2643: assign_act = self.ESI_DC_Data[default_list_num]["assign_activate"] edouard@2643: sync0_cycle_time_ns = self.ESI_DC_Data[default_list_num]["cycletime_sync0"] edouard@2643: if sync0_cycle_time_ns == 0 : edouard@2643: sync0_cycle_factor = self.ESI_DC_Data[default_list_num]["cycletime_sync0_factor"] edouard@2643: sync0_shift_time_ns = self.ESI_DC_Data[default_list_num]["shifttime_sync0"] edouard@2643: sync1_cycle_time_ns = self.ESI_DC_Data[default_list_num]["cycletime_sync1"] edouard@2643: if sync1_cycle_time_ns == 0 : edouard@2643: sync1_cycle_factor = self.ESI_DC_Data[default_list_num]["cycletime_sync1_factor"] edouard@2643: sync1_shift_time_ns = self.ESI_DC_Data[default_list_num]["shifttime_sync1"] edouard@2643: edouard@2643: cal_assign_act = self.Controler.ExtractHexDecValue(assign_act) edouard@2643: sync0_cycle_time_us = str(int(sync0_cycle_time_ns) / 1000) edouard@2643: sync0_shift_time_us = str(int(sync0_shift_time_ns) / 1000) edouard@2643: sync1_cycle_time_us = str(int(sync1_cycle_time_ns) / 1000) edouard@2643: sync1_shift_time_us = str(int(sync1_shift_time_ns) / 1000) edouard@2643: edouard@2643: task_cycle_to_us = str(int(task_cycle_ns) / 1000) edouard@2643: edouard@2643: # DC sync0 mode edouard@2643: if cal_assign_act == 768: edouard@2643: # Disable About Sync1 Objects edouard@2643: self.CheckBoxDic["Sync1Enable"].SetValue(False) edouard@2643: self.RadioButtonDic["Sync1CycleTimeUnitRadioButton"].Disable() edouard@2643: self.ComboBoxDic["Sync1UnitCycleChoice"].Disable() edouard@2643: self.RadioButtonDic["Sync1CycleTimeUserDefinedRadioButton"].Disable() edouard@2643: self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"].Disable() edouard@2643: self.TextCtrlDic["Sync1ShiftTimeUserDefined_Ctl"].Disable() edouard@2643: edouard@2643: else : edouard@2643: self.CheckBoxDic["Sync1Enable"].SetValue(True) edouard@2643: if sync1_cycle_factor is not None: edouard@2643: self.RadioButtonDic["Sync1CycleTimeUnitRadioButton"].SetValue(True) edouard@2643: self.RadioButtonDic["Sync1CycleTimeUserDefinedRadioButton"].SetValue(False) edouard@2643: self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"].Disable() edouard@2643: self.SetSyncUnitCycle(sync1_cycle_factor, edouard@2643: self.ComboBoxDic["Sync1UnitCycleChoice"]) edouard@2643: else : edouard@2643: self.RadioButtonDic["Sync1CycleTimeUnitRadioButton"].SetValue(False) edouard@2643: self.RadioButtonDic["Sync1CycleTimeUserDefinedRadioButton"].SetValue(True) edouard@2643: self.ComboBoxDic["Sync1UnitCycleChoice"].Disable() edouard@2643: self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"].SetValue(sync1_cycle_time_us) edouard@2643: edouard@2643: self.TextCtrlDic["Sync1ShiftTimeUserDefined_Ctl"].SetValue(sync1_shift_time_us) edouard@2643: edouard@2643: # Set Sync0 Objects edouard@2643: self.CheckBoxDic["Sync0Enable"].SetValue(True) edouard@2643: if sync0_cycle_factor is not None: edouard@2643: self.RadioButtonDic["Sync0CycleTimeUnitRadioButton"].SetValue(True) edouard@2643: self.RadioButtonDic["Sync0CycleTimeUserDefinedRadioButton"].SetValue(False) edouard@2643: self.TextCtrlDic["Sync0CycleTimeUserDefined_Ctl"].Disable() edouard@2643: self.SetSyncUnitCycle(sync0_cycle_factor, edouard@2643: self.ComboBoxDic["Sync0UnitCycleChoice"]) edouard@2643: else : edouard@2643: self.RadioButtonDic["Sync0CycleTimeUnitRadioButton"].SetValue(False) edouard@2643: self.RadioButtonDic["Sync0CycleTimeUserDefinedRadioButton"].SetValue(True) edouard@2643: self.ComboBoxDic["Sync0UnitCycleChoice"].Disable() edouard@2643: self.TextCtrlDic["Sync0CycleTimeUserDefined_Ctl"].SetValue(sync0_cycle_time_us) edouard@2643: edouard@2643: self.TextCtrlDic["Sync0ShiftTimeUserDefined_Ctl"].SetValue(sync0_shift_time_us) edouard@2643: edouard@2643: self.ComboBoxDic["OperationModeChoice"].SetStringSelection(config_name) edouard@2643: self.TextCtrlDic["SyncUnitCycle_Ctl"].SetValue(task_cycle_to_us) edouard@2643: else : edouard@2643: self.CheckBoxDic["Sync0Enable"].SetValue(False) edouard@2643: self.CheckBoxDic["Sync1Enable"].SetValue(False) edouard@2643: self.RadioButtonDic["Sync0CycleTimeUnitRadioButton"].SetValue(False) edouard@2643: self.RadioButtonDic["Sync0CycleTimeUserDefinedRadioButton"].SetValue(False) edouard@2643: self.RadioButtonDic["Sync1CycleTimeUnitRadioButton"].SetValue(False) edouard@2643: self.RadioButtonDic["Sync1CycleTimeUserDefinedRadioButton"].SetValue(False) edouard@2643: self.TextCtrlDic["Sync0CycleTimeUserDefined_Ctl"].SetValue("") edouard@2643: self.TextCtrlDic["Sync0ShiftTimeUserDefined_Ctl"].SetValue("") edouard@2643: self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"].SetValue("") edouard@2643: self.TextCtrlDic["Sync1ShiftTimeUserDefined_Ctl"].SetValue("") edouard@2643: edouard@2643: else : edouard@2643: self.UIOnOffSet(False) edouard@2643: #error_str = "DC Enable is not possble, please set task interval" edouard@2643: error_str = "Can't Set DC Enable" edouard@2643: self.Controler.CommonMethod.CreateErrorDialog(error_str) edouard@2643: edouard@2643: def SetSyncUnitCycle(self, factor, object): edouard@2643: # factor > 0 ==> * factor, factor < 0 ==> / factor edouard@2643: factor_to_int = int(factor) edouard@2643: if factor_to_int > 0: edouard@2643: lists = object.GetStrings() edouard@2643: edouard@2643: for token in lists: edouard@2643: temp = token.split(" ") edouard@2643: if (temp[0] == "x") and (int(temp[1]) == factor_to_int): edouard@2643: object.SetStringSelection(token) edouard@2643: return True edouard@2643: edouard@2643: else : edouard@2643: lists = object.GetStrings() edouard@2643: edouard@2643: for token in lists: edouard@2643: temp = token.split(" ") edouard@2643: if (temp[0] == "/") and (int(temp[1]) == factor_to_int): edouard@2643: object.SetStringSelection(token) edouard@2643: return True edouard@2643: edouard@2643: return False edouard@2643: edouard@2643: def GetInterval(self, mode): edouard@2643: project_infos = self.Controler.GetCTRoot().GetProjectInfos() edouard@2643: for project_info_list in project_infos["values"]: edouard@2643: if project_info_list["name"] == "Resources" : edouard@2643: token = project_info_list["values"][0]["tagname"] edouard@2643: edouard@2643: tasks, instances = self.Controler.GetCTRoot().GetEditedResourceInfos(token) edouard@2643: try: edouard@2643: task_cycle_ns = self.ParseTime(tasks[0]["Interval"]) edouard@2643: except : edouard@2643: task_cycle_ns = 0 edouard@2643: task_cycle_us = int(task_cycle_ns) / 1000 edouard@2643: edouard@2643: # mode == 1 ==> return ns edouard@2643: # mode == 2 ==> return us edouard@2643: edouard@2643: if mode == 1: edouard@2643: return task_cycle_ns edouard@2643: if mode == 2: edouard@2643: return str(task_cycle_us) edouard@2643: edouard@2643: def ParseTime(self, input): edouard@2643: # input example : 't#1ms' edouard@2643: # temp.split('#') -> ['t', '1ms'] edouard@2643: temp = input.split('#') edouard@2643: edouard@2643: # temp[1] : '1ms' edouard@2643: # temp[-2:] : 'ms' edouard@2643: # temp[:-2] : '1' edouard@2643: if temp[1][-2:] == "ms": edouard@2643: # convert nanosecond unit edouard@2643: result = int(temp[1][:-2]) * 1000000 edouard@2643: elif temp[1][-2:] == "us": edouard@2643: result = int(temp[1][:-2]) * 1000 edouard@2643: edouard@2643: return str(result) edouard@2643: edouard@2643: def SelectSync0CycleTime(self, evt): edouard@2643: selected_object = evt.GetEventObject() edouard@2643: edouard@2643: if selected_object.GetLabel() == "User Defined" : edouard@2643: self.RadioButtonDic["Sync0CycleTimeUnitRadioButton"].SetValue(False) edouard@2643: self.TextCtrlDic["Sync0CycleTimeUserDefined_Ctl"].Enable() edouard@2643: self.ComboBoxDic["Sync0UnitCycleChoice"].Disable() edouard@2643: elif selected_object.GetLabel() == "Sync Unit Cycle" : edouard@2643: self.RadioButtonDic["Sync0CycleTimeUserDefinedRadioButton"].SetValue(False) edouard@2643: self.ComboBoxDic["Sync0UnitCycleChoice"].Enable() edouard@2643: self.TextCtrlDic["Sync0CycleTimeUserDefined_Ctl"].Disable() edouard@2643: edouard@2643: def SelectSync1CycleTime(self, evt): edouard@2643: selected_object = evt.GetEventObject() edouard@2643: edouard@2643: if selected_object.GetLabel() == "User Defined" : edouard@2643: self.RadioButtonDic["Sync1CycleTimeUnitRadioButton"].SetValue(False) edouard@2643: self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"].Enable() edouard@2643: self.ComboBoxDic["Sync1UnitCycleChoice"].Disable() edouard@2643: elif selected_object.GetLabel() == "Sync Unit Cycle" : edouard@2643: self.RadioButtonDic["Sync1CycleTimeUserDefinedRadioButton"].SetValue(False) edouard@2643: self.ComboBoxDic["Sync1UnitCycleChoice"].Enable() edouard@2643: self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"].Disable() edouard@2643: edouard@2643: def GetCycle(self, period, section): edouard@2643: temp = section.split(" ") edouard@2643: edouard@2643: if temp[0] == "x": edouard@2643: result = int(period) * int(temp[1]) edouard@2643: elif temp[0] == "/" : edouard@2643: result = int(period) / int(temp[1]) edouard@2643: else : edouard@2643: result = "" edouard@2643: edouard@2643: return result edouard@2643: edouard@2643: def OnClickApplyButton(self, evt): edouard@2643: us_mode = 2 edouard@2643: dc_enable = self.CheckBoxDic["DCEnable"].GetValue() edouard@2643: dc_desc = self.ComboBoxDic["OperationModeChoice"].GetStringSelection() edouard@2643: dc_assign_activate = self.ESI_DC_Data[0]["assign_activate"] edouard@2643: dc_assign_activate_mod = dc_assign_activate.split('x')[1] edouard@2643: edouard@2643: if self.RadioButtonDic["Sync0CycleTimeUnitRadioButton"].GetValue(): edouard@2643: temp = self.ComboBoxDic["Sync0UnitCycleChoice"].GetStringSelection() edouard@2643: dc_sync0_cycle = "1_" + str(self.GetCycle(self.GetInterval(us_mode), temp)) edouard@2643: elif self.RadioButtonDic["Sync0CycleTimeUserDefinedRadioButton"].GetValue(): edouard@2643: dc_sync0_cycle = "2_" + self.TextCtrlDic["Sync0CycleTimeUserDefined_Ctl"].GetValue() edouard@2643: else : edouard@2643: dc_sync0_cycle = "" edouard@2643: edouard@2643: if self.RadioButtonDic["Sync1CycleTimeUnitRadioButton"].GetValue(): edouard@2643: temp = self.ComboBoxDic["Sync1UnitCycleChoice"].GetStringSelection() edouard@2643: dc_sync1_cycle = "1_" + self.GetCycle(self.GetInterval(us_mode), temp) edouard@2643: elif self.RadioButtonDic["Sync1CycleTimeUserDefinedRadioButton"].GetValue(): edouard@2643: dc_sync1_cycle = "2_" + self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"].GetValue() edouard@2643: else : edouard@2643: dc_sync1_cycle = "" edouard@2643: edouard@2643: dc_sync0_shift = self.TextCtrlDic["Sync0ShiftTimeUserDefined_Ctl"].GetValue() edouard@2643: dc_sync1_shift = self.TextCtrlDic["Sync1ShiftTimeUserDefined_Ctl"].GetValue() edouard@2643: edouard@2643: self.Controler.BaseParams.setDC_Enable(dc_enable) edouard@2643: self.Controler.BaseParams.setDC_Desc(dc_desc) edouard@2643: self.Controler.BaseParams.setDC_Assign_Activate(dc_assign_activate_mod) edouard@2643: if dc_sync0_cycle: edouard@2643: self.Controler.BaseParams.setDC_Sync0_Cycle_Time(dc_sync0_cycle) edouard@2643: if dc_sync0_shift: edouard@2643: self.Controler.BaseParams.setDC_Sync0_Shift_Time(dc_sync0_shift) edouard@2643: if dc_sync1_cycle: edouard@2643: self.Controler.BaseParams.setDC_Sync1_Cycle_Time(dc_sync1_cycle) edouard@2643: if dc_sync1_shift: edouard@2643: self.Controler.BaseParams.setDC_Sync1_Shift_Time(dc_sync1_shift) edouard@2643: project_infos = self.Controler.GetCTRoot().CTNRequestSave() edouard@2643: edouard@2643: def GetSymbol(self, period, cycle): edouard@2643: cmp1 = int(period) edouard@2643: cmp2 = int(cycle) edouard@2643: edouard@2643: if cmp1 == cmp2 : edouard@2643: return "x 1" edouard@2643: elif cmp2 > cmp1 : edouard@2643: temp = cmp2 / cmp1 edouard@2643: result = "x " + str(temp) edouard@2643: else : edouard@2643: temp = cmp1 / cmp2 edouard@2643: result = "/ " + str(temp) edouard@2643: edouard@2643: return result edouard@2643: edouard@2643: def SetSyncCycle(self, period, sync0_cycle, sync1_cycle): edouard@2643: if sync0_cycle != "None": edouard@2643: self.CheckBoxDic["Sync0Enable"].SetValue(True) edouard@2643: temp = sync0_cycle.split("_") edouard@2643: if temp[0] == "1": edouard@2643: symbol = self.GetSymbol(period, temp[1]) edouard@2643: self.ComboBoxDic["Sync0UnitCycleChoice"].SetStringSelection(symbol) edouard@2643: self.TextCtrlDic["Sync0CycleTimeUserDefined_Ctl"].Disable() edouard@2643: self.RadioButtonDic["Sync0CycleTimeUnitRadioButton"].SetValue(True) edouard@2643: else : edouard@2643: self.TextCtrlDic["Sync0CycleTimeUserDefined_Ctl"].SetValue(temp[1]) edouard@2643: self.ComboBoxDic["Sync0UnitCycleChoice"].Disable() edouard@2643: self.RadioButtonDic["Sync0CycleTimeUserDefinedRadioButton"].SetValue(True) edouard@2643: edouard@2643: if sync1_cycle != "None": edouard@2643: self.CheckBoxDic["Sync1Enable"].SetValue(True) edouard@2643: temp = sync1_cycle.split("_") edouard@2643: if temp[0] == "1": edouard@2643: symbol = self.GetSymbol(period, temp[1]) edouard@2643: self.ComboBoxDic["Sync1UnitChoice"].SetStringSelection(symbol) edouard@2643: self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"].Disable() edouard@2643: self.RadioButtonDic["Sync1CycleTimeUnitRadioButton"].SetValue(True) edouard@2643: else : edouard@2643: self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"].SetValue(temp[1]) edouard@2643: self.ComboBoxDic["Sync1UnitChoice"].Disable() edouard@2643: self.RadioButtonDic["Sync1CycleTimeUserDefinedRadioButton"].SetValue(True) edouard@2643: edouard@2643: def LoadProjectDCData(self): edouard@2643: ns_mode = 1 edouard@2643: task_cycle_ns = self.GetInterval(ns_mode) edouard@2643: task_cycle_to_us = int(task_cycle_ns) / 1000 edouard@2643: dc_enable = self.Controler.BaseParams.getDC_Enable() edouard@2643: dc_desc = self.Controler.BaseParams.getDC_Desc() edouard@2643: dc_assign_activate = self.Controler.BaseParams.getDC_Assign_Activate() edouard@2643: dc_sync0_cycle = self.Controler.BaseParams.getDC_Sync0_Cycle_Time() edouard@2643: dc_sync0_shift = self.Controler.BaseParams.getDC_Sync0_Shift_Time() edouard@2643: dc_sync1_cycle = self.Controler.BaseParams.getDC_Sync1_Cycle_Time() edouard@2643: dc_sync1_shift = self.Controler.BaseParams.getDC_Sync1_Shift_Time() edouard@2643: edouard@2643: self.UIOnOffSet(dc_enable) edouard@2643: edouard@2643: if dc_enable: edouard@2643: self.CheckBoxDic["DCEnable"].SetValue(dc_enable) edouard@2643: self.ComboBoxDic["OperationModeChoice"].SetStringSelection(dc_desc) edouard@2643: self.TextCtrlDic["SyncUnitCycle_Ctl"].SetValue(str(task_cycle_to_us)) edouard@2643: self.SetSyncCycle(str(task_cycle_to_us), dc_sync0_cycle, dc_sync1_cycle) edouard@2643: if dc_sync0_shift != "None": edouard@2643: self.TextCtrlDic["Sync0ShiftTimeUserDefined_Ctl"].SetValue(dc_sync0_shift) edouard@2643: if dc_sync1_shift != "None": edouard@2643: self.TextCtrlDic["Sync1ShiftTimeUserDefined_Ctl"].SetValue(dc_sync1_shift) edouard@2643: edouard@2643: if dc_assign_activate == "300": edouard@2643: self.CheckBoxDic["Sync1Enable"].SetValue(False) edouard@2643: self.RadioButtonDic["Sync1CycleTimeUnitRadioButton"].Disable() edouard@2643: self.ComboBoxDic["Sync1UnitCycleChoice"].Disable() edouard@2643: self.RadioButtonDic["Sync1CycleTimeUserDefinedRadioButton"].Disable() edouard@2643: self.TextCtrlDic["Sync1CycleTimeUserDefined_Ctl"].Disable() edouard@2643: self.TextCtrlDic["Sync1ShiftTimeUserDefined_Ctl"].Disable() edouard@2643: edouard@2643: edouard@2643: edouard@2643: edouard@2643: edouard@2643: edouard@2643: edouard@2643: edouard@2643: edouard@2643: