# SOEM

**SOEM**（Simple Open EtherCAT Master，简单开源 EtherCAT 主站）是一个用 C 语言编写的开源软件库，实现了用于实时工业通信的 EtherCAT 主站（MainDevice）。它面向资源有限的嵌入式系统设计，可运行于 Linux 和 Windows，以库的形式而非独立应用程序分发，以便开发者将 EtherCAT 通信构建到自己的程序中。<sup>[1](https://github.com/openethercatsociety/soem)</sup><sup> • </sup><sup>[2](https://index.ros.org/p/soem/)</sup>

| 关键事实 | 详情 |
|---|---|
| 是什么 | 用于开发 EtherCAT 主设备（主站）的 C 库，面向实时嵌入式通信<sup>[1](https://github.com/openethercatsociety/soem)</sup> |
| 起源与管理 | 版权所有 (C) 2005–2025 Speciaal Machinefabriek Ketels v.o.f. 与 Arthur Ketels；(C) 2009–2025 瑞典 RT-Labs AB；由 Open EtherCAT Society 托管于 GitHub<sup>[1](https://github.com/openethercatsociety/soem)</sup> |
| 许可 | 历史上为 GPLv2 附加链接例外；自 v2.0.0 起采用 GPLv3 或商业许可的双重许可，使用仍需从德国倍福自动化有限公司（Beckhoff Automation GmbH）获得 EtherCAT 主站许可<sup>[3](https://github.com/OpenEtherCATsociety/SOEM/releases)</sup><sup> • </sup><sup>[4](https://github.com/OpenEtherCATsociety/soem-ng/blob/master/LICENSE)</sup> |
| 平台 | Linux（主要目标平台）、Windows，以及包括 ERIKA、RTEMS 和 macOS（v1.4.0 新增）在内的嵌入式/RTOS 目标<sup>[2](https://index.ros.org/p/soem/)</sup><sup> • </sup><sup>[3](https://github.com/OpenEtherCATsociety/SOEM/releases)</sup> |
| 实时性能 | 在 Ubuntu 22.04 配合 Xenomai 3.3 上，实现稳定的 1 kHz 控制，平均延迟约 0.9 μs，空闲时数据包时序标准差约 202 ns，压力条件下约 499 ns<sup>[5](https://www.kci.go.kr/kciportal/ci/sereArticleSearch/ciSereArtiView.kci?sereArticleSearchBean.artiId=ART003251855)</sup> |
| 网络访问 | 使用原始套接字，因此链接 SOEM 的可执行文件需要 root 权限或被授予网络能力<sup>[2](https://index.ros.org/p/soem/)</sup> |
| 社区 | GitHub 上约 2.1k 星标、916 次复刻，主分支有 313 次提交<sup>[1](https://github.com/openethercatsociety/soem)</sup> |

## 目的与设计

EtherCAT（Ethernet for Control Automation Technology，控制自动化技术以太网）是一种基于以太网的现场总线，广泛应用于工业自动化，而主站（MainDevice）是生成 EtherCAT 帧并协调网络上从站设备的节点。<sup>[6](https://ms-iot.github.io/ROSOnWindows/tutorials/ethercat/soem.html)</sup> SOEM 以轻量级 C 库的形式提供该协议的主站侧实现。其架构最大限度地减少资源消耗，因而适合嵌入式环境，也可用于桌面 Linux 和 Windows 系统。<sup>[1](https://github.com/openethercatsociety/soem)</sup>

由于 SOEM 是一个库，应用程序仍需负责协议周边的部分：读写要发送和接收的过程数据、保持本地 I/O 数据与全局 IOmap 同步，以及检测和管理 SOEM 报告的错误。所有代码都位于应用程序本地或全局变量中，开发者可以自行调整和优化。<sup>[7](https://github.com/OrebroUniversity/soem/blob/master/doc/tutorial.txt)</sup>

## SOEM 应用程序的工作方式

典型的 SOEM 程序遵循该库教程中描述的流程。启动后，应用程序调用 `ec_init(ifname)` 将网卡绑定为 EtherCAT 以太网接口；如果 SOEM 在编译时启用了线缆冗余支持，`ec_init_redundant` 会打开第二个端口作为备份。<sup>[7](https://github.com/OrebroUniversity/soem/blob/master/doc/tutorial.txt)</sup>

SOEM 仅支持运行时配置。调用 `ec_config_init(FALSE)` 会发送地址 0 的 BRD（广播读取），所有功能正常的从站都会响应，工作计数器等于发现的从站数量。同一调用还会为支持邮箱的从站建立邮箱，并请求所有从站进入 PRE_OP 状态；读取和配置的数据存储在全局数组 `ec_slave` 中，该数组充当关键值的占位符。<sup>[7](https://github.com/OrebroUniversity/soem/blob/master/doc/tutorial.txt)</sup>

## 历史与版本

SOEM 最初托管在 BerliOS 开发站点，后迁移至 Open EtherCAT Society 组织下的 GitHub。<sup>[2](https://index.ros.org/p/soem/)</sup> 该协会还维护从站侧对应项目 **SOES**（Simple Open Source EtherCAT Slave，简单开源 EtherCAT 从站）及相关仓库。<sup>[8](https://github.com/openethercatsociety)</sup>

v1.4.0 版本新增了 ERIKA 目标、macOS 目标，以及基于现有邮箱 API 的通过 EtherCAT 传输以太网（EoE）的支持。<sup>[3](https://github.com/OpenEtherCATsociety/SOEM/releases)</sup>**v2.0.0** 版本是一次重大更新，其破坏性变更包括移除旧版 API、将重叠模式和对齐模式移入上下文，以及更改头文件布局，使 SOEM 通过 `soem/soem.h` 引入。新特性包括循环从站邮箱处理以提升多线程下的 XoE 性能、支持从 ENI 文件进行 PDO 映射和分配的 ENI 解析器，以及通过 CMake 选项在构建时配置最大尺寸和超时等设置。仓库采用现代 CMake 重构，新增了用于单调时间的公共 OSAL 函数，无人维护的移植版本被移至 contrib 文件夹。<sup>[3](https://github.com/OpenEtherCATsociety/SOEM/releases)</sup>

## 许可

SOEM 的许可分为两层。源码历史上依据 GNU 通用公共许可证第 2 版附加链接例外分发，该例外允许其他作品与其链接而无需使整个作品受 GPL 约束。<sup>[4](https://github.com/OpenEtherCATsociety/soem-ng/blob/master/LICENSE)</sup><sup> • </sup><sup>[9](https://ftp.osuosl.org/.1/ros/ros_wiki_mirror/soem.html?distro=indigo)</sup> 自 v2.0.0 起，项目转为 GPLv3 或商业许可的双重许可。<sup>[3](https://github.com/OpenEtherCATsociety/SOEM/releases)</sup>

另外，EtherCAT 技术、其商品名称及标识是德国倍福自动化有限公司的知识产权。SOEM 许可文本声明，SOEM 仅可用于创建、使用、销售或以其他方式分发 EtherCAT 网络主站，且须从德国倍福自动化有限公司获得 EtherCAT 主站许可。<sup>[4](https://github.com/OpenEtherCATsociety/soem-ng/blob/master/LICENSE)</sup> 向项目贡献代码需要签署[贡献者许可协议](https://www.edgepedia.org/zh/contributor-license-agreement)。<sup>[1](https://github.com/openethercatsociety/soem)</sup>

## 实时性能

2025 年《半导体与显示技术杂志》上的一项研究比较了 SOEM 与 EtherLab（IgH）主站，两者均部署在采用 [Xenomai](https://www.edgepedia.org/zh/xenomai) 3.3 实时框架的 [Ubuntu](https://www.edgepedia.org/zh/ubuntu) 22.04 上，并在空闲和压力条件下进行评估。两种主站均实现了稳定的 1 kHz 周期控制，空闲条件下平均延迟低于微秒，约 0.9 μs，最大抖动低于 3.6 μs；压力条件下最大抖动为 14 至 15 μs。<sup>[5](https://www.kci.go.kr/kciportal/ci/sereArticleSearch/ciSereArtiView.kci?sereArticleSearchBean.artiId=ART003251855)</sup>

在数据包层面，SOEM 空闲时的时间标准差约为 202 ns，压力条件下为 499 ns，而 EtherLab 分别以 178 ns 和 396 ns 表现出略好的稳定性。研究将差异归因于架构：SOEM 作为平台无关的用户态应用程序运行，其性能取决于 RTnet 等实时网络驱动，而 EtherLab 实现为具有原生驱动支持的 [Linux 内核](https://www.edgepedia.org/zh/linux-kernel)模块。两种方案均被判定为对实时 EtherCAT 主站运行有效。<sup>[5](https://www.kci.go.kr/kciportal/ci/sereArticleSearch/ciSereArtiView.kci?sereArticleSearchBean.artiId=ART003251855)</sup>

## 在机器人技术与 ROS 中的应用

SOEM 是[机器人操作系统](https://www.edgepedia.org/zh/robot-operating-system)生态系统中 EtherCAT 通信的常见选择。一个 ROS 封装包将上游 SOEM 仓库作为 git 子树嵌入，并提供将其作为 ROS 包发布所需的 CMake 配置支持；该包已为 ROS 发行版 indigo、kinetic 和 melodic 发布，可通过 `sudo apt install ros-<DISTRO>-soem` 安装。<sup>[2](https://index.ros.org/p/soem/)</sup> 由于 SOEM 使用原始套接字，链接它的可执行文件通常以 `sudo` 或 root 身份运行；ROS 生态系统提供了工具 `ethercat_grant`，用于改为授予所需的网络能力。<sup>[2](https://index.ros.org/p/soem/)</sup>

机器人项目以多种模式基于 SOEM 构建。ICube-Robotics 的 ethercat_driver_ros2 栈将 EtherCAT 模块与 ros2_control 结合，允许从配置文件参数化和组装硬件接口。<sup>[10](https://icube-robotics.github.io/ethercat_driver_ros2/)</sup> EcatV2 Master 项目用 [ROS 2](https://www.edgepedia.org/zh/ros-2) 封装 SOEM 1.4.0 版本，使用 YAML 配置从站拓扑和任务映射，通过 CPU 核心隔离实现低延迟控制循环，并支持断开后自动重连；在 Ubuntu 24.04 实时内核上，测得与单个从站的往返时间均值为 0.241 ms，最大值为 0.414 ms。<sup>[11](https://github.com/AIMEtherCAT/EcatV2_Master/)</sup> 欧洲空间局的一个漫游车驱动使用 SOEM 通过 EtherCAT 与 Elmo 驱动器和 ATI 力扭矩传感器通信。<sup>[12](https://github.com/hikhhbro/platform_driver_ethercat_ros2)</sup> SOEM 还附带实用工具，如用于读取从站信息的 `slaveinfo`、用于烧写从站 EEPROM 的 `eepromtool`，以及用于检查主从站连接的 `simple_test`。<sup>[11](https://github.com/AIMEtherCAT/EcatV2_Master/)</sup>

## References

1. [OpenEtherCATsociety/SOEM repository README, GitHub](https://github.com/openethercatsociety/soem)
2. [soem – ROS Package Overview, ROS Index](https://index.ros.org/p/soem/)
3. [Releases · OpenEtherCATsociety/SOEM, GitHub](https://github.com/OpenEtherCATsociety/SOEM/releases)
4. [soem-ng LICENSE, Open EtherCAT Society, GitHub](https://github.com/OpenEtherCATsociety/soem-ng/blob/master/LICENSE)
5. [Sungjin Kang (2025). Performance Comparison of Open-Source Based Real-Time EtherCAT Masters. Journal of the Semiconductor & Display Technology 24(3), 121–126. KCI](https://www.kci.go.kr/kciportal/ci/sereArticleSearch/ciSereArtiView.kci?sereArticleSearchBean.artiId=ART003251855)
6. [Getting Started with SOEM Application, ROS on Windows, Microsoft](https://ms-iot.github.io/ROSOnWindows/tutorials/ethercat/soem.html)
7. [SOEM tutorial (doc/tutorial.txt), Orebro University mirror, GitHub](https://github.com/OrebroUniversity/soem/blob/master/doc/tutorial.txt)
8. [Open EtherCAT Society organization, GitHub](https://github.com/openethercatsociety)
9. [soem ROS wiki page (license: GPLv2 with linking exception)](https://ftp.osuosl.org/.1/ros/ros_wiki_mirror/soem.html?distro=indigo)
10. [EtherCAT Driver ROS2 Stack documentation, ICube-Robotics](https://icube-robotics.github.io/ethercat_driver_ros2/)
11. [AIMEtherCAT/EcatV2_Master README, GitHub](https://github.com/AIMEtherCAT/EcatV2_Master/)
12. [hikhhbro/platform_driver_ethercat_ros2 README, GitHub](https://github.com/hikhhbro/platform_driver_ethercat_ros2)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Frameworks, libraries, and APIs

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/soem

English original: https://www.edgepedia.org/soem
