The state of an EtherCAT slave

The state of an EtherCAT slave can be gotten through the GetSlaveById, GetAxisByIndex, and GetIOByIndex function and the SlaveStatus structure.

Functions for SlaveStatus

Before you get anything from SlaveStatus, you need to indicate the device you want to get.

GetSlaveById: gets detailed information from a specified slave using the ID.

GetAxisByIndex: gets information from an axis.

GetIOByIndex: gets the information from a specified real or simulated I/O module.

One slave may contain a single or multiple axes. For example, you have eight EtherCAT slaves. One slave contains one device. The order of their ID is like this:

  1. Servo drive – Slave ID: 0 – Servo Index: 0
  2. Servo drive – Slave ID: 1 – Servo Index: 1
  3. I/O module – Slave ID: 2 – I/O Index: 0
  4. I/O module – Slave ID: 3 – I/O Index: 1
  5. Servo drive – Slave ID: 4 – Servo Index: 2
  6. Servo drive – Slave ID: 5 – Servo Index: 3
  7. I/O module – Slave ID: 6 – I/O Index: 2
  8. I/O module – Slave ID: 7 – I/O Index: 3

In a complicated case, an axis has two or more motors. The order is like this:

  1. Servo drive – Slave ID: 0 – Servo Index: 0
  2. Servo drive – Slave ID: 1 – Servo Index: 1, 2, 3, 4
  3. I/O module – Slave ID: 2 – I/O Index: 0
  4. I/O module – Slave ID: 3 – I/O Index: 1
  5. Servo drive – Slave ID: 4 – Servo Index: 5
  6. Servo drive – Slave ID: 5 – Servo Index: 6
  7. I/O module – Slave ID: 6 – I/O Index: 2
  8. I/O module – Slave ID: 7 – I/O Index: 3

To get the state of a device, you need to create an instance of the SlaveStatus structure, use the function to specify an EtherCAT slave, and then get the state of that device. The following is an example of getting the cycle time from the first EtherCAT slave, whose slave ID is zero:

NOTE:  If you don't use GetSlaveById to specify a slave first, the value you get - in this case it's cycle time - will be zero.

Copy
SlaveStatus Sts = { 0 };
nRet = GetSlaveById(0, &Sts);
RtPrintf("%s cycle time: %d\n", Sts.Name, Sts.CycleTime);

The following is an example of getting vendor ID from an axis, whose index is two:

Copy
nRet = GetAxisByIndex(2, &Sts, &resolution, NULL, NULL);
RtPrintf("%s Vendor ID: %d\n", Sts.Name, Sts.VendorId);

The following is an example of getting the input and output length from an I/O module, whose index is three:

Copy
nRet = GetIOByIndex(3, &Sts);
RtPrintf("%s input length: %d\n", Sts.Name, Sts.InputLength);
RtPrintf("%s output length: %d\n", Sts.Name, Sts.OutputLength);

 

Combined code:

Copy
int nRet = 0;
int resolution = 0;
SlaveStatus Sts = { 0 };

nRet = GetSlaveById(0, &Sts);
RtPrintf("%s cycle time: %d\n", Sts.Name, Sts.CycleTime);

nRet = GetAxisByIndex(2, &Sts, &resolution, NULL, NULL);
RtPrintf("%s Vendor ID: %d\n", Sts.Name, Sts.VendorId);

nRet = GetIOByIndex(3, &Sts);
RtPrintf("%s input length: %d\n", Sts.Name, Sts.InputLength);
RtPrintf("%s output length: %d\n", Sts.Name, Sts.OutputLength);

 

Output: