From e9fdf1b44852c4b7b1b4a69101c17483dace96e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=A4fliger?= Date: Wed, 4 Jun 2025 14:08:26 +0200 Subject: [PATCH] no message --- SofarWechselrichter/module.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SofarWechselrichter/module.php b/SofarWechselrichter/module.php index 9671512..69339f2 100644 --- a/SofarWechselrichter/module.php +++ b/SofarWechselrichter/module.php @@ -140,7 +140,7 @@ class SofarWechselrichter extends IPSModule // Bytes registerweise einzeln abfragen und zusammenfügen: $dataBytes = ''; 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 $hex = strtoupper(bin2hex($dataBytes)); @@ -181,7 +181,7 @@ class SofarWechselrichter extends IPSModule * @return string 2-Byte-Binär-String * @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 $oFrame = 'a5170010450000'; @@ -215,7 +215,7 @@ class SofarWechselrichter extends IPSModule $crcSwapped = substr($crcHex, 2, 2) . substr($crcHex, 0, 2); $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; $bArr = []; for ($i = 0; $i < $l; $i++) { @@ -258,8 +258,8 @@ class SofarWechselrichter extends IPSModule throw new Exception("Keine Antwort vom Inverter erhalten."); } - // 6) Slice-Logik: l = 2*1 + 6 = 8, slice(-8, -4) → 2 Bytes - $lModbus = 2 * 1 + 6; // = 8 + // 6) Slice-Logik: l = 2*1 + 4 = 6, dann slice(-6, -4) → 2 Bytes + $lModbus = 2 * 1 + 4; // = 6 $numBytes = 2; if (strlen($response) < $lModbus) { throw new Exception("Unerwartet kurze Antwort (< {$lModbus} Bytes).");