etherlab/CommonEtherCATFunction.py
changeset 2366 d635680e4c2c
parent 2365 bc07b9910cdb
child 2367 0fb54172a18b
equal deleted inserted replaced
2365:bc07b9910cdb 2366:d635680e4c2c
   192         Execute "ethercat master" command and parse the execution result
   192         Execute "ethercat master" command and parse the execution result
   193         @return MasterState
   193         @return MasterState
   194         """
   194         """
   195 
   195 
   196         # exectute "ethercat master" command
   196         # exectute "ethercat master" command
   197         error, return_val = self.Controler.RemoteExec(MASTER_STATE, return_val = None)
   197         error, return_val = self.Controler.RemoteExec(MASTER_STATE, return_val=None)
   198         master_state = {}
   198         master_state = {}
   199         # parse the reslut
   199         # parse the reslut
   200         for each_line in return_val.splitlines():
   200         for each_line in return_val.splitlines():
   201             if len(each_line) > 0 :
   201             if len(each_line) > 0 :
   202                 chunks = each_line.strip().split(':', 1)
   202                 chunks = each_line.strip().split(':', 1)
   217         """
   217         """
   218         Set slave state to the specified one using "ethercat states -p %d %s" command.
   218         Set slave state to the specified one using "ethercat states -p %d %s" command.
   219         Command example : "ethercat states -p 0 PREOP" (target slave position and target state are given.)
   219         Command example : "ethercat states -p 0 PREOP" (target slave position and target state are given.)
   220         @param command : target slave state
   220         @param command : target slave state
   221         """
   221         """
   222         error, return_val = self.Controler.RemoteExec(SLAVE_STATE % (self.Controler.GetSlavePos(), command), return_val = None)
   222         error, return_val = self.Controler.RemoteExec(SLAVE_STATE % (self.Controler.GetSlavePos(), command), return_val=None)
   223 
   223 
   224     def GetSlaveStateFromSlave(self):
   224     def GetSlaveStateFromSlave(self):
   225         """
   225         """
   226         Get slave information using "ethercat slaves" command and store the information into internal data structure
   226         Get slave information using "ethercat slaves" command and store the information into internal data structure
   227         (self.SlaveState) for "Slave State"
   227         (self.SlaveState) for "Slave State"
   228         return_val example : 0  0:0  PREOP  +  EL9800 (V4.30) (PIC24, SPI, ET1100)
   228         return_val example : 0  0:0  PREOP  +  EL9800 (V4.30) (PIC24, SPI, ET1100)
   229         """
   229         """
   230         error, return_val = self.Controler.RemoteExec(GET_SLAVE, return_val = None)
   230         error, return_val = self.Controler.RemoteExec(GET_SLAVE, return_val=None)
   231         self.SlaveState = return_val
   231         self.SlaveState = return_val
   232         return return_val
   232         return return_val
   233 
   233 
   234     # -------------------------------------------------------------------------------
   234     # -------------------------------------------------------------------------------
   235     #                        Used SDO Management
   235     #                        Used SDO Management
   238         """
   238         """
   239         Get SDO objects information of current slave using "ethercat sdos -p %d" command.
   239         Get SDO objects information of current slave using "ethercat sdos -p %d" command.
   240         Command example : "ethercat sdos -p 0"
   240         Command example : "ethercat sdos -p 0"
   241         @return return_val : execution results of "ethercat sdos" command (need to be parsed later)
   241         @return return_val : execution results of "ethercat sdos" command (need to be parsed later)
   242         """
   242         """
   243         error, return_val = self.Controler.RemoteExec(SLAVE_SDO % (self.Controler.GetSlavePos()), return_val = None)
   243         error, return_val = self.Controler.RemoteExec(SLAVE_SDO % (self.Controler.GetSlavePos()), return_val=None)
   244         return return_val
   244         return return_val
   245 
   245 
   246     def SDODownload(self, data_type, idx, sub_idx, value):
   246     def SDODownload(self, data_type, idx, sub_idx, value):
   247         """
   247         """
   248         Set an SDO object value to user-specified value using "ethercat download" command.
   248         Set an SDO object value to user-specified value using "ethercat download" command.
   250         @param data_type : data type of SDO entry
   250         @param data_type : data type of SDO entry
   251         @param idx : index of the SDO entry
   251         @param idx : index of the SDO entry
   252         @param sub_idx : subindex of the SDO entry
   252         @param sub_idx : subindex of the SDO entry
   253         @param value : value of SDO entry
   253         @param value : value of SDO entry
   254         """
   254         """
   255         error, return_val = self.Controler.RemoteExec(SDO_DOWNLOAD % (data_type, self.Controler.GetSlavePos(), idx, sub_idx, value), return_val = None)
   255         error, return_val = self.Controler.RemoteExec(SDO_DOWNLOAD % (data_type, self.Controler.GetSlavePos(), idx, sub_idx, value), return_val=None)
   256 
   256 
   257     def BackupSDODataSet(self):
   257     def BackupSDODataSet(self):
   258         """
   258         """
   259         Back-up current SDO entry information to restore the SDO data
   259         Back-up current SDO entry information to restore the SDO data
   260          in case that the user cancels SDO update operation.
   260          in case that the user cancels SDO update operation.
   555         """
   555         """
   556         Get slave EEPROM contents maintained by master device using "ethercat sii_read -p %d" command.
   556         Get slave EEPROM contents maintained by master device using "ethercat sii_read -p %d" command.
   557         Command example : "ethercat sii_read -p 0"
   557         Command example : "ethercat sii_read -p 0"
   558         @return return_val : result of "ethercat sii_read" (binary data)
   558         @return return_val : result of "ethercat sii_read" (binary data)
   559         """
   559         """
   560         error, return_val = self.Controler.RemoteExec(SII_READ % (self.Controler.GetSlavePos()), return_val = None)
   560         error, return_val = self.Controler.RemoteExec(SII_READ % (self.Controler.GetSlavePos()), return_val=None)
   561         self.SiiData = return_val
   561         self.SiiData = return_val
   562         return return_val
   562         return return_val
   563 
   563 
   564     def SiiWrite(self, binary):
   564     def SiiWrite(self, binary):
   565         """
   565         """
   566         Overwrite slave EEPROM contents using "ethercat sii_write -p %d" command.
   566         Overwrite slave EEPROM contents using "ethercat sii_write -p %d" command.
   567         Command example : "ethercat sii_write -p 0 - (binary contents)"
   567         Command example : "ethercat sii_write -p 0 - (binary contents)"
   568         @param binary : EEPROM contents in binary data format
   568         @param binary : EEPROM contents in binary data format
   569         @return return_val : result of "ethercat sii_write" (If it succeeds, the return value is NULL.)
   569         @return return_val : result of "ethercat sii_write" (If it succeeds, the return value is NULL.)
   570         """
   570         """
   571         error, return_val = self.Controler.RemoteExec(SII_WRITE % (self.Controler.GetSlavePos()), return_val = None, sii_data = binary)
   571         error, return_val = self.Controler.RemoteExec(SII_WRITE % (self.Controler.GetSlavePos()), return_val=None, sii_data=binary)
   572         return return_val
   572         return return_val
   573 
   573 
   574     def LoadData(self):
   574     def LoadData(self):
   575         """
   575         """
   576         Loading data from EEPROM use Sii_Read Method
   576         Loading data from EEPROM use Sii_Read Method
  1531         Command example : "ethercat reg_read -p 0 0x0c00 0x0400"
  1531         Command example : "ethercat reg_read -p 0 0x0c00 0x0400"
  1532         @param offset : register address
  1532         @param offset : register address
  1533         @param length : register length
  1533         @param length : register length
  1534         @return return_val : register data
  1534         @return return_val : register data
  1535         """
  1535         """
  1536         error, return_val = self.Controler.RemoteExec(REG_READ % (self.Controler.GetSlavePos(), offset, length), return_val = None)
  1536         error, return_val = self.Controler.RemoteExec(REG_READ % (self.Controler.GetSlavePos(), offset, length), return_val=None)
  1537         return return_val
  1537         return return_val
  1538 
  1538 
  1539     def RegWrite(self, address, data):
  1539     def RegWrite(self, address, data):
  1540         """
  1540         """
  1541         Write data to slave ESC register using "ethercat reg_write -p %d %s %s" command.
  1541         Write data to slave ESC register using "ethercat reg_write -p %d %s %s" command.
  1542         Command example : "ethercat reg_write -p 0 0x0c04 0x0001"
  1542         Command example : "ethercat reg_write -p 0 0x0c04 0x0001"
  1543         @param address : register address
  1543         @param address : register address
  1544         @param data : data to write
  1544         @param data : data to write
  1545         @return return_val : the execution result of "ethercat reg_write" (for error check)
  1545         @return return_val : the execution result of "ethercat reg_write" (for error check)
  1546         """
  1546         """
  1547         error, return_val = self.Controler.RemoteExec(REG_WRITE % (self.Controler.GetSlavePos(), address, data), return_val = None)
  1547         error, return_val = self.Controler.RemoteExec(REG_WRITE % (self.Controler.GetSlavePos(), address, data), return_val=None)
  1548         return return_val
  1548         return return_val
  1549 
  1549 
  1550     def Rescan(self):
  1550     def Rescan(self):
  1551         """
  1551         """
  1552         Synchronize EEPROM data in master controller with the data in slave device after EEPROM write.
  1552         Synchronize EEPROM data in master controller with the data in slave device after EEPROM write.
  1553         Command example : "ethercat rescan -p 0"
  1553         Command example : "ethercat rescan -p 0"
  1554         """
  1554         """
  1555         error, return_val = self.Controler.RemoteExec(RESCAN % (self.Controler.GetSlavePos()), return_val = None)
  1555         error, return_val = self.Controler.RemoteExec(RESCAN % (self.Controler.GetSlavePos()), return_val=None)
  1556 
  1556 
  1557     # -------------------------------------------------------------------------------
  1557     # -------------------------------------------------------------------------------
  1558     #                        Common Use Methods
  1558     #                        Common Use Methods
  1559     # -------------------------------------------------------------------------------
  1559     # -------------------------------------------------------------------------------
  1560     def CheckConnect(self, cyclic_flag):
  1560     def CheckConnect(self, cyclic_flag):
  1564         @return True or False
  1564         @return True or False
  1565         """
  1565         """
  1566         if self.Controler.GetCTRoot()._connector is not None:
  1566         if self.Controler.GetCTRoot()._connector is not None:
  1567             # Check connection between the master and the slave.
  1567             # Check connection between the master and the slave.
  1568             # Command example : "ethercat xml -p 0"
  1568             # Command example : "ethercat xml -p 0"
  1569             error, return_val = self.Controler.RemoteExec(SLAVE_XML % (self.Controler.GetSlavePos()), return_val = None)
  1569             error, return_val = self.Controler.RemoteExec(SLAVE_XML % (self.Controler.GetSlavePos()), return_val=None)
  1570             number_of_lines = return_val.split("\n")
  1570             number_of_lines = return_val.split("\n")
  1571             if len(number_of_lines) <= 2 :  # No slave connected to the master controller
  1571             if len(number_of_lines) <= 2 :  # No slave connected to the master controller
  1572                 if not cyclic_flag :
  1572                 if not cyclic_flag :
  1573                     self.CreateErrorDialog('No connected slaves')
  1573                     self.CreateErrorDialog('No connected slaves')
  1574                 return False
  1574                 return False