no message
This commit is contained in:
@@ -140,7 +140,7 @@ class SofarWechselrichter extends IPSModule
|
|||||||
// Bytes registerweise einzeln abfragen und zusammenfügen:
|
// Bytes registerweise einzeln abfragen und zusammenfügen:
|
||||||
$dataBytes = '';
|
$dataBytes = '';
|
||||||
for ($i = 0; $i < $numRegs; $i++) {
|
for ($i = 0; $i < $numRegs; $i++) {
|
||||||
$dataBytes .= $this->readRegister($ip, $loggerNumberStr, $regNo + $i);
|
$dataBytes .= $this->readSingleRegister($ip, $loggerNumberStr, $regNo + $i);
|
||||||
}
|
}
|
||||||
// Nun liegen 2 * $numRegs Bytes in $dataBytes
|
// Nun liegen 2 * $numRegs Bytes in $dataBytes
|
||||||
$hex = strtoupper(bin2hex($dataBytes));
|
$hex = strtoupper(bin2hex($dataBytes));
|
||||||
@@ -181,7 +181,7 @@ class SofarWechselrichter extends IPSModule
|
|||||||
* @return string 2-Byte-Binär-String
|
* @return string 2-Byte-Binär-String
|
||||||
* @throws Exception Bei Kommunikationsfehlern
|
* @throws Exception Bei Kommunikationsfehlern
|
||||||
*/
|
*/
|
||||||
private function readRegister(string $ip, string $serial_nr_str, int $reg): string
|
private function readSingleRegister(string $ip, string $serial_nr_str, int $reg): string
|
||||||
{
|
{
|
||||||
// 1) Out_Frame ohne CRC aufbauen
|
// 1) Out_Frame ohne CRC aufbauen
|
||||||
$oFrame = 'a5170010450000';
|
$oFrame = 'a5170010450000';
|
||||||
@@ -215,7 +215,7 @@ class SofarWechselrichter extends IPSModule
|
|||||||
$crcSwapped = substr($crcHex, 2, 2) . substr($crcHex, 0, 2);
|
$crcSwapped = substr($crcHex, 2, 2) . substr($crcHex, 0, 2);
|
||||||
$oFrameWithCRC = $oFrame . strtolower($crcSwapped);
|
$oFrameWithCRC = $oFrame . strtolower($crcSwapped);
|
||||||
|
|
||||||
// 3) Summen-Checksum (Bytes ab Index 1) + 0x15
|
// 3) Summen-Checksum (alle Bytes ab Index 1) + 0x15
|
||||||
$l = strlen($oFrameWithCRC) / 2;
|
$l = strlen($oFrameWithCRC) / 2;
|
||||||
$bArr = [];
|
$bArr = [];
|
||||||
for ($i = 0; $i < $l; $i++) {
|
for ($i = 0; $i < $l; $i++) {
|
||||||
@@ -258,8 +258,8 @@ class SofarWechselrichter extends IPSModule
|
|||||||
throw new Exception("Keine Antwort vom Inverter erhalten.");
|
throw new Exception("Keine Antwort vom Inverter erhalten.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6) Slice-Logik: l = 2*1 + 6 = 8, slice(-8, -4) → 2 Bytes
|
// 6) Slice-Logik: l = 2*1 + 4 = 6, dann slice(-6, -4) → 2 Bytes
|
||||||
$lModbus = 2 * 1 + 6; // = 8
|
$lModbus = 2 * 1 + 4; // = 6
|
||||||
$numBytes = 2;
|
$numBytes = 2;
|
||||||
if (strlen($response) < $lModbus) {
|
if (strlen($response) < $lModbus) {
|
||||||
throw new Exception("Unerwartet kurze Antwort (< {$lModbus} Bytes).");
|
throw new Exception("Unerwartet kurze Antwort (< {$lModbus} Bytes).");
|
||||||
|
|||||||
Reference in New Issue
Block a user