Thursday, 8 August 2013

php modbus read multiple register with mysql

php modbus read multiple register with mysql

Thanks in advance.
I am trying to read registers 146 and 601 from a modbus register using
phpmodbus from http://code.google.com/p/phpmodbus/
The script sueccessfully loads the first record but fails at the second
The error i get is: Fatal error: Maximum execution time exceeded
my code is as following:
require_once dirname(__FILE__) . '/Phpmodbus/Phpmodbus/ModbusMaster.php';
$modbus = new ModbusMaster("10.234.6.11", "TCP");
//the sql contaions the two records 146 and 601
$sql = "SELECT num FROM `main`";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
echo $row['num'] . "<br>";
$recData = $modbus->readMultipleRegisters(1, $row['num'], 1);
//modbus status
echo $modbus;
//converting
$values = array_chunk($recData, 2);
foreach($values as $bytes) {
echo PhpType::bytes2signedInt($bytes) . "<br>";
}
}

No comments:

Post a Comment