Advertisement
noam76

modbus.php

May 13th, 2023
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.38 KB | None | 0 0
  1. <?php
  2. require_once 'vendor/autoload.php';
  3. use Phpmodbus\Phpmodbus\ModbusMaster;
  4.  
  5. $ip = "192.168.1.1"; // Modbus IP device address
  6. $modbus = new ModbusMaster($ip, "TCP");
  7.  
  8. try {
  9.     $registers = $modbus->readMultipleRegisters(0, 0, 10); // Read 10 registers starting from address 0
  10.     print_r($registers);
  11. } catch (Exception $e) {
  12.     echo "Error: " . $e->getMessage();
  13. }
  14. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement