OpenPLC环境搭建指南
OpenPLC是一个开源的工业自动化平台,支持IEC 61131-3标准。以下是详细的环境搭建步骤:
方案一:在树莓派上部署(推荐)
硬件要求:
- 树莓派(3/4代兼容性最佳)
- MicroSD卡(≥8GB)
- 电源适配器
步骤:
-
刷写操作系统
# 下载树莓派OS Lite版 wget https://downloads.raspberrypi.org/raspios_lite_armhf_latest # 使用BalenaEtcher将镜像写入SD卡
-
安装OpenPLC Runtime
sudo apt update && sudo apt upgrade -y git clone https://github.com/thiagoralves/OpenPLC_v3.git cd OpenPLC_v3 ./install.sh rpi # 选择树莓派平台
-
访问Web界面
- 浏览器访问:
http://<树莓派IP>:6688
- 默认账号:
openplc
,密码:openplc
- 浏览器访问:
方案二:在Windows PC上部署
步骤:
-
安装运行环境
- 安装 Python 3.8+
- 安装 Git
-
安装OpenPLC
git clone https://github.com/thiagoralves/OpenPLC_v3.git cd OpenPLC_v3 install_win.bat # 双击运行
-
启动服务
- 运行:
OpenPLC Runtime\run_openplc.bat
- 访问:
http://localhost:6688
- 运行:
方案三:Docker容器部署
步骤:
# 拉取镜像
docker pull thiagoralves/openplc:v3
# 运行容器
docker run -d -p 6688:6688 -p 502:502 --name openplc thiagoralves/openplc:v3
# 访问:http://localhost:6688
编辑器安装(全平台通用)
-
下载OpenPLC Editor:
- Windows版
- Linux/macOS编译:
git clone https://github.com/thiagoralves/OpenPLC_Editor.git cd OpenPLC_Editor make ./openplc_editor
-
上传程序:
- 编写程序后点击 “PLC > Upload”
- 输入Runtime的IP地址(默认端口4680)
常见问题解决
-
端口冲突:
- 修改Runtime端口:编辑
webserver/webserver.py
中的PORT
值
- 修改Runtime端口:编辑
-
硬件支持:
- 添加自定义驱动:
hardware_layers/
目录下创建新驱动模板
- 添加自定义驱动:
-
Modbus通信:
- 启用Slave模式:Web界面 > Slave Devices > 添加Modbus设备
验证安装
- 在Editor中创建简单梯形图程序:
|--[ ]----[ ]--( )--| # 基本启停电路
- 上传到Runtime并监控I/O状态
提示:完整文档见OpenPLC官方文档