<?php
$debug=0;
/*
Growatt
Function 4 Read Input register
registers 0-224

*/

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
//Rpi 3B ports are ordered top to bottom, left to right viewed by looking from the end
//0-2
//1-3
//multiple /dev/ttyUSB? are assigned starting with 0 as discovered in that sequence
//To boot with two tty deivices, plug them into ports 0 and 1 and they will be assigned USB 0 and 1
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');

// Open port
$modbus->deviceOpen();

// Enable debug
$modbus->debug = $debug;

# read registers 0-224 in groups of 15
$regnos = array(); #Register Numbers 0-224
#0 to 16
$startingaddress = str_pad(dechex(0), 4, "0", STR_PAD_LEFT); 
//echo "\n$startingaddress\t";
$Numberofpoints  = str_pad(dechex(30), 4, "0", STR_PAD_LEFT); 
//echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 30);
if($debug) print_r($result);
echo "\n";
$air = array('Standby','PV and Grid Combined Discharge','Discharge','Fault','Flash','PV charge','AC charge','Combine charge','Combine charge and Bypass','PV charge and Bypass','AC charge and Bypass','Bypass','PV charge and Discharge');
//for($i=0; $i < 13; $i++) {  echo "$i $air[$i]\n"; };
for($i=0; $i < 60; $i+=2) {
    $j = $i+1;
    $register = str_pad($i,3," ", STR_PAD_LEFT);
    $register = $register/2;
    $hex = $result[$i].$result[$j];
    $dec = hexdec($hex);
    $dectenth = $dec/10;
    if ($i<19) echo " ",$register," ", 'hex Word ', $hex;
    if ($i>18)  echo $register," ", 'hex Word ', $hex;
    if ($register==0) echo "\tGrowatt ??00=standby, 01??=AC output disable";
    if ($register==1) echo "\tAC Output first prioroty 0=Bat 1=PV 2=Uti 3=PV&Uti";
    if ($register==2) echo "\tCharge Source set 0:PV_first 1:PV&Uti 2:PV_Only";
    if ($register==3) echo "\tUti Output Start time (0-23)= $dec";
    if ($register==4) echo "\tUti Output End Timer (0-23)= $dec";
    if ($register==5) echo "\tUti Charge Start Time (0-23)= $dec";
    if ($register==6) echo "\tUti Charge End Time (0-23)= $dec";
    if ($register==7) echo "\tPV Input Mode W 0:Independent 1:Parallel= $dec";
    if ($register==8) echo "\tAC Input Mode VAC 0:APL_90-140 1:UPS_65-140 2:Generator";
    if ($register==9) echo "\tFirmware version High";
    if ($register==10) echo "\tFirmware version Mid";
    if ($register==11) echo "\tFirmware version Low";
    if ($register==12) echo "\tControl Firmware version High";
    if ($register==13) echo "\tControl Firmware version Mid";
    if ($register==14) echo "\tControl Firmware version Low";
    if ($register==15) echo "\tLCD Language";
    if ($register==16) echo "\tGridV_Adj";
    if ($register==17) echo "\tInvV_Adj";
    if ($register==18) echo "\tOutputVoltType 6:120VAC";
    if ($register==19) echo "\tOutputFreqType 1:60 Hz";
    if ($register==20) {
      $hr20 = file_get_contents("hr20.txt");
      echo "\tOverLoadRestart 0:Yes 1:No 2:Switch to Uti. Was ",$hr20;
      $hr20=$hex;
      $hr20 = trim($hr20,  " \n\r\t\v\x00");
      file_put_contents("hr20.txt",$hr20);
      }      
    if ($register==21) {
      $hr21 = file_get_contents("hr21.txt");
      echo "\tOverTemperatureRestart 0:Yes 1:No. Was ",$hr21;
      $hr21 = $hex;
      $hr21 = trim($hr21,  " \n\r\t\v\x00");
      file_put_contents("hr21.txt",$hr21);
      }      
    if ($register==22) echo "\tBuzzer 1:Enable 0:Disable";
    if ($register==23) echo "\tSerial No. 5";
    if ($register==24) echo "\tSerial No. 4";
    if ($register==25) echo "\tSerial No. 3";
    if ($register==26) echo "\tSerial No. 2";
    if ($register==27) echo "\tSerial No. 1";
    if ($register==28) echo "\tInverter Module high";
    if ($register==29) echo "\tInverter Module low ";
    if ($register==30) echo "\tCommunication Address";
    if ($register==31) echo "\tFlashStart 1:Own 100:control_board";
    echo chr(10);
    $regnos[] = $result[$i] . $result[$j];
}

$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(16), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(16), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 16);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=16; $i < 48; $i+=2) {
    $j = $i+1;
    echo $i/2+16, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
#echo "<br>print_r regnos";
#print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(0), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(16), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 32);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 64; $i+=2) {
    $j = $i+1;
    #echo $i/2+8, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
echo "<br>print_r regnos";
print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 4 Read Input register
registers 0-224

*/

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
//Rpi 3B ports are ordered top to bottom, left to right viewed by looking from the end
//0-2
//1-3
//multiple /dev/ttyUSB? are assigned starting with 0 as discovered in that sequence
//To boot with two tty deivices, plug them into ports 0 and 1 and they will be assigned USB 0 and 1
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');

// Open port
$modbus->deviceOpen();

// Enable debug
$modbus->debug = $debug;

# read registers 0-224 in groups of 15
$regnos = array(); #Register Numbers 0-224
#0 to 16
$startingaddress = str_pad(dechex(120), 4, "0", STR_PAD_LEFT); 
//echo "\n$startingaddress\t";
$Numberofpoints  = str_pad(dechex(30), 4, "0", STR_PAD_LEFT); 
//echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 30);
if($debug) print_r($result);
echo "<html><body><p>Read Input Registers</p><pre>";
echo "\n";
$air = array('Standby','PV and Grid Combined Discharge','Discharge','Fault','Flash','PV charge','AC charge','Combine charge','Combine charge and Bypass','PV charge and Bypass','AC charge and Bypass','Bypass','PV charge and Discharge');
//for($i=0; $i < 13; $i++) {  echo "$i $air[$i]\n"; };
for($i=0; $i < 60; $i+=2) {
    $j = $i+1;
    $register = str_pad($i+240,3," ", STR_PAD_LEFT);
    $register = $register/2;
    $hex = $result[$i].$result[$j];
    $dec = hexdec($hex);
    $dectenth = $dec/10;
    echo " ",$register," ", 'hex Word ', $hex;
    if ($register==90) echo "\tNomOpFreq $dectenth";
    if ($register==91) echo "\tNomOpPow $dec";
    if ($register==2) echo "\tCharge Source set 0:PV_first 1:PV&Uti 2:PV_Only";
#    if ($register==3) echo "\tPV1 Power high";
    if ($register==94) echo "\tuwBatCutOffVolt $dectenth";
    if ($register==95) echo "\tAC switch to Battery $dectenth";
#    if ($register==6) echo "\tPV2 N/A";
#    if ($register==7) echo "\tBuck1 current $dectenth Amperes";
    if ($register==8) echo "\tAC Input Mode VAC 0:APL_90-140 1:UPS_65-140 2:Generator";
    if ($register==9) echo "\tFirmware version High";
    if ($register==10) echo "\tFirmware version Mid";
    if ($register==11) echo "\tFirmware version Low";
    if ($register==12) echo "\tControl Firmware version High";
    if ($register==13) echo "\tControl Firmware version Mid";
    if ($register==14) echo "\tControl Firmware version Low";
    if ($register==15) echo "\tLCD Language";
    if ($register==16) echo "\tGridV_Adj";
    if ($register==77) echo "\tRate 3000 watts? $dectenth";
    if ($register==79) echo "\tRate 3000 va? $dectenth";
    if ($register==84) echo "\tNomGridVolt $dectenth";
    if ($register==85) echo "\tNomGridFreq $dectenth";
    if ($register==86) echo "\tNomBatVolt $dectenth";
    if ($register==87) echo "\tNomPvCurr $dectenth";
    if ($register==88) echo "\tNomAcChgCurr $dectenth";
    if ($register==89) echo "\tNomOpVolt $dectenth";
    echo chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
echo "</pre></body></html>\n";

$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 4 Read Input register
registers 0-224

*/

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
//Rpi 3B ports are ordered top to bottom, left to right viewed by looking from the end
//0-2
//1-3
//multiple /dev/ttyUSB? are assigned starting with 0 as discovered in that sequence
//To boot with two tty deivices, plug them into ports 0 and 1 and they will be assigned USB 0 and 1
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');

// Open port
$modbus->deviceOpen();

// Enable debug
$modbus->debug = $debug;

# read registers 0-224 in groups of 15
$regnos = array(); #Register Numbers 0-224
#0 to 16
$startingaddress = str_pad(dechex(150), 4, "0", STR_PAD_LEFT); 
//echo "\n$startingaddress\t";
$Numberofpoints  = str_pad(dechex(30), 4, "0", STR_PAD_LEFT); 
//echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 30);
if($debug) print_r($result);
echo "<html><body><p>Read Input Registers</p><pre>";
echo "\n";
$air = array('Standby','PV and Grid Combined Discharge','Discharge','Fault','Flash','PV charge','AC charge','Combine charge','Combine charge and Bypass','PV charge and Bypass','AC charge and Bypass','Bypass','PV charge and Discharge');
//for($i=0; $i < 13; $i++) {  echo "$i $air[$i]\n"; };
for($i=0; $i < 60; $i+=2) {
    $j = $i+1;
    $register = str_pad($i+300,3," ", STR_PAD_LEFT);
    $register = $register/2;
    $hex = $result[$i].$result[$j];
    $dec = hexdec($hex);
    $dectenth = $dec/10;
    echo " ",$register," ", 'hex Word ', $hex;
    if ($register==90) echo "\tNomOpFreq $dectenth";
    if ($register==91) echo "\tNomOpPow $dec";
    if ($register==2) echo "\tCharge Source set 0:PV_first 1:PV&Uti 2:PV_Only";
#    if ($register==3) echo "\tPV1 Power high";
    if ($register==94) echo "\tuwBatCutOffVolt $dectenth";
    if ($register==95) echo "\tAC switch to Battery $dectenth";
#    if ($register==6) echo "\tPV2 N/A";
#    if ($register==7) echo "\tBuck1 current $dectenth Amperes";
    if ($register==8) echo "\tAC Input Mode VAC 0:APL_90-140 1:UPS_65-140 2:Generator";
    if ($register==9) echo "\tFirmware version High";
    if ($register==10) echo "\tFirmware version Mid";
    if ($register==11) echo "\tFirmware version Low";
    if ($register==12) echo "\tControl Firmware version High";
    if ($register==13) echo "\tControl Firmware version Mid";
    if ($register==14) echo "\tControl Firmware version Low";
    if ($register==15) echo "\tLCD Language";
    if ($register==16) echo "\tGridV_Adj";
    if ($register==77) echo "\tRate 3000 watts? $dectenth";
    if ($register==79) echo "\tRate 3000 va? $dectenth";
    if ($register==84) echo "\tNomGridVolt $dectenth";
    if ($register==85) echo "\tNomGridFreq $dectenth";
    if ($register==86) echo "\tNomBatVolt $dectenth";
    if ($register==87) echo "\tNomPvCurr $dectenth";
    if ($register==88) echo "\tNomAcChgCurr $dectenth";
    if ($register==89) echo "\tNomOpVolt $dectenth";
    echo chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
echo "</pre></body></html>\n";

$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 4 Read Input register
registers 0-224

*/

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
//Rpi 3B ports are ordered top to bottom, left to right viewed by looking from the end
//0-2
//1-3
//multiple /dev/ttyUSB? are assigned starting with 0 as discovered in that sequence
//To boot with two tty deivices, plug them into ports 0 and 1 and they will be assigned USB 0 and 1
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');

// Open port
$modbus->deviceOpen();

// Enable debug
$modbus->debug = $debug;

# read registers 0-224 in groups of 15
$regnos = array(); #Register Numbers 0-224

#0 to 14
$startingaddress = str_pad(dechex(16), 4, "0", STR_PAD_LEFT); 
//echo "\n$startingaddress\t";
$Numberofpoints  = str_pad(dechex(16), 4, "0", STR_PAD_LEFT); 
//echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 16);
if($debug) print_r($result);
echo "<html><body><p>Read Input Registers</p><pre>\n";
for($i=0; $i < 32; $i+=2) {
    $j = $i+1;
    $register = $i/2;
    $register = str_pad($register+16,3," ", STR_PAD_LEFT);
    $hex = $result[$i].$result[$j];
    $lineout = "hex $register\tword ".$hex; echo $lineout;
    //echo " hex Word  $hex \tdecimal ", hexdec($hex);
    if ($register==16) echo "\tGridV-Adj";
    if ($register==17) echo "\tInvV_Adj";
    if ($register==18) echo "\tOutputVoltType 6:120VAC";
    if ($register==19) echo "\tOutputFreqType 1:60 Hz";
    if ($register==20) echo "\tOverLoadRestart 0:Yes 1:No 2:Switch to Uti";
    if ($register==21) echo "\tOverTemperatureRestart 0:Yes 1:No";
    if ($register==22) echo "\tBuzzer 1:Enable 0:Disable";
    if ($register==23) echo "\tSerial No. 5";
    if ($register==24) echo "\tSerial No. 4";
    if ($register==25) echo "\tSerial No. 3";
    if ($register==26) echo "\tSerial No. 2";
    if ($register==27) echo "\tSerial No. 1";
    if ($register==28) echo "\tInverter Module high";
    if ($register==29) echo "\tInverter Module low ";
    if ($register==30) echo "\tCommunication Address";
    if ($register==31) echo "\tFlashStart 1:Own 100:control_board";
    echo chr(10); 
    $regnos[] = $result[$i] . $result[$j];
}
echo "</pre></body></html>\n";
$modbus->deviceClose();


?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(8), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(15), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 15);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 30; $i+=2) {
    $j = $i+1;
    echo $i/2+8, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
//echo "print_r regnos";
//print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(16), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(15), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 15);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 30; $i+=2) {
    $j = $i+1;
    echo $i/2+16, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
//echo "print_r regnos";
//print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 4 Read Input register
registers 0-224

*/

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
//Rpi 3B ports are ordered top to bottom, left to right viewed by looking from the end
//0-2
//1-3
//multiple /dev/ttyUSB? are assigned starting with 0 as discovered in that sequence
//To boot with two tty deivices, plug them into ports 0 and 1 and they will be assigned USB 0 and 1
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');

// Open port
$modbus->deviceOpen();

// Enable debug
$modbus->debug = $debug;

# read registers 0-224 in groups of 15
$regnos = array(); #Register Numbers 0-224
#0 to 16
$startingaddress = str_pad(dechex(30), 4, "0", STR_PAD_LEFT); 
//echo "\n$startingaddress\t";
$Numberofpoints  = str_pad(dechex(30), 4, "0", STR_PAD_LEFT); 
//echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 30);
if($debug) print_r($result);
echo "\n";
$air = array('Standby','PV and Grid Combined Discharge','Discharge','Fault','Flash','PV charge','AC charge','Combine charge','Combine charge and Bypass','PV charge and Bypass','AC charge and Bypass','Bypass','PV charge and Discharge');
//for($i=0; $i < 13; $i++) {  echo "$i $air[$i]\n"; };
for($i=0; $i < 60; $i+=2) {
    $j = $i+1;
    $register = str_pad($i+60,3," ", STR_PAD_LEFT);
    $register = $register/2;
    $hex = $result[$i].$result[$j];
    $dec = hexdec($hex);
    $dectenth = $dec/10;
    echo " ",$register," ", 'hex Word ', $hex;
    if ($register==30) echo "\tComm Address= $dec";
    if ($register==31) echo "\tUpdate firmware 1:Own 100:control_board";
    if ($register==32) echo "\tReset User Information 1";
    if ($register==33) echo "\tReset to factory";
    if ($register==34) echo "\tMaxChargeCurr= $dec";
    if ($register==35) echo "\tBulkChargeVolt= $dectenth";
    if ($register==36) echo "\tFloatChargeVolt= $dectenth";
    if ($register==37) echo "\tBatLowToUtiVolt= $dectenth";
    if ($register==38) echo "\tACChargeCurr= $dec amperes";
    if ($register==39) echo "\tBattery Type 2:USE 4:USE2";
    if ($register==40) echo "\tAging Mode";
    if ($register==41) echo "\tUnknown";
    if ($register==42) echo "\tUnknown";
    if ($register==43) echo "\tDevice Type Code";
    if ($register==44) echo "\tUnknown";
    if ($register==45) echo "\tSystem Time Year $dec";
    if ($register==46) echo "\tSystem Time Month $dec";
    if ($register==47) echo "\tSystem Time Day $dec";
    if ($register==48) echo "\tSystem Time Hour $dec";
    if ($register==49) echo "\tSystem Time Min $dec";
    if ($register==50) echo "\tSystem Time Sec $dec";
    if ($register==51) echo "\tBlank";
    if ($register==52) echo "\tuwAcVoltHighL";
    if ($register==53) echo "\tuwAcVoltLowL";
    if ($register==54) echo "\tuwAcFreqHighL";
    if ($register==55) echo "\tuwAcFreqLowL";
    if ($register==56) echo "\tBlank";
    if ($register==57) echo "\tBlank";
    if ($register==58) echo "\tBlank";
    if ($register==59) echo "\tManufacturer information 8";
    echo chr(10);
    $regnos[] = $result[$i] . $result[$j];
}

$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 4 Read Input register
registers 0-224

*/

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
//Rpi 3B ports are ordered top to bottom, left to right viewed by looking from the end
//0-2
//1-3
//multiple /dev/ttyUSB? are assigned starting with 0 as discovered in that sequence
//To boot with two tty deivices, plug them into ports 0 and 1 and they will be assigned USB 0 and 1
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');

// Open port
$modbus->deviceOpen();

// Enable debug
$modbus->debug = $debug;

# read registers 0-224 in groups of 15
$regnos = array(); #Register Numbers 0-224

#0 to 14
$startingaddress = str_pad(dechex(32), 4, "0", STR_PAD_LEFT); 
//echo "\n$startingaddress\t";
$Numberofpoints  = str_pad(dechex(16), 4, "0", STR_PAD_LEFT); 
//echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 16);
if($debug) print_r($result);
echo "<html><body><p>Read Input Registers</p><pre>\n";
for($i=0; $i < 32; $i+=2) {
    $j = $i+1;
    $register = $i/2;
    $register = str_pad($register+32,3," ", STR_PAD_LEFT);
    $hex = $result[$i].$result[$j];
    $dec = hexdec($hex);
    $dectenth = $dec/10;
    echo $register," ", 'hex Word ', $hex," decimal ", hexdec($hex);
#    $lineout = "hex $register\tword ".$hex; echo $lineout;
    //echo " hex Word  $hex \tdecimal ", hexdec($hex);
    if ($register==32) echo "\tHR 32";
    if ($register==33) echo "\tHR 33";
    if ($register==34) echo "\tMaxChargeCurr";
    if ($register==35) echo "\tBulkChargeVolt $dectenth";
    if ($register==36) echo "\tFloatChargeVolt $dectenth";
    if ($register==37) echo "\tBatLowToUtiVolt $dectenth";
    if ($register==38) echo "\tACChargeCurr";
    if ($register==39) echo "\tBattery Type 4:USE2";
    if ($register==40) echo "\tAging Mode";
    if ($register==41) echo "\tUnknown";
    if ($register==42) echo "\tUnknown";
    if ($register==43) echo "\tDevice Type Code";
    if ($register==44) echo "\tUnknown";
    if ($register==45) echo "\tSystem Time Year";
    if ($register==46) echo "\tSsytem Time Month";
    if ($register==47) echo "\tSystem Time Day";
    echo chr(10); 
    $regnos[] = $result[$i] . $result[$j];
}
echo "</pre></body></html>\n";
$modbus->deviceClose();


?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(24), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(15), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 15);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 30; $i+=2) {
    $j = $i+1;
    echo $i/2+24, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
//echo "print_r regnos";
//print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 4 Read Input register
registers 0-224

*/

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
//Rpi 3B ports are ordered top to bottom, left to right viewed by looking from the end
//0-2
//1-3
//multiple /dev/ttyUSB? are assigned starting with 0 as discovered in that sequence
//To boot with two tty deivices, plug them into ports 0 and 1 and they will be assigned USB 0 and 1
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');

// Open port
$modbus->deviceOpen();

// Enable debug
$modbus->debug = $debug;

# read registers 0-224 in groups of 15
$regnos = array(); #Register Numbers 0-224

#0 to 14
$startingaddress = str_pad(dechex(48), 4, "0", STR_PAD_LEFT); 
//echo "\n$startingaddress\t";
$Numberofpoints  = str_pad(dechex(16), 4, "0", STR_PAD_LEFT); 
//echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 16);
if($debug) print_r($result);
echo "<html><body><p>Read Input Registers</p><pre>\n";
for($i=0; $i < 32; $i+=2) {
    $j = $i+1;
    $register = $i/2;
    $register = str_pad($register+48,3," ", STR_PAD_LEFT);
    $hex = $result[$i].$result[$j];
    $dec = hexdec($hex);
    $dectenth = $dec/10;
    echo $register," ", 'hex Word ', $hex," decimal ", hexdec($hex);
#    $lineout = "hex $register\tword ".$hex; echo $lineout;
    //echo " hex Word  $hex \tdecimal ", hexdec($hex);
    if ($register==48) echo "\tHR 48";
    if ($register==49) echo "\tHR 49";
    if ($register==50) echo "\tMaxChargeCurr";
    if ($register==51) echo "\tBulkChargeVolt $dectenth";
    if ($register==52) echo "\tFloatChargeVolt $dectenth";
    if ($register==53) echo "\tBatLowToUtiVolt $dectenth";
    if ($register==54) echo "\tACChargeCurr";
    if ($register==55) echo "\tBattery Type 4:USE2";
    if ($register==56) echo "\tAging Mode";
    if ($register==57) echo "\tUnknown";
    if ($register==58) echo "\tUnknown";
    if ($register==59) echo "\tDevice Type Code";
    if ($register==60) echo "\tUnknown";
    if ($register==61) echo "\tSystem Time Year";
    if ($register==62) echo "\tSsytem Time Month";
    if ($register==63) echo "\tSystem Time Day";
    echo chr(10); 
    $regnos[] = $result[$i] . $result[$j];
}
echo "</pre></body></html>\n";
$modbus->deviceClose();


?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(32), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(15), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 15);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 30; $i+=2) {
    $j = $i+1;
    echo $i/2+32, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
//echo "print_r regnos";
//print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(40), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(15), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 15);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 30; $i+=2) {
    $j = $i+1;
    echo $i/2+40, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
//echo "print_r regnos";
//print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 4 Read Input register
registers 0-224

*/

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
//Rpi 3B ports are ordered top to bottom, left to right viewed by looking from the end
//0-2
//1-3
//multiple /dev/ttyUSB? are assigned starting with 0 as discovered in that sequence
//To boot with two tty deivices, plug them into ports 0 and 1 and they will be assigned USB 0 and 1
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');

// Open port
$modbus->deviceOpen();

// Enable debug
$modbus->debug = $debug;

# read registers 0-224 in groups of 15
$regnos = array(); #Register Numbers 0-224
#0 to 16
$startingaddress = str_pad(dechex(60), 4, "0", STR_PAD_LEFT); 
//echo "\n$startingaddress\t";
$Numberofpoints  = str_pad(dechex(30), 4, "0", STR_PAD_LEFT); 
//echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 30);
if($debug) print_r($result);
echo "\n";
$air = array('Standby','PV and Grid Combined Discharge','Discharge','Fault','Flash','PV charge','AC charge','Combine charge','Combine charge and Bypass','PV charge and Bypass','AC charge and Bypass','Bypass','PV charge and Discharge');
//for($i=0; $i < 13; $i++) {  echo "$i $air[$i]\n"; };
for($i=0; $i < 60; $i+=2) {
    $j = $i+1;
    $register = str_pad($i+120,3," ", STR_PAD_LEFT);
    $register = $register/2;
    $hex = $result[$i].$result[$j];
    $dec = hexdec($hex);
    $dectenth = $dec/10;
    echo " ",$register," ", 'hex Word ', $hex;
    if ($register==60) echo "\tManufacturer information 7";
    if ($register==61) echo "\tManufacturer information 6";
    if ($register==62) echo "\tManufacturer information 5";
    if ($register==63) echo "\tManufacturer information 4";
    if ($register==64) echo "\tManufacturer information 3";
    if ($register==65) echo "\tManufacturer information 2";
    if ($register==66) echo "\tManufacturer information 1";
    if ($register==67) echo "\tControl FW Build 2";
    if ($register==68) echo "\tControl FW Build 1";
    if ($register==69) echo "\tCom FW Build 2";
    if ($register==70) echo "\tCom FW Build 1";
    if ($register==71) echo "\tBlank";
    if ($register==72) echo "\tSys Weekly";
    if ($register==73) echo "\tModbus Version";
    if ($register==74) echo "\tBlank";
    if ($register==75) echo "\tBlank";
    if ($register==76) echo "\tRate active power high";
    if ($register==77) echo "\tRate active power low= $dectenth";
    if ($register==78) echo "\tRate apparent power high?= $dectenth";
    if ($register==79) echo "\tRate apparent power low?= $dectenth";
    if ($register==80) echo "\tFactory ODM Info code= $dec";
    if ($register==81) echo "\tuwBatPieceNum= $dec";
    if ($register==82) echo "\tCutoff value voltage= $dectenth";
    if ($register==83) echo "\tBlank";
    if ($register==84) echo "\tNomGridVolt $dectenth";
    if ($register==85) echo "\tNomGridFreq $dectenth";
    if ($register==86) echo "\tNomBatVolt $dectenth";
    if ($register==87) echo "\tNomPvCurr $dectenth";
    if ($register==88) echo "\tNomAcChgCurr $dectenth";
    if ($register==89) echo "\tNomOpVolt $dectenth";
    echo chr(10);
    $regnos[] = $result[$i] . $result[$j];
}

$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(48), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(15), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 15);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 30; $i+=2) {
    $j = $i+1;
    echo $i/2+48, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
//echo "print_r regnos";
//print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(56), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(15), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 15);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 30; $i+=2) {
    $j = $i+1;
    echo $i/2+56, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
//echo "print_r regnos";
//print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(64), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(15), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 15);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 30; $i+=2) {
    $j = $i+1;
    echo $i/2+64, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
//echo "print_r regnos";
//print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 4 Read Input register
registers 0-224

*/

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
//Rpi 3B ports are ordered top to bottom, left to right viewed by looking from the end
//0-2
//1-3
//multiple /dev/ttyUSB? are assigned starting with 0 as discovered in that sequence
//To boot with two tty deivices, plug them into ports 0 and 1 and they will be assigned USB 0 and 1
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');

// Open port
$modbus->deviceOpen();

// Enable debug
$modbus->debug = $debug;

# read registers 0-224 in groups of 15
$regnos = array(); #Register Numbers 0-224
#0 to 16
$startingaddress = str_pad(dechex(90), 4, "0", STR_PAD_LEFT); 
//echo "\n$startingaddress\t";
$Numberofpoints  = str_pad(dechex(30), 4, "0", STR_PAD_LEFT); 
//echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 30);
if($debug) print_r($result);
echo "\n";
$air = array('Standby','PV and Grid Combined Discharge','Discharge','Fault','Flash','PV charge','AC charge','Combine charge','Combine charge and Bypass','PV charge and Bypass','AC charge and Bypass','Bypass','PV charge and Discharge');
//for($i=0; $i < 13; $i++) {  echo "$i $air[$i]\n"; };
for($i=0; $i < 60; $i+=2) {
    $j = $i+1;
    $register = str_pad($i+180,3," ", STR_PAD_LEFT);
    $register = $register/2;
    $hex = $result[$i].$result[$j];
    $dec = hexdec($hex);
    $dectenth = $dec/10;
    if ($register<100) echo " ",$register," ", 'hex Word ', $hex;
    if ($register>99)  echo $register," ", 'hex Word ', $hex;
    if ($register==90) echo "\tNomOpFreq= $dectenth";
    if ($register==91) echo "\tNomOpPow= $dec";
    if ($register==92) echo "\tBlank";
    if ($register==93) echo "\tBlank";
    if ($register==94) echo "\tuwBatCutOffVolt= $dectenth";
    if ($register==95) echo "\tAC switch to Battery= $dectenth";
    if ($register==96) echo "\tBypEnable";
    if ($register==97) echo "\tPowSavingEn";
    if ($register==98) echo "\tSPowBAlEn";
    if ($register==99) echo "\tClrEnergyToday";
    if ($register==100) echo "\tClrEnergyAll";
    if ($register==101) echo "\tBurnInTestEn";
    if ($register==102) echo "\tManualStartEn";
    if ($register==103) echo "\tSciChkEn";
    if ($register==104) echo "\tControl BLightEn";
    if ($register==105) echo "\tParaMaxChgCurr";
    if ($register==106) echo "\tLi Protocol Type";
    if ($register==107) echo "\tAudioAlarmEn";
    if ($register==108) echo "\tuwEqEn";
    if ($register==109) echo "\tuwEqChgVolt= $dectenth";
    if ($register==110) echo "\tuwEqTime= $dectenth";
    if ($register==111) echo "\tuwEqTimeOut= $dectenth";
    if ($register==112) echo "\tuqEqInterval= $dectenth";
    if ($register==113) echo "\tuwMaxDisChgCurr= $dectenth";
    if ($register>113) echo "\tUnknown";
    echo chr(10);
    $regnos[] = $result[$i] . $result[$j];
}

$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(72), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(15), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 15);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 30; $i+=2) {
    $j = $i+1;
    echo $i/2+72, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
//echo "print_r regnos";
//print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(80), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(15), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 15);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 30; $i+=2) {
    $j = $i+1;
    echo $i/2+80, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
//echo "print_r regnos";
//print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(88), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(15), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 15);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 30; $i+=2) {
    $j = $i+1;
    echo $i/2+88, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
//echo "print_r regnos";
//print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(96), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(16), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 16);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 32; $i+=2) {
    $j = $i+1;
    echo $i/2+96, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
//echo "print_r regnos";
//print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 0;

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');
//print_r($modbus);
//sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
//sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(104), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
echo "starting address = $startingaddress \n";
$Numberofpoints  = str_pad(dechex(16), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 16);
if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
//print_r($result);
//sleep(9);

for($i=0; $i < 32; $i+=2) {
    $j = $i+1;
    echo $i/2+104, '<br> Word = ', $result[$i] . $result[$j], chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
//echo "print_r regnos";
//print_r($regnos);
$modbus->deviceClose();

?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 1;



// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyGW',38400,'none',8,2,'none');
//print_r($modbus);
sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(0), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
$Numberofpoints  = str_pad(dechex(15), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
//echo "\nNumberofpoints = $Numberofpoints\n";
$result=$modbus->sendQuery(01,03,22,3);
//if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
echo "\nresult\n";
print_r($result);
echo "\nend\n";
//sleep(9);
$modbus->deviceClose();
?>
<?php
$debug=0;
/*
Growatt
Function 3 Read holding register
0-162
*/
$debug = 1;



// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
$modbus->deviceInit('/dev/ttyUSB0',38400,'none',8,2,'none');
//print_r($modbus);
sleep(9);

// Open port
$modbus->deviceOpen();
//print_r($modbus);
sleep(9);

// Enable debug
$modbus->debug = $debug;

# read registers 0-162
$regnos = array(); #Register Numbers 0-162

$startingaddress = str_pad(dechex(0), 4, "0", STR_PAD_LEFT); echo "\n$startingaddress\n";
$Numberofpoints  = str_pad(dechex(15), 4, "0", STR_PAD_LEFT); echo "\n$Numberofpoints\n";
//echo "\nNumberofpoints = $Numberofpoints\n";
$result=$modbus->sendQuery(01,03,22,3);
//if($debug) print_r($result);
//print ("1,3,$startingaddress,15");
echo "\nresult\n";
print_r($result);
echo "\nend\n";
//sleep(9);
$modbus->deviceClose();
?>
<?php
$debug=0;
/*
Growatt
Function 4 Read Input register
registers 0-224

*/

// Include Php Serial Modbus Class
require 'PhpSerialModbus.php';

// Create an instance of the class
$modbus = new PhpSerialModbus;

// Initialize port. pdf page 3
//Rpi 3B ports are ordered top to bottom, left to right viewed by looking from the end
//0-2
//1-3
//multiple /dev/ttyUSB? are assigned starting with 0 as discovered in that sequence
//To boot with two tty deivices, plug them into ports 0 and 1 and they will be assigned USB 0 and 1
$modbus->deviceInit('/dev/ttyGW',9600,'none',8,2,'none');

// Open port
$modbus->deviceOpen();

// Enable debug
$modbus->debug = $debug;

# read registers 0-224 in groups of 15
$regnos = array(); #Register Numbers 0-224
#0 to 16
$startingaddress = str_pad(dechex(150), 4, "0", STR_PAD_LEFT); 
//echo "\n$startingaddress\t";
$Numberofpoints  = str_pad(dechex(30), 4, "0", STR_PAD_LEFT); 
//echo "\n$Numberofpoints\n";
$result=$modbus->sendQuery(1,3,"$startingaddress", 30);
if($debug) print_r($result);
echo "<html><body><p>Read Input Registers</p><pre>";
echo "\n";
$air = array('Standby','PV and Grid Combined Discharge','Discharge','Fault','Flash','PV charge','AC charge','Combine charge','Combine charge and Bypass','PV charge and Bypass','AC charge and Bypass','Bypass','PV charge and Discharge');
//for($i=0; $i < 13; $i++) {  echo "$i $air[$i]\n"; };
for($i=0; $i < 60; $i+=2) {
    $j = $i+1;
    $register = str_pad($i+300,3," ", STR_PAD_LEFT);
    $register = $register/2;
    $hex = $result[$i].$result[$j];
    $dec = hexdec($hex);
    $dectenth = $dec/10;
    echo " ",$register," ", 'hex Word ', $hex;
    if ($register==90) echo "\tNomOpFreq $dectenth";
    if ($register==91) echo "\tNomOpPow $dec";
    if ($register==2) echo "\tCharge Source set 0:PV_first 1:PV&Uti 2:PV_Only";
#    if ($register==3) echo "\tPV1 Power high";
    if ($register==94) echo "\tuwBatCutOffVolt $dectenth";
    if ($register==95) echo "\tAC switch to Battery $dectenth";
#    if ($register==6) echo "\tPV2 N/A";
#    if ($register==7) echo "\tBuck1 current $dectenth Amperes";
    if ($register==8) echo "\tAC Input Mode VAC 0:APL_90-140 1:UPS_65-140 2:Generator";
    if ($register==9) echo "\tFirmware version High";
    if ($register==10) echo "\tFirmware version Mid";
    if ($register==11) echo "\tFirmware version Low";
    if ($register==12) echo "\tControl Firmware version High";
    if ($register==13) echo "\tControl Firmware version Mid";
    if ($register==14) echo "\tControl Firmware version Low";
    if ($register==15) echo "\tLCD Language";
    if ($register==16) echo "\tGridV_Adj";
    if ($register==77) echo "\tRate 3000 watts? $dectenth";
    if ($register==79) echo "\tRate 3000 va? $dectenth";
    if ($register==84) echo "\tNomGridVolt $dectenth";
    if ($register==85) echo "\tNomGridFreq $dectenth";
    if ($register==86) echo "\tNomBatVolt $dectenth";
    if ($register==87) echo "\tNomPvCurr $dectenth";
    if ($register==88) echo "\tNomAcChgCurr $dectenth";
    if ($register==89) echo "\tNomOpVolt $dectenth";
    echo chr(10);
    $regnos[] = $result[$i] . $result[$j];
}
echo "</pre></body></html>\n";

$modbus->deviceClose();

?>
