Accessing hardware IOs via EC-Engineer
In EC-Engineer: Connecting to the fieldbus, scanning the fieldbus, exporting ENI-file, requesting ESI-files
logi.CAD 3 needs the ENI-file ("EtherCAT Network Information" file) in XML-format that is created in →EC-Engineer. The following steps help you to create this ENI-file quickly. If you require more help on using EC-Engineer, see the documentation of EC-Engineer (menu Help within EC-Engineer).
Start EC-Engineer. Most likely, the English language is already enabled. If not, do so in order to reproduce the following steps more easily.
How to change the language in EC-Engineer (if German is enabled): menu Einstellungen – Sprache – Choose the English language.In EC-Engineer, connect to the EtherCAT fieldbus:
In the Device Editor (Start Page), click TCP/IP — Remote Configuration.
Select EtherCAT Master Unit (Class A) and click OK.
In the Device Editor under Slaves connected to remote system, enter the IP-address of the PLC (of the Windows PC). Click Select.
If you are using a Windows PC as PLC, mind that you do not enter the IP-address of the reserved network interface card.In menu Network, select Scan EtherCAT Network.
Result: The EtherCAT fieldbus is found and scanned because of the entries in file RTSIO.cfg existing on the PLC. The project explorer of EC-Engineer displays one item Slave_xxxx (for each terminal on the fieldbus).Make sure that the names of the variables (listed in the Device Editor, tab Variables) are →IEC-identifiers. If the names contain special characters, such as umlauts (ä, ö, ü) or ß, logi.CAD 3 cannot access the hardware IOs.
Click Export ENI in the toolbar. Save the ENI-file to any folder.
The ENI-file may have any name. Example: EK1110.xml
Moreover, logi.CAD 3 needs the ESI-files ("EtherCAT Slave Information" file) in XML-format. A ESI-file contains the EtherCAT device description and can be requested from the device manufacturer.
In logi.CAD 3: Dragging ENI-file and ESI-files into the project, creating a global-object, configuring PLC-object and include the GLOBALS section
Change to logi.CAD 3 and perform the following steps:
Drag the ENI-file and the ESI-files into any folder of the logi.CAD 3 project.
Enhance the PLC-object of the project as follows:
Open the PLC-object representing the PLC to be addressed.
Only required for the alternate scenario (engineering-PC ≠ PLC): Search for the line with ADDRESS or PORT and replace the entered IP address or port by the appropriate data for your PLC (details: see under "Configuring PLC within PLC-object").
Search for the text part RESOURCE ... ON. Replace the platform entered behind ON by the appropriate platform:
The PLC is:
Enter this platform:
Example for change line within the PLC-object
a Windows PC
WindowsX86
RESOURCE local ON WindowsX86 { ON_CHANNEL := LocalChannel }
After this line, enter the specification for IO_IMPORT. Best practice is to use the template ioe provided by the content assist.
Complete the inserted specification accordingly. Best practice is to use the content assist again whenever a content assist list is provided.Example for a resource with the ENI-file EK1110.xml that has been dragged to the folder 'src'RESOURCE local ON WindowsX86 { ON_CHANNEL := LocalChannel }
{ IO_IMPORT PROVIDER := EtherCatProvider, SERVICE := EtherCAT, PARAMS := "src/EK1110.xml", GLOBALS := "src/GlobalsEK1110" }
The attribute GLOBALS specifies the project-relative path and name for the global-object in which the declarations for the resource-global variables are to be created by logi.CAD 3 later on. Here GlobalsEK1110 with folder src is specified.
The attribute PARAMS specifies the project-relative path and name of the ENI-file on which basis the declaration will be created later on.After the line with IO_IMPORT, enter the specification for INCLUDE_GLOBALS and complete it by the name of the global-object as it has been specified for the attribute GLOBALS.
Result, if the global-object does not exist: The specification for INCLUDE_GLOBALS is highlighted as faulty. Ignore this highlighting because the global-object will be created in a later step.ExampleRESOURCE local ON WindowsX86 { ON_CHANNEL := LocalChannel }
{ IO_IMPORT PROVIDER := EtherCatProvider, SERVICE := EtherCAT, PARAMS := "src/EK1110.xml", GLOBALS := "src/GlobalsEK1110" }
{INCLUDE_GLOBALS GlobalsEK1110}
Declare several tasks and label one of those tasks as IO task. See under "Assigning more program types (= creating new instances)" for details on the procedure.
Take care that the IO-task is responsible for accessing the bus when using the EC-master. If the cycle time is too high, it is possible that the in- and output modules pass into a failsafe state. Subsequently, the application might not receive data from them or write data to them any longer. As experiences has shown, an INTERVAL in the range of a few milliseconds (e.g. 2 ms) is fitting. Moreover, a high priority (a small number) should be assigned to the IO-task, if the EC-master is used.Example for a test structure with an IO-taskTASK DefaultTask(INTERVAL := TIME#500ms, PRIORITY := 38229);
{ IO } TASK FastTask(INTERVAL := TIME#2ms, PRIORITY := 2); (* This is the IO-task. *)
As an option you are able to specify the IO service for the IO task as this IO service has been defined with the specification for IO_IMPORT.
Example for a test structure with an IO task and IO serviceTASK DefaultTask(INTERVAL := TIME#500ms, PRIORITY := 38229);
{ IO := EtherCAT } TASK FastTask(INTERVAL := TIME#2ms, PRIORITY := 2);
Declare several program instances and assign the previously declared tasks accordingly:
Example for several program instancesPROGRAM Program1 WITH DefaultTask :
Program1;
PROGRAM AccessIO WITH FastTask:
Program1;
See under "Assigning more program types (= creating new instances)" for details on the procedure.
Save the PLC-object: menu File – Save
Synchronize the resource with the ENI-file: context menu of the PLC-object, command Synchronize with IO Providers
Result: The specified global-object (here: GlobalsEK1110) is created or updated. The required declarations for the resource-global variables are created in its GLOBALS section. These resource-global variables represent the hardware IOs, their physical addresses have already been specified (after the keyword AT).Example for the synchronized content/***** Generated File - DO NOT EDIT - Last updated: 2017-04-24 09:41:41 *****/
/** generated from RESOURCE "myResource" with the following directive: **/
/** { IO_IMPORT PROVIDER := EtherCatProvider, SERVICE := EtherCAT, PARAMS := "src/EK1110.xml", GLOBALS := "src/GlobalsEK1110" } **/
GLOBALS GlobalsEK1110
VAR_GLOBAL
Slave_1002EL1008Channel1Input AT %IX1.0.0 : BOOL;
Slave_1002EL1008Channel2Input AT %IX1.0.1 : BOOL;
Slave_1004EL3102Channel1Status AT %IB1.1 : BYTE;
Slave_1004EL3102Channel2Value AT %IW1.5 : INT;
END_VAR
END_GLOBALS
Do not change the resource-global variables
logi.cals recommends to
not change the name of the GLOBALS section.
Reason: Otherwise the corresponding reference for INCLUDE_GLOBALS within the PLC-object cannot be resolved.not change these resource-global variables.
Reason: The declarations of the resource-global variables are synchronized and updated, if the command Synchronize with IO Providers is selected (see "Considering changed hardware IOs" for details on the update procedure).
In logi.CAD 3: Accessing the declared variables within the ST-code
Now you are able to access the declared global variables in the context of →POUs by using →external variables:
In the ST-object, declare an external variable – in particular within the declaration of the POU where the access is necessary. Access is possible within the declaration of the program, the declaration of a function block or the declaration of a function.
Example for declarations of external variablesVAR_EXTERNAL
Slave_1002EL1008Channel1Input : BOOL;
Slave_1002EL1008Channel2Input : BOOL;
Slave_1004EL3102Channel1Status : BYTE;
Slave_1004EL3102Channel2Value : INT;
END_VAR
See "Declaration of external variables in ST" on the syntax required for the external variable.
In the ST-object, use the external variable within the declaration of the POU (e.g. enter it within an assignment).
Save the ST-object: menu File – Save
Possibilities for diagnostics
If you need information about the EC-Master within your ST-code, logi.CAD 3 provides blocks for Acontis. Use these blocks accordingly in your ST-object.
See "Problems when using EtherCAT field buses" for troubleshooting.
After you have concluded these steps, you can access the hardware IOs within the ST-code.
The article "Considering changed hardware IOs" lists steps to perform when hardware IOs on the EtherCAT-Feldbus are changed. The article "Physical addresses that are based on EC-Master and EC-Engineer" contains background information on the physical addresses.