How to request a new EtherCAT state of a device from the application code
| Version Number | Description |
|---|---|
| 1.0 | Initial version: Steps to change the state of EtherCAT devices using application code running on the iC9226. |
This application note explains how to change the state of EtherCAT devices via the application Code layer.
1. Supported Components
| Component Name | Version |
|---|---|
| iC922x Controller | ≥ 2024.3 |
| iCube Engineer | ≥ 2024.3 |
2. Changing EtherCAT state of connected devices using application code
The current EtherCAT state of a device can be seen under the
Online Functions
tab of EtherCAT and can be changed from here as well.
In order to change the state of EtherCAT devices via code, function block
Y_EC_COE_SdoWrite
can be used.
Registers 0x3000- 0x3FFF contain Slave Configuration and Information Objects where all information about the slave can be found, read and written. Subindex 15 is used to write (request) a new state for a slave. The first slave objects are in register 0x3000 , while the second slave's information is in register 0x3001 and so on. Sub-index 16 can be used to read the current state of the slave using
Y_EC_COE_SdoWrite
.
- Record : The data to be written is presented here. Data type is ANY, but UDINT can be used in order to write an EtherCAT state as an input.
- NetworkID : Network ID of the EtherCAT master. Default value is 1.
- Station Address: Enter "0". (EtherCAT Station Address of the Master). Station Address 0 can be used for the two scenarios below:
- To modify the EtherCAT state of the master
- To modify the EtherCAT state of the slave
- Index : The register that needs to be modified.
- To modify the
master
EtherCAT state, use 0x2000 (Master State Change Command).
- To modify the slave EtherCAT state, use 0x3000, 0x3001... according to the number of slaves in the system and which slave data needs to be read.
- Note: The Index number 0X3000 in the FB refers to EC_SLAVE_STATE[1] on the hardware side, similarly 0x3001 will correspond to EC_SLAVE_STATE[2] and so on. This depends on the sequence in which the slaves are connected on the network. Function block #21119 should be used to obtain the index of the slave device from the system variable array EC_SLAVE_STATE if the station address is known.
- Subindex : To request a state change on a sub device, the sub index will be 15 which is 16#0F in hexadecimal. To request a state change in a If the subindex does not exist then let it be 0 as in the case of Master state.
EtherCAT State Values:
- 0: Invalid
- 1: Init
- 2: Pre-operational
- 3: Bootstrap
- 4: Safe-operational
- 8: Operational
After executing the above function block, in order to verify if the state of the device has changed, three options are possible:
-
Manually: check the in the EtherCAT node the
Online Function tab
.
-
By code using function block:
Use
Y_EC_COE_SdoRead
function block to verify if the requested state is changed for the particular device or not.. The Read function block is also used in a similar manner as the write function block. The subindex should be 16 (that is 16#10 in hexadecimal).
- By code with System variables:
-
Master state
can be read with
EC_MASTER_STATE
variable
-
Slave state
can be read with
EC_SLAVE_STATE
variable with the related SlaveID index. Function block #21119 can be used to obtain the index of the slave device from the system variable array EC_SLAVE_STATE if the station address is known.