PLCOpen 运行环境测试与搭建(Beremiz 开源软 PLC)
👁 1
分类:工业互联网
在 Ubuntu 18.04 实时内核上搭建 PLCOpen(Beremiz)开源软 PLC 运行环境:依赖安装、MatIEC/CanFestival/modbus/BACnet/EtherCAT 源码编译,以及 IDE 与 Runtime 的启动调试全流程。
PLCOpen 运行环境测试与搭建(Beremiz 开源软 PLC)
一、项目背景
PLCOpen 是 PLC 编程领域的国际标准化组织,定义了 IEC 61131-3 编程语言标准。Beremiz 是一款遵循该标准的开源软 PLC(Soft PLC)IDE + Runtime 解决方案:IDE 负责编写/编译梯形图、ST、FBD 等 IEC 61131-3 语言,Runtime 负责在 Linux 等平台上实时执行编译后的代码,并支持 Modbus、CANopen、BACnet、EtherCAT 等多种现场总线。
本篇文章在 Ubuntu 18.04 实时内核上完整搭建 Beremiz 运行环境,为后续 PLC 应用开发与总线调试提供平台基础。
二、技术方案:环境与组件
- 系统:Ubuntu 18.04.6 LTS,内核 5.4.10-rt5-rt(PREEMPT_RT 实时内核)
- IDE:Beremiz(基于 Python 的 PLC 编程 IDE)
- 编译器:MatIEC(IEC 61131-3 语言 → C 代码编译器)
- 总线栈:CanFestival(CANopen)、modbus、BACnet、EtherCAT(ethercat-1.5.2)
实时内核配合软 PLC Runtime,可在通用 x86 平台上实现确定性控制周期,替代部分传统硬 PLC 场景。
三、系统架构:安装依赖
# 基础编译工具
sudo apt-get install build-essential bison flex autoconf
sudo apt-get install python-wxgtk3.0 pyro mercurial
sudo apt-get install python-nevow python-matplotlib python-lxml python-zeroconf python-cycler
sudo apt-get install python-autobahn python-u-msgpack
sudo apt-get install libpython2.7-dev
# Python 2 环境(Beremiz 依赖)
sudo apt install python-pip
pip2 install --user sslpsk posix_spawn
sudo apt install subversion
pip install future
四、实施过程:源码下载与编译
4.1 下载源码
git clone https://bitbucket.org/automforge/beremiz.git
git clone https://bitbucket.org/automforge/matiec_git.git
git clone https://bitbucket.org/mjsousa/modbus_git.git
svn checkout https://svn.code.sf.net/p/bacnet/code/trunk /bacnet-stack/ BACnet
4.2 编译各总线模块
# (1) 编译 MatIEC(IEC61131-3 编译器)
autoreconf -i
./configure
make
# (2) 编译 CanFestival(CANopen 协议栈,虚拟模式)
./configure --can=virtual
make
# (3) 编译 modbus
make
# (4) 编译 BACnet
make MAKE_DEFINE='-fPIC' MY_BACNET_DEFINES='-DPRINT_ENABLED=1 -DBACAPP_ALL -DBACFILE -DINTRINSIC_REPORTING -DBACNET_TIME_MASTER -DBACNET_PROPERTY_LISTS=1 -DBACNET_PROTOCOL_REVISION=16' library
# (5) 编译 EtherCAT 主站
tar -xvf ethercat-1.5.2.tar.bz2
./configure --help # 查询需要的模块
./configure --enable-8139too=no
4.3 启动 IDE 与 Runtime
# 创建工作目录
mkdir plcwork
# 开启 IDE
python Beremiz.py
# 开启 Runtime(监听 61194 端口,绑定本地)
cd ~/plcopen/beremiz/
python Beremiz_service.py -p 61194 -i localhost -x 0 -a 1 ~/plcopen/plcwork/
五、应用价值
- 开源可控:整套软 PLC 方案无授权费用,代码开放,可深度定制总线与功能块;
- 实时性:PREEMPT_RT 内核下 Runtime 可满足多数工业控制场景的周期要求;
- 多总线:一个平台同时支持 Modbus、CANopen、BACnet、EtherCAT,适合设备联网与 SCADA 场景;
- 学习价值:从 IEC 61131-3 语言到 C 代码生成、从 IDE 到 Runtime 的完整链路,是理解 PLC 工作原理的最佳开源范本。
六、SEO关键词
PLCOpen、Beremiz、开源PLC、软PLC、MatIEC、IEC61131-3、Ubuntu18.04、CanFestival、EtherCAT主站、PLC编程环境
