FUNCTION "FC_Direction" : Void
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      nInSwitchNo : USInt;
   END_VAR

   VAR_OUTPUT 
      nOutDirection : USInt;   // Ziel für Switch-Baustein
   END_VAR

   VAR_IN_OUT 
      InOutCarrier : "stCarrier";
   END_VAR


BEGIN
	// Destination vom Carrier, immer unterschiedlich je nach Anlagenbereich, soll übertragen werden auf universale Switch Direction (1-4)
	
	REGION Vergabe Direction
	    CASE #nInSwitchNo OF
	        "cSwi505.1":
	            REGION Switch 505.1
	                IF (#InOutCarrier.nDestination = "cDestWS1_1") THEN // 
	                    #nOutDirection := 1; // LINKS, 1->3
	                ELSE // Auf Kreisel bleiben, alle anderen Fälle + Fallbackstrategie (?)
	                    #nOutDirection := 2; // RECHTS, 1->4
	                END_IF;
	            END_REGION
	            
	        "cSwi510.1":
	            REGION Switch 510.1
	                IF #InOutCarrier.nDestination = "cDestWS1_0" THEN 
	                    #nOutDirection := 1; // LINKS, 1->3
	                ELSE
	                    #nOutDirection := 2; 
	                END_IF;
	            END_REGION
	            
	        "cSwi514.1":
	            REGION Switch 514.1
	                IF #InOutCarrier.nDestination = "cDestWS2_0" THEN
	                    #nOutDirection := 1; // LINKS, 1->3
	                ELSE
	                    #nOutDirection := 2; 
	                END_IF;
	            END_REGION
	            
	        "cSwi518.1":
	            REGION Switch 518.1
	                IF #InOutCarrier.nDestination = "cDestWS3_0" THEN
	                    #nOutDirection := 1; // LINKS, 1->3
	                ELSE
	                    #nOutDirection := 2; 
	                END_IF;
	            END_REGION
	            
	        "cSwi522.1":
	            REGION Switch 522.1
	                IF #InOutCarrier.nDestination = "cDestWS4_0" THEN
	                    #nOutDirection := 1; // LINKS, 1->3
	                ELSE
	                    #nOutDirection := 2; 
	                END_IF;
	            END_REGION
	            
	        "cSwi527.1":
	            REGION Switch 527.1
	                IF #InOutCarrier.nDestination = "cDestLeaveF2H" THEN
	                    #nOutDirection := 1; // LINKS, 1->3
	                ELSE
	                    #nOutDirection := 2;
	                END_IF;
	            END_REGION
	            
	    END_CASE;
	END_REGION
END_FUNCTION

