IGH Ethercat主站安装配置

记录在使用安装IGH过程中遇到的问题,目前存在大坑:

  • 实时内核版本大于5.0的不用试了,别听论坛瞎BB肯定不支持。
  • 最新源码要通过github下载,其他位置的下载源码有问题!!
    eg:https://sourceforge.net/projects/etherlabmaster/ 大坑
  • xenomai实时内核补丁不同版本igh安装会有问题,1.5/1.5.2有坑,没有踩完,推荐还是先prempt安装测试,后续有机会再弄Xenomai

[TOC]

安装步骤

1.安装编译工具依赖

1
sudo apt-get install autoconf autogen libtool

2.编译配置IGH源码

1
2
3
4
5
6
7
cd etherlab ##进入IGH源码包
./bootstrap ##执行配置脚步
## 设置配置项 实时网卡驱动 安装到的内核目录
./configure --enable-cycles --enable-hrtimer --enable-8139too=no --with-linux-dir=/usr/src/linux-headers-4.19.r26/
##编译并安装到内核模块
make -j$(nproc) all modules ##编译内核模块
sudo make modules_install install

亦可执行下述操作实现IGH内核模块编译安装
make #编译用户态的库
make modules #编译ethercat驱动
sudo make install #安装库文件
sudo make modules_install #安装驱动
sudo depmod

3.将启动文件添加到系统命令中

1
2
3
4
sudo mkdir /etc/sysconfig
## 不同版本IGH安装后的目录不同 /usr/local/ 或 /opt/etherlab 具体情况具体对待
ln -s /usr/local/etc/init.d/ethercat /etc/init.d/ethercat
ln -s /opt/etherlab/etc/init.d/ethercat /etc/init.d/ethercat

使用 ifconfig命令查询网口mac地址 (68:ed:a6:03:9f:0d )

 ifocnfig
    enp1s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
    ether 68:ed:a6:03:9f:0d  txqueuelen 1000  (以太网)
    RX packets 0  bytes 0 (0.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 0  bytes 0 (0.0 B)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    device memory 0xdf200000-df21ffff  

修改/opt/etherlab/etc/sysconfig/ethercat 或 opt/etherlab/etc/ethercat.conf文件
注意路径 “/usr/local 或 /opt/etherlab”

1
2
MASTER0_DEVICE="68:ed:a6:03:9f:0d  "  ##引号中的内容换成要作为EtherCAT总线的网卡地址,
DEVICE_MODULES="generic" ##引号里面填入 generic

将修改后的文件进行拷贝

1
2
3
##注意路径 “/usr/local 或 /opt/etherlab"
sudo cp /opt/etherlab/etc/sysconfig/ethercat /etc/sysconfig/ethercat
sudo cp /opt/etherlab/etc/ethercat.conf /etc

4.重启系统并测试

1
2
3
sudo /etc/init.d/ethercat start
#显示如下
Starting EtherCAT master 1.5.2 done

5.Ethercat tool测试

ethercat slaves

1
2
3
4
5
6
0  0:0  PREOP  +  CoolDrive R Series
1 0:1 PREOP + CoolDrive R Series
2 0:2 PREOP + CoolDrive R Series
3 0:3 PREOP + CoolDrive R Series
4 0:4 PREOP + CoolDrive R Series
5 0:5 PREOP + CoolDrive R Series

ethercat master

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Master0
Phase: Idle
Active: no
Slaves: 0
Ethernet devices:
Main: c4:00:ad:41:ce:72 (attached)
Link: DOWN
Tx frames: 0
Tx bytes: 0
Rx frames: 0
Rx bytes: 0
Tx errors: 0
Tx frame rate [1/s]: 0 0 0
Tx rate [KByte/s]: 0.0 0.0 0.0
Rx frame rate [1/s]: 0 0 0
Rx rate [KByte/s]: 0.0 0.0 0.0
Common:
Tx frames: 0
Tx bytes: 0
Rx frames: 0
Rx bytes: 0
Lost frames: 0
Tx frame rate [1/s]: 0 0 0
Tx rate [KByte/s]: 0.0 0.0 0.0
Rx frame rate [1/s]: 0 0 0
Rx rate [KByte/s]: 0.0 0.0 0.0
Loss rate [1/s]: 0 0 0
Frame loss [%]: 0.0 0.0 0.0
Distributed clocks:
Reference clock: None
DC reference time: 0
Application time: 0
2000-01-01 00:00:00.000000000