robert-burger / libethercat

EtherCAT master library. This library is used to build a deterministic fieldbus network with EtherCAT components.
https://www.dlr.de/rm
Other
29 stars 6 forks source link
ethercat-master fieldbus

libethercat

EtherCAT-master library

This library provides all functionality to communicate with EtherCAT slaves attached to a Network interface.

Network device access

Legal notices

This software was developed and made available to the public by the Institute of Robotics and Mechatronics of the German Aerospace Center (DLR).

Please note that the use of the EtherCAT technology, the EtherCAT brand name and the EtherCAT logo is only permitted if the property rights of Beckhoff Automation GmbH are observed. For further information please contact Beckhoff Automation GmbH & Co. KG, Hülshorstweg 20, D-33415 Verl, Germany (www.beckhoff.com) or the EtherCAT Technology Group, Ostendstraße 196, D-90482 Nuremberg, Germany (ETG, www.ethercat.org).

Usage

See INTRODUCTION.md or gh-pages for reference.

Build from source

libethercat uses autotools as build system.

Prerequisites

Ensure that libosal is installed in your system. You can get libosal from here https://github.com/robert-burger/libosal.git . To build libethercat from source execute something like:

git clone https://github.com/robert-burger/libethercat.git
cd libethercat
autoreconf -is
./configure
make
sudo make install

This will build and install a static as well as a dynamic library. For use in other project you can use the generated pkg-config file to retreave cflags and linker flags.

CMake

Steps to build:

mkdir build
cd build
# Please change the path to the install dir. If you chose a global install you can omit the CMAKE_PREFIX_PATH option
# You can specify which EtherCAT devices should be included into the build with -DECAT_DEVICE="sock_raw+sock_raw_mmaped+..."
cmake -DCMAKE_PREFIX_PATH=<installdir of libosal> -DECAT_DEVICE="sock_raw+sock_raw_mmaped" ..
cmake --build . 

Configuration parameters

Parameter Default Description
CMAKE_PREFIX_PATH Install directory of the libosal
ECAT_DEVICE sock_raw List of EtherCAT devices as + separated list. Possible values: sock_raw+sock_raw_mmaped+file+pikeos+bpf
BUILD_SHARED_LIBS OFF Flag to build shared libraries instead of static ones.
MBX_SUPPORT_COE ON Flag to enable or disable Mailbox CoE support
MBX_SUPPORT_FOE ON Flag to enable or disable Mailbox FoE support
MBX_SUPPORT_SOE ON Flag to enable or disable Mailbox SoE support
MBX_SUPPORT_EOE ON Flag to enable or disable Mailbox EoE support

Tools

libethercat also provides some small helper programs for the EtherCAT bus.

eepromtool

With eepromtool you can read and write EtherCAT slave's eeprom.

read eeprom

To do a read operation simply run:

eepromtool -i eth1 -s 0 -r -f eeprom.bin

If no filename if specified, eepromtool will print the contents to stdout, which you can pipe to hexdump for example.

eepromtool -i eth1 -s 0 -r | hexdump -v -C | less -S

write

To do a write operation simply run:

eepromtool -i eth1 -s 0 -w -f eeprom.bin

If no filename if specified, eepromtool will read from stdin.

cat eeprom.bin | eepromtool -i eth1 -s 0 -w

example_with_dc

This is a more complex example on how to use libethercat in realtime/control systems.

It tries to do the following: