Writing and reading CoE objects using function blocks
The function blocks "FB_EcCoeSdoReadEx" and "FB_EcCoeSdoWriteEx" from the Tc2_EtherCAT library can be used to read and write CoE values in the PLC project.

To use the function blocks, proceed as follows:
- 1. Add the "Tc2_EtherCAT" library:
- 2. Right-click on "References" in the PLC project and select "Add library". The "Add Library" dialog box opens.
- 3. Select "IO" -> "Tc2_EtherCAT" and close the dialog box with "OK".
- 4. The Tc2_EtherCAT library is now displayed under References in the TwinCAT tree.
- 5. Press the "F2" button to open the input wizard.
- 6. Activate the checkbox "Insert with arguments" and select the function block
- "FB_EcCoeSdoReadEx" for reading CoE values or
- "FB_EcCoeSdoWriteEx" for writing CoE values
- 7. Confirm with "OK". The "Auto Declare" dialog box opens.
- 8. Instantiate the function block in the "Auto Declare" dialog box by entering the name and confirming with "OK".
- 9. Initialize the function blocks in your PLC program. Use the following sample code for reading and writing the "DC OK threshold" (0x8000:16) as a guide.



Code sample: Reading and writing the CoE value for the DC OK threshold
- 10. After starting the controller and logging in, you will see the following screen:
Read command:
A positive edge of "startRead" starts the read command. The value of the variable "fDCOKthreshold" is written.

Online data for reading and writing the DC OK threshold
Write command:
A positive edge of "startWrite" starts the write command. The CoE object 0x8000:16 "DC OK threshold" is read and the value in the variable "fDCOKthreshold" is written to the CoE object "DC OK threshold" 0x8000:16.