FUNCTION_BLOCK "FB-OPC_UA_System-Stat"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      nInSystemStat : Int;   // Main State
      xInFireAlarm : Bool;   // Feueralarm
      xInSafetyStop : Bool;   // Not-Halt
      xInError : Bool;   // Störung
      xInCommunicationError : Bool;   // Kommunikationsstörung
   END_VAR

   VAR_OUTPUT 
      nOutScadaStatus : Int;
   END_VAR


BEGIN
	//Priority Chain 
	//Emergency
	//Fault/Restore
	//Manual
	//Energy Saving
	//Cleaning / Warning
	//Running/Stopped
	
	IF #xInFireAlarm THEN
	    #nOutScadaStatus := 1;
	ELSIF #xInSafetyStop THEN
	    #nOutScadaStatus := 3;
	ELSIF #xInError THEN
	    #nOutScadaStatus := 5;
	ELSIF #xInCommunicationError THEN
	    #nOutScadaStatus := 23;
	ELSIF #nInSystemStat = "E_DeviceState.eExecute" THEN
	    #nOutScadaStatus := 19;
	ELSIF (#nInSystemStat = "E_DeviceState.eStopped") OR (#nInSystemStat = "E_DeviceState.eIdle") THEN
	    #nOutScadaStatus := 17;
	END_IF;
	
	(* CASE #nInSystemStat OF
	        
	    "E_DeviceState.eStopped":
	        #nOutScadaStatus := 17;
	        
	    "E_DeviceState.eIdle":
	        #nOutScadaStatus := 17;
	        
	    "E_DeviceState.eExecute":
	        #nOutScadaStatus := 19;
	        
	    "E_DeviceState.eHolding":
	        #nOutScadaStatus := 3;
	        
	    "E_DeviceState.eHeld":
	        #nOutScadaStatus := 13;
	        
	    "E_DeviceState.eSuspended":
	        #nOutScadaStatus := 13;
	        
	    "E_DeviceState.eStarting",
	    120,
	    "E_DeviceState.eUnholding",
	    "E_DeviceState.eUnsuspending",
	    "E_DeviceState.eStopping":
	        #nOutScadaStatus := 7;
	        
	    ELSE
	        #nOutScadaStatus := 5;
	        
	END_CASE; *)
END_FUNCTION_BLOCK

