天天看點

【實操填坑】在樹莓派上編譯 EtherCAT IgH Master 主站程式

官網下載下傳位址:

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/<uname -r>/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 <COMMAND> [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 <master> 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主站部分完結, 之後就是如何使用主站來控制 伺服點選轉圈圈了。#

繼續閱讀