etherlab/EtherCATManagementEditor.py
changeset 2365 bc07b9910cdb
parent 2364 4ea781f30555
child 2366 d635680e4c2c
equal deleted inserted replaced
2364:4ea781f30555 2365:bc07b9910cdb
   602             self.Controler.CommonMethod.Check_PREOP = True
   602             self.Controler.CommonMethod.Check_PREOP = True
   603             write_flag = True
   603             write_flag = True
   604         if check[3:4] == 'w' :
   604         if check[3:4] == 'w' :
   605             self.Controler.CommonMethod.Check_SAFEOP = True
   605             self.Controler.CommonMethod.Check_SAFEOP = True
   606             write_flag = True
   606             write_flag = True
   607         if check[5:] =='w' :
   607         if check[5:] == 'w' :
   608             self.Controler.CommonMethod.Check_OP = True
   608             self.Controler.CommonMethod.Check_OP = True
   609             write_flag = True
   609             write_flag = True
   610 
   610 
   611         return write_flag
   611         return write_flag
   612 
   612 
  1048     def SetEEPROMData(self):
  1048     def SetEEPROMData(self):
  1049         """
  1049         """
  1050         Set data based on slave EEPROM.
  1050         Set data based on slave EEPROM.
  1051         """
  1051         """
  1052         # sii_dict = { Parameter : (WordAddress, WordSize) }
  1052         # sii_dict = { Parameter : (WordAddress, WordSize) }
  1053         sii_dict= { 'PDIControl' :                          ( '0', 1),
  1053         sii_dict = {
  1054                     'PDIConfiguration' :                    ( '1', 1),
  1054             'PDIControl' :                          ( '0', 1),
  1055                     'PulseLengthOfSYNCSignals' :            ( '2', 1),
  1055             'PDIConfiguration' :                    ( '1', 1),
  1056                     'ExtendedPDIConfiguration' :            ( '3', 1),
  1056             'PulseLengthOfSYNCSignals' :            ( '2', 1),
  1057                     'ConfiguredStationAlias' :              ( '4', 1),
  1057             'ExtendedPDIConfiguration' :            ( '3', 1),
  1058                     'Checksum' :                            ( '7', 1),
  1058             'ConfiguredStationAlias' :              ( '4', 1),
  1059                     'VendorID' :                            ( '8', 2),
  1059             'Checksum' :                            ( '7', 1),
  1060                     'ProductCode' :                         ( 'a', 2),
  1060             'VendorID' :                            ( '8', 2),
  1061                     'RevisionNumber' :                      ( 'c', 2),
  1061             'ProductCode' :                         ( 'a', 2),
  1062                     'SerialNumber' :                        ( 'e', 2),
  1062             'RevisionNumber' :                      ( 'c', 2),
  1063                     'Execution Delay' :                     ('10', 1),
  1063             'SerialNumber' :                        ( 'e', 2),
  1064                     'Port0Delay' :                          ('11', 1),
  1064             'Execution Delay' :                     ('10', 1),
  1065                     'Port1Delay' :                          ('12', 1),
  1065             'Port0Delay' :                          ('11', 1),
  1066                     'BootstrapReceiveMailboxOffset' :       ('14', 1),
  1066             'Port1Delay' :                          ('12', 1),
  1067                     'BootstrapReceiveMailboxSize' :         ('15', 1),
  1067             'BootstrapReceiveMailboxOffset' :       ('14', 1),
  1068                     'BootstrapSendMailboxOffset' :          ('16', 1),
  1068             'BootstrapReceiveMailboxSize' :         ('15', 1),
  1069                     'BootstrapSendMailboxSize' :            ('17', 1),
  1069             'BootstrapSendMailboxOffset' :          ('16', 1),
  1070                     'StandardReceiveMailboxOffset' :        ('18', 1),
  1070             'BootstrapSendMailboxSize' :            ('17', 1),
  1071                     'StandardReceiveMailboxSize' :          ('19', 1),
  1071             'StandardReceiveMailboxOffset' :        ('18', 1),
  1072                     'StandardSendMailboxOffset' :           ('1a', 1),
  1072             'StandardReceiveMailboxSize' :          ('19', 1),
  1073                     'StandardSendMailboxSize' :             ('1b', 1),
  1073             'StandardSendMailboxOffset' :           ('1a', 1),
  1074                     'MailboxProtocol' :                     ('1c', 1),
  1074             'StandardSendMailboxSize' :             ('1b', 1),
  1075                     'Size' :                                ('3e', 1),
  1075             'MailboxProtocol' :                     ('1c', 1),
  1076                     'Version' :                             ('3f', 1),
  1076             'Size' :                                ('3e', 1),
  1077                     'First Category Type/Vendor Specific' : ('40', 1),
  1077             'Version' :                             ('3f', 1),
  1078                     'Following Category Word Size' :        ('41', 1),
  1078             'First Category Type/Vendor Specific' : ('40', 1),
  1079                     'Category Data' :                       ('42', 1),
  1079             'Following Category Word Size' :        ('41', 1),
  1080                 }
  1080             'Category Data' :                       ('42', 1),
       
  1081         }
  1081 
  1082 
  1082         # Config Data: EEPROM Size, PDI Type, Device Emulation
  1083         # Config Data: EEPROM Size, PDI Type, Device Emulation
  1083         # EEPROM's data in address '0x003f' is Size of EEPROM in KBit-1
  1084         # EEPROM's data in address '0x003f' is Size of EEPROM in KBit-1
  1084         eeprom_size = str((int(self.GetWordAddressData( sii_dict.get('Size'), 10 ))+1)/8*1024)
  1085         eeprom_size = str((int(self.GetWordAddressData( sii_dict.get('Size'), 10 ))+1)/8*1024)
  1085         # Find PDI Type in pdiType dictionary
  1086         # Find PDI Type in pdiType dictionary
  1108         # Mailbox
  1109         # Mailbox
  1109         # EEORPOM's word address '1c' indicates supported mailbox protocol.
  1110         # EEORPOM's word address '1c' indicates supported mailbox protocol.
  1110         # each value of mailbox protocol :
  1111         # each value of mailbox protocol :
  1111         # VoE(0x0020), SoE(0x0010), FoE(0x0008), CoE(0x0004), EoE(0x0002), AoE(0x0001)
  1112         # VoE(0x0020), SoE(0x0010), FoE(0x0008), CoE(0x0004), EoE(0x0002), AoE(0x0001)
  1112         supported_mailbox = ""
  1113         supported_mailbox = ""
  1113         mailbox_protocol=["VoE,  ", "SoE,  ", "FoE,  ", "CoE,  ", "EoE,  ", "AoE,  "]
  1114         mailbox_protocol = ["VoE,  ", "SoE,  ", "FoE,  ", "CoE,  ", "EoE,  ", "AoE,  "]
  1114         mailbox_data = "{:0>8b}".format(int(self.GetWordAddressData( sii_dict.get('MailboxProtocol'), 16 ), 16))
  1115         mailbox_data = "{:0>8b}".format(int(self.GetWordAddressData( sii_dict.get('MailboxProtocol'), 16 ), 16))
  1115         for protocol in range(6):
  1116         for protocol in range(6):
  1116             if mailbox_data[protocol+2] == '1':
  1117             if mailbox_data[protocol+2] == '1':
  1117                 supported_mailbox += mailbox_protocol[protocol]
  1118                 supported_mailbox += mailbox_protocol[protocol]
  1118         supported_mailbox = supported_mailbox.strip(",  ")
  1119         supported_mailbox = supported_mailbox.strip(",  ")
  1186 
  1187 
  1187         wx.Panel.__init__(self, parent, -1, size=(350, 500))
  1188         wx.Panel.__init__(self, parent, -1, size=(350, 500))
  1188 
  1189 
  1189         self.Tree = wx.gizmos.TreeListCtrl(self, -1, size=(350, 500),
  1190         self.Tree = wx.gizmos.TreeListCtrl(self, -1, size=(350, 500),
  1190                                            style=wx.TR_DEFAULT_STYLE
  1191                                            style=wx.TR_DEFAULT_STYLE
  1191                                                 |wx.TR_FULL_ROW_HIGHLIGHT
  1192                                                | wx.TR_FULL_ROW_HIGHLIGHT
  1192                                                 |wx.TR_HIDE_ROOT
  1193                                                | wx.TR_HIDE_ROOT
  1193                                                 |wx.TR_COLUMN_LINES
  1194                                                | wx.TR_COLUMN_LINES
  1194                                                 |wx.TR_ROW_LINES)
  1195                                                | wx.TR_ROW_LINES)
  1195 
  1196 
  1196         self.Tree.AddColumn("Description", width=200)
  1197         self.Tree.AddColumn("Description", width=200)
  1197         self.Tree.AddColumn("Value", width=140)
  1198         self.Tree.AddColumn("Value", width=140)
  1198         self.Tree.SetMainColumn(0)
  1199         self.Tree.SetMainColumn(0)
  1199 
  1200 
  1700                 row_data.append('0x'+reg_word)
  1701                 row_data.append('0x'+reg_word)
  1701 
  1702 
  1702                 # append ASCII value
  1703                 # append ASCII value
  1703                 char_data = ""
  1704                 char_data = ""
  1704                 for iter in range(2):
  1705                 for iter in range(2):
  1705                     if int(reg_word[iter*2:iter*2+2], 16)>=32 and int(reg_word[iter*2:iter*2+2], 16)<=126:
  1706                     if int(reg_word[iter*2:iter*2+2], 16) >= 32 and int(reg_word[iter*2:iter*2+2], 16) <= 126:
  1706                         char_data = char_data + chr(int(reg_word[iter*2:iter*2+2], 16))
  1707                         char_data = char_data + chr(int(reg_word[iter*2:iter*2+2], 16))
  1707                     else:
  1708                     else:
  1708                         char_data = char_data + "."
  1709                         char_data = char_data + "."
  1709                 row_data.append(char_data)
  1710                 row_data.append(char_data)
  1710 
  1711 
  1741         @param event: wx.EVT_CHECKBOX object
  1742         @param event: wx.EVT_CHECKBOX object
  1742         """
  1743         """
  1743 
  1744 
  1744         # If "Compact View" Checkbox is True
  1745         # If "Compact View" Checkbox is True
  1745         ## 'event' is argument of this method or event of checkbox.
  1746         ## 'event' is argument of this method or event of checkbox.
  1746         if event==True or event.GetEventObject().GetValue():
  1747         if event == True or event.GetEventObject().GetValue():
  1747             self.CompactFlag = True
  1748             self.CompactFlag = True
  1748 
  1749 
  1749             reg_compact_data = []
  1750             reg_compact_data = []
  1750             page_row = [0, 0, 0, 0]
  1751             page_row = [0, 0, 0, 0]
  1751             for index in range(4):
  1752             for index in range(4):
  1986 
  1987 
  1987         # Check if this register's detail description is exist or not,
  1988         # Check if this register's detail description is exist or not,
  1988         # and create data structure for the detail description table ; sub grid
  1989         # and create data structure for the detail description table ; sub grid
  1989         if address in self.RegisterAccessPanel.RegisterSubGridDict:
  1990         if address in self.RegisterAccessPanel.RegisterSubGridDict:
  1990             for element in self.RegisterAccessPanel.RegisterSubGridDict[address]:
  1991             for element in self.RegisterAccessPanel.RegisterSubGridDict[address]:
  1991                 row_data =[]
  1992                 row_data = []
  1992                 row_data.append(element[BIT_RANGE])
  1993                 row_data.append(element[BIT_RANGE])
  1993                 row_data.append(element[NAME])
  1994                 row_data.append(element[NAME])
  1994                 bin_data = "{:0>16b}".format(int(self.GetCellValue(event.GetRow(), 1)))
  1995                 bin_data = "{:0>16b}".format(int(self.GetCellValue(event.GetRow(), 1)))
  1995                 value_range = element[BIT_RANGE].split('-')
  1996                 value_range = element[BIT_RANGE].split('-')
  1996                 value = (bin_data[8:16][::-1]+bin_data[0:8][::-1])[int(value_range[0]):(int(value_range[-1])+1)][::-1]
  1997                 value = (bin_data[8:16][::-1]+bin_data[0:8][::-1])[int(value_range[0]):(int(value_range[-1])+1)][::-1]
  2029 
  2030 
  2030                     # reg_write
  2031                     # reg_write
  2031                     # ex) ethercat reg_write -p 0 -t uint16 0x0000 0x0000
  2032                     # ex) ethercat reg_write -p 0 -t uint16 0x0000 0x0000
  2032                     return_val = self.Controler.CommonMethod.RegWrite('0x'+self.GetRowLabelValue(event.GetRow()), dlg.GetValue())
  2033                     return_val = self.Controler.CommonMethod.RegWrite('0x'+self.GetRowLabelValue(event.GetRow()), dlg.GetValue())
  2033 
  2034 
  2034                     if len(return_val)==0:
  2035                     if len(return_val) == 0:
  2035                         # set dec
  2036                         # set dec
  2036                         self.SetCellValue(event.GetRow(), 1, str(int(dlg.GetValue(), 0)))
  2037                         self.SetCellValue(event.GetRow(), 1, str(int(dlg.GetValue(), 0)))
  2037                         # set hex
  2038                         # set hex
  2038                         hex_data = '0x'+"{:0>4x}".format(int(dlg.GetValue(), 0))
  2039                         hex_data = '0x'+"{:0>4x}".format(int(dlg.GetValue(), 0))
  2039                         self.SetCellValue(event.GetRow(), 2, hex_data)
  2040                         self.SetCellValue(event.GetRow(), 2, hex_data)
  2040                         # set char
  2041                         # set char
  2041                         char_data = ""
  2042                         char_data = ""
  2042                         # If hex_data is been able to convert to ascii code, append ascii code.
  2043                         # If hex_data is been able to convert to ascii code, append ascii code.
  2043                         for iter in range(2):
  2044                         for iter in range(2):
  2044                             if int(hex_data[(iter+1)*2:(iter+2)*2], 16)>=32 and int(hex_data[(iter+1)*2:(iter+2)*2], 16)<=126:
  2045                             if int(hex_data[(iter+1)*2:(iter+2)*2], 16) >= 32 and int(hex_data[(iter+1)*2:(iter+2)*2], 16) <= 126:
  2045                                 char_data = char_data + chr(int(hex_data[(iter+1)*2:(iter+2)*2], 16))
  2046                                 char_data = char_data + chr(int(hex_data[(iter+1)*2:(iter+2)*2], 16))
  2046                             else:
  2047                             else:
  2047                                 char_data = char_data + "."
  2048                                 char_data = char_data + "."
  2048 
  2049 
  2049                         self.SetCellValue(event.GetRow(), 3, char_data)
  2050                         self.SetCellValue(event.GetRow(), 3, char_data)