Ethercat installation from repositories - how to step by step

More
13 Mar 2022 11:12 - 13 Mar 2022 11:28 #237098 by rodw
Ethercat installation instructions from repositories maintained unofficially by the IgH Etherlabmaster team

This has now also been tested by Niko so here is a nice easy way to install ethercat master without compiling code. So here goes
open a terminal
sudo apt install geany curl
sudo geany /etc/apt/sources.list
Insert this line at the end of the file
deb [allow-insecure=yes] https://download.opensuse.org/repositories/home:/bone11111:/branches:/science:/EtherLab/Debian_10/ ./
Save and close geany
sudo apt update
Enter these two commands to create a security key
KEYRING=/usr/share/keyrings/ethercat.gpg
curl -fsSL https://download.opensuse.org/repositories/home:/bone11111:/branches:/science:/EtherLab/Debian_10/Release.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null

Install the headers and the ethercat master
sudo apt install -y linux-headers-rt-amd64
sudo apt-get install ethercat-dkms libethercat libethercat-dev ethercat-master
ip a
Save the MAC address of the NIC to be used for ethercat
sudo geany /etc/ethercat.conf
set your Master0 device to your MAC address and device modules to generic. Make these edits
MASTER0_DEVICE="xx:aa:yy:zz:bb:cc"
DEVICE_MODULES="generic"
save and close geany and enter these commands to start the ethercat service.
sudo systemctl enable ethercat.service
sudo systemctl start ethercat.service
sudo systemctl status ethercat.service
sudo chmod 666 /dev/EtherCAT0
Ethercat should be running. If the above command is not found, you have a problem
You can list the slaves if you type
ethercat slaves
Now time to install the linuxcnc ethercat driver
You may need to run this command but I didn't with a Debian Sid install. Try it anyway.
sudo apt install expat libexpat1 libexpat1-dev

Now get on with the driver install
mkdir dev
cd dev
git clone https://github.com/sittner/linuxcnc-ethercat.git
cd linuxcnc-ethercat/src
replace the contents of realtime.mk with the revisions on this forum thread:
forum.linuxcnc.org/9-installing-linuxcnc...ve-config-sdo#203252
repeated for convenience here:
include ../config.mk
include Kbuild

cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
             > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)

.PHONY: all clean install

ifeq ($(BUILDSYS),kbuild)

module = $(patsubst %.o,%.ko,$(obj-m))

ifeq (,$(findstring -Wframe-larger-than=,$(EXTRA_CFLAGS)))
  EXTRA_CFLAGS += $(call cc-option,-Wframe-larger-than=2560)
endif

$(module):
    $(MAKE) EXTRA_CFLAGS="$(EXTRA_CFLAGS)" KBUILD_EXTRA_SYMBOLS="$(RTLIBDIR)/Module.symvers $(RTAIDIR)/modules/ethercat/Module.symvers" -C $(KERNELDIR) SUBDIRS=`pwd` CC=$(CC) V=0 modules

clean::
    rm -f $(obj-m)
    rm -f *.mod.c .*.cmd
    rm -f modules.order Module.symvers
    rm -rf .tmp_versions

else

module = $(patsubst %.o,%.so,$(obj-m))

EXTRA_CFLAGS := $(filter-out -Wframe-larger-than=%,$(EXTRA_CFLAGS))

$(module): $(lcec-objs)
    $(CC) -shared -o $@ $(lcec-objs) -Wl,-rpath,$(LIBDIR) -L$(LIBDIR) -llinuxcnchal -lethercat -lrt

%.o: %.c
    $(CC) -o $@ $(EXTRA_CFLAGS) -Os -c $<

endif

all: $(module)

clean::
    rm -f $(module)
    rm -f $(lcec-objs)

install: $(module)
    mkdir -p $(DESTDIR)$(RTLIBDIR)
    cp $(module) $(DESTDIR)$(RTLIBDIR)/

Make and install the ethercat driver
make clean
sudo make install
cd ..
[code]

If you are using cia402 compatible drives:
[code]
git clone https://github.com/dbraun1981/hal-cia402
cd hal-cia402
sudo halcompile --install cia402.comp
so to test its working from Linuxcnc
If you don't have an xml config file yet (preferred), download an ethercat config file of mine from
github.com/rodw-au/linuxcnc-cia402/blob/main/ethercat-conf.xml
in that folder type:
halcmd halcmd loadusr -W lcec_conf ethercat-conf.xml
halcmd show pin lcec
You should see this and hopefully a few other pins displayed
Component Pins:
Owner   Type  Dir         Value  Name
     4  u32   OUT    0x00000001  lcec.conf.master-count
     4  u32   OUT    0x00000004  lcec.conf.slave-count


Let us know how you get on.
Pehaps this could be made a sticky if the mods are handy.
Last edit: 13 Mar 2022 11:28 by rodw.
The following user(s) said Thank You: tommylight, Niko, sqmathlete, anfänger, medicusdkfz, energien

Please Log in or Create an account to join the conversation.

More
17 Mar 2022 21:31 #237567 by rodw
A slight update. Sometimes the ethercat master gets confused about the kernel version and looks in the wrong folder.
This can happen if you install preempt_rt or upgrade your copy of Linux to a later version

So we can use uname -r to get the exact kernel running when we install the headers

Install the headers and the ethercat master
sudo apt install -y linux-headers-$(uname -r)
sudo apt-get install ethercat-dkms libethercat libethercat-dev ethercat-master
ip a
The following user(s) said Thank You: medicusdkfz, energien

Please Log in or Create an account to join the conversation.

More
30 Apr 2022 22:03 #241740 by rodw
One more update to ensure the ethercat port has permissions on startup. Create a udev rule
sudo nano /etc/udev/rules.d/99-ethercat.rules

Add the following:
KERNEL=="EtherCAT[0-9]", MODE="0777" 

Save and exit, then type
sudo udevadm control --reload-rules

and reboot your computer.

Without this, on a restart, you always needed to chmod the ethercat port.
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
16 May 2022 18:47 #243096 by rodw
In the two steps above where we wget the security key and edit sources.list, you will see we used Debian_10 (which is buster)
For later Debian distros, If you get security issues, replace Debian_10 as follows
Bullseye: Debian_11
Testing (aka currently Bookworm): Debian_Testing

For more info review the repo notes (click on show more):
build.opensuse.org/project/show/home:bon...hes:science:EtherLab

 

Please Log in or Create an account to join the conversation.

More
01 Jul 2022 16:46 #246380 by DmitryKV
Hello.
Tell me, is there a description of the rules for compiling an xml file or a schema? Intuitively, of course, it is clear what data is described in xml. But if there is a scheme, this would help to avoid mistakes in names. It would be nice to know what names are available for description. For example, there is a line in xml <dcConf assignActivate="300" sync0Cycle="*1" sync0Shift="0"/> 
Probably dcConf is Distributed Clocks, very similar. It would be nice if didn't have to guess.

For me, this topic is new, maybe I do not know the obvious things. Please be understanding.

Regards, Dmitry

Please Log in or Create an account to join the conversation.

More
27 Jul 2022 05:27 #248388 by kangkang
hello!!

EtherCAT installation is in progress using LinuxCNC 2.8.2 Debian 10 Buster PREEMPT-RT ISO provided on LinuxCNC official website.

EtherCAT was installed by referring to the well described installation process.

After that, the systemctl start ethercat.service command was executed, but an error occurred.

If execute the sudo systemctl status ethercat.service command, the following error message is displayed.

● ethercat.service - EtherCAT Master Kernel Modules
   Loaded: loaded (/lib/systemd/system/ethercat.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2022-07-27 14:08:46 KST; 4min 14s ago
  Process: 2355 ExecStart=/usr/sbin/ethercatctl start (code=exited, status=1/FAILURE)
 Main PID: 2355 (code=exited, status=1/FAILURE)

Jul 27 14:08:46 192 systemd[1]: Starting EtherCAT Master Kernel Modules...
Jul 27 14:08:46 192 ethercatctl[2355]: modprobe: FATAL: Module ec_master not found in directory /lib/modules/4.19.0-17-rt-amd64
Jul 27 14:08:46 192 systemd[1]: ethercat.service: Main process exited, code=exited, status=1/FAILURE
Jul 27 14:08:46 192 systemd[1]: ethercat.service: Failed with result 'exit-code'.
Jul 27 14:08:46 192 systemd[1]: Failed to start EtherCAT Master Kernel Modules.

Is there any way to solve the following error?

Thank you!!

Please Log in or Create an account to join the conversation.

More
31 Jul 2022 11:56 #248724 by andypugh
Do you have anything in /lib/modules with a slightly different name?

Please Log in or Create an account to join the conversation.

More
31 Jul 2022 19:56 #248747 by rodw
Did you read this post earlier in this thread?

forum.linuxcnc.org/ethercat/45336-etherc...-step-by-step#237567

That should fix it.

Please Log in or Create an account to join the conversation.

Time to create page: 0.127 seconds
Powered by Kunena Forum