<?php

use PHPModbus\ModbusMaster;
// Create Modbus object
$modbus = new ModbusMaster("192.192.15.51", "UDP");
// Data to be writen
$bitValue = true;
$bitNumber = 2;
$andMask = 0xffff ^ pow(2, $bitNumber);
$orMask = 0x0 ^ pow(2, $bitNumber) * $bitValue;
try {
    // FC22
    $modbus->maskWriteRegister(0, 12288, $andMask, $orMask);
} catch (Exception $e) {
    // Print error information if any
    echo $modbus;
    echo $e;
    exit;
}
// Print status information
echo $modbus;
Exemple #2
0
<?php

use PHPModbus\ModbusMaster;
// Create Modbus object
$modbus = new ModbusMaster("192.192.15.51", "UDP");
// Data to be writen
$data = array(-1000);
try {
    // FC6
    $modbus->writeSingleRegister(0, 12288, $data);
} catch (Exception $e) {
    // Print error information if any
    echo $modbus;
    echo $e;
    exit;
}
// Print status information
echo $modbus;
<?php

use PHPModbus\ModbusMaster;
// Create Modbus object
$modbus = new ModbusMaster("192.192.15.51", "UDP");
// Data to be written - supports both 0/1 and booleans (true, false)
$data = array(1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
try {
    // FC15
    $modbus->writeMultipleCoils(0, 12288, $data);
} catch (Exception $e) {
    // Print error information if any
    echo $modbus;
    echo $e;
    exit;
}
// Print status information
echo $modbus;
Exemple #4
0
<?php

use PHPModbus\ModbusMaster;
// Create Modbus object
$modbus = new ModbusMaster("192.192.15.51", "UDP");
try {
    // FC 1
    $recData = $modbus->readCoils(0, 12288, 12);
} catch (Exception $e) {
    // Print error information if any
    echo $modbus;
    echo $e;
    exit;
}
// Print status information
echo "</br>Status:</br>" . $modbus;
// Print read data
echo "</br>Data:</br>";
var_dump($recData);
echo "</br>";
<?php

use PHPModbus\ModbusMaster;
// Create Modbus object
$modbus = new ModbusMaster("192.192.15.51", "UDP");
// Data to be writen
$data = array(10, -1000, 2000, 3.0);
$dataTypes = array("WORD", "INT", "DINT", "REAL");
try {
    // FC16
    $modbus->writeMultipleRegister(0, 12288, $data, $dataTypes);
} catch (Exception $e) {
    // Print error information if any
    echo $modbus;
    echo $e;
    exit;
}
// Print status information
echo $modbus;
<?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) {
<?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;
Exemple #8
0
<?php

use PHPModbus\ModbusMaster;
// Create Modbus object
$modbus = new ModbusMaster("192.192.15.51", "UDP");
try {
    // FC 2
    // read 2 input bits from address 0x0 (Wago input image)
    $recData = $modbus->readInputDiscretes(0, 0, 2);
} catch (Exception $e) {
    // Print error information if any
    echo $modbus;
    echo $e;
    exit;
}
// Print status information
echo "</br>Status:</br>" . $modbus;
// Print read data
echo "</br>Data:</br>";
var_dump($recData);
echo "</br>";
<?php

use PHPModbus\ModbusMaster;
// Create Modbus object
$modbus = new ModbusMaster("192.192.15.51", "UDP");
// Data to be writen
$data = array(10, -1000, 2000, 3.0);
$dataTypes = array("WORD", "INT", "DINT", "REAL");
try {
    // FC23
    $recData = $modbus->readWriteRegisters(0, 12288, 6, 12288, $data, $dataTypes);
} catch (Exception $e) {
    // Print error information if any
    echo $modbus;
    echo $e;
    exit;
}
// Print status information
echo "</br>Status:</br>" . $modbus;
// Print read data
echo "</br>Data:</br>";
print_r($recData);
echo "</br>";