<?php require_once dirname(__FILE__) . '/../../Phpmodbus/ModbusMasterTcp.php'; require_once dirname(__FILE__) . '/../config.php'; // Create Modbus object $modbus = new ModbusMasterTcp($test_host_ip); // Data to be writen - BYTE $data = array(0, 1, 1, pow(2, 8) - 1, pow(2, 8) - 1); $dataTypes = array("BYTE", "BYTE", "BYTE", "BYTE", "BYTE"); // Write data - FC 16 $modbus->writeMultipleRegister(0, 12288, $data, $dataTypes); // Read data - FC3 $recData = $modbus->readMultipleRegisters(0, 12288, 5); print_r($recData); // Data to be writen - INT $data = array(0, 1, -1, pow(2, 15) - 1, -pow(2, 15)); $dataTypes = array("INT", "INT", "INT", "INT", "INT"); // Write data - FC 16 $modbus->writeMultipleRegister(0, 12288, $data, $dataTypes); // Read data - FC3 $recData = $modbus->readMultipleRegisters(0, 12288, 5); print_r($recData); // Data to be writen - DINT $data = array(0, 1, -1, pow(2, 31) - 1, -pow(2, 31)); $dataTypes = array("DINT", "DINT", "DINT", "DINT", "DINT"); // Write data - FC 16 $modbus->writeMultipleRegister(0, 12288, $data, $dataTypes); // Read data - FC3 $recData = $modbus->readMultipleRegisters(0, 12288, 10); print_r($recData); // Data to be writen - REAL
echo 'Available runmodes:' . "\n"; foreach ($runmode as $runmod => $val) { echo ' --' . $runmod . "\n"; } die; } // Make it possible to test in source directory // This is for PEAR developers only ini_set('include_path', ini_get('include_path') . ':..'); // Include Class error_reporting(E_STRICT); require_once "System/Daemon.php"; include 'https/Connections/GLTSERVER.php'; require_once dirname(__FILE__) . '/https/Phpmodbus/ModbusMasterTcp.php'; // Create Modbus object $modbus = new ModbusMasterTcp($sps, 'TCP'); // Setup $options = array('appName' => 'modbusd', 'appDir' => dirname(__FILE__), 'appDescription' => 'Parses modbus data in rrd', 'authorName' => 'Michael Penzkofer', 'authorEmail' => '*****@*****.**', 'sysMaxExecutionTime' => '0', 'sysMaxInputTime' => '0', 'sysMemoryLimit' => '1024M'); System_Daemon::setOptions($options); // This program can also be run in the forground with runmode --no-daemon if (!$runmode['no-daemon']) { // Spawn Daemon System_Daemon::start(); } // With the runmode --write-initd, this program can automatically write a // system startup file called: 'init.d' // This will make sure your daemon will be started on reboot if (!$runmode['write-initd']) { System_Daemon::info('not writing an init.d script this time'); } else { if (($initd_location = System_Daemon::writeAutoRun()) === false) {
<?php require_once dirname(__FILE__) . '/../../Phpmodbus/ModbusMasterTcp.php'; require_once dirname(__FILE__) . '/../config.php'; // Create Modbus object $modbus = new ModbusMasterTcp($test_host_ip); // Data to be writen $data = array(1000, 2000, 1.25, 1.25); $dataTypes = array("REAL", "REAL", "REAL", "REAL"); // FC23 $recData = $modbus->readWriteRegisters(0, 12288, 6, 12288, $data, $dataTypes); if (!$recData) { // Print error information if any echo "</br>Error:</br>" . $modbus->errstr . "</br>"; // exit; } // Print status information echo "writeMultipleRegister (FC26): DONE";