FUNCTION_BLOCK "FB_EventLog_Root"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      xInTrigger : Bool;
      sInInstance : String[50];   // he instance that called the function - see Beckhoff {attribute 'instance-path'} or library example project for how to retrieve this automatically.
      nInLogLevel : Int;
      sInMessage : String;
   END_VAR

   VAR 
      fbProgram_Alarm {InstructionName := 'Program_Alarm'; LibVersion := '1.0'} : Program_Alarm;
      wStatus : Word;
      xTriggerFlag : Bool;
   END_VAR

   VAR_TEMP 
      xError : Bool;
      sLogMessage : String;
      xLogEnable : Bool;
   END_VAR

   VAR CONSTANT 
      cSeperationChar : String := ';';
   END_VAR


BEGIN
	//#sInInstanceName := GetInstancePath(size:=1);
	#xLogEnable := #nInLogLevel <= "DB_MachineGlobal".nLogLevel;
	REGION Meldetext
	    IF #xInTrigger AND NOT #xTriggerFlag THEN
	            #sLogMessage := CONCAT_STRING(IN1 := "FC_DateAsString"(),
	                                          IN2 := #cSeperationChar,
	                                          IN3 := "FC_TimeAsString"(),
	                                          IN4 := #cSeperationChar,
	                                          IN5 := "FC_Loglevel_to_String"(#nInLogLevel),
	                                          IN6 := #cSeperationChar,
	                                          IN7 := #sInInstance,
	                                          IN8 := #cSeperationChar,
	                                          IN9 := #sInMessage);
	    END_IF;
	END_REGION
	
	REGION Program Alarm
	    #fbProgram_Alarm(SIG := #xInTrigger AND NOT #xTriggerFlag AND #xLogEnable,
	                     SD_1 := #sLogMessage,
	                     Status => #wStatus,
	                     Error => #xError);
	END_REGION
	
	
	REGION Flanken
	    #xTriggerFlag := #xInTrigger;
	END_REGION
END_FUNCTION_BLOCK

