etherlab/CommonEtherCATFunction.py
changeset 2356 c26e0c66d8d5
parent 2355 fec77f2b9e07
child 2358 8e5a9830867e
equal deleted inserted replaced
2355:fec77f2b9e07 2356:c26e0c66d8d5
    42         for name in names:
    42         for name in names:
    43             if name.getLcId() == 1033:
    43             if name.getLcId() == 1033:
    44                 return name.getcontent()
    44                 return name.getcontent()
    45     return default
    45     return default
    46 
    46 
    47 #--------------------------------------------------
    47 # --------------------------------------------------
    48 #         Remote Exec Etherlab Commands
    48 #         Remote Exec Etherlab Commands
    49 #--------------------------------------------------
    49 # --------------------------------------------------
    50 
    50 
    51 # --------------------- for master ---------------------------
    51 # --------------------- for master ---------------------------
    52 MASTER_STATE = """
    52 MASTER_STATE = """
    53 import commands
    53 import commands
    54 result = commands.getoutput("ethercat master")
    54 result = commands.getoutput("ethercat master")
   134 import commands
   134 import commands
   135 result = commands.getoutput("ethercat rescan -p %d")
   135 result = commands.getoutput("ethercat rescan -p %d")
   136 returnVal =result
   136 returnVal =result
   137 """
   137 """
   138 
   138 
   139 #--------------------------------------------------
   139 # --------------------------------------------------
   140 #    Common Method For EtherCAT Management
   140 #    Common Method For EtherCAT Management
   141 #--------------------------------------------------
   141 # --------------------------------------------------
   142 class _CommonSlave:
   142 class _CommonSlave:
   143 
   143 
   144     # ----- Data Structure for ethercat management ----
   144     # ----- Data Structure for ethercat management ----
   145     SlaveState = ""
   145     SlaveState = ""
   146 
   146 
   179         """
   179         """
   180         self.Controler = controler
   180         self.Controler = controler
   181 
   181 
   182         self.ClearSDODataSet()
   182         self.ClearSDODataSet()
   183 
   183 
   184     #-------------------------------------------------------------------------------
   184     # -------------------------------------------------------------------------------
   185     #                        Used Master State
   185     #                        Used Master State
   186     #-------------------------------------------------------------------------------
   186     # -------------------------------------------------------------------------------
   187     def GetMasterState(self):
   187     def GetMasterState(self):
   188         """
   188         """
   189         Execute "ethercat master" command and parse the execution result
   189         Execute "ethercat master" command and parse the execution result
   190         @return MasterState
   190         @return MasterState
   191         """
   191         """
   205                     value.remove('(attached)')
   205                     value.remove('(attached)')
   206                 master_state[key] = value
   206                 master_state[key] = value
   207 
   207 
   208         return master_state
   208         return master_state
   209 
   209 
   210     #-------------------------------------------------------------------------------
   210     # -------------------------------------------------------------------------------
   211     #                        Used Slave State
   211     #                        Used Slave State
   212     #-------------------------------------------------------------------------------
   212     # -------------------------------------------------------------------------------
   213     def RequestSlaveState(self, command):
   213     def RequestSlaveState(self, command):
   214         """
   214         """
   215         Set slave state to the specified one using "ethercat states -p %d %s" command.
   215         Set slave state to the specified one using "ethercat states -p %d %s" command.
   216         Command example : "ethercat states -p 0 PREOP" (target slave position and target state are given.)
   216         Command example : "ethercat states -p 0 PREOP" (target slave position and target state are given.)
   217         @param command : target slave state
   217         @param command : target slave state
   226         """
   226         """
   227         error, return_val = self.Controler.RemoteExec(GET_SLAVE, return_val = None)
   227         error, return_val = self.Controler.RemoteExec(GET_SLAVE, return_val = None)
   228         self.SlaveState = return_val
   228         self.SlaveState = return_val
   229         return return_val
   229         return return_val
   230 
   230 
   231     #-------------------------------------------------------------------------------
   231     # -------------------------------------------------------------------------------
   232     #                        Used SDO Management
   232     #                        Used SDO Management
   233     #-------------------------------------------------------------------------------
   233     # -------------------------------------------------------------------------------
   234     def GetSlaveSDOFromSlave(self):
   234     def GetSlaveSDOFromSlave(self):
   235         """
   235         """
   236         Get SDO objects information of current slave using "ethercat sdos -p %d" command.
   236         Get SDO objects information of current slave using "ethercat sdos -p %d" command.
   237         Command example : "ethercat sdos -p 0"
   237         Command example : "ethercat sdos -p 0"
   238         @return return_val : execution results of "ethercat sdos" command (need to be parsed later)
   238         @return return_val : execution results of "ethercat sdos" command (need to be parsed later)
   268         Clear the specified SDO entry information.
   268         Clear the specified SDO entry information.
   269         """
   269         """
   270         for count in range(6):
   270         for count in range(6):
   271             self.SaveSDOData.append([])
   271             self.SaveSDOData.append([])
   272 
   272 
   273     #-------------------------------------------------------------------------------
   273     # -------------------------------------------------------------------------------
   274     #                        Used PDO Monitoring
   274     #                        Used PDO Monitoring
   275     #-------------------------------------------------------------------------------
   275     # -------------------------------------------------------------------------------
   276     def RequestPDOInfo(self):
   276     def RequestPDOInfo(self):
   277         """
   277         """
   278         Load slave information from RootClass (XML data) and parse the information (calling SlavePDOData() method).
   278         Load slave information from RootClass (XML data) and parse the information (calling SlavePDOData() method).
   279         """
   279         """
   280         # Load slave information from ESI XML file (def EthercatMaster.py)
   280         # Load slave information from ESI XML file (def EthercatMaster.py)
   395         self.TxPDOInfos = []
   395         self.TxPDOInfos = []
   396         self.TxPDOCategorys = []
   396         self.TxPDOCategorys = []
   397         self.RxPDOInfos = []
   397         self.RxPDOInfos = []
   398         self.RxPDOCategorys = []
   398         self.RxPDOCategorys = []
   399 
   399 
   400     #-------------------------------------------------------------------------------
   400     # -------------------------------------------------------------------------------
   401     #                        Used EEPROM Management
   401     #                        Used EEPROM Management
   402     #-------------------------------------------------------------------------------
   402     # -------------------------------------------------------------------------------
   403     # Base data types in ETG2000; format = {"Name": "BitSize"}
   403     # Base data types in ETG2000; format = {"Name": "BitSize"}
   404     BaseDataTypeDict = {"BOOL": "01",
   404     BaseDataTypeDict = {"BOOL": "01",
   405                         "SINT": "02",
   405                         "SINT": "02",
   406                         "INT": "03",
   406                         "INT": "03",
   407                         "DINT": "04",
   407                         "DINT": "04",
  1517                     eeprom.append(data[0:2])
  1517                     eeprom.append(data[0:2])
  1518                 data = data[2:len(data)]
  1518                 data = data[2:len(data)]
  1519 
  1519 
  1520         return eeprom
  1520         return eeprom
  1521 
  1521 
  1522     #-------------------------------------------------------------------------------
  1522     # -------------------------------------------------------------------------------
  1523     #                        Used Register Access
  1523     #                        Used Register Access
  1524     #-------------------------------------------------------------------------------
  1524     # -------------------------------------------------------------------------------
  1525     def RegRead(self, offset, length):
  1525     def RegRead(self, offset, length):
  1526         """
  1526         """
  1527         Read slave ESC register content using "ethercat reg_read -p %d %s %s" command.
  1527         Read slave ESC register content using "ethercat reg_read -p %d %s %s" command.
  1528         Command example : "ethercat reg_read -p 0 0x0c00 0x0400"
  1528         Command example : "ethercat reg_read -p 0 0x0c00 0x0400"
  1529         @param offset : register address
  1529         @param offset : register address
  1549         Synchronize EEPROM data in master controller with the data in slave device after EEPROM write.
  1549         Synchronize EEPROM data in master controller with the data in slave device after EEPROM write.
  1550         Command example : "ethercat rescan -p 0"
  1550         Command example : "ethercat rescan -p 0"
  1551         """
  1551         """
  1552         error, return_val = self.Controler.RemoteExec(RESCAN%(self.Controler.GetSlavePos()), return_val = None)
  1552         error, return_val = self.Controler.RemoteExec(RESCAN%(self.Controler.GetSlavePos()), return_val = None)
  1553 
  1553 
  1554     #-------------------------------------------------------------------------------
  1554     # -------------------------------------------------------------------------------
  1555     #                        Common Use Methods
  1555     #                        Common Use Methods
  1556     #-------------------------------------------------------------------------------
  1556     # -------------------------------------------------------------------------------
  1557     def CheckConnect(self, cyclic_flag):
  1557     def CheckConnect(self, cyclic_flag):
  1558         """
  1558         """
  1559         Check connection status (1) between Beremiz and the master (2) between the master and the slave.
  1559         Check connection status (1) between Beremiz and the master (2) between the master and the slave.
  1560         @param cyclic_flag: 0 - one shot, 1 - periodic
  1560         @param cyclic_flag: 0 - one shot, 1 - periodic
  1561         @return True or False
  1561         @return True or False