PHP file:
require_once dirname(FILE) . ‘/Phpmodbus/Phpmodbus/ModbusMaster.php’;
// Create Modbus object
$modbus = new ModbusMaster(“192.168.1.199”, “TCP”);
try {
// FC 3
$recData = $modbus->readMultipleRegisters(1, 32262, 1); // PV1 voltage
}
catch (Exception $e) {
// Print error information if any
echo $modbus;
echo $e;
exit;
}
// Print status information
echo “Status: ” . $modbus;
// Print read data
echo “Data: “;
print_r($recData);
echo “
“;
$data = (256*$recData[0]) + ($recData[1]);
echo “Data: “;
print_r($data/10);
echo ” VDC”;
Result:
Status:
readMultipleRegisters: START
Connected
Packet: 336c0000000601037e060001
Send
Wait data …
Data received
Packet: 336c0000000501030216b9
Modbus response error code: NOERROR
Disconnected
readMultipleRegisters: DONE
RAW Data:Array ( [0] => 22 [1] => 185 )
PV1 voltage : 581.7 VDC