FUNCTION_BLOCK "Fb_PriorityManagerV2"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      xInQuit : Bool;
      udtIn_Source1Req : "UDT_Request";
      udtIn_Source2Req : "UDT_Request";
      udtIn_Source3Req : "UDT_Request";
      udtIn_Source4Req : "UDT_Request";
      nIn_SwitchAmountSoruce1 : UDInt;
      nIn_SwitchAmountSoruce2 : UDInt;
      nIn_SwitchAmountSoruce3 : UDInt;
      nIn_SwitchAmountSoruce4 : UDInt;
      nIn_PrioInterrupt : UInt;
      wsIn_ObjectName : WString[50];
      tIn_ReleaseTime1 : Time;
      tIn_ReleaseTime2 : Time;
      tIn_ReleaseTime3 : Time;
      tIn_ReleaseTime4 : Time;
      tIn_Watchdog : Time;
      tin_InterruptMaxDuration : Time;
      tIn_SourceChangeDelayTime : Time := T#10s;   // Zeit die abgewartet wird bis ein Source Wechsel stattfinden darf
      xInClearJam : Bool;
   END_VAR

   VAR_OUTPUT 
      udtOut_Source1Resp : "UDT_Response";
      udtOut_Source2Resp : "UDT_Response";
      udtOut_Source3Resp : "UDT_Response";
      udtOut_Source4Resp : "UDT_Response";
   END_VAR

   VAR_IN_OUT 
      udt_PrioParameter : "UDT_PrioParameter";
      udt_InterruptParameter : "udt_InterruptParameter";
   END_VAR

   VAR 
      PrgAlarm_Failmessage {InstructionName := 'Program_Alarm'; LibVersion := '1.0'} : Program_Alarm;
      xDummy : Bool;
      xError : Bool;
      wsErrorMessage : WString[50];
      nErrorID : USInt;
      n_AmountSource : USInt;
      n_TimedMode2Source : USInt;
      n_QuantityMode2Source : USInt;
      n_TraficLightMode2Source : USInt;
      n_InterruptMode2Source : USInt;
      n_TimedMode3Source : USInt;
      n_QuantityMode3Source : USInt;
      n_TraficLightMode3Source : USInt;
      n_TimedMode4Source : USInt;
      n_QuantityMode4Source : USInt;
      n_TraficLightMode4Source : USInt;
      n_CounterSource1 : UDInt;
      n_CounterSource2 : UDInt;
      n_CounterSource3 : UDInt;
      n_CounterSource4 : UDInt;
      ton_ReleaseSource1 {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
      ton_ReleaseSource2 {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
      ton_ReleaseSource3 {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
      ton_ReleaseSource4 {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
      ton_InterruptDelay {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
      ton_ReleaseInterrupt {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
      ton_WatchdogQuantity {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
      ton_runtime {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
      ton_InterruptMaxDuration {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
      arrx_SourcePrio : Array[0..4] of Bool;
      arrx_SourcePrioClear : Array[0..4] of Bool;
      udt_MainSourceResp : "UDT_Response";
      udt_InterruptSourceREsp : "UDT_Response";
      udt_InterruptSourceReq : "UDT_Request";
   END_VAR

   VAR_TEMP 
      nTempRetVal : Int;
      tTempLocalTime {InstructionName := 'DTL'; LibVersion := '1.0'} : DTL;
      nCount : USInt;
   END_VAR

   VAR CONSTANT 
      "****NumberOfSources****" : Bool;
      c4Sources : USInt := 4;
      c3Sources : USInt := 3;
      c2Sources : USInt := 2;
      c1Source : USInt := 1;
      c10ErrorNoSource : USInt := 10;
      "****PrioMode******" : USInt;
      c1ZeitGesteuert : USInt := 1;
      c2MengenGesteuert : USInt := 2;
      c3PrioAmpel : USInt := 3;
      c4Interrupt : USInt := 4;
      "****Sources****" : USInt;
      cSource1 : USInt := 1;
      cSource2 : USInt := 2;
      "****Sequence*****" : USInt;
      c000_WaitForRequest : USInt;
      c010_SetReleaseSource1 : USInt := 10;
      c010_WaitPathClear : USInt := 10;
      c020_SetReleaseSourceInterrupt : USInt := 20;
      c011_Countup : USInt := 11;
      c012_WaitShuttleGone : USInt := 12;
      c015_Reset : USInt := 15;
      c020_SetReleaseSource2 : USInt := 20;
      c021_Countup : USInt := 21;
      c022_WaitShuttleGone : USInt := 22;
      c025_Reset : USInt := 25;
      c030_SetReleaseSource3 : USInt := 30;
      c031_Countup : USInt := 31;
      c032_WaitShuttleGone : USInt := 32;
      c035_Reset : USInt := 35;
      c040_SetReleaseSource4 : USInt := 40;
      c041_Countup : USInt := 41;
      c042_WaitShuttleGone : USInt := 42;
      c045_Reset : USInt := 45;
   END_VAR


BEGIN
	REGION Info
	(* Company: Schönenberger Systeme GmbH / (C) Copyright (2022). All rights reserved.
	-----------------------------------------------------------------------------------------
	Title: FB_PriorityManager
	Comment/Function: controls the priority at intersections
	Library/Family: -
	Author: department: "Automatisierung" ; person in charge / contact: C.Nottelmann (Automated Intelligence)
	Target System: CPU 1518F-4 PN/DP
	Engineering: TIA Portal V20
	Restrictions: -
	Requirements: -
	-----------------------------------------------------------------------------------------
	Change log table:
	Version     | Date       | Signature (Safety) | Expert in charge | Changes applied
	------------|------------|--------------------|------------------|-----------------------
	001.000.000 | 2025-03-17 | -                  |                  | Header added on 17.03.2025
	                                                                   
	*)
	END_REGION
	
	REGION LocalTime
	    // read local time for timestamp ------------------------------------------
	    #nTempRetVal := RD_LOC_T(#tTempLocalTime);
	END_REGION
	
	REGION ToDo
	    
	    (*
	    
	    - Blockierungen untereinander verhindern. MaxZeit offen?
	    
	    
	    
	    *)
	    
	END_REGION
	
	REGION Times and Trigger
	    
	    #ton_ReleaseSource1(IN := #n_TimedMode2Source = #c010_SetReleaseSource1
	                        OR #n_TimedMode3Source = #c010_SetReleaseSource1
	                        OR #n_TimedMode4Source = #c010_SetReleaseSource1
	                        OR #n_TraficLightMode2Source = #c010_SetReleaseSource1
	                        OR #n_TraficLightMode3Source = #c010_SetReleaseSource1
	                        OR #n_TraficLightMode4Source = #c010_SetReleaseSource1,
	                        PT := #tIn_ReleaseTime1);
	    
	    #ton_ReleaseSource2(IN := #n_TimedMode2Source = #c020_SetReleaseSource2
	                        OR #n_TimedMode3Source = #c020_SetReleaseSource2
	                        OR #n_TimedMode4Source = #c020_SetReleaseSource2
	                        OR #n_TraficLightMode2Source = #c020_SetReleaseSource2
	                        OR #n_TraficLightMode3Source = #c020_SetReleaseSource2
	                        OR #n_TraficLightMode4Source = #c020_SetReleaseSource2,
	                        PT := #tIn_ReleaseTime2);
	    
	    #ton_ReleaseSource3(IN := #n_TimedMode3Source = #c030_SetReleaseSource3
	                        OR #n_TimedMode4Source = #c030_SetReleaseSource3
	                        OR #n_TraficLightMode3Source = #c030_SetReleaseSource3
	                        OR #n_TraficLightMode4Source = #c030_SetReleaseSource3,
	                        PT := #tIn_ReleaseTime3);
	    
	    #ton_ReleaseSource4(IN := #n_TimedMode4Source = #c040_SetReleaseSource4
	                        OR #n_TraficLightMode4Source = #c040_SetReleaseSource4,
	                        PT := #tIn_ReleaseTime4);
	    
	    #ton_WatchdogQuantity(IN := #n_QuantityMode2Source = #c010_SetReleaseSource1
	                          OR #n_QuantityMode2Source = #c020_SetReleaseSource2
	                          OR #n_QuantityMode3Source = #c010_SetReleaseSource1
	                          OR #n_QuantityMode3Source = #c020_SetReleaseSource2
	                          OR #n_QuantityMode3Source = #c030_SetReleaseSource3
	                          OR #n_QuantityMode4Source = #c010_SetReleaseSource1
	                          OR #n_QuantityMode4Source = #c020_SetReleaseSource2
	                          OR #n_QuantityMode4Source = #c030_SetReleaseSource3
	                          OR #n_QuantityMode4Source = #c040_SetReleaseSource4,
	                          PT := #tIn_Watchdog);
	    
	    #ton_InterruptDelay(IN:=#n_InterruptMode2Source = #c010_WaitPathClear,
	                        PT:=#udt_InterruptParameter.t_PathClearDelay);
	    
	    #ton_ReleaseInterrupt(IN:=#n_InterruptMode2Source = #c020_SetReleaseSourceInterrupt
	                          AND NOT #udt_InterruptSourceReq.xTransportReq,
	                          PT:=#udt_InterruptParameter.t_InterruptDuration);
	    
	    #ton_InterruptMaxDuration(IN:=#n_InterruptMode2Source = #c020_SetReleaseSourceInterrupt,
	                              PT:=#tin_InterruptMaxDuration);
	    
	    
	    #ton_runtime(IN := (#n_TimedMode2Source = #c015_Reset) OR (#n_TimedMode2Source = #c025_Reset) OR (#n_TimedMode3Source = #c015_Reset) OR (#n_TimedMode3Source = #c025_Reset) OR (#n_TimedMode3Source = #c035_Reset),
	                 PT := #tIn_SourceChangeDelayTime);
	    
	END_REGION
	
	REGION Check number of sources
	    //Auswertung wieviele Eingänge verwendet werden
	    #nCount := 0;
	    
	    IF #udtIn_Source1Req.nTroId > 0 THEN
	        #nCount += 1;
	    END_IF;
	    
	    IF #udtIn_Source2Req.nTroId > 0 THEN
	        #nCount += 1;
	    END_IF;
	    
	    IF #udtIn_Source3Req.nTroId > 0 THEN
	        #nCount += 1;
	    END_IF;
	    
	    IF #udtIn_Source4Req.nTroId > 0 THEN
	        #nCount += 1;
	    END_IF;
	    
	    
	    #n_AmountSource := #nCount;
	    
	    //Keine Quelle definiert
	    
	    IF #n_AmountSource = 0
	    THEN
	        #xError := TRUE;
	        #nErrorID := #c10ErrorNoSource;
	    END_IF;
	    
	    
	END_REGION
	
	REGION Prio Mapping
	    
	    #arrx_SourcePrio[1] := #nIn_PrioInterrupt = #c1Source AND #udtIn_Source1Req.xTransportReq;
	    #arrx_SourcePrio[2] := #nIn_PrioInterrupt = #c2Sources AND #udtIn_Source2Req.xTransportReq;
	    #arrx_SourcePrio[3] := #nIn_PrioInterrupt = #c3Sources AND #udtIn_Source3Req.xTransportReq;
	    #arrx_SourcePrio[4] := #nIn_PrioInterrupt = #c4Sources AND #udtIn_Source4Req.xTransportReq;
	END_REGION
	
	
	REGION Prio Logic
	    
	    CASE #n_AmountSource OF
	        #c1Source:
	            REGION 1 Source
	                
	                IF #udtIn_Source1Req.xTransportReq
	                    AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                    AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                    AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                THEN
	                    #udtOut_Source1Resp.xReleaseOk := True;
	                ELSE
	                    #udtOut_Source1Resp.xReleaseOk := False;
	                END_IF;
	                
	                //keine Vorfahrtsregelung notwendig//
	                
	            END_REGION
	        #c2Sources:
	            REGION 2 Sources
	                CASE #udt_PrioParameter.nPrioMode OF
	                    #c1ZeitGesteuert:
	                        REGION Zeit gesteuert
	                            CASE #n_TimedMode2Source OF
	                                #c000_WaitForRequest:
	                                    //Action
	                                    //Zurücksetzen der nicht aktiven Sequenzen der anderen Modi
	                                    #n_QuantityMode2Source := 0;
	                                    #n_TraficLightMode2Source := 0;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source1Req.xTransportReq  // Prüfung ob ein Request ansteht
	                                        AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2 //Prüfen ob ein Stau im Förderbereich ansteht
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear //Prüfen ob ein Prio Interrupt ansteht
	                                    THEN
	                                        #n_TimedMode2Source := #c010_SetReleaseSource1;
	                                    ELSIF #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TimedMode2Source := #c020_SetReleaseSource2;
	                                    ELSIF #arrx_SourcePrio[1]   // Prio Interrupt Quelle 1 und Request Quelle 1 aktiv
	                                    THEN
	                                        #n_TimedMode2Source := #c010_SetReleaseSource1;
	                                    ELSIF #arrx_SourcePrio[2]  // Prio Interrupt Quelle 2 und Request Quelle 2 aktiv
	                                    THEN
	                                        #n_TimedMode2Source := #c020_SetReleaseSource2;
	                                    END_IF;
	                                    
	                                #c010_SetReleaseSource1:
	                                    //Action
	                                    IF NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source1Resp.xReleaseOk := True; //Freigabe an TRO wird erteilt
	                                    ELSE
	                                        #udtOut_Source1Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource1.Q    // Warten bis vorgegebene Durchlasszeit endet
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[1])//Prüfen ob während Druchlasszeit ein Prio interrupt ansteht
	                                        OR (NOT #udtIn_Source1Req.xTransportReq AND NOT #udtIn_Source1Req.stSensor.xDbncdSensor AND #udtIn_Source1Req.stSensor.tDirectChangeLast > T#2s)
	                                    THEN
	                                        #n_TimedMode2Source := #c015_Reset;
	                                    END_IF;
	                                    
	                                #c015_Reset:
	                                    //Action
	                                    #udtOut_Source1Resp.xReleaseOk := False; //Freigabe an TRO wird zurückgesetzt
	                                    
	                                    //Transition
	                                 //   IF (#xInClearJam AND #udtIn_Source1Req.stJamExit.Status.nCount = 0) OR NOT #xInClearJam THEN
	                                    IF #udtIn_Source2Req.xTransportReq AND #ton_runtime.Q AND ((#xInClearJam AND #udtIn_Source1Req.stJamExit.Status.nCount = 0) OR NOT #xInClearJam)
	                                        THEN
	                                            #n_TimedMode2Source := #c020_SetReleaseSource2;
	                                        ELSIF
	                                            (#udtIn_Source1Req.xTransportReq AND NOT #udtIn_Source2Req.xTransportReq)
	                                            OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                        THEN
	                                            #n_TimedMode2Source := #c000_WaitForRequest;
	                                 //       END_IF;
	                                   // ELSIF NOT #xInClearJam AND #ton_runtime.Q THEN
	(*                                        IF #udtIn_Source2Req.xTransportReq
	                                        THEN
	                                            #n_TimedMode2Source := #c020_SetReleaseSource2;
	                                        ELSIF
	                                            (#udtIn_Source1Req.xTransportReq AND NOT #udtIn_Source2Req.xTransportReq)
	                                            OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                        THEN
	                                            #n_TimedMode2Source := #c000_WaitForRequest;
	                                        END_IF; *)
	                                   END_IF;
	                                    
	                                #c020_SetReleaseSource2:
	                                    //Action
	                                    IF NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source2Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source2Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource2.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[2])
	                                        OR (NOT #udtIn_Source2Req.xTransportReq AND NOT #udtIn_Source2Req.stSensor.xDbncdSensor AND #udtIn_Source2Req.stSensor.tDirectChangeLast > T#2s)
	                                    THEN
	                                        #n_TimedMode2Source := #c025_Reset;
	                                    END_IF;
	                                    
	                                #c025_Reset:
	                                    //Action
	                                    #udtOut_Source2Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                  //  IF (#xInClearJam AND #udtIn_Source2Req.stJamExit.Status.nCount = 0) OR NOT #xInClearJam THEN
	                                    IF #udtIn_Source1Req.xTransportReq AND #ton_runtime.Q AND ((#xInClearJam AND #udtIn_Source1Req.stJamExit.Status.nCount = 0) OR NOT #xInClearJam)
	                                        THEN
	                                            #n_TimedMode2Source := #c010_SetReleaseSource1;
	                                        ELSIF
	                                            (#udtIn_Source2Req.xTransportReq AND NOT #udtIn_Source1Req.xTransportReq)
	                                            OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                        THEN
	                                            #n_TimedMode2Source := #c000_WaitForRequest;
	                                        END_IF;
	                                        // ELSIF NOT #xInClearJam AND #ton_runtime.Q THEN
	                                        //     IF #udtIn_Source1Req.xTransportReq
	                                        //     THEN
	                                        //         #n_TimedMode2Source := #c010_SetReleaseSource1;
	                                        //     ELSIF
	                                        //         (#udtIn_Source2Req.xTransportReq AND NOT #udtIn_Source1Req.xTransportReq)
	                                        //         OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                        //     THEN
	                                        //         #n_TimedMode2Source := #c000_WaitForRequest;
	                                        //     END_IF;
	                               //     END_IF;
	                                    
	                            END_CASE;
	                        END_REGION
	                        
	                        
	                    #c2MengenGesteuert:
	                        REGION Mengen gesteuert 
	                            CASE #n_QuantityMode2Source OF
	                                #c000_WaitForRequest:
	                                    //Action
	                                    #n_TimedMode2Source := 0;
	                                    #n_TraficLightMode2Source := 0;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode2Source := #c010_SetReleaseSource1;
	                                    ELSIF #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode2Source := #c020_SetReleaseSource2;
	                                    ELSIF #arrx_SourcePrio[1]
	                                    THEN
	                                        #n_QuantityMode2Source := #c010_SetReleaseSource1;
	                                    ELSIF #arrx_SourcePrio[2]
	                                    THEN
	                                        #n_QuantityMode2Source := #c020_SetReleaseSource2;
	                                        
	                                    END_IF;
	                                    
	                                #c010_SetReleaseSource1:
	                                    //Action
	                                    IF NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source1Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source1Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source1Req.xTrolleyPresent
	                                    THEN
	                                        #n_QuantityMode2Source := #c011_Countup;
	                                    ELSIF #ton_WatchdogQuantity.Q
	                                    THEN
	                                        #n_QuantityMode2Source := #c015_Reset;
	                                    END_IF;
	                                    
	                                    
	                                #c011_Countup:
	                                    //Action
	                                    #n_CounterSource1 += 1;
	                                    
	                                    //Transition
	                                    #n_QuantityMode2Source := #c012_WaitShuttleGone;
	                                    
	                                #c012_WaitShuttleGone:
	                                    //Action
	                                    //
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source1Req.xTrolleyPresent
	                                        AND #n_CounterSource1 < #nIn_SwitchAmountSoruce1
	                                    THEN
	                                        #n_QuantityMode2Source := #c010_SetReleaseSource1;
	                                    ELSIF NOT #udtIn_Source1Req.xTrolleyPresent
	                                        AND #n_CounterSource1 >= #nIn_SwitchAmountSoruce1
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[1])
	                                    THEN
	                                        #n_QuantityMode2Source := #c015_Reset;
	                                    END_IF;
	                                    
	                                    
	                                    
	                                #c015_Reset:
	                                    //Action
	                                    #udtOut_Source1Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source2Req.xTransportReq
	                                        OR (#udtIn_Source1Req.xTransportReq AND NOT #udtIn_Source2Req.xTransportReq)
	                                        OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode2Source := #c000_WaitForRequest;
	                                    END_IF;
	                                    
	                                #c020_SetReleaseSource2:
	                                    //Action
	                                    IF NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source2Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source2Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source2Req.xTrolleyPresent
	                                    THEN
	                                        #n_QuantityMode2Source := #c021_Countup;
	                                    ELSIF #ton_WatchdogQuantity.Q
	                                    THEN
	                                        #n_QuantityMode2Source := #c025_Reset;
	                                    END_IF;
	                                    
	                                #c021_Countup:
	                                    //Action
	                                    #n_CounterSource2 += 1;
	                                    
	                                    //Transition
	                                    #n_QuantityMode2Source := #c022_WaitShuttleGone;
	                                    
	                                #c022_WaitShuttleGone:
	                                    //Action
	                                    //
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source2Req.xTrolleyPresent
	                                        AND #n_CounterSource2 < #nIn_SwitchAmountSoruce2
	                                    THEN
	                                        #n_QuantityMode2Source := #c020_SetReleaseSource2;
	                                    ELSIF NOT #udtIn_Source2Req.xTrolleyPresent
	                                        AND #n_CounterSource2 >= #nIn_SwitchAmountSoruce2
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[2])
	                                    THEN
	                                        #n_QuantityMode2Source := #c025_Reset;
	                                    END_IF;
	                                    
	                                #c025_Reset:
	                                    //Action
	                                    #udtOut_Source2Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source1Req.xTransportReq
	                                        OR (#udtIn_Source2Req.xTransportReq AND NOT #udtIn_Source1Req.xTransportReq)
	                                        OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode2Source := #c000_WaitForRequest;
	                                    END_IF;
	                                    
	                            END_CASE;
	                        END_REGION
	                    #c3PrioAmpel:
	                        REGION Ampel gesteuert
	                            CASE #n_TraficLightMode2Source OF
	                                #c000_WaitForRequest:
	                                    //Action
	                                    #n_QuantityMode2Source := 0;
	                                    #n_TimedMode2Source := 0;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode2Source := #c010_SetReleaseSource1;
	                                    ELSIF #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode2Source := #c020_SetReleaseSource2;
	                                    ELSIF #arrx_SourcePrio[1]
	                                    THEN
	                                        #n_QuantityMode2Source := #c010_SetReleaseSource1;
	                                    ELSIF #arrx_SourcePrio[2]
	                                    THEN
	                                        #n_QuantityMode2Source := #c020_SetReleaseSource2;
	                                    END_IF;
	                                    
	                                #c010_SetReleaseSource1:
	                                    //Action
	                                    IF NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source1Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source1Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource1.Q
	                                        OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode2Source := #c015_Reset;
	                                    END_IF;
	                                    
	                                #c015_Reset:
	                                    //Action
	                                    #udtOut_Source1Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    #n_TraficLightMode2Source := #c020_SetReleaseSource2;
	                                    IF #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode2Source := #c000_WaitForRequest;
	                                    END_IF;
	                                    
	                                #c020_SetReleaseSource2:
	                                    //Action
	                                    IF NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source2Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source2Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource2.Q
	                                        OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode2Source := #c025_Reset;
	                                    END_IF;
	                                    
	                                #c025_Reset:
	                                    //Action
	                                    #udtOut_Source2Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    #n_TraficLightMode2Source := #c000_WaitForRequest;
	                                    IF #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode2Source := #c000_WaitForRequest;
	                                    END_IF;
	                                    
	                            END_CASE;
	                        END_REGION
	                        
	                    #c4Interrupt:
	                        
	                        REGION Interrupt gesteuert
	                            
	                            REGION Interrupt Mapping
	                                IF #udt_InterruptParameter.n_InterruptSource = #cSource1
	                                THEN
	                                    #udt_InterruptSourceReq := #udtIn_Source1Req;
	                                ELSIF #udt_InterruptParameter.n_InterruptSource = #cSource2
	                                THEN
	                                    #udt_InterruptSourceReq := #udtIn_Source2Req;
	                              (*  ELSE
	                                    Error *)
	                                END_IF;  
	                                    
	                                
	                                
	                            END_REGION
	                            
	                            CASE #n_InterruptMode2Source OF
	                                #c000_WaitForRequest:
	                                    //Action
	                                    #n_TimedMode2Source := 0;
	                                    #n_QuantityMode2Source := 0;
	                                    #n_TraficLightMode2Source := 0;
	                                    #udt_MainSourceResp.xReleaseOk := True;
	                                    #udt_InterruptSourceREsp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    IF #udt_InterruptSourceReq.xTransportReq
	                                        AND NOT #udt_InterruptSourceReq.stJamExit.Status.bByte.%X2
	                                        AND #udt_InterruptSourceReq.stJamExit.Status.nCount < #udt_InterruptSourceReq.stJamExit.Config.nCapacitySet
	                                        AND #udt_InterruptSourceReq.stJamExit.Status.nCount < #udt_InterruptSourceReq.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #n_InterruptMode2Source := #c010_WaitPathClear;
	                                        
	                                        
	                                    END_IF;
	                                    
	                                #c010_WaitPathClear:
	                                    //Action
	                                    #udt_MainSourceResp.xReleaseOk := FALSE;
	                                    
	                                    //Transition
	                                    IF #ton_InterruptDelay.Q
	                                    THEN
	                                        #n_InterruptMode2Source := #c020_SetReleaseSourceInterrupt;
	                                    END_IF;
	                                    
	                                #c020_SetReleaseSourceInterrupt:
	                                    //Action
	                                    IF NOT #udt_InterruptSourceReq.stJamExit.Status.bByte.%X2
	                                        AND #udt_InterruptSourceReq.stJamExit.Status.nCount < #udt_InterruptSourceReq.stJamExit.Config.nCapacitySet
	                                        AND #udt_InterruptSourceReq.stJamExit.Status.nCount < #udt_InterruptSourceReq.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        
	                                        #udt_InterruptSourceREsp.xReleaseOk := True;
	                                    ELSE
	                                        #udt_InterruptSourceREsp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseInterrupt.Q AND NOT #udt_InterruptSourceReq.xTransportReq
	                                        OR #ton_InterruptMaxDuration.Q
	                                    THEN
	                                        #n_InterruptMode2Source := #c025_Reset;
	                                    END_IF;
	                                    
	                                #c025_Reset:
	                                    //Action
	                                    #udt_InterruptSourceREsp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    #n_InterruptMode2Source := #c000_WaitForRequest;
	                                    
	                                    
	                                    ;
	                            END_CASE;
	                            
	                            REGION Output Mapping
	                                
	                                IF #udt_InterruptParameter.n_InterruptSource = #cSource1
	                                THEN
	                                    #udtOut_Source1Resp := #udt_InterruptSourceREsp;
	                                    #udtOut_Source2Resp := #udt_MainSourceResp;
	                                ELSIF #udt_InterruptParameter.n_InterruptSource = #cSource2
	                                THEN
	                                    #udtOut_Source2Resp := #udt_InterruptSourceREsp;
	                                    #udtOut_Source1Resp := #udt_MainSourceResp;
	                                END_IF;
	                                
	                            END_REGION
	                            
	                            
	                        END_REGION
	                        
	                        
	                        
	                END_CASE;
	                ;
	                
	            END_REGION
	        #c3Sources:
	            REGION 3 Sources
	                CASE #udt_PrioParameter.nPrioMode OF
	                    #c1ZeitGesteuert:
	                        REGION Zeit gesteuert
	                            CASE #n_TimedMode3Source OF
	                                #c000_WaitForRequest:
	                                    //Action
	                                    //Zurücksetzen der nicht aktiven Sequenzen der anderen Modi
	                                    #n_QuantityMode3Source := 0;
	                                    #n_TraficLightMode3Source := 0;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TimedMode3Source := #c010_SetReleaseSource1;
	                                    ELSIF #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TimedMode3Source := #c020_SetReleaseSource2;
	                                    ELSIF #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TimedMode3Source := #c030_SetReleaseSource3;
	                                    ELSIF #arrx_SourcePrio[1]
	                                    THEN
	                                        #n_TimedMode3Source := #c010_SetReleaseSource1;
	                                    ELSIF #arrx_SourcePrio[2]
	                                    THEN
	                                        #n_TimedMode3Source := #c020_SetReleaseSource2;
	                                    ELSIF #arrx_SourcePrio[3]
	                                    THEN
	                                        #n_TimedMode3Source := #c030_SetReleaseSource3;
	                                    END_IF;
	                                    
	                                #c010_SetReleaseSource1:
	                                    //Action
	                                    IF NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source1Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source1Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource1.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[1])
	                                    THEN
	                                        #n_TimedMode3Source := #c015_Reset;
	                                    END_IF;
	                                    
	                                #c015_Reset:
	                                    //Action
	                                    #udtOut_Source1Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                   // IF (#xInClearJam AND #udtIn_Source1Req.stJamExit.Status.nCount = 0) OR NOT #xInClearJam THEN
	                                        IF NOT #udtIn_Source2Req.xTransportReq
	                                            AND (#udtIn_Source1Req.xTransportReq        //Prüfen ob die gleiche Quelle weiter transportieren darf oder andere Quellen warten
	                                            AND NOT #udtIn_Source2Req.xTransportReq
	                                            AND NOT #udtIn_Source3Req.xTransportReq)
	                                            OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                        THEN
	                                            #n_TimedMode3Source := #c000_WaitForRequest;
	                                        ELSIF #udtIn_Source2Req.xTransportReq AND #ton_runtime.Q AND ((#xInClearJam AND #udtIn_Source1Req.stJamExit.Status.nCount = 0) OR NOT #xInClearJam)          // nächste Quelle in der Reihe darf transportieren 
	                                        THEN
	                                            #n_TimedMode3Source := #c020_SetReleaseSource2;
	                                        ELSIF(* NOT #udtIn_Source1Req.xTransportReq       // übernächste Quelle darf transportieren
	                                            AND NOT #udtIn_Source2Req.xTransportReq 
	                                            AND*) #udtIn_Source3Req.xTransportReq
	                                            AND #ton_runtime.Q AND ((#xInClearJam AND #udtIn_Source1Req.stJamExit.Status.nCount = 0) OR NOT #xInClearJam)
	                                        THEN
	                                            #n_TimedMode3Source := #c030_SetReleaseSource3;
	                                        END_IF;
	                               //     END_IF;
	                                    
	                                #c020_SetReleaseSource2:
	                                    //Action
	                                    IF NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source2Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source2Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource2.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[2])
	                                    THEN
	                                        #n_TimedMode3Source := #c025_Reset;
	                                    END_IF;
	                                    
	                                #c025_Reset:
	                                    //Action
	                                    #udtOut_Source2Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                  //  IF (#xInClearJam AND #udtIn_Source2Req.stJamExit.Status.nCount = 0) OR NOT #xInClearJam THEN
	                                        IF NOT #udtIn_Source3Req.xTransportReq
	                                            AND (#udtIn_Source2Req.xTransportReq            //Prüfen ob die gleiche Quelle weitet transportieren darf oder andere Quellen warten
	                                            AND NOT #udtIn_Source1Req.xTransportReq
	                                            AND NOT #udtIn_Source3Req.xTransportReq)
	                                            OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                        THEN
	                                            #n_TimedMode3Source := #c000_WaitForRequest;
	                                        ELSIF #udtIn_Source3Req.xTransportReq AND #ton_runtime.Q AND ((#xInClearJam AND #udtIn_Source1Req.stJamExit.Status.nCount = 0) OR NOT #xInClearJam)             // nächste Quelle in der Reihe darf transportieren 
	                                        THEN
	                                            #n_TimedMode3Source := #c030_SetReleaseSource3;
	                                        ELSIF #udtIn_Source1Req.xTransportReq AND #ton_runtime.Q               // übernächste Quelle darf transportieren
	                                           (* AND NOT #udtIn_Source2Req.xTransportReq
	                                            AND NOT #udtIn_Source3Req.xTransportReq*)
	                                            AND ((#xInClearJam AND #udtIn_Source1Req.stJamExit.Status.nCount = 0) OR NOT #xInClearJam)
	                                        THEN
	                                            #n_TimedMode3Source := #c010_SetReleaseSource1;
	                                        END_IF;
	                                //    END_IF;
	                                    
	                                #c030_SetReleaseSource3:
	                                    //Action
	                                    IF NOT #udtIn_Source3Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source3Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source3Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource3.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[3])
	                                    THEN
	                                        #n_TimedMode3Source := #c035_Reset;
	                                    END_IF;
	                                    
	                                #c035_Reset:
	                                 
	                                    
	                                  
	                                    //**************************************************************
	                                    //Action
	                                    #udtOut_Source3Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                 //   IF (#xInClearJam AND #udtIn_Source3Req.stJamExit.Status.nCount = 0) OR NOT #xInClearJam THEN
	                                        IF NOT #udtIn_Source1Req.xTransportReq
	                                            AND (#udtIn_Source3Req.xTransportReq            //Prüfen ob die gleiche Quelle weitet transportieren darf oder andere Quellen warten
	                                            AND NOT #udtIn_Source2Req.xTransportReq
	                                            AND NOT #udtIn_Source1Req.xTransportReq)
	                                            OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                        THEN
	                                            #n_TimedMode3Source := #c000_WaitForRequest;
	                                        ELSIF #udtIn_Source1Req.xTransportReq AND #ton_runtime.Q AND ((#xInClearJam AND #udtIn_Source1Req.stJamExit.Status.nCount = 0) OR NOT #xInClearJam)             // nächste Quelle in der Reihe darf transportieren 
	                                        THEN
	                                            #n_TimedMode3Source := #c010_SetReleaseSource1;
	                                        ELSIF #udtIn_Source2Req.xTransportReq AND #ton_runtime.Q               // übernächste Quelle darf transportieren
	                                         //   AND NOT #udtIn_Source1Req.xTransportReq
	                                         //   AND NOT #udtIn_Source3Req.xTransportReq
	                                            AND ((#xInClearJam AND #udtIn_Source1Req.stJamExit.Status.nCount = 0) OR NOT #xInClearJam)
	                                        THEN
	                                            #n_TimedMode3Source := #c020_SetReleaseSource2;
	                                        END_IF;
	                                //    END_IF;
	                                    
	                            END_CASE;
	                        END_REGION
	                    #c2MengenGesteuert:
	                        REGION Mengen gesteuert
	                            CASE #n_QuantityMode3Source OF
	                                #c000_WaitForRequest:
	                                    //Action
	                                    //
	                                    
	                                    //Transition
	                                    IF #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode3Source := #c010_SetReleaseSource1;
	                                    ELSIF #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode3Source := #c020_SetReleaseSource2;
	                                    ELSIF #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode3Source := #c030_SetReleaseSource3;
	                                    ELSIF #arrx_SourcePrio[1]
	                                    THEN
	                                        #n_QuantityMode3Source := #c010_SetReleaseSource1;
	                                    ELSIF #arrx_SourcePrio[2]
	                                    THEN
	                                        #n_QuantityMode3Source := #c020_SetReleaseSource2;
	                                    ELSIF #arrx_SourcePrio[3]
	                                    THEN
	                                        #n_QuantityMode3Source := #c030_SetReleaseSource3;
	                                        
	                                    END_IF;
	                                    
	                                #c010_SetReleaseSource1:
	                                    //Action
	                                    IF NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source1Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source1Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source1Req.xTrolleyPresent
	                                    THEN
	                                        #n_QuantityMode3Source := #c011_Countup;
	                                    ELSIF #ton_WatchdogQuantity.Q
	                                    THEN
	                                        #n_QuantityMode3Source := #c015_Reset;
	                                    END_IF;
	                                    
	                                #c011_Countup:
	                                    //Action
	                                    #n_CounterSource1 += 1;
	                                    
	                                    //Transition
	                                    #n_QuantityMode3Source := #c012_WaitShuttleGone;
	                                    
	                                #c012_WaitShuttleGone:
	                                    //Action
	                                    //
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source1Req.xTrolleyPresent
	                                        AND #n_CounterSource1 < #nIn_SwitchAmountSoruce1
	                                    THEN
	                                        #n_QuantityMode3Source := #c010_SetReleaseSource1;
	                                    ELSIF NOT #udtIn_Source1Req.xTrolleyPresent
	                                        AND #n_CounterSource1 >= #nIn_SwitchAmountSoruce1
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[1])
	                                    THEN
	                                        #n_QuantityMode3Source := #c015_Reset;
	                                    END_IF;
	                                    
	                                #c015_Reset:
	                                    //Action
	                                    #udtOut_Source1Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source2Req.xTransportReq
	                                        AND (#udtIn_Source1Req.xTransportReq                //Prüfen ob die gleiche Quelle weitet transportieren darf oder andere Quellen warten
	                                        AND NOT #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq)
	                                    THEN
	                                        #n_QuantityMode3Source := #c000_WaitForRequest;
	                                    ELSIF #udtIn_Source2Req.xTransportReq                   // nächste Quelle in der Reihe darf transportieren
	                                    THEN
	                                        #n_QuantityMode3Source := #c020_SetReleaseSource2;
	                                    ELSIF NOT #udtIn_Source1Req.xTransportReq               // übernächste Quelle darf transportieren
	                                        AND NOT #udtIn_Source2Req.xTransportReq
	                                        AND #udtIn_Source3Req.xTransportReq
	                                    THEN
	                                        #n_QuantityMode3Source := #c030_SetReleaseSource3;
	                                    END_IF;
	                                    
	                                #c020_SetReleaseSource2:
	                                    //Action
	                                    IF NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source3Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source3Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source2Req.xTrolleyPresent
	                                    THEN
	                                        #n_QuantityMode3Source := #c021_Countup;
	                                    ELSIF #ton_WatchdogQuantity.Q
	                                    THEN
	                                        #n_QuantityMode3Source := #c025_Reset;
	                                    END_IF;
	                                    
	                                #c021_Countup:
	                                    //Action
	                                    #n_CounterSource2 += 1;
	                                    
	                                    //Transition
	                                    #n_QuantityMode3Source := #c022_WaitShuttleGone;
	                                    
	                                #c022_WaitShuttleGone:
	                                    //Action
	                                    //
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source2Req.xTrolleyPresent
	                                        AND #n_CounterSource2 < #nIn_SwitchAmountSoruce2
	                                    THEN
	                                        #n_QuantityMode3Source := #c020_SetReleaseSource2;
	                                    ELSIF NOT #udtIn_Source2Req.xTrolleyPresent
	                                        AND #n_CounterSource2 >= #nIn_SwitchAmountSoruce2
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[2])
	                                    THEN
	                                        #n_QuantityMode3Source := #c025_Reset;
	                                    END_IF;
	                                    
	                                #c025_Reset:
	                                    //Action
	                                    #udtOut_Source3Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source3Req.xTransportReq
	                                        AND (#udtIn_Source2Req.xTransportReq                   //Prüfen ob die gleiche Quelle weitet transportieren darf oder andere Quellen warten  
	                                        AND NOT #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq)
	                                    THEN
	                                        #n_QuantityMode3Source := #c000_WaitForRequest;
	                                    ELSIF #udtIn_Source3Req.xTransportReq                       // nächste Quelle in der Reihe darf transportieren
	                                    THEN
	                                        #n_QuantityMode3Source := #c030_SetReleaseSource3;
	                                    ELSIF #udtIn_Source1Req.xTransportReq                       // übernächste Quelle darf transportieren
	                                        AND NOT #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq
	                                    THEN
	                                        #n_QuantityMode3Source := #c010_SetReleaseSource1;
	                                    END_IF;
	                                    
	                                #c030_SetReleaseSource3:
	                                    //Action
	                                    IF NOT #udtIn_Source3Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source3Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source3Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source3Req.xTrolleyPresent
	                                    THEN
	                                        #n_QuantityMode3Source := #c031_Countup;
	                                    ELSIF #ton_WatchdogQuantity.Q
	                                    THEN
	                                        #n_QuantityMode3Source := #c035_Reset;
	                                    END_IF;
	                                    
	                                #c031_Countup:
	                                    //Action
	                                    #n_CounterSource3 += 1;
	                                    
	                                    //Transition
	                                    #n_QuantityMode3Source := #c032_WaitShuttleGone;
	                                    
	                                #c032_WaitShuttleGone:
	                                    //Action
	                                    //
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source3Req.xTrolleyPresent
	                                        AND #n_CounterSource3 < #nIn_SwitchAmountSoruce3
	                                    THEN
	                                        #n_QuantityMode3Source := #c030_SetReleaseSource3;
	                                    ELSIF NOT #udtIn_Source3Req.xTrolleyPresent
	                                        AND #n_CounterSource3 >= #nIn_SwitchAmountSoruce3
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[3])
	                                    THEN
	                                        #n_QuantityMode3Source := #c035_Reset;
	                                    END_IF;
	                                    
	                                #c035_Reset:
	                                    //Action
	                                    #udtOut_Source3Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    
	                                    #n_QuantityMode3Source := #c000_WaitForRequest;
	                                    
	                                    
	                            END_CASE;
	                        END_REGION
	                    #c3PrioAmpel:
	                        REGION Ampel gesteuert
	                            CASE #n_TraficLightMode3Source OF
	                                #c000_WaitForRequest:
	                                    //Action
	                                    //
	                                    
	                                    //Transition
	                                    IF #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode3Source := #c010_SetReleaseSource1;
	                                    ELSIF #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode3Source := #c020_SetReleaseSource2;
	                                    ELSIF #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode3Source := #c030_SetReleaseSource3;
	                                    ELSIF #arrx_SourcePrio[1]
	                                    THEN
	                                        #n_TraficLightMode3Source := #c010_SetReleaseSource1;
	                                    ELSIF #arrx_SourcePrio[2]
	                                    THEN
	                                        #n_TraficLightMode3Source := #c020_SetReleaseSource2;
	                                    ELSIF #arrx_SourcePrio[3]
	                                    THEN
	                                        #n_TraficLightMode3Source := #c030_SetReleaseSource3;
	                                    END_IF;
	                                    
	                                #c010_SetReleaseSource1:
	                                    //Action
	                                    IF NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source1Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source1Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource1.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[1])
	                                    THEN
	                                        #n_TraficLightMode3Source := #c015_Reset;
	                                    END_IF;
	                                    
	                                #c015_Reset:
	                                    //Action
	                                    #udtOut_Source1Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    #n_TraficLightMode3Source := #c020_SetReleaseSource2;
	                                    IF #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode3Source := #c000_WaitForRequest;
	                                    END_IF;
	                                    
	                                #c020_SetReleaseSource2:
	                                    //Action
	                                    IF NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source3Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source3Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource2.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[2])
	                                    THEN
	                                        #n_TraficLightMode3Source := #c025_Reset;
	                                    END_IF;
	                                    
	                                #c025_Reset:
	                                    //Action
	                                    #udtOut_Source3Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    #n_TraficLightMode3Source := #c030_SetReleaseSource3;
	                                    IF #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode3Source := #c000_WaitForRequest;
	                                    END_IF;
	                                    
	                                    
	                                #c030_SetReleaseSource3:
	                                    //Action
	                                    IF NOT #udtIn_Source3Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source3Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source3Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource3.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[3])
	                                    THEN
	                                        #n_TraficLightMode3Source := #c035_Reset;
	                                    END_IF;
	                                    
	                                #c035_Reset:
	                                    //Action
	                                    #udtOut_Source3Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    
	                                    #n_TraficLightMode3Source := #c000_WaitForRequest;
	                                    IF #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode3Source := #c000_WaitForRequest;
	                                    END_IF;
	                                    
	                                    
	                            END_CASE;
	                            
	                            
	                        END_REGION
	                        
	                        
	                        
	                END_CASE;
	                ;
	            END_REGION
	        #c4Sources:
	            REGION 4 Sources
	                CASE #udt_PrioParameter.nPrioMode OF
	                    #c1ZeitGesteuert:
	                        REGION Zeit gesteuert
	                            CASE #n_TimedMode4Source OF
	                                #c000_WaitForRequest:
	                                    //Action
	                                    //
	                                    
	                                    //Transition
	                                    IF #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TimedMode4Source := #c010_SetReleaseSource1;
	                                        
	                                    ELSIF #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TimedMode4Source := #c020_SetReleaseSource2;
	                                        
	                                    ELSIF #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TimedMode4Source := #c030_SetReleaseSource3;
	                                        
	                                    ELSIF #udtIn_Source4Req.xTransportReq
	                                        AND NOT #udtIn_Source4Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source4Req.stJamExit.Status.nCount < #udtIn_Source4Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source4Req.stJamExit.Status.nCount < #udtIn_Source4Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TimedMode4Source := #c040_SetReleaseSource4;
	                                        
	                                    ELSIF #arrx_SourcePrio[1]
	                                    THEN
	                                        #n_TimedMode4Source := #c010_SetReleaseSource1;
	                                    ELSIF #arrx_SourcePrio[2]
	                                    THEN
	                                        #n_TimedMode4Source := #c020_SetReleaseSource2;
	                                    ELSIF #arrx_SourcePrio[3]
	                                    THEN
	                                        #n_TimedMode4Source := #c030_SetReleaseSource3;
	                                    ELSIF #arrx_SourcePrio[4]
	                                    THEN
	                                        #n_TimedMode4Source := #c040_SetReleaseSource4;
	                                        
	                                    END_IF;
	                                    
	                                #c010_SetReleaseSource1:
	                                    //Action
	                                    IF NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source1Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source1Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource1.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[1])
	                                    THEN
	                                        #n_TimedMode4Source := #c015_Reset;
	                                    END_IF;
	                                    
	                                #c015_Reset:
	                                    //Action
	                                    #udtOut_Source1Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source2Req.xTransportReq
	                                        AND (#udtIn_Source1Req.xTransportReq                    //Prüfen ob die gleiche Quelle weitet transportieren darf oder andere Quellen warten  
	                                        AND NOT #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source4Req.xTransportReq)
	                                        OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TimedMode4Source := #c000_WaitForRequest;
	                                    ELSIF #udtIn_Source2Req.xTransportReq                       // nächste Quelle in der Reihe darf transportieren
	                                    THEN
	                                        #n_TimedMode4Source := #c020_SetReleaseSource2;
	                                    ELSIF NOT #udtIn_Source2Req.xTransportReq                   // übernächste Quelle darf transportieren
	                                        AND #udtIn_Source3Req.xTransportReq
	                                    THEN
	                                        #n_TimedMode4Source := #c030_SetReleaseSource3;
	                                        
	                                    ELSIF NOT #udtIn_Source1Req.xTransportReq                   // letzte Quelle darf transportieren
	                                        AND NOT #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq
	                                        AND #udtIn_Source4Req.xTransportReq
	                                    THEN
	                                        #n_TimedMode4Source := #c040_SetReleaseSource4;
	                                        
	                                    END_IF;
	                                    
	                                #c020_SetReleaseSource2:
	                                    //Action
	                                    IF NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source2Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source2Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource2.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[2])
	                                    THEN
	                                        #n_TimedMode4Source := #c025_Reset;
	                                    END_IF;
	                                    
	                                #c025_Reset:
	                                    //Action
	                                    #udtOut_Source2Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source3Req.xTransportReq
	                                        AND (#udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source4Req.xTransportReq)
	                                        OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TimedMode4Source := #c000_WaitForRequest;
	                                    ELSIF #udtIn_Source3Req.xTransportReq
	                                    THEN
	                                        #n_TimedMode4Source := #c030_SetReleaseSource3;
	                                    ELSIF #udtIn_Source4Req.xTransportReq
	                                        AND NOT #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq
	                                    THEN
	                                        #n_TimedMode4Source := #c040_SetReleaseSource4;
	                                        
	                                    ELSIF #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source4Req.xTransportReq
	                                    THEN
	                                        #n_TimedMode4Source := #c010_SetReleaseSource1;
	                                    END_IF;
	                                    
	                                #c030_SetReleaseSource3:
	                                    //Action
	                                    IF NOT #udtIn_Source3Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source3Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source3Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource3.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[3])
	                                    THEN
	                                        #n_TimedMode4Source := #c035_Reset;
	                                    END_IF;
	                                    
	                                #c035_Reset:
	                                    //Action
	                                    #udtOut_Source3Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source4Req.xTransportReq
	                                        AND (#udtIn_Source3Req.xTransportReq                    //Prüfen ob die gleiche Quelle weitet transportieren darf oder andere Quellen warten
	                                        AND NOT #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source2Req.xTransportReq)
	                                        OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TimedMode4Source := #c000_WaitForRequest;
	                                    ELSIF #udtIn_Source4Req.xTransportReq                       // nächste Quelle in der Reihe darf transportieren
	                                    THEN
	                                        #n_TimedMode4Source := #c040_SetReleaseSource4;
	                                    ELSIF #udtIn_Source2Req.xTransportReq                       // übernächste Quelle darf transportieren
	                                        AND NOT #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source4Req.xTransportReq
	                                    THEN
	                                        #n_TimedMode4Source := #c020_SetReleaseSource2;
	                                        
	                                    ELSIF #udtIn_Source1Req.xTransportReq                       // letzte Quelle darf transportieren
	                                        AND NOT #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source4Req.xTransportReq
	                                    THEN
	                                        #n_TimedMode4Source := #c010_SetReleaseSource1;
	                                    END_IF;
	                                    
	                                #c040_SetReleaseSource4:
	                                    //Action
	                                    IF NOT #udtIn_Source4Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source4Req.stJamExit.Status.nCount < #udtIn_Source4Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source4Req.stJamExit.Status.nCount < #udtIn_Source4Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source4Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source4Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource4.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[4])
	                                    THEN
	                                        #n_TimedMode4Source := #c035_Reset;
	                                    END_IF;
	                                    
	                                #c045_Reset:
	                                    //Action
	                                    #udtOut_Source4Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    
	                                    #n_TimedMode4Source := #c000_WaitForRequest;
	                                    
	                                    
	                            END_CASE;
	                        END_REGION
	                    #c2MengenGesteuert:
	                        REGION Mengen Gesteuert
	                            
	                            CASE #n_QuantityMode4Source OF
	                                #c000_WaitForRequest:
	                                    //Action
	                                    
	                                    
	                                    //Transition
	                                    IF #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode4Source := #c010_SetReleaseSource1;
	                                        
	                                    ELSIF #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode4Source := #c020_SetReleaseSource2;
	                                        
	                                    ELSIF #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode4Source := #c030_SetReleaseSource3;
	                                        
	                                    ELSIF #udtIn_Source4Req.xTransportReq
	                                        AND NOT #udtIn_Source4Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source4Req.stJamExit.Status.nCount < #udtIn_Source4Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source4Req.stJamExit.Status.nCount < #udtIn_Source4Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode4Source := #c040_SetReleaseSource4;
	                                    ELSIF #arrx_SourcePrio[1]
	                                    THEN
	                                        #n_QuantityMode4Source := #c010_SetReleaseSource1;
	                                    ELSIF #arrx_SourcePrio[2]
	                                    THEN
	                                        #n_QuantityMode4Source := #c020_SetReleaseSource2;
	                                    ELSIF #arrx_SourcePrio[3]
	                                    THEN
	                                        #n_QuantityMode4Source := #c030_SetReleaseSource3;
	                                    ELSIF #arrx_SourcePrio[4]
	                                    THEN
	                                        #n_QuantityMode4Source := #c040_SetReleaseSource4;
	                                    END_IF;
	                                    
	                                #c010_SetReleaseSource1:
	                                    //Action
	                                    IF NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source1Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source1Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source1Req.xTrolleyPresent
	                                    THEN
	                                        #n_QuantityMode4Source := #c011_Countup;
	                                    ELSIF #ton_WatchdogQuantity.Q
	                                    THEN
	                                        #n_QuantityMode4Source := #c015_Reset;
	                                    END_IF;
	                                    
	                                #c011_Countup:
	                                    //Action
	                                    #n_CounterSource1 += 1;
	                                    
	                                    //Transition
	                                    #n_QuantityMode4Source := #c012_WaitShuttleGone;
	                                    
	                                #c012_WaitShuttleGone:
	                                    //Action
	                                    //
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source1Req.xTrolleyPresent
	                                        AND #n_CounterSource1 < #nIn_SwitchAmountSoruce1
	                                    THEN
	                                        #n_QuantityMode4Source := #c010_SetReleaseSource1;
	                                    ELSIF NOT #udtIn_Source1Req.xTrolleyPresent
	                                        AND #n_CounterSource1 >= #nIn_SwitchAmountSoruce1
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[1])
	                                    THEN
	                                        #n_QuantityMode4Source := #c015_Reset;
	                                    END_IF;
	                                    
	                                #c015_Reset:
	                                    //Action
	                                    #udtOut_Source1Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source2Req.xTransportReq
	                                        AND (#udtIn_Source1Req.xTransportReq                        //Prüfen ob die gleiche Quelle weitet transportieren darf oder andere Quellen warten
	                                        AND NOT #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source4Req.xTransportReq)
	                                        OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode4Source := #c000_WaitForRequest;
	                                    ELSIF #udtIn_Source2Req.xTransportReq                           // nächste Quelle in der Reihe darf transportieren
	                                    THEN
	                                        #n_QuantityMode4Source := #c020_SetReleaseSource2;
	                                    ELSIF NOT #udtIn_Source2Req.xTransportReq                       // übernächste Quelle darf transportieren
	                                        AND #udtIn_Source3Req.xTransportReq
	                                    THEN
	                                        #n_QuantityMode4Source := #c030_SetReleaseSource3;
	                                        
	                                    ELSIF NOT #udtIn_Source1Req.xTransportReq                       // letzte Quelle darf transportieren
	                                        AND NOT #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq
	                                        AND #udtIn_Source4Req.xTransportReq
	                                    THEN
	                                        #n_QuantityMode4Source := #c040_SetReleaseSource4;
	                                        
	                                    END_IF;
	                                    
	                                #c020_SetReleaseSource2:
	                                    //Action
	                                    IF NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source2Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source2Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source2Req.xTrolleyPresent
	                                    THEN
	                                        #n_QuantityMode4Source := #c021_Countup;
	                                    ELSIF #ton_WatchdogQuantity.Q
	                                    THEN
	                                        #n_QuantityMode4Source := #c025_Reset;
	                                    END_IF;
	                                    
	                                #c021_Countup:
	                                    //Action
	                                    #n_CounterSource2 += 1;
	                                    
	                                    //Transition
	                                    #n_QuantityMode4Source := #c022_WaitShuttleGone;
	                                    
	                                #c022_WaitShuttleGone:
	                                    //Action
	                                    //
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source2Req.xTrolleyPresent
	                                        AND #n_CounterSource2 < #nIn_SwitchAmountSoruce2
	                                    THEN
	                                        #n_QuantityMode4Source := #c020_SetReleaseSource2;
	                                    ELSIF NOT #udtIn_Source2Req.xTrolleyPresent
	                                        AND #n_CounterSource2 >= #nIn_SwitchAmountSoruce2
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[2])
	                                    THEN
	                                        #n_QuantityMode4Source := #c025_Reset;
	                                    END_IF;
	                                    
	                                #c025_Reset:
	                                    //Action
	                                    #udtOut_Source2Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source3Req.xTransportReq
	                                        AND (#udtIn_Source2Req.xTransportReq                        //Prüfen ob die gleiche Quelle weitet transportieren darf oder andere Quellen warten
	                                        AND NOT #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source4Req.xTransportReq)
	                                        OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode4Source := #c000_WaitForRequest;
	                                    ELSIF #udtIn_Source3Req.xTransportReq                           // nächste Quelle in der Reihe darf transportieren
	                                    THEN
	                                        #n_QuantityMode4Source := #c030_SetReleaseSource3;
	                                    ELSIF #udtIn_Source4Req.xTransportReq                           // übernächste Quelle darf transportieren
	                                        AND NOT #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq
	                                    THEN
	                                        #n_QuantityMode4Source := #c040_SetReleaseSource4;
	                                        
	                                    ELSIF #udtIn_Source1Req.xTransportReq                           // letzte Quelle darf transportieren
	                                        AND NOT #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source4Req.xTransportReq
	                                    THEN
	                                        #n_QuantityMode4Source := #c010_SetReleaseSource1;
	                                    END_IF;
	                                    
	                                #c030_SetReleaseSource3:
	                                    //Action
	                                    IF NOT #udtIn_Source3Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source3Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source3Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #udtIn_Source3Req.xTrolleyPresent
	                                    THEN
	                                        #n_QuantityMode4Source := #c031_Countup;
	                                    ELSIF #ton_WatchdogQuantity.Q
	                                    THEN
	                                        #n_QuantityMode4Source := #c035_Reset;
	                                    END_IF;
	                                    
	                                #c031_Countup:
	                                    //Action
	                                    #n_CounterSource3 += 1;
	                                    
	                                    //Transition
	                                    #n_QuantityMode4Source := #c032_WaitShuttleGone;
	                                    
	                                #c032_WaitShuttleGone:
	                                    //Action
	                                    //
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source3Req.xTrolleyPresent
	                                        AND #n_CounterSource3 < #nIn_SwitchAmountSoruce3
	                                    THEN
	                                        #n_QuantityMode4Source := #c030_SetReleaseSource3;
	                                    ELSIF NOT #udtIn_Source3Req.xTrolleyPresent
	                                        AND #n_CounterSource3 >= #nIn_SwitchAmountSoruce3
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[3])
	                                    THEN
	                                        #n_QuantityMode4Source := #c035_Reset;
	                                    END_IF;
	                                    
	                                #c035_Reset:
	                                    //Action
	                                    #udtOut_Source3Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source4Req.xTransportReq
	                                        AND (#udtIn_Source3Req.xTransportReq                        //Prüfen ob die gleiche Quelle weitet transportieren darf oder andere Quellen warten
	                                        AND NOT #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source2Req.xTransportReq)
	                                        OR #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_QuantityMode4Source := #c000_WaitForRequest;
	                                    ELSIF #udtIn_Source4Req.xTransportReq                           // nächste Quelle in der Reihe darf transportieren
	                                    THEN
	                                        #n_QuantityMode4Source := #c040_SetReleaseSource4;
	                                    ELSIF #udtIn_Source2Req.xTransportReq                           // übernächste Quelle darf transportieren
	                                        AND NOT #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source4Req.xTransportReq
	                                    THEN
	                                        #n_QuantityMode4Source := #c020_SetReleaseSource2;
	                                        
	                                    ELSIF #udtIn_Source1Req.xTransportReq                           // letzte Quelle darf transportieren
	                                        AND NOT #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source4Req.xTransportReq
	                                    THEN
	                                        #n_QuantityMode4Source := #c010_SetReleaseSource1;
	                                    END_IF;
	                                    
	                                #c040_SetReleaseSource4:
	                                    //Action
	                                    IF NOT #udtIn_Source4Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source4Req.stJamExit.Status.nCount < #udtIn_Source4Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source4Req.stJamExit.Status.nCount < #udtIn_Source4Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source4Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source4Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    //Transition
	                                    IF #udtIn_Source4Req.xTrolleyPresent
	                                    THEN
	                                        #n_QuantityMode4Source := #c041_Countup;
	                                    ELSIF #ton_WatchdogQuantity.Q
	                                    THEN
	                                        #n_QuantityMode4Source := #c045_Reset;
	                                    END_IF;
	                                    
	                                #c041_Countup:
	                                    //Action
	                                    #n_CounterSource4 += 1;
	                                    
	                                    //Transition
	                                    #n_QuantityMode4Source := #c042_WaitShuttleGone;
	                                    
	                                #c042_WaitShuttleGone:
	                                    //Action
	                                    //
	                                    
	                                    //Transition
	                                    IF NOT #udtIn_Source4Req.xTrolleyPresent
	                                        AND #n_CounterSource4 < #nIn_SwitchAmountSoruce4
	                                    THEN
	                                        #n_QuantityMode4Source := #c040_SetReleaseSource4;
	                                    ELSIF NOT #udtIn_Source4Req.xTrolleyPresent
	                                        AND #n_CounterSource4 >= #nIn_SwitchAmountSoruce4
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[4])
	                                    THEN
	                                        #n_QuantityMode4Source := #c045_Reset;
	                                    END_IF;
	                                    
	                                #c045_Reset:
	                                    //Action
	                                    #udtOut_Source4Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    
	                                    #n_QuantityMode4Source := #c000_WaitForRequest;
	                                    
	                                    
	                            END_CASE;
	                        END_REGION
	                        
	                    #c3PrioAmpel:
	                        REGION Ampel gesteuert
	                            CASE #n_TraficLightMode4Source OF
	                                #c000_WaitForRequest:
	                                    //Action 
	                                    //
	                                    
	                                    //Transition
	                                    IF #udtIn_Source1Req.xTransportReq
	                                        AND NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode4Source := #c010_SetReleaseSource1;
	                                        
	                                    ELSIF #udtIn_Source2Req.xTransportReq
	                                        AND NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source2Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode4Source := #c020_SetReleaseSource2;
	                                        
	                                    ELSIF #udtIn_Source3Req.xTransportReq
	                                        AND NOT #udtIn_Source3Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode4Source := #c030_SetReleaseSource3;
	                                        
	                                    ELSIF #udtIn_Source4Req.xTransportReq
	                                        AND NOT #udtIn_Source4Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source4Req.stJamExit.Status.nCount < #udtIn_Source4Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source4Req.stJamExit.Status.nCount < #udtIn_Source4Req.stJamExit.Config.nCapacityMax
	                                        AND #arrx_SourcePrio = #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode4Source := #c040_SetReleaseSource4;
	                                        
	                                    ELSIF #arrx_SourcePrio[1]
	                                    THEN
	                                        #n_TraficLightMode4Source := #c010_SetReleaseSource1;
	                                    ELSIF #arrx_SourcePrio[2]
	                                    THEN
	                                        #n_TraficLightMode4Source := #c020_SetReleaseSource2;
	                                    ELSIF #arrx_SourcePrio[3]
	                                    THEN
	                                        #n_TraficLightMode4Source := #c030_SetReleaseSource3;
	                                    ELSIF #arrx_SourcePrio[4]
	                                    THEN
	                                        #n_TraficLightMode4Source := #c040_SetReleaseSource4;
	                                        
	                                    END_IF;
	                                    
	                                #c010_SetReleaseSource1:
	                                    //Action
	                                    IF NOT #udtIn_Source1Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source1Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source1Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source1Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource1.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[1])
	                                    THEN
	                                        #n_TraficLightMode4Source := #c015_Reset;
	                                    END_IF;
	                                    
	                                #c015_Reset:
	                                    //Action
	                                    #udtOut_Source1Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    #n_TraficLightMode4Source := #c020_SetReleaseSource2;
	                                    IF #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode4Source := #c000_WaitForRequest;
	                                    END_IF;
	                                    
	                                    
	                                #c020_SetReleaseSource2:
	                                    //Action
	                                    IF NOT #udtIn_Source2Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source2Req.stJamExit.Status.nCount < #udtIn_Source1Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source2Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source2Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource2.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[2])
	                                    THEN
	                                        #n_TraficLightMode4Source := #c025_Reset;
	                                    END_IF;
	                                    
	                                #c025_Reset:
	                                    //Action
	                                    #udtOut_Source2Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    #n_TraficLightMode4Source := #c030_SetReleaseSource3;
	                                    IF #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode4Source := #c000_WaitForRequest;
	                                    END_IF;
	                                    
	                                #c030_SetReleaseSource3:
	                                    //Action
	                                    IF NOT #udtIn_Source3Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source3Req.stJamExit.Status.nCount < #udtIn_Source3Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source3Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source3Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource3.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[3])
	                                    THEN
	                                        #n_TraficLightMode4Source := #c035_Reset;
	                                    END_IF;
	                                    
	                                #c035_Reset:
	                                    //Action
	                                    #udtOut_Source3Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    #n_TraficLightMode4Source := #c040_SetReleaseSource4;
	                                    IF #arrx_SourcePrio <> #arrx_SourcePrioClear
	                                    THEN
	                                        #n_TraficLightMode4Source := #c000_WaitForRequest;
	                                    END_IF;
	                                    
	                                #c040_SetReleaseSource4:
	                                    //Action
	                                    IF NOT #udtIn_Source4Req.stJamExit.Status.bByte.%X2
	                                        AND #udtIn_Source4Req.stJamExit.Status.nCount < #udtIn_Source4Req.stJamExit.Config.nCapacitySet
	                                        AND #udtIn_Source4Req.stJamExit.Status.nCount < #udtIn_Source4Req.stJamExit.Config.nCapacityMax
	                                    THEN
	                                        #udtOut_Source4Resp.xReleaseOk := True;
	                                    ELSE
	                                        #udtOut_Source4Resp.xReleaseOk := False;
	                                    END_IF;
	                                    
	                                    //Transition
	                                    IF #ton_ReleaseSource4.Q
	                                        OR (#arrx_SourcePrio <> #arrx_SourcePrioClear AND NOT #arrx_SourcePrio[4])
	                                    THEN
	                                        #n_TraficLightMode4Source := #c035_Reset;
	                                    END_IF;
	                                    
	                                #c045_Reset:
	                                    //Action
	                                    #udtOut_Source4Resp.xReleaseOk := False;
	                                    
	                                    //Transition
	                                    
	                                    #n_TraficLightMode4Source := #c000_WaitForRequest;
	                                    
	                                    
	                            END_CASE;
	                            
	                        END_REGION
	                        
	                        
	                        
	                END_CASE;
	                ;
	            END_REGION
	            
	    END_CASE;
	    
	    
	    
	    
	    
	END_REGION
	
	
	
	
	REGION Error Management
	    //Quit setzt Error Word zurück
	    IF #xInQuit
	    THEN
	        #xError := False;
	    END_IF;
	    
	    IF #xError AND #nErrorID = #c10ErrorNoSource
	    THEN
	        #wsErrorMessage := WSTRING#'Keine Quelle konfiguriert';
	        
	    END_IF;
	    
	    #PrgAlarm_Failmessage(SIG := #xError,
	                          TIMESTAMP := #tTempLocalTime,
	                          SD_1 := #wsIn_ObjectName,
	                          SD_2 := #wsErrorMessage);
	    
	    
	    
	END_REGION
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
END_FUNCTION_BLOCK

