Wiederverbinden [viessmann] fehlgeschlagen = Zugriff verweigert Fehlmermeldung

Hallo vielleicht kann mir ja wer weiterhelfen hab keine Lösung gefunden. Frage per Usb meine Viessmann Wärmepumpe ab (Symcon Win 11 Pro) und irgendwann bekam ich immer wider diese Fehlermeldungen ohne ersichtlichen Grund finde aber einfach keine Lösung dafür. Hat irgendwer eine Ahnung wo das herkommen kann? Zwischen den Fehlermeldungen funktioniert die Abfrage wider einwandfrei.

gruß Stefan

<?php
 
 // 60 Sekunden Fehlermeldung Laufzeit unterdrücken
 ini_set('max_execution_time', 150); 
 
  // Variablen Includieren
  include( "ViessmannDeviceTools.inc.php" );

  // Verbindung zur Heizung öffnen
  ViessmannOpen();

  // Wert Abfragen
  ViessmannSetVariableByCommand( "BetriebsartHeizung", 52053 );
  ViessmannSetVariableByCommand( "Warmwassertemperaturoben", 58530 );
  ViessmannSetVariableByCommand( "VorlauftemperaturPrimaerquelle", 25814 )/10;
  ViessmannSetVariableByCommand( "RuecklauftemperaturSekundaer", 55771 );  	
  ViessmannSetVariableByCommand( "VorlauftemperaturSekundaer", 39911 );		 
  ViessmannSetVariableByCommand( "BetriebsartLueftung", 50037 );  
  ViessmannSetVariableByCommand( "Ventil Heizen/WW", 23921 );  
  ViessmannSetVariableByCommand( "Heizkreispumpe", 18821 );
  ViessmannSetVariableByCommand( "Primärpumpe", 22217 );
  ViessmannSetVariableByCommand( "Verdichter", 55796 );
  ViessmannSetVariableByCommand( "luftungablufttemperautr", 47634 );
  ViessmannSetVariableByCommand( "luftungzulufttemperatur", 36363 );
  ViessmannSetVariableByCommand( "luftungforttemperatur", 29711 );
  ViessmannSetVariableByCommand( "luftungaussentemperatur", 30774 );
  ViessmannSetVariableByCommand( "fortluftvolumenstrom", 50259 );
  ViessmannSetVariableByCommand( "zuluftvolumenstrom", 43479 );
  

  // Verbindung schliessen
  ViessmannClose();

?>
<?php
  include( "ViessmannVariables.inc.php");

  // Constants
  define( "VIESSMANN_PING",             chr(0x05) );
  define( "VIESSMANN_KW_READ_PRAEFIX",  chr(0x01).chr(0xF7) );
  define( "VIESSMANN_KW_WRITE_PRAEFIX", chr(0x01).chr(0xF4) );

  // init variables
  $CurrentAction   = ""; $CurrentProtocol = ""; $CurrentCommand  = "";
  $CurrentLength   = ""; $CurrentSetValue = "";

  $ViessmannDeviceID = GetValueString( VIESSMANN_VARIABLE_DEVICE );

  // get current Command if available or determine Device ID automatically
  $Command = GetValueString( VIESSMANN_VARIABLE_COMMAND );
  if ( $ViessmannDeviceID == "" AND strlen( $Command ) == 0 )
  {
	 $Command = "R:KW:00F8:2: "; // retrieve Device ID
	 SetValueString( VIESSMANN_DEVICE_COMMAND, $Command );
  }

  if ( $Command != "" )
  {
    $CommandArray = explode(":", $Command);
    $parts = count( $CommandArray );
    if ( $parts > 0 ) $CurrentAction   = $CommandArray[0];
    if ( $parts > 1 ) $CurrentProtocol = $CommandArray[1];
    if ( $parts > 2 ) $CurrentAddress  = $CommandArray[2];
    if ( $parts > 3 ) $CurrentLength   = $CommandArray[3];
    if ( $parts > 4 ) $CurrentSetValue = $CommandArray[4];
  }

  // Get remaining data in the com port via the buffer of the register variable
  $ComData = RegVar_GetBuffer( VIESSMANN_VARIABLE_REGISTER );
  // and merge it together with the passed data
  $ComData .= $IPS_VALUE;
echo $CurrentAction."-";
if ($ComData == VIESSMANN_PING ) echo "Ping"; else echo strlen( $ComData );
  // Process Com Data ----------------------------------------------------------
  if (   $ComData == VIESSMANN_PING AND
		 ( $CurrentAction == "R" OR $CurrentAction == "W" ) )
  {
    // No data expected (Command available), so execute command if available

    // Check, if expected Action and Command capabilities fit

    // Prepare Command Address + Length
    $Address =  chr(hexdec(substr($CurrentAddress,0,2)));
    $Address .= chr(hexdec(substr($CurrentAddress,2,2)));
    switch ( $CurrentAction )
    {
      case "R": // Read
        $CommandString = VIESSMANN_KW_READ_PRAEFIX.$Address.chr($CurrentLength);
        $Command[0] = "-"; // Mark Command as executed
        break;
      case "W": // Write
        $CommandString = VIESSMANN_KW_WRITE_PRAEFIX.$Address.chr($CurrentLength).$CurrentSetValue;
        $Command = ""; // Clear command
        break;
      default:
        $CommandString = "";
        break;
    }
    if ( $CommandString != "" )
    {
      SetValueString( VIESSMANN_VARIABLE_COMMAND, $Command );
	   // Clear current result
      SetValueString( VIESSMANN_VARIABLE_RESULT, "" );
		// Send command to Viessmann heating device via COM Port
		COMPort_SendText( VIESSMANN_VARIABLE_COMPORT, $CommandString );
    }
  }
  else
  {
	  if ( $CurrentAction == "-" and strlen( $ComData ) >= $CurrentLength )
	  {
		  // Com Data is equal or longer as needed
		  $Result = substr( $ComData, 0, $CurrentLength );
		  // Set Result in IPS Variable
        SetValue( VIESSMANN_VARIABLE_RESULT, bin2hex($Result));

        // if Device ID is initial and command was to retrieve device ID
        if ( $ViessmannDeviceID == "" AND $Command == "-:KW:00F8:2: " )
        {
			 // set device ID
			 $DeviceID = "";
          for( $x=0; $x < strlen($Result); $x++)
          {
            if ( ord($Result[$x]) < 10 ) $DeviceID .= "0";
            $DeviceID .= strtoupper(dechex(ord($Result[$x])));
          }
          SetValueString( VIESSMANN_VARIABLE_DEVICE, $DeviceID );
        }

        // clear command and remaining buffer of register variable
	  	  SetValueString( VIESSMANN_VARIABLE_COMMAND, "" );
        RegVar_SetBuffer( VIESSMANN_VARIABLE_REGISTER, "" );
	  }
	  else
	  {
        // as a result is expected and the current length of data is not
        // sufficient, write the data back to the buffer of the register var
        if ( $Command != "" AND $CurrentAction == "-" )
          RegVar_SetBuffer( VIESSMANN_VARIABLE_REGISTER, $ComData);
		  else
		    RegVar_SetBuffer( VIESSMANN_VARIABLE_REGISTER, "");
    }

  }
?>
<?
  // Constant definition for processing ----------------------------------------
  define( "VIESSMANN_GERAETEKENNUNG",   chr(0x00).chr(0xF8) );

  include( "ViessmannVariables.inc.php");

  // Get XML
  $ViessmannDeviceID = GetValueString( VIESSMANN_VARIABLE_DEVICE );
  $DeviceXMLName = IPS_GetKernelDir()."scripts\\ViessmannDevice".$ViessmannDeviceID.".xml";
  try
  {
    $ViessmannDeviceXML = simplexml_load_file( $DeviceXMLName );
  }
  catch (Exception $e)
  {
    $ViessmannDeviceXML = "";
  }

  function ViessmannGetCommand( $Command )
  {
    $CommandData = array();

    global $ViessmannDeviceXML;
    if ( !isset( $ViessmannDeviceXML ) OR $ViessmannDeviceXML == "" )
      return false;

    $CommandData["deviceid"] = $ViessmannDeviceXML["id"];
    $CommandData["protocol"] = $ViessmannDeviceXML["protocol"];

    // Get Command details
    $ViessmannDeviceCommands = $ViessmannDeviceXML->commands[0];

    foreach($ViessmannDeviceXML->commands[0] as $a => $XMLCommand )
    {
      if ( $XMLCommand["name"] == $Command )
      {
        $CommandData["name"]        = $Command;
        $CommandData["action"]      = $XMLCommand["action"];
        $CommandData["address"]     = $XMLCommand->address[0];
        $CommandData["length"]      = $XMLCommand->length[0];
        $CommandData["description"] = $XMLCommand->description[0];
        $CommandData["format"]      = $XMLCommand->format[0];
        break; // for
      }
    }
    if ( isset( $CommandData["name"] ) )
      return $CommandData;
    else
      return false;
  }

  function ViessmannResultToHexDisplay( $Result )
  {
    $ResultConv = "";
    for( $x=0; $x < strlen($Result); $x++)
    {
      if ( ord($Result[$x]) < 10 ) $ResultConv .= "0";
      $ResultConv .= strtoupper(dechex(ord($Result[$x])));
    }
    return $ResultConv;
  }

  function ViessmannConvertData( $Command, $Data )
  {
	  global $ViessmannDeviceID;
	  $ViessmannCommand = ViessmannGetCommand( $Command, $ViessmannDeviceID );
	  if ( $ViessmannCommand === false ) return false;
	  $Format = $ViessmannCommand["format"];
  
	  switch( $Format )
	  {
 		  case "Boolean":
		    if ( ord( $Data[0] ) == 0 )
		       return false;
			   else
				   return true;
		      break;
		  case "Temperature10":
			  $lowByte = ord( $Data[0] );
			  $highByte = ord( $Data[1] );
			  return (( $highByte * 256 ) + $lowByte ) / 10;
			  break;
		  case "Temperature100":
			  $lowByte = ord( $Data[0] );
			  $highByte = ord( $Data[1] );
			  return (( $highByte * 256 ) + $lowByte ) / 100;
			  break;
		  case "Count" or "Mode":
			  $Count = 0;
			  $HexString = ViessmannResultToHexDisplay( $Data );
			  for ( $x=0; $x < strlen( $Data ); $x=$x+2 )
			  {
				 $hex = substr( $HexString, $x,2 );
				 $dec = hexdec( $hex );
				 switch ( $x )
				 {
					case 0:
					  $Count = $Count + $dec;
					  break;
					case 2:
					  $Count = $Count + ( $dec * 256 );
					  break;
					case 4:
					  $Count = $Count + ( $dec * 65536 );
					  break;
					case 6:
					  $Count = $Count + ( $dec * 16777216 );
					  break;
					default:
					  break;
			    }
			  }
			  return $Count;
			  break;
			case "BooleanPercent":
			  return "BOOLEANPERCENT convertion not coded yet.";
			  break;
			case "Triple":
			  return "TRIPLE convertion not coded yet.";
			  break;
			case "Mode":
			  return hexdec(ord($Data[0]));
			  break;
		   case "ControlID":
		     $Result = "";
           for( $x=0; $x < strlen($Data); $x++)
           {
             if ( ord($Data[$x]) < 10 ) $Result .= "0";
             $Result .= strtoupper(dechex(ord($Data[$x])));
           }
           return $Result;
           break;
  		   default:
			  return "";
			  break;
		}
		return $ConvertedResult;
  }
  
function ViessmannGetData( $Command )
  {
     $Run = 1; // Maximum time a recheck is done, if Ping (0x05 is returnvalue)
     // get Command Data
      $ViessmannCommand = ViessmannGetCommand( $Command );
     if ( $ViessmannCommand === false ) return false;
     
     // clear previous result
     do
     {
        SetValueString( VIESSMANN_VARIABLE_RESULT, "" );
        // create command string and send to COM Port
        $CommandString = "R:".$ViessmannCommand["protocol"].":".$ViessmannCommand["address"].":".$ViessmannCommand["length"].": ";
        //$StartTime = microtime(true);
        //$RunTime = 0;
        SetValueString( VIESSMANN_VARIABLE_COMMAND, $CommandString );
        // wait for execution
        $status = getvalue( VIESSMANN_VARIABLE_COMMAND );
        //while ($status != "" AND $RunTime < 1 )
        //{
              //$status = getvalue( VIESSMANN_VARIABLE_COMMAND );
              //$RunTime = microtime(true) - $StartTime;
        //}
        sleep(5);
        // get result
        $Result = hex2bin(GetValue( VIESSMANN_VARIABLE_RESULT ));
        
        if ( $Result != chr(0x05) ) $Run = -1;
        $Run--;
     } while ( $Run > 0 );
     return $Result;
  }  

  function ViessmannSetData( $Command, $Data )
  {
	 // get Command Data
 	 $ViessmannCommand = ViessmannGetCommand( $Command );
	 if ( $ViessmannCommand === false ) return false;
	 if ( $ViessmannCommand["action"] != "ReadWrite" ) return false;
	 // clear previous result
    SetValueString( VIESSMANN_VARIABLE_RESULT, "" );
    // create command string and send to COM Port
  	 $CommandString = "W:".$ViessmannCommand["protocol"].":".$ViessmannCommand["address"].":".$ViessmannCommand["length"].":".$Data;
    SetValueString( VIESSMANN_VARIABLE_COMMAND, $CommandString );
    // wait for execution
    $status = getvalue( VIESSMANN_VARIABLE_COMMAND );
    while ($status != "") $status = getvalue( VIESSMANN_VARIABLE_COMMAND );
    // get result
    $Result = hex2bin(GetValue( VIESSMANN_VARIABLE_RESULT ));
    return $Result;
  }
  
  function ViessmannOpen()
  {
    // Open Com Port
    if ( COMPort_GetOpen( VIESSMANN_VARIABLE_COMPORT ) != true )
    {
	   COMPort_SetOpen( VIESSMANN_VARIABLE_COMPORT, true );
	   IPS_ApplyChanges( VIESSMANN_VARIABLE_COMPORT );
    }
  }
  
  function ViessmannClose()
  {
    // Close Com Port
    if ( COMPort_GetOpen( VIESSMANN_VARIABLE_COMPORT ) != false )
    {
	   COMPort_SetOpen( VIESSMANN_VARIABLE_COMPORT, false );
	   IPS_ApplyChanges( VIESSMANN_VARIABLE_COMPORT );
    }
  }
  
  function ViessmannSetVariableByCommand( $Command, $Var )
  {
    $Value = ViessmannGetData( $Command );
    if ( $Value === false )
	 {
	   SetValueBoolean( VIESSMANN_VARIABLE_CONNECTOK, false );
	 }
    else
    {
      SetValueBoolean( VIESSMANN_VARIABLE_CONNECTOK, true );
	   SetValue( $Var, ViessmannConvertData( $Command, $Value ) );
	 }
  }

?>
<?
  include( "ViessmannVariables.inc.php");

  // Constants
  define( "VIESSMANN_PING",             chr(0x05) );
  define( "VIESSMANN_KW_READ_PRAEFIX",  chr(0x01).chr(0xF7) );
  define( "VIESSMANN_KW_WRITE_PRAEFIX", chr(0x01).chr(0xF4) );

  // init variables
  $CurrentAction   = ""; $CurrentProtocol = ""; $CurrentCommand  = "";
  $CurrentLength   = ""; $CurrentSetValue = "";
  
  $ViessmannDeviceID = GetValueString( VIESSMANN_VARIABLE_DEVICE );

  // get current Command if available or determine Device ID automatically
  $Command = GetValueString( VIESSMANN_VARIABLE_COMMAND );
  if ( $ViessmannDeviceID == "" AND strlen( $Command ) == 0 )
  { 
	 $Command = "R:KW:00F8:2: "; // retrieve Device ID
	 SetValueString( VIESSMANN_DEVICE_COMMAND, $Command );
  }

  if ( $Command != "" )
  {
    $CommandArray = explode(":", $Command);
    $parts = count( $CommandArray );
    if ( $parts > 0 ) $CurrentAction   = $CommandArray[0];
    if ( $parts > 1 ) $CurrentProtocol = $CommandArray[1];
    if ( $parts > 2 ) $CurrentAddress  = $CommandArray[2];
    if ( $parts > 3 ) $CurrentLength   = $CommandArray[3];
    if ( $parts > 4 ) $CurrentSetValue = $CommandArray[4];
  }

  // Get remaining data in the com port via the buffer of the register variable
  $ComData = RegVar_GetBuffer( VIESSMANN_VARIABLE_REGISTER );
  // and merge it together with the passed data
  $ComData .= $IPS_VALUE;
echo $CurrentAction."-";
if ($ComData == VIESSMANN_PING ) echo "Ping"; else echo strlen( $ComData );
  // Process Com Data ----------------------------------------------------------
  if (   $ComData == VIESSMANN_PING AND
		 ( $CurrentAction == "R" OR $CurrentAction == "W" ) )
  { 
    // No data expected (Command available), so execute command if available

    // Check, if expected Action and Command capabilities fit

    // Prepare Command Address + Length
    $Address =  chr(hexdec(substr($CurrentAddress,0,2)));
    $Address .= chr(hexdec(substr($CurrentAddress,2,2)));
    switch ( $CurrentAction )
    {
      case "R": // Read
        $CommandString = VIESSMANN_KW_READ_PRAEFIX.$Address.chr($CurrentLength);
        $Command[0] = "-"; // Mark Command as executed
        break;
      case "W": // Write
        $CommandString = VIESSMANN_KW_WRITE_PRAEFIX.$Address.chr($CurrentLength).$CurrentSetValue;
        $Command = ""; // Clear command
        break;
      default:
        $CommandString = "";
        break;
    }
    if ( $CommandString != "" )
    {
      SetValueString( VIESSMANN_VARIABLE_COMMAND, $Command );
	   // Clear current result
      SetValueString( VIESSMANN_VARIABLE_RESULT, "" );
		// Send command to Viessmann heating device via COM Port
		COMPort_SendText( VIESSMANN_VARIABLE_COMPORT, $CommandString );
    }
  }
  else
  {
	  if ( $CurrentAction == "-" and strlen( $ComData ) >= $CurrentLength )
	  {
		  // Com Data is equal or longer as needed
		  $Result = substr( $ComData, 0, $CurrentLength );
		  // Set Result in IPS Variable
        SetValue( VIESSMANN_VARIABLE_RESULT, bin2hex($Result));
        
        // if Device ID is initial and command was to retrieve device ID
        if ( $ViessmannDeviceID == "" AND $Command == "-:KW:00F8:2: " )
        {
			 // set device ID
			 $DeviceID = "";
          for( $x=0; $x < strlen($Result); $x++)
          {
            if ( ord($Result[$x]) < 10 ) $DeviceID .= "0";
            $DeviceID .= strtoupper(dechex(ord($Result[$x])));
          }
          SetValueString( VIESSMANN_VARIABLE_DEVICE, $DeviceID );
        }
        
        // clear command and remaining buffer of register variable
	  	  SetValueString( VIESSMANN_VARIABLE_COMMAND, "" );
        RegVar_SetBuffer( VIESSMANN_VARIABLE_REGISTER, "" );
	  }
	  else
	  {
        // as a result is expected and the current length of data is not
        // sufficient, write the data back to the buffer of the register var
        if ( $Command != "" AND $CurrentAction == "-" )
          RegVar_SetBuffer( VIESSMANN_VARIABLE_REGISTER, $ComData);
		  else
		    RegVar_SetBuffer( VIESSMANN_VARIABLE_REGISTER, "");
    }

  }
?>