Hallo,
seit meiner Umstellung auf V5.0 werde ich mit Fehlermeldungen zugeschüttet. Ich habe schon einiges gelesen über den Constructor in PHP7 aber leider keine Ahnung wie ich das Problem in meinen Fall lösen kann.
Ich hoffe es kann mir jemand helfen.
Mein Fehler:
12.08.2018 10:31:16 | Register Variable | <br />
<b>Deprecated</b>: Methods with the same name as their class will not be constructors in a future version of PHP; FroniusCom has a deprecated constructor in <b>C:\IPSYMCON\scripts\58818.ips.php</b> on line <b>47</b><br />
58818:
<?
/**
* File contains FRONIUS class for protocol implememtation:
*/
// Define required IPS-variables for communication with inverter
// replace yyyyy with your own IPS ID's
define( "FRONIUS_REGVAR", 32820 /*[Bauernhaus\Fronius\Wechselrichter 2\Register Variable Fronius2]*/);
//define( "FRONIUS_COMPORT", 12678 /*[Serial Port Fronius Stick]*/);
define( "FRONIUS_COMPORT", 42288 /*[USR_TCP232_306_Fronius]*/);
// Define required IPS-variables for Fronius inverter
// replace xxxxx with your own IPS ID's
define( "POWER_NOW", 39301 /*[Bauernhaus\Fronius\Wechselrichter 2\Leistung jetzt]*/ );
define( "ENERGY_DAY", 10496 /*[Bauernhaus\Fronius\Wechselrichter 2\Energie Heute]*/ );
define( "ENERGY_YESTERDAY", 56400 /*[Bauernhaus\Fronius\Wechselrichter 2\Energie Gestern]*/);
define( "ENERGY_MONTH", 28057 /*[Bauernhaus\Fronius\Wechselrichter 2\Energie Monat]*/);
define( "ENERGY_YEAR", 31504 /*[Bauernhaus\Fronius\Wechselrichter 2\Energie Jahr]*/);
define( "AC_CURRENT_NOW", 51878 /*[Bauernhaus\Fronius\Wechselrichter 2\Wechselstrom]*/ );
define( "AC_VOLTAGE_NOW", 38707 /*[Bauernhaus\Fronius\Wechselrichter 2\Wechselspannung]*/ );
define( "AC_FREQUENCY_NOW", 40145 /*[Bauernhaus\Fronius\Wechselrichter 2\Frequenz]*/ );
//define( "DC_CURRENT_NOW", 29769 );
//define( "DC_VOLTAGE_NOW", 58266 );
define( "OPERATING_HOURS_DAY", 45465 /*[Bauernhaus\Fronius\Wechselrichter 2\Betriebszeit Heute]*/ );
define( "OPERATING_HOURS_YESTERDAY", 46102 /*[Bauernhaus\Fronius\Wechselrichter 2\Betriebszeit Gestern]*/ );
define( "OPERATING_HOURS_TOTAL", 41234 /*[Bauernhaus\Fronius\Wechselrichter 2\Betriebszeit Gesamt]*/ );
define( "ENERGY_TOTAL_EX", 56884 /*[Bauernhaus\Fronius\Wechselrichter 2\Energie Gesamt]*/ );
define( "ENERGY_TOTAL_EX_LAST_YEAR", 38834 /*[Bauernhaus\Fronius\Wechselrichter 2\Energie Gesamt letztes Jahr]*/ );
define( "ENERGY_TOTAL_EX_LAST_MONTH", 49395 /*[Bauernhaus\Fronius\Wechselrichter 2\Energie Gesamt letzten Monat]*/ );
define( "ENERGY_TOTAL_EX_LAST_DAY", 17679 /*[Bauernhaus\Fronius\Wechselrichter 2\Energie Gesamt Gestern]*/);
define( "INVERTER_STATUS", 22240 /*[Bauernhaus\Fronius\Wechselrichter 2\Status]*/ );
/* ***** Do not change values here following ***** */
define( "STARTSEQUENCE", chr(0x80).chr(0x80).chr(0x80) );
define( "GET_POWER_NOW", chr(0x10) ); // aktuelle Leistung [W] unsigned
define( "GET_ENERGY_DAY", chr(0x12) ); // Tagesenergie [Wh in kWh] unsigned
define( "GET_AC_CURRENT_NOW", chr(0x14) ); // Aktueller Wechselstrom
define( "GET_AC_VOLTAGE_NOW", chr(0x15) ); // Aktuelle Wechselspannung
define( "GET_AC_FREQUENCY_NOW", chr(0x16) ); // Aktuelle Frequenz
define( "GET_DC_CURRENT_NOW", chr(0x17) ); // Aktueller Gleichstrom
define( "GET_DC_VOLTAGE_NOW", chr(0x18) ); // Aktuelle Gleichspannung
define( "GET_OPERATING_HOURS_DAY", chr(0x1E) ); // Tagesbetriebszeit in Minuten
define( "GET_OPERATING_HOURS_TOTAL", chr(0x2A) ); // Betriebszeit Gesamt
define( "GET_ENERGY_TOTAL_EX", chr(0x36) ); // Erzeugte Gesamt-Energie
define( "GET_INVERTER_STATUS", chr(0x37) ); // Status Wechselrichter
class FroniusCom {
var $comport;
var $regvar;
var $status;
var $timeout_sec = 5; // 5 sec
var $endianess = 0; // defines endian codding (little endian == 0, big endian == 1)
/**
* FroniusCom
*
* This is the constructor that defines the ComPort and the Register
* Variable RegVar
*
* @param comport Id of serial communication port.
* @param regvar Register Variable which will hold the converter response
*/
function FroniusCom( $comport, $regvar ){
$this->comport = $comport;
$this->regvar = $regvar;
}
/**
* readData
*
* Reads data from the inverter
*
* @param command Fronius protocol command 0x10 - 0x35
* $param device Fronius device id (e.g. 0x01 = inverter)
* @param number ID of the device
*/
function readData ( $command, $device = 1, $number = 2 )
{
// log protocol-flow in status variable - initialize string
$this->status = "readValue: START
";
//open ComPort, if not open return false
if( !$this->openComPort() ) { return false; }
// send packet
$packet = $this->buildPacket( $command, $device, $number );
$this->status .= "commandPacket: ".$this->printPacket( $packet );
$this->sendCommand( $packet );
IPS_SLEEP(50); // TEST
// receive response
$rpacket = $this->receiveResponse();
$this->status .= "responsePacket: ".$this->printPacket( $rpacket );
if( $rpacket == "" ) { $rpacket = $packet; }
//close ComPort
$this->closeComPort();
// parse packet
$return = $this->parsePacket( $packet, $rpacket );
$this->status .= "readData: DONE
";
return (boolean)$return;
}
/**
* buildPacket
*
* @param command Fronius protocol command 0x10 - 0x35
* @param device Fronius device id (e.g. 0x01 = converter)
* @param number ID of the device
* @return packet string
*/
private function buildPacket( $command, $device, $number )
{
// Packet: Startsequenz - Länge - Gerät/Option - Nummer - Befehl - CheckSumme
if( $command == GET_ENERGY_TOTAL_EX ) {
$checksum = $this->calculateCheckSum( chr(0x01).chr($device).chr($number).$command.chr(0x01) );
$packet = STARTSEQUENCE.chr(0x01).chr($device).chr($number).$command.chr(0x01).chr($checksum);
} else {
$checksum = $this->calculateCheckSum( chr(0x00).chr($device).chr($number).$command );
$packet = STARTSEQUENCE.chr(0x00).chr($device).chr($number).$command.chr($checksum);
}
return $packet;
}
/**
* parse packet
*
* parse packet received from inverter and set value in IPS
*
* @param string command packet
* @param string response packet
* @return value
*/
private function parsePacket( $packet, $rpacket )
{
//SetValue(31054 /*[Überwachung\Meldung (aktuell)]*/,bin2hex($packet));
//SetValue(31054 /*[Überwachung\Meldung (aktuell)]*/,bin2hex($rpacket));
// check start sequence
if( ord( substr( $rpacket, 0, 3 ) ) != ord( STARTSEQUENCE ) ) {
$this->status .= "Packet error: Packet with incorrect startsequence
";
return false;
}
/*
// evaluate check sum
$rchecksum = ord( substr( $rpacket, strlen( $rpacket ) - 1, 1 ) );
$checksum = $this->calculateCheckSum( substr( $rpacket, 3, strlen( $rpacket ) - 4) );
if( $rchecksum != $checksum ) {
$this->status .= "Packet-error: Incorrect checksum
";
return false;
}
*/
// loopback - set status = inactive
if( $packet == $rpacket ) {
$this->status .= "Inverter-loopback: inverter is inactive
";
SetValue( INVERTER_STATUS, 0 );
return false;
}
// check match of device and device number in both packet and rpacket
if( substr( $packet, 4, 2) != substr( $rpacket, 4, 2 ) ) {
$this->status .= "Packet-error: Packet mismatch
";
return false;
}
// check for protocoll error
if( ord( substr( $rpacket, 6, 1 ) ) == 14 ) {
$this->status .= "Protocol-error:
Command ".$this->byte2hex( ord( substr( $rpacket, 7, 1 ) ) ).
" error information: ".ord( substr( $rpacket, 8, 1 ) )."
";
return false;
}
// process data in case of command
switch( ord( substr( $rpacket, 6, 1 ) ) ) {
case ord( GET_ENERGY_DAY ):
$value = $this->calculateMeteringValue( $rpacket ) / 1000;
if( $value > 0 ) {
SetValue( ENERGY_DAY, $value );
}
break;
case ord( GET_OPERATING_HOURS_DAY ):
$value = $this->calculateMeteringValue( $rpacket );
if( $value > 0 ) {
$stunden = $value / 60;
SetValue( OPERATING_HOURS_DAY, $stunden );
}
break;
case ord( GET_OPERATING_HOURS_TOTAL ):
$value = $this->calculateMeteringValue( $rpacket );
if( $value > 0 ) {
$stunden = $value / 60;
SetValue( OPERATING_HOURS_TOTAL, $stunden );
}
break;
case ord( GET_POWER_NOW ):
$value = $this->calculateMeteringValue( $rpacket );
if( $value < 0 ) $value = 0;
SetValue( POWER_NOW, $value );
break;
case ord( GET_AC_CURRENT_NOW ):
$value = $this->calculateMeteringValue( $rpacket );
SetValue( AC_CURRENT_NOW, $value );
break;
case ord( GET_AC_VOLTAGE_NOW ):
$value = $this->calculateMeteringValue( $rpacket );
SetValue( AC_VOLTAGE_NOW, $value );
break;
case ord( GET_AC_FREQUENCY_NOW ):
$value = $this->calculateMeteringValue( $rpacket );
SetValue( AC_FREQUENCY_NOW, $value );
break;
case ord( GET_DC_CURRENT_NOW ):
$value = $this->calculateMeteringValue( $rpacket );
SetValue( DC_CURRENT_NOW, $value );
break;
case ord( GET_DC_VOLTAGE_NOW ):
$value = $this->calculateMeteringValue( $rpacket );
SetValue( DC_VOLTAGE_NOW, $value );
break;
case ord( GET_ENERGY_TOTAL_EX ):
$value = $this->calculateMeteringValue( $rpacket ) / 1000;
if ($value > GetValue(ENERGY_TOTAL_EX) and $value < (GetValue(ENERGY_TOTAL_EX) + 1000)){
SetValue( ENERGY_TOTAL_EX, $value );
}
break;
/* case ord( GET_ENERGY_TOTAL_EX_LAST_DAY ):
$value = $this->calculateMeteringValue( $rpacket ) / 1000;
if ($value > 0){
SetValue( ENERGY_TOTAL_EX_LAST_DAY, $value );
}
break;
case ord( GET_ENERGY_TOTAL_EX_LAST_YEAR ):
$value = $this->calculateMeteringValue( $rpacket ) / 1000;
if ($value > 0){
SetValue( ENERGY_TOTAL_EX_LAST_YEAR, $value );
}
break; */
case ord( GET_INVERTER_STATUS ):
$value = ord( substr( $rpacket, 7, 1 ) );
SetValue( INVERTER_STATUS, $value );
break;
default:
IPS_LogMessage( "FroniusClass1", "Command ".ord( substr( $rpacket, 6, 1 ) )." not defined" );
break;
} // end switch
return true;
}
/**
* open
*
* open the comport
*
* @return bool
*/
function openComPort()
{
if (IPS_SemaphoreEnter("FR_COMPORT", 2000))
{
if ( IPS_GetProperty( $this->comport,'Open') == false )
{
IPS_SetProperty( $this->comport,'Open', true );
IPS_ApplyChanges( $this->comport );
RegVar_SetBuffer( $this->regvar, "" );
$this->status .= "Comport is open
";
}
return true;
} else {
// COM-Port already open - IPS-script via semaphore
$this->status .= "Comport couldn't be opened
";
return false;
}
}
/**
* close
*
* close the comport
*
* @return bool
*/
function closeComPort()
{
if ( IPS_GetProperty( $this->comport,'Open') == true )
{
IPS_SetProperty( $this->comport,'Open', false );
IPS_ApplyChanges( $this->comport );
$this->status .= "Comport has been closed
";
}
IPS_SemaphoreLeave("FR_COMPORT");
return true;
}
/**
* sendCommand
*
* Send the packet via Modbus
*
* @param string $packet
*/
private function sendCommand($packet){
//SPRT_SendText( $this->comport, $packet );
CSCK_SendText( $this->comport, $packet ); //Geändert von SPRT_SendText
$this->status .= "Send packet
";
}
/**
* receiveResponse
*
* Receive data via RegVar
*
* @return device message | Timeout
*/
private function receiveResponse(){
$this->status .= "Wait data ...
";
$last_access = time();
$data = "";
//IPS_SLEEP(500); // TEST
while ( $data == "" ) {
//IPS_SLEEP(500); // TEST
$data = RegVar_GetBuffer( $this->regvar );
if ( time() - $last_access >= $this->timeout_sec ) {
// $this->closeComPort();
IPS_LogMessage( "FroniusClass2", "Fronius Watchdog time expired [ ".$this->timeout_sec ." sec]!!! Time out " );
return $data;
}
if ( $data == "" ) IPS_SLEEP(10); //IPS_SLEEP(10)
}
RegVar_SetBuffer( $this->regvar, "" );
return $data;
}
/**
* calculateMeteringValue
*
* calculate value of inverter metering
*
* @param string rpacket
* @return value
*/
private function calculateMeteringValue( $rpacket )
{
//print_r("Befehl: ".ord( substr( $rpacket, 6, 1 ) )."
");
if( ord( substr( $rpacket, 6, 1 ) ) == ord( GET_ENERGY_TOTAL_EX ) ) { // command 0x36
$value = 0;
for( $i = 8; $i < 16; $i++ ) { // loop from pos 8 to 15
$value += ord( substr( $rpacket, $i, 1 ) ) * pow( 256, 15 - $i );
//print_r("Value: ...".$value."
");
}
$exp = $this->byte2hex( ord( substr( $rpacket, 16, 1) ) );
} else { // command 0x10 - 0x35, 0xE0 - 0xF9
$value = ord( substr( $rpacket, 7, 1 ) ) * 256 + ord( substr( $rpacket, 8, 1 ) );
$exp = $this->hexdecs( $this->byte2hex( ord( substr( $rpacket, 9, 1) ) ) );
}
if ( $exp <= 10 && $exp >= -3 ) {
return (float)( $value * pow( 10, $exp ) );
} else {
IPS_LogMessage( "FroniusClass1", "Protocol error: Over- or underflow of exponent" );
return 0;
}
}
/**
* calculate CheckSum
*
* calculate CheckSum as 8-bit addition without consideration of overflows
*
* @param string
* @return checksum
*/
private function calculateCheckSum( $string )
{
$checksum = 0;
for( $i = 0; $i < strlen( $string ); $i++ ) {
$checksum += ord( substr( $string, $i, 1 ) );
if ( $checksum > 255 ) $checksum -= 255;
}
return ( $checksum );
}
/**
* byte2hex
*
* Parse data and get it to the Hex form
*
* @param char $value
* @return string
*/
private function byte2hex( $value ){
$h = dechex( ( $value >> 4 ) & 0x0F );
$l = dechex( $value & 0x0F );
return "$h$l";
}
/**
* printPacket
*
* Print a packet in the hex form
*
* @param string $packet
* @return string
*/
private function printPacket($packet){
$str = "";
$str .= "Packet: ";
for($i=0;$i<strlen($packet);$i++){
$str .= $this->byte2hex(ord($packet[$i]));
}
$str .= "
";
return $str;
}
/**
* converts a hex string to signed decimal number
*
* @param hex string
* $return decimal number
*/
private function hexdecs( $hex ) {
// ignore non hex characters
$hex = preg_replace('/[^0-9A-Fa-f]/', '', $hex);
// converted decimal value:
$dec = hexdec($hex);
// maximum decimal value based on length of hex + 1:
// number of bits in hex number is 8 bits for each 2 hex -> max = 2^n
// use 'pow(2,n)' since '1 << n' is only for integers and therefore limited to integer size.
$max = pow(2, 4 * (strlen($hex) + (strlen($hex) % 2)));
// complement = maximum - converted hex:
$_dec = $max - $dec;
// if dec value is larger than its complement we have a negative value (first bit is set)
return $dec > $_dec ? -$_dec : $dec;
}
} //end of class FroniusCom
?>