thewateringcan/phpmodbus

PhpModBus 的 Composer 版本

0.8 2023-09-14 14:07 UTC

This package is auto-updated.

Last update: 2024-09-10 18:23:53 UTC


README

本项目是使用 PHP 实现基于 Modbus TCP 和 UDP 协议基本功能的一个实现。它是 Google Code 上的项目页面的发布版本的副本,并增加了 composer 支持。

特性

  • Modbus 主站
    • FC1 - 读取线圈
    • FC2 - 读取输入离散量
    • FC3 - 读取保持寄存器
    • FC4 - 读取保持输入寄存器
    • FC5 - 写单个线圈
    • FC6 - 写单个寄存器
    • FC15 - 写多个线圈
    • FC16 - 写多个寄存器
    • FC22 - 掩码写寄存器
    • FC23 - 读取/写入多个寄存器

示例

 // Modbus master UDP
 $modbus = new ModbusMaster("192.168.1.1", "UDP");
 // Read multiple registers
 try {
     $recData = $modbus->readMultipleRegisters(0, 12288, 5);
 }
 catch (Exception $e) {
     // Print error information if any
     echo $modbus;
     echo $e;
     exit;
 }
 // Print data in string format
 echo PhpType::bytes2string($recData);

更多内容请参阅 文档常见问题解答