Accessing hardware IOs via EC-Engineer


In logi.CAD 3: Creating a project

If not already done, start logi.CAD 3 and create a project in which you want to access the hardware IOs.

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).

  1. 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 EinstellungenSprache – Choose the English language.

  2. In EC-Engineer, connect to the EtherCAT fieldbus:

    1. In the Device Editor (Start Page), click TCP/IP — Remote Configuration.

      images/download/attachments/414779368/ECEngineer_EN-version-1-modificationdate-1534428158947-api-v2.png
    2. Select EtherCAT Master Unit (Class A) and click OK.

    3. 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.

    4. 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).

    5. 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.

  3. 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:

  1. Drag the ENI-file and the ESI-files into any folder of the logi.CAD 3 project.

  2. Enhance the PLC-object of the project as follows:

    1. Open the PLC-object representing the PLC to be addressed.

    2. 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").

    3. 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 }
    4. 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.

    5. 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.

      Example
      RESOURCE local ON WindowsX86 { ON_CHANNEL := LocalChannel }
      { IO_IMPORT PROVIDER := EtherCatProvider, SERVICE := EtherCAT, PARAMS := "src/EK1110.xml", GLOBALS := "src/GlobalsEK1110" }
      {INCLUDE_GLOBALS GlobalsEK1110}
    6. 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.
      images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg 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-task
      TASK 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 service
      TASK DefaultTask(INTERVAL := TIME#500ms, PRIORITY := 38229);
      { IO := EtherCAT } TASK FastTask(INTERVAL := TIME#2ms, PRIORITY := 2);
    7. Declare several program instances and assign the previously declared tasks accordingly:

      Example for several program instances
      PROGRAM Program1 WITH DefaultTask :
      Program1;
      PROGRAM AccessIO WITH FastTask:
      Program1;

      See under "Assigning more program types (= creating new instances)" for details on the procedure.

    8. Save the PLC-object: menu FileSave

  3. 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:

  1. Open an ST-object.

  2. 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 variables
    VAR_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.

  3. In the ST-object, use the external variable within the declaration of the POU (e.g. enter it within an assignment).

  4. Save the ST-object: menu FileSave

Possibilities for diagnostics


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.