コード例 #1
0
<?php

use PHPModbus\ModbusMaster;
use PHPModbus\PhpType;
// Create Modbus object
$modbus = new ModbusMaster("192.192.15.51", "UDP");
try {
    // FC 3
    // read 10 words (20 bytes) from device ID=0, address=12288
    $recData = $modbus->readMultipleRegisters(0, 12288, 10);
} catch (Exception $e) {
    // Print error information if any
    echo $modbus;
    echo $e;
    exit;
}
// Received data
echo "<h1>Received Data</h1>\n";
print_r($recData);
// Conversion
echo "<h2>32 bits types</h2>\n";
// Chunk the data array to set of 4 bytes
$values = array_chunk($recData, 4);
// Get float from REAL interpretation
echo "<h3>REAL to Float</h3>\n";
foreach ($values as $bytes) {
    echo PhpType::bytes2float($bytes) . "</br>";
}
// Get integer from DINT interpretation
echo "<h3>DINT to integer </h3>\n";
foreach ($values as $bytes) {
コード例 #2
0
<?php

use PHPModbus\ModbusMaster;
// Create Modbus object
$ip = "192.192.15.51";
$modbus = new ModbusMaster($ip, "UDP");
try {
    // FC 3
    $moduleId = 0;
    $reference = 12288;
    $mw0address = 12288;
    $quantity = 6;
    $recData = $modbus->readMultipleRegisters($moduleId, $reference, $quantity);
} catch (Exception $e) {
    echo $modbus;
    echo $e;
    exit;
}
?>
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=windows-1250">
		<meta name="generator" content="PSPad editor, www.pspad.com">
		<title>WAGO 750-841 M-memory dump</title>
	</head>
	<body>
	<h1>Dump of M-memory from WAGO 750-84x series coupler.</h1>
	<ul>
		<li>PLC: 750-84x series</li>
		<li>IP: <?php 
echo $ip;