Configuration example
Configuration example
The functionality of FoE will now be illustrated on the basis of a programming example. The following illustration shows the physical structure with a CX2040 Embedded PC incl. CX2100-0014 power supply unit and downstream EL2809, EL1004 und EL6695, where the Ethernet connector X001 of the CX PC is connected to the “upper” RJ45 connector X1 of the EL6695 bridge terminal:
Furthermore, the CoE object 0x1A05 is to be added in the System Manager so that it is possible on the receiving side to detect, on the basis of the info object “Data Bytes Pending”, whether data or a file have been received. To do this the respective checkbox must be activated in the process data. This is shown in the illustration only for the secondary side, which represents the receiving side in this example. Furthermore, the openly accessible variable “ScndFoeBytesToRead” contained in the TwinCAT sample program is to be linked with “Data Bytes Pending”.
Init – startup configuration
In accordance with the configuration definition of the object 0xF800 (see CoE/Parameter directory – profile-specific objects), two values have to be entered in 0xF800 for the transition from the Init state to the PreOp state (I → P):
- The value 0x4000 in 0xF800:01 (to deactivate EoE)
- The value 0x0100 in 0xF800:02 (special mode to reserve an FoE buffer memory on the EL6695)
The procedure using the System Manager (TC3.1) user interface is shown below, the selected “Startup” tab on the primary or secondary side marked terminal or box:
The value 0x4000 (type 00 40) is to be entered here for the object 0xF800, subindex 01 in order to deactivate EoE. This is necessary only due to the use in this example of the connection of the primary and secondary side of the terminal, since both sides are connected to an EtherCAT master.
Blocking the EoE protocol under FoE If the primary and secondary sides are connected in one EtherCAT line, the EoE protocol must be blocked by setting bit 14 (0x4000) in object 0xF800:01 on the terminal, since otherwise the terminal will be blocked (due to repeated ARP Ethernet requests). |
Furthermore, the value 0x0100 (type 00 01) must be entered for 0xF800:02 (Comment = Config 2: Enable FoE Buffer). It doesn’t matter whether this is done on the primary or the secondary side of the EL6695 bridge terminal, since these settings are always also adopted on the respective other side.
Changing the Device Config 0xF800 The object 0xF800 is configurable on both the primary and secondary side and is always adopted by the respective other side. |
Care must be taken that the correct transition is selected: P → S must be off, I → P must be activated. Once this has been done it should look like the following illustration:
Explanations regarding the program example
The program example in the attachment, which is intended to illustrate an FoE data transfer, is based on the state diagram for the write and read access illustrated in the following.
The bEnabled flag defined in the program is intended for the control of the program and is used for the start condition or restart condition. On account of the additional declaration AT%I*, this flag can be linked with a “real” input of an input terminal in order to control the program “from the outside”, e.g. with a connected button (up +).
- Start condition Read: bEnabled must be TRUE (e.g. actuate externally connected button); in addition, “ScndFoeBytesToRead” is checked for incoming data and must be > 0.
- Restart condition Write: bEnabled must be FALSE again (e.g. release externally connected button again).
In addition, the bEnabled flag is tested for TRUE within state 1 of the state machine for writing the data, whereby the write process is then only started by an OPEN.
On account of the additional declaration AT%Q*, bDataEqual can be linked with an output variable of a terminal that provides digital outputs. By this one can see at the end whether the correct data transport has taken place.
The individual states 0 to 4 are programmed as follows as iWrState:
- [iWrState =0]: execution of initializations:
- Set FALSE → bDataEqual
- Generate random data in aWrBuffer
- Preparation of the call of the function block for OPEN: Set FALSE → bExecute
- Set next state: 1 → iWrState
- [iWrState =1]: Query the input variable bEnabled as to whether to start calling the function block for OPEN. If bEnabled = TRUE, the OPEN function block is called with the following parameters:
- EC_MasterNetId_Wr → sNetId
- EL6695_WR_EcAddr → nPort
- 16#12345678 → dwPass
- 1 → eMode (identifier for writing)
- TRUE → bExecute
- T#10S → tTimeout
- This call is repeated until a query of the bBusy flag returns FALSE; the following then takes place:
- Set next state: 2 → iWrState; if bBusy = TRUE, then no change of state takes place. The handling of the error cases by the bError flag of the OPEN function block (for read/write) is not considered in this example or for any other function block (ACCESS, CLOSE for read/write).
- Preparation of the call of the function block for ACCESS: Set FALSE → bExecute
- [iWrState =2]: The ACCESS function block is called with the following parameters:
- fbWrFoeOpen.hFoe → hFoe
- ADR(aWrBuffer) →pBuffer
- TRUE → bExecute
- T#14S → tTimeout
- This call is repeated until a query of the bBusy flag returns FALSE; the following then takes place:
- Set next state: 3 → iWrState
- Preparation of the call of the function block for CLOSE: Set FALSE → bExecute
- [iWrState =3]: The CLOSE function block is called with the following parameters:
- fbWrFoeOpen.hFoe → hFoe
- TRUE → bExecute
- T#14S → tTimeout
- This call is repeated until a query of the bBusy flag returns FALSE; the following then takes place:
- Set next state: 4 → iWrState
- [iWrState =4]: in this state the input variable bEnabled is merely queried as to whether it is FALSE again. The program then begins again with the start state:
- If bEnabled = FALSE, then set the next state: 0 → iWrState
At the next start new random numbers are generated again, which should once again correspond to the read values when compared. The bDataEqual flag is provided for and can indicate this, as we shall see in the following.
The state diagram for the read access looks similar in principle and has in state 4 a program section for the data comparison of the written values with the read values.
The individual states 0 to 4 are programmed as follows as iRdState:
- [iRdState =0]: in this state the input variable bEnabled is queried as to whether it is TRUE. With that the program begins with the querying of the input variable “ScndFoeBytesToRead”, which is linked to [FoE Info].Data Bytes Pending (object 0x1A05), in order to determine whether data are “present” on the receiving side.
- Query of ScndFoeBytesToRead if bDataEqual = TRUE
- Set next state: 1 →iRdState if ScndFoeBytesToRead = TRUE
- Set to prepare the call of the function block for OPEN: set FALSE → bExecute if ScndFoeBytesToRead = TRUE
- [iRdState =1]: Query the input variable bEnabled as to whether to start calling the function block for OPEN. If bEnabled = TRUE, the OPEN function block is called with the following parameters:
- EC_MasterNetId_Rd → sNetId
- EL6695_RD_EcAddr → nPort
- 16#12345678 → dwPass
- 0 → eMode (identifier for reading)
- TRUE → bExecute
- T#10S → tTimeout
- This call is repeated until a query of the bBusy flag returns FALSE; the following then takes place:
- Set next state: 2 → iRdState
- Preparation of the call of the function block for ACCESS: Set FALSE → bExecute
- [iRdState =2]: The ACCESS function block is called with the following parameters:
- fbRdFoeOpen.hFoe → hFoe
- ADR(aRdBuffer) →pBuffer
- TRUE → bExecute
- T#14S → tTimeout
- This call is repeated until a query of the bBusy flag returns FALSE; the following then takes place:
- Set next state: 3 → iRdState
- Preparation of the call of the function block for CLOSE: Set FALSE → bExecute
- [iRdState =3]: The CLOSE function block is called with the following parameters:
- fbRdFoeOpen.hFoe → hFoe
- TRUE → bExecute
- T#14S → tTimeout
- This call is repeated until a query of the bBusy flag returns FALSE; the following then takes place:
- Set next state: 4 → iRdState
- [iRdState =4]: In this state the check of both memory areas takes place at the end and the bDataEqual flag is set to TRUE if both memory areas are identical. It is recommended to make this flag "visible" as an output variable so that, for example, it can be switched to an output via an output terminal.
- Set next state: 0 → iRdState
Using the sample programs This document contains sample applications of our products for certain areas of application. The application notes provided here are based on typical features of our products and only serve as examples. The notes contained in this document explicitly do not refer to specific applications. The customer is therefore responsible for assessing and deciding whether the product is suitable for a particular application. We accept no responsibility for the completeness and correctness of the source code contained in this document. We reserve the right to modify the content of this document at any time and accept no responsibility for errors and missing information. |
Preparations for starting the sample programs (tnzip file / TwinCAT 3)
- Click on the download button to save the Zip archive locally on your hard disk, then unzip the *.tnzip archive file in a temporary folder.
- Select the .tnzip file (sample program).
- A further selection window opens. Select the destination directory for storing the project.
- For a description of the general PLC commissioning procedure and starting the program please refer to the terminal documentation or the EtherCAT system documentation.
- The EtherCAT device of the example should usually be declared your present system. After selection of the EtherCAT device in the “Solutionexplorer” select the “Adapter” tab and click on “Search...”:
- Checking NetId: the “EtherCAT” tab of the EtherCAT device shows the configured NetId:.
The first four numbers must be identical with the project NetId of the target system. The project NetId can be viewed within the TwinCAT environment above, where a pull down menu can be opened to choose a target system (by clicking right in the text field). The number blocks are placed in brackets there next to each computer name of a target system. - Modify the NetId: By right clicking on “EtherCAT device” within the solution explorer a context menu opens where “Change NetId...” have to be selected. The first four numbers of the NetId of the target computer must be entered; both last values are 4.1 usually.
Example: - NetId of project: myComputer (123.45.67.89.1.1)
- Entry via „Change NetId...“: 123.45.67.89.4.1