erikwang2013 / industrial-protocols-dnp3
DNP3 协议包 — 电力自动化通信,Class 0 轮询,CRC-16/DNP 校验
Package info
github.com/erikwang2013/industrial-protocols-dnp3
Type:industrial-protocol
pkg:composer/erikwang2013/industrial-protocols-dnp3
Requires
- php: >=8.1
- erikwang2013/industrial-protocols-kernel: *
README
DNP3 协议包 — 电力自动化通信,Class 0 轮询,CRC-16/DNP 校验。纯 PHP 实现,通过内核框架适配器兼容 6 种 PHP 运行时环境。
安装
composer require erikwang2013/industrial-protocols-kernel erikwang2013/industrial-protocols-dnp3
本包依赖 erikwang2013/industrial-protocols-kernel,内核提供连接管理、协议注册、协程适配、事件系统等基础设施。
架构
基于内核 SDK 接口(ProtocolInterface/ConnectorInterface/DriverInterface/FrameInterface)构建,通过 Dnp3Driver 实现底层通信,Dnp3Connector 封装为统一 ConnectorInterface。
功能
完整的 dnp3 协议帧编解码、驱动层通信、Connector 封装、健康检查、连接策略支持(Lazy/Eager/Pooled)
支持的框架
本包通过内核的框架适配器兼容以下 6 种 PHP 运行时环境:Laravel (ServiceProvider+Facade+artisan)、Webman (config/plugin 自动发现+ProtocolProcess)、Hyperf (ConfigProvider+DI+KernelFactory)、ThinkPHP (services.php+IndustrialProtocolsService)、Yii2 (Bootstrap+组件注册)、Plain PHP (直接实例化 Kernel)
Laravel 示例
use Erikwang2013\IndustrialProtocols\Kernel; use Erikwang2013\IndustrialProtocols\Modbus\ModbusProtocol; // AppServiceProvider::boot() $kernel = app(Kernel::class); $kernel->getProtocolRegistry()->register(new ModbusProtocol()); $kernel->boot(); $conn = $kernel->getConnectionManager()->connect('device-id'); $result = $conn->read('address'); // 或使用 Facade \Erikwang2013\IndustrialProtocols\Framework\Laravel\IndustrialProtocolsFacade::connect('device-id')->read('address');
Webman 示例
Worker 启动时 ProtocolProcess 自动初始化。配置 config/plugin/erikwang2013/industrial-protocols-kernel/config/industrial-protocols.php。
Hyperf 示例
$kernel = \Hyperf\Context\ApplicationContext::getContainer()->get(Kernel::class); $conn = $kernel->getConnectionManager()->connect('device-id');
使用说明
$conn = $kernel->getConnectionManager()->connect('rtu-001'); $result = $conn->read('30:1:5'); // Group 30, Variation 1, Index 5 $conn->write(['10:2:1' => 1]); // Select-Before-Operate
配置示例
'devices' => [ 'device-id' => [ 'protocol' => 'dnp3', 'host' => '192.168.1.10', 'port' => 20000, 'timeout' => 3000, ], ],
适配厂商
Hilscher (netX)、Moxa (MGate)、Siemens (SICAM)
系统要求
- PHP >= 8.1
- Composer
- erikwang2013/industrial-protocols-kernel
相关链接
License
MIT — Copyright (c) 2026 erik erik@erik.xyz — https://erik.xyz