Hallo Leute,
nachdem ich hier schon seit einiger Zeit lesenderweise unterwegs bin, möchte nun auch etwas beitragen was evtl. hilfreich ist.
Aus dem Script von dfhome und den vielen wertvollen Hinweisen (vielen herzlichen Dank dafür) habe ich mir ein eigenes Script „gebastelt“, welches alle Funktionen abfragen und die wichtigsten schreiben kann.
Damit benötigt man kein zusätzliches Programm zum setzten der ID oder rücksetzen des Zählers mehr.
<?
$serialID = "000000000032"; //auszulesende Zähler-ID (12 Stellen), Standard: "000000000000"
$sleep = 280; //Bei Ausleseschwierigkeiten erhöhen! Standard: 280
$password = "(00000000)"; //Passwort (8 Stellen), Standard: "(00000000)"
$ComPort = 10587 /*[Serial Port RS232-485 com 8 - Elektrozähler]*/; //Serial Port
$RegVar = 10239 /*[Info\Elektrozähler\Register Variable]*/; //Register Variable
//-----------------------------------------------------------------------------------------------------------------------------------------------------
$Wcmd = 5; //Schreibbefehl; 5 = keiner; 4 = Zähler-ID; 3 = Zeit nullen; 2 = Zählerstand nullen; 1 = Zählerstand und Zeit nullen;
$ID = "000000000032"; //neue Zähler-ID (12 Stellen); z.B.: "000000000032"
//-----------------------------------------------------------------------------------------------------------------------------------------------------
//Init
COMPort_SetOpen($ComPort, true);
IPS_ApplyChanges($ComPort);
$cmd = chr(0x2F).chr(0x3F).$serialID.chr(0x21).chr(0x0D).chr(0x0A);
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
//ACK / Option Select Message senden ('Programming Mode')
$cmd = chr(0x06).chr(0x30).":".chr(0x31).chr(0x0D).chr(0x0A);
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."P1".chr(0x02).$password.chr(0x03).chr(0x61);
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
//Schreibbefehle---------------------------------------------------------------------------------------------------------------------------------------
if ($Wcmd == 1){
echo "Zählerstand und Zeit nullen.
";
// Zähler Reset (0)
$cmd = chr(0x01)."W1".chr(0x02)."00000040(0)".chr(0x03).chr(0x52);
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
// Zeit setzen
$F = "00000031";
//$datum = date("ymd",time());
//$uhrzeit = date("His",time());
//$W = ($datum."00".$uhrzeit); // aktuelle Zeit oder
$W = "00010100000000"; // nullen entspricht 01.01.2000; 00:00:00
$cmd = "$F"."($W)";
$bcc = CalcBCC("W1".chr(0x02).$cmd.chr(0x03));
$CMD = chr(0x01)."W1".chr(0x02).$cmd.chr(0x03).chr($bcc);
COMPort_SendText($ComPort, $CMD);
IPS_Sleep($sleep);
}
if ($Wcmd == 2){
echo "Zählerstand nullen.
";
//****************** Zähler Reset (0)
$cmd = chr(0x01)."W1".chr(0x02)."00000040(0)".chr(0x03).chr(0x52);
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
}
if ($Wcmd == 3){
echo "Zeit nullen.
";
// Zeit setzen
$F = "00000031";
//$datum = date("ymd",time());
//$uhrzeit = date("His",time());
//$W = ($datum."00".$uhrzeit); // aktuelle Zeit oder
$W = "00010100000000"; // nullen
$cmd = "$F"."($W)";
$bcc = CalcBCC("W1".chr(0x02).$cmd.chr(0x03));
$CMD = chr(0x01)."W1".chr(0x02).$cmd.chr(0x03).chr($bcc);
COMPort_SendText($ComPort, $CMD);
IPS_Sleep($sleep);
}
if ($Wcmd == 4){
echo "Zähler-ID setzen.
";
//Zähler-ID setzen
$F = "00000036";
echo "neue Zähler-ID: $ID
";
$cmd = "$F"."($ID)";
$bcc = CalcBCC("W1".chr(0x02).$cmd.chr(0x03));
$CMD = chr(0x01)."W1".chr(0x02).$cmd.chr(0x03).chr($bcc);
COMPort_SendText($ComPort, $CMD);
IPS_Sleep($sleep);
}
if ($Wcmd == 5){
echo "Keine Schreibfunktion ausgewählt!
";
}
//if ($Wcmd == 9){
//Baudrate setzen
//$F = "00000035";
//$W = "0004"; //(0001=1200 (Achtung: sleep auf min. 500!); 00002=2400; 00003=4800; 00004=9600)
//$cmd = "$F"."($W)";
//$bcc = CalcBCC("W1".chr(0x02).$cmd.chr(0x03));
//$CMD = chr(0x01)."W1".chr(0x02).$cmd.chr(0x03).chr($bcc);
//COMPort_SendText($ComPort, $CMD);
//IPS_Sleep($sleep);
//}
//Abfrage---------------------------------------------------------------------------------------------------------------------------------------
$cmd = chr(0x01)."R1".chr(0x02)."00000000()".chr(0x03).chr(0x63); //****************** Spannung
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000001()".chr(0x03).chr(0x62); //****************** Strom
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000002()".chr(0x03).chr(0x61); //****************** Frequenz
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000003()".chr(0x03).chr(0x60); //****************** Wirkleistung
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000004()".chr(0x03).chr(0x67); //****************** Blindleistung
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000005()".chr(0x03).chr(0x66); //****************** Scheinleistung
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000006()".chr(0x03).chr(0x65); //****************** Leistungsfaktor
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000010()".chr(0x03).chr(0x62); //****************** Gesamtleistung/Zählerstand
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000011()".chr(0x03).chr(0x63); //****************** Gesamtleistung/Zählerstand (Kopie von ...10)
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000020()".chr(0x03).chr(0x61); //****************** Energie in Rückwärtsrichtung
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000021()".chr(0x03).chr(0x60); //****************** Energie in Rückwärtsrichtung (Kopie von ...20)
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000031()".chr(0x03).chr(0x61); //****************** Zeit (YYMMTT??hhmmss)
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000032()".chr(0x03).chr(0x62); //****************** Temperatur
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000034()".chr(0x03).chr(0x64); //****************** Seriennummer
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000035()".chr(0x03).chr(0x65); //****************** Baudrate
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."R1".chr(0x02)."00000036()".chr(0x03).chr(0x66); //****************** Zähler-ID
COMPort_SendText($ComPort, $cmd);
IPS_Sleep($sleep);
$cmd = chr(0x01)."B0".chr(0x03).chr(0x71);
COMPort_SendText($ComPort, $cmd);
COMPort_SetOpen($ComPort, false);
IPS_ApplyChanges($ComPort);
IPS_Sleep($sleep);
//Auslesen------------------------------------------------------------------------------------------------------------------------------------------------
$data = RegVar_GetBuffer($RegVar);
//echo "Data: $data
";
$value = substr($data, strpos($data, "/")+1,3); //Hersteller (Antwort)
echo "Antwort Hersteller: $value
";
$value = substr($data, strpos($data, ":")+1,12); //Zähler-ID (Antwort)
echo "Antwort Zähler-ID: $value
";
$value = substr($data, strpos($data, "00000000(")+9,4)/10; //Spannung / 10 V
echo "Spannung: $value V
";
//SetValue(35532 /*[Info\Elektrozähler\Administration\Spannung]*/, $value);
$value = substr($data, strpos($data, "00000001(")+9,4)/10; //Strom //Strom / 10 A
echo "Strom: $value A
";
//SetValue(45094 /*[Info\Elektrozähler\Administration\Strom]*/, $value);
$value = substr($data, strpos($data, "00000002(")+9,4)/10; //Frequenz / 10 HZ
echo "Frequenz: $value Hz
";
//SetValue(51097 /*[Info\Elektrozähler\Administration\Frequenz]*/, $value);
$value = substr($data, strpos($data, "00000003(")+9,4)*10; //Wirkleistung x 10 W
echo "Wirkleistung: $value W
";
//SetValue(14053 /*[Info\Elektrozähler\Administration\Wirkleistung]*/, $value);
$value = substr($data, strpos($data, "00000004(")+9,4)*10; //Blindleistung x 10 VAr (nur bei induktiver Last)
echo "Blindleistung: $value VAr
";
//SetValue(52726 /*[Info\Elektrozähler\Administration\Blindleistung]*/, $value);
$value = substr($data, strpos($data, "00000005(")+9,4)*10; //Scheinleistung x 10 VA
echo "Scheinleistung: $value VA
";
//SetValue(14444 /*[Info\Elektrozähler\Administration\Scheinleistung]*/, $value);
$value = substr($data, strpos($data, "00000006(")+9,4)/1000; //Leistungsfaktor / 1000
echo "Leistungsfaktor: $value
";
//SetValue(24547 /*[Info\Elektrozähler\Administration\Leistungsfaktor]*/, $value);
$value = substr($data, strpos($data, "00000010(")+9,8)/1000; //Gesamtleistung/Zählerstand / 1000 kWh
echo "Zählerstand 1: $value kWh
";
//SetValue(23900 /*[Info\Elektrozähler\Administration\Zählerstand / Gesamtleistung -1-]*/, $value);
$value = substr($data, strpos($data, "00000011(")+9,8)/1000; //Gesamtleistung/Zählerstand / 1000 kWh (Kopie von ...10)
echo "Zählerstand 2: $value kWh
";
//SetValue(35912 /*[Info\Elektrozähler\Administration\Zählerstand / Gesamtleistung -2-]*/, $value);
$value = substr($data, strpos($data, "00000020(")+9,8)/1000; //Energie in Rückwärtsrichtung / 1000 kWh
echo "Leistung auswärts 1: $value kWh
";
//SetValue(54517 /*[Info\Elektrozähler\Administration\Energie rückwärts]*/, $value);
$value = substr($data, strpos($data, "00000021(")+9,8)/1000; //Energie in Rückwärtsrichtung / 1000 kWh (Kopie von ...20)
echo "Leistung auswärts 2: $value kWh
";
$tmp = substr($data, strpos($data, "00000031(")+9,14); //Zeit (YYMMDDxxhhmmss) xx = Tage seit Reset
$value = substr($tmp,4,2).".".substr($tmp,2,2).".20".substr($tmp,0,2)."; ".substr($tmp,8,2).":".substr($tmp,10,2).":".substr($tmp,12,2)."
";
echo "Zeit: $value";
//SetValue(36489 /*[Info\Elektrozähler\Administration\Zeit]*/, $value);
$value = substr($data, strpos($data, "00000032(")+9,4)/1; //Temperatur / °C (ändert sich nicht)
echo "Temperatur: $value °C
";
//SetValue(52124 /*[Info\Elektrozähler\Administration\Temperatur (ignorieren)]*/, $value);
$value = substr($data, strpos($data, "00000034(")+9,12); //Seriennummer
echo "Seriennummer: $value
";
//SetValue(47632 /*[Info\Elektrozähler\Administration\Seriennummer]*/, $value);
$value = substr($data, strpos($data, "00000035(")+9,4)*1; //Baudrate
echo "Baudrate: $value (1=1200; 2=2400; 3=4800; 4=9600)
";
//SetValue(52967 /*[Info\Elektrozähler\Administration\Baud]*/, $value);
$value = substr($data, strpos($data, "00000036(")+9,12); //Zähler-ID
echo "Zähler-ID: $value
";
//SetValue(23885 /*[Info\Elektrozähler\Administration\Zähler-ID]*/, $value);
RegVar_SetBuffer($RegVar, ""); //Variable löschen
//Checksumme berechnen_________________________________________________________________________________________________________________________________________
function CalcBCC($string) {
$bcc = "";
for ($i = 0; $i <= strlen($string); $i++) {
$bcc = $bcc ^ ord(substr($string, $i, 1));
}
return ("0x".dechex($bcc));
}
//_____________________________________________________________________________________________________________________________________________________________
?>
Von den DRS155M habe ich momentan 7 Stück im Gebrauch, wovon allerdings zwei „rumzicken“ (tlw. falsche Werte).
Die restlichen funktionieren problemlos.
Grüße
Marmangra