0.3 Release

This commit is contained in:
John Long
2013-06-14 07:38:13 -05:00
parent fbb70f23e5
commit da9731662c
17 changed files with 622 additions and 537 deletions
+29 -23
View File
@@ -1,55 +1,61 @@
<?php
require_once dirname(__FILE__) . './Phpmodbus/ModbusMasterUdp.php';
require_once dirname(__FILE__) . '/../Phpmodbus/ModbusMasterUdp.php';
// Create Modbus object
$modbus = new ModbusMasterUdp("192.168.1.99");
$modbus = new ModbusMasterUdp("192.192.15.51");
// FC 3
// read 10 words (20 bytes) from device ID=0, address=12288
$recData = $modbus->readMultipleRegisters(0, 12288, 10);
if(!$recData) {
// Print error information if any
echo "</br>Error:</br>" . $modbus->errstr . "</br>";
exit;
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>";
echo "<h1>Received Data</h1>\n";
print_r($recData);
// Conversion
echo "<h2>32 bits types</h2>";
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>";
echo "<h3>REAL to Float</h3>\n";
foreach($values as $bytes)
echo PhpType::bytes2float($bytes) . "</br>";
echo PhpType::bytes2float($bytes) . "</br>";
// Get integer from DINT interpretation
echo "<h3>DINT to integer </h3>";
echo "<h3>DINT to integer </h3>\n";
foreach($values as $bytes)
echo PhpType::bytes2signedInt($bytes) . "</br>";
echo PhpType::bytes2signedInt($bytes) . "</br>";
// Get integer of float from DINT interpretation
echo "<h3>DWORD to integer (or float) </h3>";
echo "<h3>DWORD to integer (or float) </h3>\n";
foreach($values as $bytes)
echo PhpType::bytes2unsignedInt($bytes) . "</br>";
echo PhpType::bytes2unsignedInt($bytes) . "</br>";
echo "<h2>16 bit types</h2>";
echo "<h2>16 bit types</h2>\n";
// Chunk the data array to set of 4 bytes
$values = array_chunk($recData, 2);
// Get signed integer from INT interpretation
echo "<h3>INT to integer </h3>";
echo "<h3>INT to integer </h3>\n";
foreach($values as $bytes)
echo PhpType::bytes2signedInt($bytes) . "</br>";
echo PhpType::bytes2signedInt($bytes) . "</br>";
// Get unsigned integer from WORD interpretation
echo "<h3>WORD to integer </h3>";
echo "<h3>WORD to integer </h3>\n";
foreach($values as $bytes)
echo PhpType::bytes2unsignedInt($bytes) . "</br>";
echo PhpType::bytes2unsignedInt($bytes) . "</br>";
// Get string from STRING interpretation
echo "<h3>STRING to string </h3>\n";
echo PhpType::bytes2string($recData) . "</br>";
?>