[Ethercat Device]
Description
Initialize the object of this EtherCAT slave device class and attach it to the object of EthercatMaster class based on the ID of the slave device on the network.
Syntax
int attach(uint16_t slave_id, EthercatMaster *master, EthercatAttachMode mode = ECAT_SLAVE_NO);
int attach(uint16_t slave_id, EthercatMaster &master, EthercatAttachMode mode = ECAT_SLAVE_NO);
Parameters
[in] uint16_t slave_id
The ID of the slave device on the EtherCAT bus. The definition of this ID is determined based on the mode parameter.[in] EthercatMaster *master
The object of EthercatMaster class to which it should be attached.[in] EthercatAttachMode mode
The definition of slave_id:ECAT_SLAVE_NO
The sequence number of the EtherCAT slave device on the network, 0 indicates the first slave device, 1 indicates the second slave device, and so on.ECAT_ALIAS_ADDRESS
The alias address of the slave device on the network, which is defined at byte offset 8 in the SII EEPROM of the slave device.
Return Value
Return an error code. If the returned value is zero, it indicates a successful execution of this function.
Comment
The function must be called after EthercatMaster::begin()
. This function is blocking and cannot be called within the Cyclic Callback.
Example
#include "Ethercat.h" EthercatMaster master; EthercatDevice_Generic slave; void setup() { master.begin(); slave.attach(0, master); master.start(); } void loop() { //... }
Please see the EtherCAT Library User Manual for more QEC EtherCAT instructions and API usage.