197 # exectute "ethercat master" command |
197 # exectute "ethercat master" command |
198 error, return_val = self.Controler.RemoteExec(MASTER_STATE, return_val=None) |
198 error, return_val = self.Controler.RemoteExec(MASTER_STATE, return_val=None) |
199 master_state = {} |
199 master_state = {} |
200 # parse the reslut |
200 # parse the reslut |
201 for each_line in return_val.splitlines(): |
201 for each_line in return_val.splitlines(): |
202 if len(each_line) > 0 : |
202 if len(each_line) > 0: |
203 chunks = each_line.strip().split(':', 1) |
203 chunks = each_line.strip().split(':', 1) |
204 key = chunks[0] |
204 key = chunks[0] |
205 value = [] |
205 value = [] |
206 if len(chunks) > 1 : |
206 if len(chunks) > 1: |
207 value = chunks[1].split() |
207 value = chunks[1].split() |
208 if '(attached)' in value: |
208 if '(attached)' in value: |
209 value.remove('(attached)') |
209 value.remove('(attached)') |
210 master_state[key] = value |
210 master_state[key] = value |
211 |
211 |
288 device, alignment = self.Controler.CTNParent.GetModuleInfos(type_infos) |
288 device, alignment = self.Controler.CTNParent.GetModuleInfos(type_infos) |
289 # Initialize PDO data set |
289 # Initialize PDO data set |
290 self.ClearDataSet() |
290 self.ClearDataSet() |
291 |
291 |
292 # if 'device' object is valid, call SavePDOData() to parse PDO data |
292 # if 'device' object is valid, call SavePDOData() to parse PDO data |
293 if device is not None : |
293 if device is not None: |
294 self.SavePDOData(device) |
294 self.SavePDOData(device) |
295 |
295 |
296 def SavePDOData(self, device): |
296 def SavePDOData(self, device): |
297 """ |
297 """ |
298 Parse PDO data and store the results in TXPDOCategory and RXPDOCategory |
298 Parse PDO data and store the results in TXPDOCategory and RXPDOCategory |
314 for entry in entries: |
314 for entry in entries: |
315 # Save index and subindex |
315 # Save index and subindex |
316 index = ExtractHexDecValue(entry.getIndex().getcontent()) |
316 index = ExtractHexDecValue(entry.getIndex().getcontent()) |
317 subindex = ExtractHexDecValue(entry.getSubIndex()) |
317 subindex = ExtractHexDecValue(entry.getSubIndex()) |
318 # if entry name exists, save entry data |
318 # if entry name exists, save entry data |
319 if ExtractName(entry.getName()) is not None : |
319 if ExtractName(entry.getName()) is not None: |
320 entry_infos = { |
320 entry_infos = { |
321 "entry_index" : index, |
321 "entry_index": index, |
322 "subindex" : subindex, |
322 "subindex": subindex, |
323 "name" : ExtractName(entry.getName()), |
323 "name": ExtractName(entry.getName()), |
324 "bitlen" : entry.getBitLen(), |
324 "bitlen": entry.getBitLen(), |
325 "type" : entry.getDataType().getcontent() |
325 "type": entry.getDataType().getcontent() |
326 } |
326 } |
327 self.TxPDOInfo.append(entry_infos) |
327 self.TxPDOInfo.append(entry_infos) |
328 count += 1 |
328 count += 1 |
329 |
329 |
330 categorys = {"pdo_index" : pdo_index, "name" : pdo_name, "number_of_entry" : count} |
330 categorys = {"pdo_index": pdo_index, "name": pdo_name, "number_of_entry": count} |
331 self.TxPDOCategory.append(categorys) |
331 self.TxPDOCategory.append(categorys) |
332 |
332 |
333 # Parsing RxPDO entries |
333 # Parsing RxPDO entries |
334 for pdo, pdo_info in ([(pdo, "Outputs") for pdo in device.getRxPdo()]): |
334 for pdo, pdo_info in ([(pdo, "Outputs") for pdo in device.getRxPdo()]): |
335 # Save pdo_index, entry, and name of each entry |
335 # Save pdo_index, entry, and name of each entry |
344 for entry in entries: |
344 for entry in entries: |
345 # Save index and subindex |
345 # Save index and subindex |
346 index = ExtractHexDecValue(entry.getIndex().getcontent()) |
346 index = ExtractHexDecValue(entry.getIndex().getcontent()) |
347 subindex = ExtractHexDecValue(entry.getSubIndex()) |
347 subindex = ExtractHexDecValue(entry.getSubIndex()) |
348 # if entry name exists, save entry data |
348 # if entry name exists, save entry data |
349 if ExtractName(entry.getName()) is not None : |
349 if ExtractName(entry.getName()) is not None: |
350 entry_infos = { |
350 entry_infos = { |
351 "entry_index" : index, |
351 "entry_index": index, |
352 "subindex" : subindex, |
352 "subindex": subindex, |
353 "name" : ExtractName(entry.getName()), |
353 "name": ExtractName(entry.getName()), |
354 "bitlen" : str(entry.getBitLen()), |
354 "bitlen": str(entry.getBitLen()), |
355 "type" : entry.getDataType().getcontent() |
355 "type": entry.getDataType().getcontent() |
356 } |
356 } |
357 self.RxPDOInfo.append(entry_infos) |
357 self.RxPDOInfo.append(entry_infos) |
358 count += 1 |
358 count += 1 |
359 |
359 |
360 categorys = {"pdo_index" : pdo_index, "name" : pdo_name, "number_of_entry" : count} |
360 categorys = {"pdo_index": pdo_index, "name": pdo_name, "number_of_entry": count} |
361 self.RxPDOCategory.append(categorys) |
361 self.RxPDOCategory.append(categorys) |
362 |
362 |
363 def GetTxPDOCategory(self): |
363 def GetTxPDOCategory(self): |
364 """ |
364 """ |
365 Get TxPDOCategory data structure (Meta informaton of TxPDO). |
365 Get TxPDOCategory data structure (Meta informaton of TxPDO). |
615 if int(digithexstr, 16) >= 32 and int(digithexstr, 16) <= 126: |
615 if int(digithexstr, 16) >= 32 and int(digithexstr, 16) <= 126: |
616 row_text = row_text + chr(int(digithexstr, 16)) |
616 row_text = row_text + chr(int(digithexstr, 16)) |
617 else: |
617 else: |
618 row_text = row_text + "." |
618 row_text = row_text + "." |
619 |
619 |
620 if index != 0 : |
620 if index != 0: |
621 if len(row_code) == (hexview_table_col - 1): |
621 if len(row_code) == (hexview_table_col - 1): |
622 row_code.append(row_text) |
622 row_code.append(row_text) |
623 hex_code.append(row_code) |
623 hex_code.append(row_code) |
624 row_text = "" |
624 row_text = "" |
625 row_code = [] |
625 row_code = [] |
783 eeprom.append(standard_send_mailbox_size[0:2]) |
783 eeprom.append(standard_send_mailbox_size[0:2]) |
784 |
784 |
785 # get supported mailbox protocols for EEPROM offset 0x0038-0x0039; |
785 # get supported mailbox protocols for EEPROM offset 0x0038-0x0039; |
786 data = 0 |
786 data = 0 |
787 mb = device.getMailbox() |
787 mb = device.getMailbox() |
788 if mb is not None : |
788 if mb is not None: |
789 for bit, mbprot in enumerate(mailbox_protocols): |
789 for bit, mbprot in enumerate(mailbox_protocols): |
790 if getattr(mb, "get%s" % mbprot)() is not None: |
790 if getattr(mb, "get%s" % mbprot)() is not None: |
791 data += 1 << bit |
791 data += 1 << bit |
792 data = "{:0>4x}".format(data) |
792 data = "{:0>4x}".format(data) |
793 eeprom.append(data[2:4]) |
793 eeprom.append(data[2:4]) |
1177 eeprom.append("01") # Physical Layer Port info - assume 01 |
1177 eeprom.append("01") # Physical Layer Port info - assume 01 |
1178 # CoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<CoE> |
1178 # CoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<CoE> |
1179 coe_details = 0 |
1179 coe_details = 0 |
1180 mb = device.getMailbox() |
1180 mb = device.getMailbox() |
1181 coe_details = 1 # sdo enabled |
1181 coe_details = 1 # sdo enabled |
1182 if mb is not None : |
1182 if mb is not None: |
1183 coe = mb.getCoE() |
1183 coe = mb.getCoE() |
1184 if coe is not None: |
1184 if coe is not None: |
1185 for bit, flag in enumerate(["SdoInfo", "PdoAssign", "PdoConfig", |
1185 for bit, flag in enumerate(["SdoInfo", "PdoAssign", "PdoConfig", |
1186 "PdoUpload", "CompleteAccess"]): |
1186 "PdoUpload", "CompleteAccess"]): |
1187 if getattr(coe, "get%s" % flag)() is not None: |
1187 if getattr(coe, "get%s" % flag)() is not None: |
1206 eeprom.append("01") |
1206 eeprom.append("01") |
1207 else: |
1207 else: |
1208 eeprom.append("00") |
1208 eeprom.append("00") |
1209 # DS402Channels; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<CoE>: DS402Channels |
1209 # DS402Channels; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<CoE>: DS402Channels |
1210 ds402ch = False |
1210 ds402ch = False |
1211 if mb is not None : |
1211 if mb is not None: |
1212 coe = mb.getCoE() |
1212 coe = mb.getCoE() |
1213 if coe is not None : |
1213 if coe is not None: |
1214 ds402ch = coe.getDS402Channels() |
1214 ds402ch = coe.getDS402Channels() |
1215 eeprom.append("01" if ds402ch in [True, 1] else "00") |
1215 eeprom.append("01" if ds402ch in [True, 1] else "00") |
1216 |
1216 |
1217 # word 6 : SysmanClass(reserved) and Flags |
1217 # word 6 : SysmanClass(reserved) and Flags |
1218 eeprom.append("00") # reserved |
1218 eeprom.append("00") # reserved |
1567 if self.Controler.GetCTRoot()._connector is not None: |
1567 if self.Controler.GetCTRoot()._connector is not None: |
1568 # Check connection between the master and the slave. |
1568 # Check connection between the master and the slave. |
1569 # Command example : "ethercat xml -p 0" |
1569 # Command example : "ethercat xml -p 0" |
1570 error, return_val = self.Controler.RemoteExec(SLAVE_XML % (self.Controler.GetSlavePos()), return_val=None) |
1570 error, return_val = self.Controler.RemoteExec(SLAVE_XML % (self.Controler.GetSlavePos()), return_val=None) |
1571 number_of_lines = return_val.split("\n") |
1571 number_of_lines = return_val.split("\n") |
1572 if len(number_of_lines) <= 2 : # No slave connected to the master controller |
1572 if len(number_of_lines) <= 2: # No slave connected to the master controller |
1573 if not cyclic_flag : |
1573 if not cyclic_flag: |
1574 self.CreateErrorDialog('No connected slaves') |
1574 self.CreateErrorDialog('No connected slaves') |
1575 return False |
1575 return False |
1576 |
1576 |
1577 elif len(number_of_lines) > 2 : |
1577 elif len(number_of_lines) > 2: |
1578 return True |
1578 return True |
1579 else: |
1579 else: |
1580 # The master controller is not connected to Beremiz host |
1580 # The master controller is not connected to Beremiz host |
1581 if not cyclic_flag : |
1581 if not cyclic_flag: |
1582 self.CreateErrorDialog('PLC not connected!') |
1582 self.CreateErrorDialog('PLC not connected!') |
1583 return False |
1583 return False |
1584 |
1584 |
1585 def CreateErrorDialog(self, mention): |
1585 def CreateErrorDialog(self, mention): |
1586 """ |
1586 """ |