赞
踩
1、下载igh源码
gary@jxes:~$ git clone https://gitlab.com/etherlab.org/ethercat.git
2、配置(可参考官方文档)
gary@jxes:~/Xenomai/xenomai-v3.2.1$ sudo cp …/…/ethercat/ . -r
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat$ sudo ./bootstrap
为了验证,于是重新下载了版本igh(带有E100E网卡):
https://gitlab.com/etherlab.org/ethercat/-/tree/e1000e-5.10?ref_type=heads
步骤与上面一样:
gary@jxes:~/Xenomai/xenomai-v3.2.1$ sudo cp ~/Downloads/ethercat-e1000e-5.10 . -r
gary@jxes:~/Xenomai/xenomai-v3.2.1$ cd ethercat-e1000e-5.10/
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ sudo ./bootstrap
3、编译
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat$ sudo make #编译
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat$ sudo make modules #编译模块
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat$ sudo make install #安装
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat$ sudo make modules_install #安装模块
最终在安装目录有如下内容:
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ ls /opt/etherlab/
bin etc include lib sbin share
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ sudo cp /opt/etherlab/etc/sysconfig/ethercat /etc/sysconfig/
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ sudo cp /opt/etherlab/etc/init.d/ethercat /etc/init.d/
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ ls /opt/etherlab/bin/
ethercat
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ ls /opt/etherlab/etc/
ethercat.conf init.d sysconfig
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ ls /opt/etherlab/etc/init.d/
ethercat
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ ls /opt/etherlab/etc/sysconfig/
ethercat
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ ls /opt/etherlab/lib/
cmake libethercat.a libethercat.la libethercat.so libethercat.so.1 libethercat.so.1.1.0 pkgconfig
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ ls /opt/etherlab/sbin/
ethercatctl
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ ls /opt/etherlab/share/
bash-completion
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ ls /opt/etherlab/share/bash-completion/
completions
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ ls /opt/etherlab/share/bash-completion/completions/
ethercat
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$
4、配置
sudo mkdir /etc/sysconfig #创建文件夹
sudo cp /opt/etherlab/etc/sysconfig/ethercat /etc/sysconfig/ #复制配置文件
sudo cp /opt/etherlab/etc/init.d/ethercat /etc/init.d/ #复制启动脚本
sudo chmod a+x /etc/init.d/ethercat
sudo update-rc.d ethercat defaults
使能
sudo ln -s /opt/etherlab/bin/ethercat /usr/local/bin/ethercat
配置用户权限
sudo gedit /etc/udev/rules.d/99-EtherCAT.rules
输入下列内容
KERNEL==“EtherCAT[0-9]*”, MODE=“0664”, GROUP=“users”
把相关模块放进系统目录,如果使用通用网卡是这样的
sudo cp devices/ec_generic.ko /lib/modules/
(
u
n
a
m
e
−
r
)
s
u
d
o
c
p
m
a
s
t
e
r
/
e
c
m
a
s
t
e
r
.
k
o
/
l
i
b
/
m
o
d
u
l
e
s
/
(uname -r) sudo cp master/ec_master.ko /lib/modules/
(uname−r)sudocpmaster/ecmaster.ko/lib/modules/(uname -r)
这边用的是专用网卡
sudo cp devices/e1000e/ec_e1000e.ko /lib/modules/
(
u
n
a
m
e
−
r
)
s
u
d
o
c
p
m
a
s
t
e
r
/
e
c
m
a
s
t
e
r
.
k
o
/
l
i
b
/
m
o
d
u
l
e
s
/
(uname -r) sudo cp master/ec_master.ko /lib/modules/
(uname−r)sudocpmaster/ecmaster.ko/lib/modules/(uname -r)
执行
sudo depmod
查看网卡MAC地址和类型
ifconfig
得到ethercat通信的地址为
enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fbe:4e35:95d4:4056 prefixlen 64 scopeid 0x20
ether 00:e8:4c:68:30:de txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 19 bytes 3183 (3.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 19 memory 0xf7d00000-f7d20000
配置网卡
sudo gedit /etc/sysconfig/ethercat
在大约27行和60行处填入自己的网卡信息
MASTER0_DEVICE=“00:e8:4c:68:30:de” # mac 地址
DEVICE_MODULES=“e1000e” # 通用网卡填generic
启动主站
sudo /etc/init.d/ethercat start
这里只能用通用网卡演示:(e1000e网卡不存在)
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ sudo /etc/init.d/ethercat start
Starting EtherCAT master 1.5.2 done
主站启动成功表示安装成功。
ethercat 工具可以用帮助查看如下:
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ sudo ethercat --h
Usage: ethercat [OPTIONS] [ARGUMENTS]
Commands (can be abbreviated):
alias Write alias addresses.
config Show slave configurations.
crc CRC error register diagnosis.
cstruct Generate slave PDO information in C language.
data Output binary domain process data.
debug Set the master’s debug level.
domains Show configured domains.
download Write an SDO entry to a slave.
eoe Display Ethernet over EtherCAT statictics.
foe_read Read a file from a slave via FoE.
foe_write Store a file on a slave via FoE.
graph Output the bus topology as a graph.
master Show master and Ethernet device information.
pdos List Sync managers, PDO assignment and mapping.
reg_read Output a slave’s register contents.
reg_write Write data to a slave’s registers.
rescan Rescan the bus.
sdos List SDO dictionaries.
sii_read Output a slave’s SII contents.
sii_write Write SII contents to a slave.
slaves Display slaves on the bus.
soe_read Read an SoE IDN from a slave.
soe_write Write an SoE IDN to a slave.
states Request application-layer states.
upload Read an SDO entry from a slave.
version Show version information.
xml Generate slave information XML.
Global options:
–master -m Comma separated list of masters
to select, ranges are allowed.
Examples: ‘1,3’, ‘5-7,9’, ‘-3’.
Default: ‘-’ (all).
–force -f Force a command.
–quiet -q Output less information.
–verbose -v Output more information.
–help -h Show this help.
Numerical values can be specified either with decimal (no
prefix), octal (prefix ‘0’) or hexadecimal (prefix ‘0x’) base.
Call ‘ethercat --help’ for command-specific help.
Send bug reports to fp@igh-essen.com.
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ ethercat pdos
这里没有接任何ethercat设备,所以查看不到。
5、让应用程序可以使用到ethercat库
确认ethercat没有问题后,配置系统,让应用程序可以使用 /opt/etherlab/lib 到你的 /etc/ld.so.conf(/opt/ethercatlab前缀实在前面配置ethercat是选定的,默认是/opt/ethercatlab)
sudo gedit /etc/ld.so.conf
添加
/opt/etherlab/lib
执行
sudo ldconfig
测试是否安装,若成功,最后一行会显示 libethercat.so.1 -> libethercat.so.1.1.0
sudo ldconfig -v | grep libether*
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$ sudo ldconfig -v | grep libether*
/sbin/ldconfig.real: Can’t stat /usr/local/lib/x86_64-linux-gnu: No such file or directory
/sbin/ldconfig.real: Path /usr/lib/x86_64-linux-gnu' given more than once /sbin/ldconfig.real: Path
/usr/lib32’ given more than once
/sbin/ldconfig.real: Path /usr/libx32' given more than once /sbin/ldconfig.real: Path
/lib/x86_64-linux-gnu’ given more than once
/sbin/ldconfig.real: Path /usr/lib/x86_64-linux-gnu' given more than once /sbin/ldconfig.real: Path
/usr/lib’ given more than once
/sbin/ldconfig.real: /lib/x86_64-linux-gnu/ld-2.31.so is the dynamic linker, ignoring
/sbin/ldconfig.real: /lib32/ld-2.31.so is the dynamic linker, ignoring
libethercat.so.1 -> libethercat.so.1.1.0
gary@jxes:~/Xenomai/xenomai-v3.2.1/ethercat-e1000e-5.10$
=======================================================
重新制作基于通用网卡的Igh主站,其实前面第一次下载的ethercat默认就是通用网卡的,
编译过程同上。因为目前没有实时环境和ethercat设备,所以下面这个基于通用网卡的主站比较适合我。
git clone http://gitlab.com/etherlab.org/ethercat.git
cd ethercat/
./bootstrap
./configure --enable-8139too=no
sudo make
sudo make modules
sudo make install
sudo make modules_install
ifconfig
cd /opt/etherlab
sudo cp etc/sysconfig/ethercat /etc/sysconfig/
sudo ln -s /opt/etherlab/etc/init.d/ethercat /etc/init.d/
sudo gedit /etc/sysconfig/ethercat
MASTER0_DEVICE=“08:00:27:7c:5d:e8”
DEVICE_MODULES=“generic”
gedit ~/.bashrc
PATH=$PATH:/opt/etherlab/bin
source ~/.bashrc
sudo depmod
gary@jxes:/opt/etherlab$ sudo ethercat slave
Failed to obtain number of masters: ioctl() version magic is differing: /dev/EtherCAT0: 30, ethercat tool: 37
主站编译安装配置完成后,需要重启ubuntu就OK了。
在下次启动ubuntu时,扫描不到网卡:
gary@jxes:~$ ethercat slave
Failed to obtain number of masters: Failed to open master device /dev/EtherCAT0: No such file or directory
需要启动ethercat主站:
gary@jxes:~$ sudo /etc/init.d/ethercat start
[sudo] password for gary:
Starting EtherCAT master 1.5.2 done
gary@jxes:~$ ls /dev/EtherCAT0
/dev/EtherCAT0
gary@jxes:~$
gary@jxes:~$ ethercat slave
gary@jxes:~$ sudo ethercat slaves
[sudo] password for gary:
gary@jxes:~$ ls /dev/EtherCAT0
/dev/EtherCAT0
gary@jxes:~$ sudo ethercat slave
gary@jxes:~$
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。