【实操填坑】在树莓派上编译 EtherCAT IgH Master 主站程序
阅读原文时间:2023年07月08日阅读:1

官网下载地址:
https://etherlab.org/download/ethercat/  (可list查看文件列表)
https://etherlab.org/download/ethercat/ethercat-1.5.2.pdf (pdf doc手册)

===============================================
本人操作环境:树莓派 3B+
pi@ProfinetPI:~ $ uname -a
Linux ProfinetPI 4.19.71-rt24-v8 #1 SMP PREEMPT RT Wed Jan 26 01:35:13 CST 2022 aarch64 GNU/Linux

ethercat代码版本为: 1.5.2-master-3ee5e50a
(注意:1.5.2 release包,在内核>4.15.x时会编译make modules出错,因为从4.15开始内核timer使用方式更改。)

==============================================
1. 编译ethercat master和安装:

$ git clone https://gitlab.com/etherlab.org/ethercat.git

$ cd ethercat (进入clone的源码主目录)

$ ./bootstrap (若下载的是tar.bz包,其中带有m4子目录,则不需此步骤; git clone的才需要)

$ ./configure --prefix=/opt/etherlab --with-linux-dir=/usr/src/linux --enable-8139too=no --enable-generic=yes  (提前准备好内核源码,已编译)

$ make -j 4 (4个线程加快)

$ make modules (需要有Modules.symvers和 System.map文件)(分别是编译内核,编译内核模块后产生)
(此命令执行的结尾会运行depmod, 注意不能skip, 否则安装时 modprobe会有问题)

# make install
# make modules_install //注意 depmod是否执行了. 安装到了 /lib/modules//ethercat/ 目录下

2. 开始与系统集成【二选1】
//【方案1】 如果要用 init.d脚本, 那么用下面3行:
$ sudo mkdir /etc/sysconfig
$ sudo cp /opt/etherlab/etc/sysconfig/ethercat /etc/sysconfig/ethercat //这是配置文件
$ sudo cp /opt/etherlab/etc/init.d/ethercat /etc/init.d/ethercat //这是启动脚本,特别要注意修改其中 -c 的配置文件位置!!!
$ insserv ethercat (安装为开机自启动服务)
// 方案1启停 master内核主站的命令为: # /etc/init.d/ethercat start| stop| reload (或 #service ethercat start|stop)

//【方案2】 如果是用的 systemd管理服务, 则运行如下命令:
# cp /opt/etherlab/etc/ethercat.conf /etc/ethercat.conf (配置文件的位置)
# nano /usr/lib/systemd/system/ethercat.service (如果没有,照着pdf doc 第7.4节拷贝一个.)
         (这里特别要修改其中的命令!!!! 显式自己手动写上配置文件位置 -c /path/to/conf_file 再 start) (坑:不会如pdf所说默认去找/etc/ethercat.conf作为配置文件)
# systemctl enable ethercat.service (设置开机启动服务)
// 方案2启停 master内核主站的命令为: # systemctl start| stop| status ethercat.service

其实这两种系统集成方案,都是用了ethercat提供的最基础的命令来启停 内核模块,
也可以直接运行基础命令来启停【方案3】, 指令如下:
# /opt/etherlab/sbin/ethercatctl -c /path/to/conf_file start|stop 【注意配置文件路径要正确

3.启动EtherCAT主站内核模块

三种方案不管用哪种, 在启动前都要修改自己的配置文件

启动前一定要确保对应配置文件中加入了 网卡mac 和 内核模块类型
$ sudo vi /etc/sysconfig/ethercat //更改配置文件:(填入MAC地址或"eth0",以及网卡类型 "generic"

正式开始启动Master主站 (三种方法选一种即可,以方案1为例)
# /etc/init.d/ethercat start|stop //注意配置文件中路径是否对.

启动后,检查是否已经载入了内核模块:
# lsmod | grep ec_ (会输出两行, ec_generic 和 ec_master, 说明已装载)

4.使用tools工具

tools工具为:/opt/etherlab/bin/ethercat, 连接符号到/usr/bin/下以方便使用:
$ sudo ln -s /opt/etherlab/bin/ethercat /usr/bin/ethercat //软连接

tools的使用(/opt/etherlab/bin/ethercat为tools工具)参见 pdf doc 第7章,简单命令如下:
# ethercat slave (显示挂载在主站上的从站信息)
0 0:0 PREOP + SV660_1Axis_00913  (显示出了挂在主站网络上的 汇川 SV660N伺服)

pi@ProfinetPI:~ $ 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.
ip Set EoE IP parameters.
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.

#安装IgH EtherCAT主站部分完结, 之后就是如何使用主站来控制 伺服点击转圈圈了。#

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章