no message

This commit is contained in:
2025-06-04 14:08:26 +02:00
parent 021c693164
commit e9fdf1b448
+5 -5
View File
@@ -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).");