2. Getting Started

2.1. EC-Simulator Architecture

The EC-Simulator library is implemented in C++ and can be easily ported to any embedded OS platforms using an appropriate C++ compiler. The API interfaces are C language interfaces, thus the stack can be used in ANSI-C as well as in C++ environments.

There are two different architecture editions as described below. The architectures contain the following:

  • EC-Simulator stack Core: In the core module cyclic (process data update) and acyclic (mailbox) EtherCAT commands are sent and received. Among others there exist some state machines to handle for example the mailbox protocols.

  • Configuration Layer: The EC-Simulator stack is configured using a XML file whose format is fixed in the EtherCAT specification ETG.2100 (ENI) with extended information (EXI). The EC-Simulator contains an OS independent XML parser.

  • Real-time Ethernet Driver Layer: This layer exchanges Ethernet frames between the master and the simulator. If hard real-time requirements exist, this layer has to be optimized for the network adapter card in use.

  • OS Layer: All OS dependent system calls are encapsulated in a small OS layer. Most functions are that easy that they can be implemented using simple C macros.

2.2. Extended EtherCAT Network Configuration (EXI)

The EC-Simulator stack has to know about the EtherCAT bus topology and the cyclic/acyclic frames to exchange with the slaves. This configuration is determined in a configuration file which has to be available in the EtherCAT Network Information Format (ENI). This format is completely independent from EtherCAT slave vendors, from master stack vendors and from EtherCAT configuration tools. Thus inter-operability between those vendors is guaranteed.

Because the ENI file does not include information about the slave hardware, the EXI (EtherCAT Extended Information) file includes EEPROM content and Slave Object Dictionary from ESI and ESC register values from real network is typically needed. The EXI file can be exported using EC-Engineer.

2.3. HiL Simulation Software architecture

The EC-Simulator software is ready-to-run on various operating systems, e. g. Linux and Windows, and makes use of the Real-time Ethernet Drivers.

The EC-Simulator offers a “C” language API for integration into a Software PLC (LogicLab, logi.cals) or into professional simulation software like ISG Virtuos, etc.

2.4. Mixed mode of real slaves and simulated slaves

In order to implement restbus simulation it is possible to mix real slaves and simulated slaves like this:

All real slaves must be configured accordingly:

See also /EtherCATConfig/ExtendedConfig/Slaves/Slave/Simulated in the EXI file:

The EC-Simulator will automatically assign the network adapters to the corresponding ports in order of configuration.

2.5. Operating system configuration

The main task is to setup the operating system to support the appropriate network adapter for EtherCAT usage and for some systems real-time configuration may be needed.

The operating system-specific settings and configurations are described in Platform and Operating Systems (OS).

2.6. Running EcSimulatorHilDemoGuiDotNet

EC-Simulator HiL for Windows contains an .NET example application, the EcSimulatorHilDemoGuiDotNet.

Selecting the appropriate network adapter and providing an EtherCAT Network Configuration file (ENI / EXI) is mandatory before clicking “Start” to run the EC-Simulator:

EcSimulatorHilDemoGuiDotNet start parameters

2.7. Running EcSimulatorHilDemo

The EcSimulatorHilDemo is an EC-Simulator example application that handles the following tasks:

  • Showing basic EtherCAT communication

  • Stack initialization

  • Process Data operations for e.g. Beckhoff EL2004, EL1004 and EL4132

  • Periodic diagnosis task

  • Periodic Job Task

  • Logging to EcSimulator0.log, error0.log

The EcSimulatorHilDemo is available “out of the box” for different operating systems. The operating system must be prepared for running EtherCAT® applications,

2.7.1. Setting up and running EcSimulatorHilDemo

2.7.1.1. Linux (EcSimulatorHilDemo)

  1. Operating system configuration: See the section Operating system configuration for how to prepare the operating system

  2. Starting EcSimulatorHilDemo

cd /opt/EC-Simulator/Bin/Linux/x64
LD_LIBRARY_PATH=. ./EcSimulatorHilDemo -f exi.xml -intelgbe 2 1 -perf

2.7.1.2. Microsoft Windows (EcSimulatorHilDemo)

  1. Windows configuration: See the section Operating system configuration for how to prepare the operating system

  2. Determine the network interface: Using the command line option the network interface card used by the example application can be determined. For example the option -ndis 192.168.157.2 0 will be using the network adapter card with the IP address 192.168.157.2 .

  3. Simulating EtherCAT modules: The simulator has to be connected with the target system using an Ethernet switch or a patch cable. Local IT infrastructure should not be mixed with EtherCAT modules at the same switch as the master will send many broadcast packets! EtherCAT® requires a 100Mbit/s connection. Gigabit-Ethernet connections between simulator and master can be typically used, too.

  4. Copy all of the example application files into one directory: The application EcSimulatorHilDemo.exe together with the stack DLL EcSimulator.dll, the Ethernet Driver DLL emllPcap.dll and the EXI file have to be copied into one directory.

  5. Run the example application: EcSimulatorHilDemo.exe has to be executed. The file name of the EXI file has to be given as a command line parameter as well as the appropriate Real-time Ethernet Driver settings.

EcSimulatorHilDemo.exe -ndis 192.168.157.2 0 -f exi.xml -t 0 -v 3

2.7.2. Command line parameters

EcSimulatorHilDemo <LinkLayer> [-f ENI-FileName] [-t cycle time] [-b time] [-a affinity] [-v level] [-perf [level]] [-log prefix [msg cnt]] [-lic key] [-oem key] [-flash address] [-sp [port]] [-rec [prefix [frame cnt]]]

The parameters are as follows:

-f <configFileName>

Path to ENI file

-t <time>

Running duration in msec. When the time expires the demo application exits completely.

<time>

Time in msec, 0 = forever (default = 120000)

-b <cycle time>

Specifies the bus cycle time. Defaults to 1000 µs (1 ms).

<cycle time>

Bus cycle time in µsec

-a <affinity>

The CPU affinity specifies which CPU the demo application ought to use.

<affinity>

0 = first CPU, 1 = second, …

-v <level>

The verbosity level specifies how much console output messages will be generated by the demo application. A high verbosity level leads to more messages.

<level>

Verbosity level: 0=off (default), 1..n=more messages

-perf [<level>]

Enable max. and average time measurement in µs for all EtherCAT jobs (e.g. ProcessAllRxFrames).

<level>

Depending on level the performance histogram can be activated as well.

-log <prefix> [<msg cnt>]

Use given file name prefix for log files.

<prefix>

<msg cnt>

Messages count for log buffer allocation

-lic <key>

Set License key.

<key>

License key string

-oem <key>

Use OEM key

<key>

64 bit OEM key.

-flash <address>

Flash outputs

<address>

0=all, >0 = slave station address

-sp [<port>]

If platform has support for IP Sockets, this command-line option enables the Remote API Server to be started. The Remote API Server is going to listen on TCP Port 6000 (or port parameter if given) and is available for connecting Remote API Clients.

<port>

RAS server port

-rec [<prefix> [<frame cnt>]]

Packet capture file recording

<prefix>

File name prefix

<frame cnt>

Frame count for log buffer allocation

2.8. EC-Simulator Software Development Kit (SDK)

The EC-Simulator SDK is needed to write applications based on the EC-Simulator stack. The EC-Simulator stack is shipped as a library which is linked together with the application.

The following components are supplied together with an SDK:

  • ….Bin: Executables containing the EC-Simulator stack

  • ….Doc: Documentation

  • ….Examples: Example application(s)

  • Libraries and header files to build C/C++-applications.
    • ….\SDK\INC: header files to be included with the application

    • ….\SDK\LIB: libraries to be linked with the application

  • ….\Sources\Common: Shared C++-files

For all operating systems the same principal rules to generate the example applications can be used.

Include search path

The header files are located in the following two directories:

  1. <InstallPath>\Examples\<ExampleName> (whith e.g. <ExampleName>=EcSimulatorHilDemo)

  2. <InstallPath>\Examples\Common\<OS> (where <OS> is a placeholder for the operating system)

  3. <InstallPath>\Examples\Common

  4. <InstallPath>\SDK\INC\<OS> (where <OS> is a placeholder for the operating system)

  5. <InstallPath>\SDK\INC

  6. <InstallPath>\Sources\Common

Preprocessor macro

The demo applications are the same for all operating systems. The appropriate pre-processor macro has to be set for the operating system.

Libraries

The libraries located in <InstallPath>\SDK\LIB\<OS>\<ARCH> have to be added (<OS> is a placeholder for the operating system used and <ARCH> for the architecture if different architectures are supported).

2.8.1. OS Compiler settings

2.8.1.1. Linux Compiler settings

The following settings are necessary to build the example application for Linux.

  • Possible ARCHs (see ATECAT_ARCHSTR in SDK/INC/Linux/EcOsPlatform.h):

aarch64 (ARM 64Bit), armv4t-eabi (ARM 32Bit), armv6-vfp-eabihf (ARM 32Bit), armv7-vfp-eabihf (ARM 32Bit), PPC (PPC 32Bit with “-te500v2”), riscv64 (RISC-V 64Bit), x64 (x86 64Bit), x86 (x86 32Bit)

The ARM 32Bit architectures armv4t-eabi and armv6-vfp-eabihf/armv7-vfp-eabihf are incompatible with each other. An ARM VFP system returns success on “readelf -A /proc/self/exe | grep Tag_ABI_VFP_args”. If “readelf” isn’t available on the target, the matching ARM version can be figured out by trying to run EcSimulatorHilDemo.

  • Extra include paths:

    <InstallPath>/Examples/EcSimulatorHilDemo <InstallPath>/SDK/INC/Linux <InstallPath>/SDK/INC <InstallPath>/Sources/Common

  • Extra source paths:

    <InstallPath>/Examples/EcSimulatorHilDemo <InstallPath>/Sources/Common/EcTimer.cpp

  • Extra library paths to the main EtherCAT components (replace “x86” according to ARCH):

    <InstallPath>/SDK/LIB/Linux/x86

  • Extra libraries (in this order)

    EcSimulatorRasServer EcSimulator pthread dl rt

2.8.1.2. Microsoft Windows

The following settings are necessary to build the example application for Windows:

  • Library path of the main EtherCAT components:

    <InstallPath>/SDK/LIB/Windows/<Arch>

  • Include path:

    <InstallPath>/SDK/INC/Windows <InstallPath>/SDK/INC <InstallPath>/Sources/Common

2.9. Real-time Ethernet Driver configuration for EcSimulatorHilDemo

The different Real-time Ethernet Driver modules are selected and parametered by a common structure (shared by all Real-time Ethernet Driver) and a Real-time Ethernet Driver specific structure, pointed to by an element within the common structure. This parameter set is given to the EC-Simulator stack with the call of esInitSimulator().