# PLC INTER **Repository Path**: qulee/plc-inter ## Basic Information - **Project Name**: PLC INTER - **Description**: 使用HTTP接口读取PLC的中间件. - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: release_2.x - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-05 - **Last Updated**: 2026-07-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # PLC API Gateway PLC读写操作中间件程序,提供“PLC-数据库”、“数据库-PLC”、“PLC-PLC”间的数据同步同步功能,并提供PLC的HTTP和TCP数据读写接口。 ## 功能特性 - 目前支持 PLC 类型(Rockwell/Allen-Bradley、Siemens S7、Modbus TCP、模拟 PLC);Modbus 标签地址串格式见 `plc_core/modbus_tcp.py` 模块文档 - RESTful HTTP API 接口,支持读写 PLC 标签 - TCP API 接口,支持高频读写操作(status、批量读取、批量写入) - PLC 与数据库双向同步功能有做同步任务管理(启动、暂停、恢复、停止)和 性能优化(缓存、请求合并、熔断保护) - 动态脚本加载器:支持在运行时动态加载、启动和停止 Python 脚本 ## 系统要求 - **Python版本**: 3.8 或更高版本(推荐 3.9+) - ⚠️ **重要**:`pydantic>=2.0.0` 需要 Python 3.8+ - 如果部署服务器使用 Python 3.7,requirements 文件会自动安装兼容版本(pydantic<2.0.0) - **建议**:开发环境和部署服务器使用相同的 Python 版本,以避免依赖兼容性问题 ## 安装和构建 ### 安装依赖 使用 `install_all_deps.py` 脚本自动安装所有必要的依赖包(含 FastAPI、Rockwell、Siemens、**Modbus TCP** 等): ```bash # 不使用代理 python install_all_deps.py # 使用代理 python install_all_deps.py --proxy 10.60.1.2:8080 ``` 仅按需安装 PLC 驱动时,可单独安装对应 `requirements` 文件,例如: ```bash pip install -r requirements.fastapi.txt pip install -r requirements.rockwell.txt pip install -r requirements.siemens.txt pip install -r requirements.modbus.txt ``` | PLC 协议 | 依赖文件 | 主要 Python 包 | |----------|----------|----------------| | Rockwell / Allen-Bradley | `requirements.rockwell.txt` | `pylogix` | | Siemens S7 | `requirements.siemens.txt` | `python-snap7` | | Modbus TCP | `requirements.modbus.txt` | `pymodbus` | ### 构建可执行文件 使用 `build_with_deps.py` 脚本构建单文件可执行程序: ```bash # 构建 FastAPI 版本 python build_with_deps.py # 检查依赖是否安装 python build_with_deps.py --check-deps ``` 构建完成后,可执行文件位于 `dist/http_plc_inter_fastapi.exe`(Windows)或 `dist/http_plc_inter_fastapi`(Linux)。 ## 快速开始 1. 安装依赖:`python install_all_deps.py` 2. 配置 `config.json` 文件 3. 启动服务:`python -m plc_api_gateway.server` 默认服务地址: - HTTP API: `http://0.0.0.0:8678` - TCP API: `tcp://0.0.0.0:8679` ## 文档 - [HTTP API 接口文档](docs/http_api.md) - 完整的 HTTP API 接口说明和示例(含各 PLC **标签/地址串格式**,见文档内「标签格式说明」) - [TCP API 接口文档](docs/tcp_api.md) - TCP 接口协议说明和客户端示例(标签格式与 HTTP 一致) - [配置指南](docs/configuration_guide.md) - `config.json` 详细说明(含 `plcs[].type`、`Modbus` 的 `port` / `unit_id` 等) - [动态脚本加载器使用指南](docs/script_loader_guide.md) - 动态脚本加载功能的使用说明和示例 - [CSV to Topics 快速开始](config/csv_to_topics/QUICK_START.md) - 从 CSV 生成 `topics` 配置:默认图形界面、命令行合并 `config.json`、批量示例;详细说明见同目录 [CSV_TO_TOPICS_README.md](config/csv_to_topics/CSV_TO_TOPICS_README.md) Modbus TCP 地址串语法摘要见源码 [`plc_core/modbus_tcp.py`](plc_core/modbus_tcp.py) 模块顶部说明。 ## 许可证 详见 [LICENSE](LICENSE) 文件。