FUNCTION_BLOCK "FB_StorageManagement"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      xInQuit : Bool;
      stIn_JamDataBlock1 : Struct
         stIn_JamData2101 : Struct
            udt_JamData2101_1 : "stJamData";
            udt_JamData2101_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2102 : Struct
            udt_JamData2102_1 : "stJamData";
            udt_JamData2102_2 : "stJamData";
            udt_JamData2102_3 : "stJamData";
            udt_JamData2102_4 : "stJamData";
            udt_JamData2102_5 : "stJamData";
         END_STRUCT;
         stIn_JamData2103 : Struct
            udt_JamData2103_1 : "stJamData";
            udt_JamData2103_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2104 : Struct
            udt_JamData2104_1 : "stJamData";
            udt_JamData2104_2 : "stJamData";
            udt_JamData2104_3 : "stJamData";
            udt_JamData2104_4 : "stJamData";
         END_STRUCT;
         stIn_JamData2105 : Struct
            udt_JamData2105_1 : "stJamData";
            udt_JamData2105_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2106 : Struct
            udt_JamData2106_1 : "stJamData";
            udt_JamData2106_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2107 : Struct
            udt_JamData2107_1 : "stJamData";
            udt_JamData2107_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2108 : Struct
            udt_JamData2108_1 : "stJamData";
            udt_JamData2108_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2109 : Struct
            stJam2109_1 : Struct
               arCarrier : Array[1.."cJam2109_1"] of "stCarrier";
               stData : "stJamData" := (((), ()), (3, 3));
            END_STRUCT;
            stJam2109_2 : Struct
               arCarrier : Array[1.."cJam2109_2"] of "stCarrier";
               stData : "stJamData" := (((), ()), (50, 50));
            END_STRUCT;
         END_STRUCT;
      END_STRUCT;
      stIn_JamDataBlock2 : Struct
         stIn_JamData2201 : Struct
            udt_JamData2201_1 : "stJamData";
            udt_JamData2201_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2202 : Struct
            udt_JamData2202_1 : "stJamData";
            udt_JamData2202_2 : "stJamData";
            udt_JamData2202_3 : "stJamData";
            udt_JamData2202_4 : "stJamData";
            udt_JamData2202_5 : "stJamData";
         END_STRUCT;
         stIn_JamData2203 : Struct
            udt_JamData2203_1 : "stJamData";
            udt_JamData2203_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2204 : Struct
            udt_JamData2204_1 : "stJamData";
            udt_JamData2204_2 : "stJamData";
            udt_JamData2204_3 : "stJamData";
            udt_JamData2204_4 : "stJamData";
         END_STRUCT;
         stIn_JamData2205 : Struct
            udt_JamData2205_1 : "stJamData";
            udt_JamData2205_2 : "stJamData";
            udt_JamData2205_3 : "stJamData";
         END_STRUCT;
         stIn_JamData2206 : Struct
            udt_JamData2206_1 : "stJamData";
            udt_JamData2206_2 : "stJamData";
            udt_JamData2206_3 : "stJamData";
         END_STRUCT;
         stIn_JamData2207 : Struct
            udt_JamData2207_1 : "stJamData";
            udt_JamData2207_2 : "stJamData";
            udt_JamData2207_3 : "stJamData";
         END_STRUCT;
         stIn_JamData2208 : Struct
            udt_JamData2208_1 : "stJamData";
            udt_JamData2208_2 : "stJamData";
            udt_JamData2208_3 : "stJamData";
         END_STRUCT;
         stIn_JamData2209 : Struct
            udt_JamData2209_1 : "stJamData";
            udt_JamData2209_2 : "stJamData";
         END_STRUCT;
      END_STRUCT;
      stIn_JamDataBlock3 : Struct
         stIn_JamData2301 : Struct
            udt_JamData2301_1 : "stJamData";
            udt_JamData2301_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2302 : Struct
            udt_JamData2302_1 : "stJamData";
            udt_JamData2302_2 : "stJamData";
            udt_JamData2302_3 : "stJamData";
            udt_JamData2302_4 : "stJamData";
         END_STRUCT;
         stIn_JamData2303 : Struct
            udt_JamData2303_1 : "stJamData";
            udt_JamData2303_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2304 : Struct
            udt_JamData2304_1 : "stJamData";
            udt_JamData2304_2 : "stJamData";
            udt_JamData2304_3 : "stJamData";
            udt_JamData2304_4 : "stJamData";
         END_STRUCT;
         stIn_JamData2305 : Struct
            udt_JamData2305_1 : "stJamData";
            udt_JamData2305_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2306 : Struct
            udt_JamData2306_1 : "stJamData";
            udt_JamData2306_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2307 : Struct
            udt_JamData2307_1 : "stJamData";
            udt_JamData2307_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2308 : Struct
            udt_JamData2308_1 : "stJamData";
            udt_JamData2308_2 : "stJamData";
         END_STRUCT;
         stIn_JamData2309 : Struct
            udt_JamData2309_1 : "stJamData";
            udt_JamData2309_2 : "stJamData";
         END_STRUCT;
      END_STRUCT;
      udtIn_DataMES : "UDT_Telegram_GOHDRespM";
      udtIn_Lv1StorageRelease : "udt_Lv1StorageRelease";
      nIn_StorageMode : USInt;   // 0 = uneven; 1= even
      wsIn_ObjectName : WString[50];
      xInCapacityConfigChanged : Bool;
   END_VAR

   VAR_IN_OUT 
      arrudt_InOutCarrierBuffer : Array[*] of "UDT_Telegram_GOHDRespM";
      arrudt_InOutJAM_Conv1_2 : Array[*] of "stCarrier";
      arrudt_InOutStorage211 : Array[1.."cNoLines"] of "stStorageLine";
      udt_InOutStorage211BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage212 : Array[1.."cNoLines"] of "stStorageLine";
      udt_InOutStorage212BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage213 : Array[1.."cNoLines"] of "stStorageLine";
      udt_InOutStorage213BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage214 : Array[1.."cNoLines"] of "stStorageLine";
      udt_InOutStorage214BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage221 : Array[1.."cNoLines"] of "stStorageLine";
      udt_InOutStorage221BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage222 : Array[1.."cNoLines"] of "stStorageLine";
      udt_InOutStorage222BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage223 : Array[1.."cNoLines"] of "stStorageLine";
      udt_InOutStorage223BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage224 : Array[1.."cNoLines"] of "stStorageLine";
      udt_InOutStorage224BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage231 : Array[1.."cNoLines"] of "stStorageLine";
      udt_InOutStorage231BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage232 : Array[1.."cNoLines"] of "stStorageLine";
      udt_InOutStorage232BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage233 : Array[1.."cNoLines"] of "stStorageLine";
      udt_InOutStorage233BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage234 : Array[1.."cNoLines"] of "stStorageLine";
      udt_InOutStorage234BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage111 : Array[1.."cNoLines"] of "stStorageData";
      udt_InOutStorage111BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage112 : Array[1.."cNoLines"] of "stStorageData";
      udt_InOutStorage112BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage113 : Array[1.."cNoLines"] of "stStorageData";
      udt_InOutStorage113BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage114 : Array[1.."cNoLines"] of "stStorageData";
      udt_InOutStorage114BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage121 : Array[1.."cNoLines"] of "stStorageData";
      udt_InOutStorage121BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage122 : Array[1.."cNoLines"] of "stStorageData";
      udt_InOutStorage122BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage123 : Array[1.."cNoLines"] of "stStorageData";
      udt_InOutStorage123BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage124 : Array[1.."cNoLines"] of "stStorageData";
      udt_InOutStorage124BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage131 : Array[1.."cNoLines"] of "stStorageData";
      udt_InOutStorage131BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage132 : Array[1.."cNoLines"] of "stStorageData";
      udt_InOutStorage132BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage133 : Array[1.."cNoLines"] of "stStorageData";
      udt_InOutStorage133BlockData : "UDT_StorageBlockData";
      arrudt_InOutStorage134 : Array[1.."cNoLines"] of "stStorageData";
      udt_InOutStorage134BlockData : "UDT_StorageBlockData";
      xInOutError : Bool;
      nInOutErrorID : USInt;
      udt_InOut_HandshakeDataMES : "udt_HandshakeMessageFromMES";
   END_VAR

   VAR 
      st_AreaDisabledLevel2 { S7_SetPoint := 'False'} : "udt_AreaDisabled";
      udt_DataMESSave { S7_SetPoint := 'False'} : "UDT_Payload_GOHDRespM";
      n_IDXSearchData { S7_SetPoint := 'True'} : USInt;
      n_UpperBound : USInt;
      n_UpperBoundBuffer : USInt;
      n_LowerBound : USInt;
      n_LowerBoundBuffer : USInt;
      n_FreierIndex : USInt;
      n_JamAreaIDX : USInt;
      xIDGefunden : Bool;
      xIDBereitsVorhanden : Bool;
      xIDHinzugefügt : Bool;
      xDSucheAbgeschlossen : Bool;
      xSucheStart : Bool;
      nIDWithoutDest : DInt;
      n_CarrierTyp : USInt;   // 0= undefiniert; 1= kurz; 2=lang; 3=Leer
      n_Block21IDX : USInt;
      n_Block22IDX : USInt;
      n_Block23IDX : USInt;
      n_Block11IDX : USInt;
      n_Block12IDX : USInt;
      n_Block13IDX : USInt;
      n_DatenBufferIDX : USInt;
      n_DatenJamArea : USInt;
      udt_CapacityStorage { S7_SetPoint := 'False'} : "udt_CapacityStorage";
      st_JamAreaCarrier : Struct
         st_Data { S7_SetPoint := 'False'} : "stCarrier";
         str_Type { S7_SetPoint := 'True'} : String;
      END_STRUCT;
      st_JamAreaCarrierClear : Struct
         st_Data { S7_SetPoint := 'False'} : "stCarrier";
         str_Type { S7_SetPoint := 'True'} : String;
      END_STRUCT;
      st_BufferClear { S7_SetPoint := 'False'} : "UDT_Telegram_GOHDRespM";
      xDestinationGranted : Bool;
      PrgAlarm_Failmessage {InstructionName := 'Program_Alarm'; LibVersion := '1.0'; S7_SetPoint := 'False'} : Program_Alarm;
      wsErrorMessage1 { S7_SetPoint := 'True'} : WString[50];
      wsErrorMessage2 : WString[50];
      wsErrorMessage3 : WString[50];
      n_StepBufferMES : Int;
      n_EmptyElementIDX : USInt;
      n_EmptyElementIDXSave : Int;
   END_VAR

   VAR_TEMP 
      nTempTransferDataIDX : USInt;
      nTempDeleteBufferData : USInt;
      nTempMinBefuellungBlock1 : USInt;
      nTempMinBefuellungBlock2 : USInt;
      nTempMinBefuellungBlock3 : USInt;
      nTempLinieIDX : USInt;
      nTempCalculateStorageCapacity : USInt;
      nTempRetVal : Int;
      tTempLocalTime {InstructionName := 'DTL'; LibVersion := '1.0'} : DTL;
   END_VAR

   VAR CONSTANT 
      cAreaEmpty : Byte := 16#1;
      cAreaOK : Byte;
      "~~~~~~~~~~~CarrierType~~~~~~~~~~~~~" : Byte;
      c000_undefinert : USInt;
      c001_CarrierKurz : USInt := 1;
      c002_CarrierLang : USInt := 2;
      c003_CarrierLeer : USInt := 3;
      "~~~~~~~~~~~StorageMode~~~~~~~~~~~~~" : USInt;
      c000_uneven : USInt;
      c001_even : USInt := 1;
      "~~~~~~~~~~~ErrorID~~~~~~~~~~~~~" : USInt;
      c000_KeinFehler : USInt;
      c010_CarrierDatenFehlerhaft : USInt := 10;
      c020_KeinZielVerfuegbar : USInt := 20;
      "~~~~~~~~BufferSequence~~~~~~~~" : Int;
      c000_Wait : Int;
      c010_NewData : Int := 10;
      c020_SearchEmptyElement : Int := 20;
      c030_Finish : Int := 30;
      c040_Reset : Int := 40;
   END_VAR


BEGIN
	
	REGION Info
	(* Company: Schönenberger Systeme GmbH / (C) Copyright (2022). All rights reserved.
	-----------------------------------------------------------------------------------------
	Title: FB_StorageManagement
	Comment/Function: manages storage in to the individual storage areas
	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-18 | -                  |                  | Header added on 18.03.2025
	                                                                   
	*)
	END_REGION
	
	REGION TODO
	    (*
	    - *DONE*  Carrier Leer Verteilung / Config Byte (Linie für volle Carrier / Linie für leere Carrier) *DONE*
	    - *DONE* Signale von Ebene 1 / Carrier zu Ebene 1 schicken *DONE*
	    - HMI Anbindung
	    - *DONE* Korrektur capacity Storage, Menge muss vor erneuter Auswertung auf 0 gesetzt werden *DONE*
	    - *DONE* Übertragen des Shuttle Typs in die Destination Auswertung überprüfen, Abfrage "loaded" mit einbinden *DONE*
	    Fill up Buffer
	    - MES Handshake erforderlich
	    - #xSucheStart beschreiben
	    - SucheAbgeschlossen für Handshake verwenden
	    
	    //Linien config
	    // X2 = Linie für volle Carrier; X3 = Linie für leere Carrier; X4 = Linie für leere und volle Carrier
	    
	    *)
	    
	    REGION Verwaltung Ideen/Brainstorm
	        
	        //Regel: Lang darf nur in 2.1 und 2.2 -> bereits berücksichtigt
	        //Regel: Kurz darf nur in 2.3, 1.1, 1.2, 1.3 -> bereits berücksichtigt
	        //Leercarrier darf theoretisch überall hin -> aktuell nur 1.3 vorbereitet
	        //möglichst alles sortenrein -> wird berücksichtigt
	        //Für Leercarrier
	        //  - erst Platz in 2.3 suchen -> bereits berücksichtigt
	        //  - wenn 2.3 keine Linie mehr sortenrein frei für leercarrier hat
	        //      - dann suche irgendwo eine freie Linie und flage sie für leercarrier
	        //      -> ab sofort dürfen hier nur noch leercarrier hin, bis diese Linie z.B. wieder entleert ist, dann ist sie wieder frei für volle oder leere carrier -> TODO???
	        //      -> Hinweis: Die Linie muss leer sein und theoretisch, darf nichts zu dieser Linie unterwegs sein, eventuell müssen wir hier auch noch die Carrier auf dem Pinband berücksichtigen... 
	        //  - notfalls: leere und volle mischen -> TODO???
	        
	        
	        //Fortgeschrittene Strategiemöglichkeiten: Einlagern und Umlagern koordinieren
	        //z.B. Sektion 2.1
	        //  - Block 2.1.1 und 2.1.2 können Umlagern
	        //  - Block 2.1.3 und 2.1.4 können Einlagern
	        //     -> Umlagern und Einlagern behindert sich nicht gegenseitig, da die Eingangskreisel unabhängig arbeiten können
	        //     -> Umlagern und Einlagern immer so koordinieren, dass  jeder Block die Chance zum Umlagern bekommt, die andere Seite übernimmt in der Zwischenzeit das Einlagern
	        //     
	        //   - Beim Vergeben der Einlagerziele möglichst einen Block finden, der keine bis wenige angeforderte Carrier hat ("Kalter" Block)
	        //   - Blöcke bei denen viel angefordert ist als "Heißen" Block betrachten und möglichst nichts zum Einlagern schicken, da z.B. das Rotieren behindert wird
	    END_REGION
	    
	    
	    
	END_REGION
	
	REGION Local Time
	    
	    
	    // read local time for timestamp ------------------------------------------
	    #nTempRetVal := RD_LOC_T(#tTempLocalTime);
	    
	    
	END_REGION
	
	REGION check Array size
	    /// Conv
	    #n_LowerBound := DINT_TO_USINT(LOWER_BOUND(ARR := #arrudt_InOutJAM_Conv1_2, DIM := 1));
	    #n_UpperBound := DINT_TO_USINT(UPPER_BOUND(ARR := #arrudt_InOutJAM_Conv1_2, DIM := 1));
	    
	    //Buffer
	    #n_LowerBoundBuffer := DINT_TO_USINT(LOWER_BOUND(ARR := #arrudt_InOutCarrierBuffer, DIM := 1));
	    #n_UpperBoundBuffer := DINT_TO_USINT(UPPER_BOUND(ARR := #arrudt_InOutCarrierBuffer, DIM := 1));
	    
	END_REGION
	
	REGION calculate max storage size of Block x
	    // Lagergröße der Blöcke berechnen
	    IF true //"FirstScan" OR NOT #xInCapacityConfigChanged
	    THEN
	        FOR #nTempCalculateStorageCapacity := 1 TO 22 DO
	            IF #nTempCalculateStorageCapacity >= 1 AND #nTempCalculateStorageCapacity <= 21
	            THEN
	                IF #nTempCalculateStorageCapacity = 1
	                THEN
	                    #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage111 := 0;
	                    #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage112 := 0;
	                    #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage113 := 0;
	                    #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage114 := 0;
	                    #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage121 := 0;
	                    #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage122 := 0;
	                    #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage123 := 0;
	                    #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage124 := 0;
	                    #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage131 := 0;
	                    #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage132 := 0;
	                    #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage133 := 0;
	                    #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage134 := 0;
	                    #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage211 := 0;
	                    #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage212 := 0;
	                    #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage213 := 0;
	                    #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage214 := 0;
	                    #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage221 := 0;
	                    #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage222 := 0;
	                    #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage223 := 0;
	                    #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage224 := 0;
	                    #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage231 := 0;
	                    #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage232 := 0;
	                    #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage233 := 0;
	                    #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage234 := 0;
	                END_IF;
	                
	                    #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage111 := #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage111 + #arrudt_InOutStorage111[#nTempCalculateStorageCapacity].Config.nCapacitySet;
	                    
	                    #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage112 := #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage112 + #arrudt_InOutStorage112[#nTempCalculateStorageCapacity].Config.nCapacitySet;
	                    
	                    #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage113 := #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage113 + #arrudt_InOutStorage113[#nTempCalculateStorageCapacity].Config.nCapacitySet;
	                    
	                    #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage114 := #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage114 + #arrudt_InOutStorage114[#nTempCalculateStorageCapacity].Config.nCapacitySet;
	                    
	                    #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage121 := #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage121 + #arrudt_InOutStorage121[#nTempCalculateStorageCapacity].Config.nCapacitySet;
	                    
	                    #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage122 := #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage122 + #arrudt_InOutStorage122[#nTempCalculateStorageCapacity].Config.nCapacitySet;
	                
	
	                    #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage123 := #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage123 + #arrudt_InOutStorage123[#nTempCalculateStorageCapacity].Config.nCapacitySet;
	
	                
	
	                    #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage124 := #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage124 + #arrudt_InOutStorage124[#nTempCalculateStorageCapacity].Config.nCapacitySet;
	
	                
	
	                    #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage131 := #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage131 + #arrudt_InOutStorage131[#nTempCalculateStorageCapacity].Config.nCapacitySet;
	
	                
	
	                    #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage132 := #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage132 + #arrudt_InOutStorage132[#nTempCalculateStorageCapacity].Config.nCapacitySet;
	  
	                
	
	                    #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage133 := #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage133 + #arrudt_InOutStorage133[#nTempCalculateStorageCapacity].Config.nCapacitySet;
	
	                
	
	                    #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage134 := #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage134 + #arrudt_InOutStorage134[#nTempCalculateStorageCapacity].Config.nCapacitySet;
	    
	                
	                    #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage211 := #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage211 + #arrudt_InOutStorage211[#nTempCalculateStorageCapacity].stData.Config.nCapacitySet;
	             
	
	
	                    #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage212 := #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage212 + #arrudt_InOutStorage212[#nTempCalculateStorageCapacity].stData.Config.nCapacitySet;
	               
	
	
	                    #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage213 := #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage213 + #arrudt_InOutStorage213[#nTempCalculateStorageCapacity].stData.Config.nCapacitySet;
	              
	
	
	                    #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage214 := #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage214 + #arrudt_InOutStorage214[#nTempCalculateStorageCapacity].stData.Config.nCapacitySet;
	             
	
	
	                    #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage221 := #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage221 + #arrudt_InOutStorage221[#nTempCalculateStorageCapacity].stData.Config.nCapacitySet;
	             
	
	
	                    #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage222 := #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage222 + #arrudt_InOutStorage222[#nTempCalculateStorageCapacity].stData.Config.nCapacitySet;
	               
	
	
	                    #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage223 := #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage223 + #arrudt_InOutStorage223[#nTempCalculateStorageCapacity].stData.Config.nCapacitySet;
	             
	
	
	                    #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage224 := #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage224 + #arrudt_InOutStorage224[#nTempCalculateStorageCapacity].stData.Config.nCapacitySet;
	               
	
	
	                    #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage231 := #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage231 + #arrudt_InOutStorage231[#nTempCalculateStorageCapacity].stData.Config.nCapacitySet;
	             
	
	 
	                    #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage232 := #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage232 + #arrudt_InOutStorage232[#nTempCalculateStorageCapacity].stData.Config.nCapacitySet;
	            
	
	
	                    #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage233 := #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage233 + #arrudt_InOutStorage233[#nTempCalculateStorageCapacity].stData.Config.nCapacitySet;
	              
	
	
	                    #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage234 := #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage234 + #arrudt_InOutStorage234[#nTempCalculateStorageCapacity].stData.Config.nCapacitySet;
	               
	
	                
	                
	            END_IF;
	        END_FOR;
	    END_IF;
	    
	    
	END_REGION
	
	REGION Error/ Jam Group Areas
	    
	   (* REGION Block 1
	        
	        #st_AreaDisabledLevel2.str_Block1.xSection2101disabled := #stIn_JamDataBlock1.stIn_JamData2101.udt_JamData2101_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2101.udt_JamData2101_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock1.stIn_JamData2101.udt_JamData2101_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2101.udt_JamData2101_2.Status.bByte <> #cAreaEmpty
	        ;
	        
	        #st_AreaDisabledLevel2.str_Block1.xSection2102disabled := #stIn_JamDataBlock1.stIn_JamData2102.udt_JamData2102_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2102.udt_JamData2102_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock1.stIn_JamData2102.udt_JamData2102_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2102.udt_JamData2102_2.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock1.stIn_JamData2102.udt_JamData2102_3.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2102.udt_JamData2102_3.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock1.stIn_JamData2102.udt_JamData2102_4.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2102.udt_JamData2102_4.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock1.stIn_JamData2102.udt_JamData2102_5.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2102.udt_JamData2102_5.Status.bByte <> #cAreaEmpty
	        ;
	        
	        #st_AreaDisabledLevel2.str_Block1.xSection2103disabled := #stIn_JamDataBlock1.stIn_JamData2103.udt_JamData2103_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2103.udt_JamData2103_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock1.stIn_JamData2103.udt_JamData2103_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2103.udt_JamData2103_2.Status.bByte <> #cAreaEmpty
	        ;
	        
	        #st_AreaDisabledLevel2.str_Block1.xSection2104disabled := #stIn_JamDataBlock1.stIn_JamData2104.udt_JamData2104_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2104.udt_JamData2104_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock1.stIn_JamData2104.udt_JamData2104_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2104.udt_JamData2104_2.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock1.stIn_JamData2104.udt_JamData2104_3.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2104.udt_JamData2104_3.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock1.stIn_JamData2104.udt_JamData2104_4.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2104.udt_JamData2104_4.Status.bByte <> #cAreaEmpty
	        ;
	        
	        #st_AreaDisabledLevel2.str_Block1.xSection2105disabled := #stIn_JamDataBlock1.stIn_JamData2105.udt_JamData2105_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2105.udt_JamData2105_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock1.stIn_JamData2105.udt_JamData2105_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2105.udt_JamData2105_2.Status.bByte <> #cAreaEmpty
	        ;
	
	        
	        
	        #st_AreaDisabledLevel2.str_Block1.xSection2106disabled := #stIn_JamDataBlock1.stIn_JamData2106.udt_JamData2106_1.Status.bByte <> #cAreaOK
	       // AND #stIn_JamDataBlock1.stIn_JamData2106.udt_JamData2106_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock1.stIn_JamData2106.udt_JamData2106_2.Status.bByte <> #cAreaOK
	       // AND #stIn_JamDataBlock1.stIn_JamData2106.udt_JamData2106_2.Status.bByte <> #cAreaEmpty
	       ;
	        
	        #st_AreaDisabledLevel2.str_Block1.xSection2107disabled := #stIn_JamDataBlock1.stIn_JamData2107.udt_JamData2107_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2107.udt_JamData2107_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock1.stIn_JamData2107.udt_JamData2107_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2107.udt_JamData2107_2.Status.bByte <> #cAreaEmpty
	;
	        
	        #st_AreaDisabledLevel2.str_Block1.xSection2108disabled := #stIn_JamDataBlock1.stIn_JamData2108.udt_JamData2108_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2108.udt_JamData2108_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock1.stIn_JamData2108.udt_JamData2108_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock1.stIn_JamData2108.udt_JamData2108_2.Status.bByte <> #cAreaEmpty
	;
	        
	        #st_AreaDisabledLevel2.str_Block1.xBlock1disabled := #st_AreaDisabledLevel2.str_Block1.xSection2101disabled
	        OR #st_AreaDisabledLevel2.str_Block1.xSection2102disabled
	(*        OR #st_AreaDisabledLevel2.str_Block1.xSection2103disabled
	        OR #st_AreaDisabledLevel2.str_Block1.xSection2104disabled
	        OR #st_AreaDisabledLevel2.str_Block1.xSection2105disabled
	        OR #st_AreaDisabledLevel2.str_Block1.xSection2106disabled
	        OR #st_AreaDisabledLevel2.str_Block1.xSection2107disabled
	        OR #st_AreaDisabledLevel2.str_Block1.xSection2108disabled *);
	        
	        
	    END_REGION
	    
	    
	    REGION Block 2
	        
	        #st_AreaDisabledLevel2.str_Block2.xSection2201disabled := #stIn_JamDataBlock2.stIn_JamData2201.udt_JamData2201_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2201.udt_JamData2201_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2201.udt_JamData2201_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2201.udt_JamData2201_2.Status.bByte <> #cAreaEmpty
	        ;
	        
	        #st_AreaDisabledLevel2.str_Block2.xSection2202disabled := #stIn_JamDataBlock2.stIn_JamData2202.udt_JamData2202_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2202.udt_JamData2202_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2202.udt_JamData2202_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2202.udt_JamData2202_2.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2202.udt_JamData2202_3.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2202.udt_JamData2202_3.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2202.udt_JamData2202_4.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2202.udt_JamData2202_4.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2202.udt_JamData2202_5.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2202.udt_JamData2202_5.Status.bByte <> #cAreaEmpty
	        ;
	        
	        #st_AreaDisabledLevel2.str_Block2.xSection2203disabled := #stIn_JamDataBlock2.stIn_JamData2203.udt_JamData2203_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2203.udt_JamData2203_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2203.udt_JamData2203_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2203.udt_JamData2203_2.Status.bByte <> #cAreaEmpty
	        ;
	        
	        #st_AreaDisabledLevel2.str_Block2.xSection2204disabled := #stIn_JamDataBlock2.stIn_JamData2204.udt_JamData2204_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2204.udt_JamData2204_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2204.udt_JamData2204_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2204.udt_JamData2204_2.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2204.udt_JamData2204_3.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2204.udt_JamData2204_3.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2204.udt_JamData2204_4.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2204.udt_JamData2204_4.Status.bByte <> #cAreaEmpty
	        ;
	        
	        #st_AreaDisabledLevel2.str_Block2.xSection2205disabled := #stIn_JamDataBlock2.stIn_JamData2205.udt_JamData2205_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2205.udt_JamData2205_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2205.udt_JamData2205_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2205.udt_JamData2205_2.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2205.udt_JamData2205_3.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2205.udt_JamData2205_3.Status.bByte <> #cAreaEmpty
	        ;
	        
	        
	        #st_AreaDisabledLevel2.str_Block2.xSection2206disabled := #stIn_JamDataBlock2.stIn_JamData2206.udt_JamData2206_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2206.udt_JamData2206_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2206.udt_JamData2206_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2206.udt_JamData2206_2.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2206.udt_JamData2206_3.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2206.udt_JamData2206_3.Status.bByte <> #cAreaEmpty
	        ;
	        
	        #st_AreaDisabledLevel2.str_Block2.xSection2207disabled := #stIn_JamDataBlock2.stIn_JamData2207.udt_JamData2207_1.Status.bByte <> #cAreaOK
	       // AND #stIn_JamDataBlock2.stIn_JamData2207.udt_JamData2207_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2207.udt_JamData2207_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2207.udt_JamData2207_2.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2207.udt_JamData2207_3.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2207.udt_JamData2207_3.Status.bByte <> #cAreaEmpty
	        ;
	        
	        #st_AreaDisabledLevel2.str_Block2.xSection2208disabled := #stIn_JamDataBlock2.stIn_JamData2208.udt_JamData2208_1.Status.bByte <> #cAreaOK
	       // AND #stIn_JamDataBlock2.stIn_JamData2208.udt_JamData2208_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2208.udt_JamData2208_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock2.stIn_JamData2208.udt_JamData2208_2.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock2.stIn_JamData2208.udt_JamData2208_3.Status.bByte <> #cAreaOK
	       // AND #stIn_JamDataBlock2.stIn_JamData2208.udt_JamData2208_3.Status.bByte <> #cAreaEmpty
	       ;
	        
	        #st_AreaDisabledLevel2.str_Block2.xBlock2disabled := #st_AreaDisabledLevel2.str_Block2.xSection2201disabled
	        OR #st_AreaDisabledLevel2.str_Block2.xSection2202disabled
	(*        OR #st_AreaDisabledLevel2.str_Block2.xSection2203disabled
	        OR #st_AreaDisabledLevel2.str_Block2.xSection2204disabled
	        OR #st_AreaDisabledLevel2.str_Block2.xSection2205disabled
	        OR #st_AreaDisabledLevel2.str_Block2.xSection2206disabled
	        OR #st_AreaDisabledLevel2.str_Block2.xSection2207disabled
	        OR #st_AreaDisabledLevel2.str_Block2.xSection2208disabled *);
	        
	        
	    END_REGION *)
	    
	    REGION Level 1 Storage Release
	        
	        
	        
	        
	    END_REGION
	    
	    
	    REGION Block 3
	        //Überarbeiten
	        (*
	        #st_AreaDisabledLevel2.str_Block3.xSection2301disabled := #stIn_JamDataBlock3.stIn_JamData2301.udt_JamData2301_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock3.stIn_JamData2301.udt_JamData2301_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock3.stIn_JamData2301.udt_JamData2301_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock3.stIn_JamData2301.udt_JamData2301_2.Status.bByte <> #cAreaEmpty
	        ;
	        
	        #st_AreaDisabledLevel2.str_Block3.xSection2302disabled := #stIn_JamDataBlock3.stIn_JamData2302.udt_JamData2302_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock3.stIn_JamData2302.udt_JamData2302_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock3.stIn_JamData2302.udt_JamData2302_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock3.stIn_JamData2302.udt_JamData2302_2.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock3.stIn_JamData2302.udt_JamData2302_3.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock3.stIn_JamData2302.udt_JamData2302_3.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock3.stIn_JamData2302.udt_JamData2302_4.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock3.stIn_JamData2302.udt_JamData2302_4.Status.bByte <> #cAreaEmpty
	;
	        
	        #st_AreaDisabledLevel2.str_Block3.xSection2303disabled := #stIn_JamDataBlock3.stIn_JamData2303.udt_JamData2303_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock3.stIn_JamData2303.udt_JamData2303_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock3.stIn_JamData2303.udt_JamData2303_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock3.stIn_JamData2303.udt_JamData2303_2.Status.bByte <> #cAreaEmpty
	        ;
	        
	        #st_AreaDisabledLevel2.str_Block3.xSection2304disabled := #stIn_JamDataBlock3.stIn_JamData2304.udt_JamData2304_1.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock3.stIn_JamData2304.udt_JamData2304_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock3.stIn_JamData2304.udt_JamData2304_2.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock3.stIn_JamData2304.udt_JamData2304_2.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock3.stIn_JamData2304.udt_JamData2304_3.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock3.stIn_JamData2304.udt_JamData2304_3.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock3.stIn_JamData2304.udt_JamData2304_4.Status.bByte <> #cAreaOK
	        //AND #stIn_JamDataBlock3.stIn_JamData2304.udt_JamData2304_4.Status.bByte <> #cAreaEmpty
	        ;
	        
	        #st_AreaDisabledLevel2.str_Block3.xSection2305disabled := #stIn_JamDataBlock3.stIn_JamData2305.udt_JamData2305_1.Status.bByte <> #cAreaOK
	       // AND #stIn_JamDataBlock3.stIn_JamData2305.udt_JamData2305_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock3.stIn_JamData2305.udt_JamData2305_2.Status.bByte <> #cAreaOK
	       // AND #stIn_JamDataBlock3.stIn_JamData2305.udt_JamData2305_2.Status.bByte <> #cAreaEmpty
	;
	        
	        
	        #st_AreaDisabledLevel2.str_Block3.xSection2306disabled := #stIn_JamDataBlock3.stIn_JamData2306.udt_JamData2306_1.Status.bByte <> #cAreaOK
	       // AND #stIn_JamDataBlock3.stIn_JamData2306.udt_JamData2306_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock3.stIn_JamData2306.udt_JamData2306_2.Status.bByte <> #cAreaOK
	       // AND #stIn_JamDataBlock3.stIn_JamData2306.udt_JamData2306_2.Status.bByte <> #cAreaEmpty
	;
	        
	        #st_AreaDisabledLevel2.str_Block3.xSection2307disabled := #stIn_JamDataBlock3.stIn_JamData2307.udt_JamData2307_1.Status.bByte <> #cAreaOK
	        AND #stIn_JamDataBlock3.stIn_JamData2307.udt_JamData2307_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock3.stIn_JamData2307.udt_JamData2307_2.Status.bByte <> #cAreaOK
	        AND #stIn_JamDataBlock3.stIn_JamData2307.udt_JamData2307_2.Status.bByte <> #cAreaEmpty
	;
	        
	        #st_AreaDisabledLevel2.str_Block3.xSection2308disabled := #stIn_JamDataBlock3.stIn_JamData2308.udt_JamData2308_1.Status.bByte <> #cAreaOK
	       // AND #stIn_JamDataBlock3.stIn_JamData2308.udt_JamData2308_1.Status.bByte <> #cAreaEmpty
	        AND #stIn_JamDataBlock3.stIn_JamData2308.udt_JamData2308_2.Status.bByte <> #cAreaOK
	       // AND #stIn_JamDataBlock3.stIn_JamData2308.udt_JamData2308_2.Status.bByte <> #cAreaEmpty
	;
	        
	#st_AreaDisabledLevel2.str_Block3.xBlock3disabled := FALSE; //TODO #st_AreaDisabledLevel2.str_Block3.xSection2301disabled
	       // OR #st_AreaDisabledLevel2.str_Block3.xSection2302disabled *)
	(*        OR #st_AreaDisabledLevel2.str_Block3.xSection2303disabled
	        OR #st_AreaDisabledLevel2.str_Block3.xSection2304disabled
	        OR #st_AreaDisabledLevel2.str_Block3.xSection2305disabled
	        OR #st_AreaDisabledLevel2.str_Block3.xSection2306disabled
	        OR #st_AreaDisabledLevel2.str_Block3.xSection2307disabled
	        OR #st_AreaDisabledLevel2.str_Block3.xSection2308disabled *)
	        ; 
	        
	        
	    END_REGION
	    
	    
	END_REGION
	
	
	REGION Buffer MES Message
	    
	    CASE #n_StepBufferMES OF
	        #c000_Wait:
	            REGION c000_Wait
	                ;
	                //Action
	                
	                
	                //Transition
	                IF #udt_InOut_HandshakeDataMES.str_Ctrl.xNewDataAvaible
	                THEN
	                    #n_StepBufferMES := #c010_NewData;
	                END_IF;
	            END_REGION
	            
	        #c010_NewData:
	            REGION c010_NewData
	                
	                //Action
	                #udt_DataMESSave := #udtIn_DataMES.stPayload;
	                #udt_InOut_HandshakeDataMES.str_Status.xReadingNewData := True;
	                //Transition
	                IF #udt_DataMESSave.nBarcode > 0
	                THEN
	                    #n_StepBufferMES := #c020_SearchEmptyElement;
	                    //Else Error
	                END_IF;
	            END_REGION
	
	            
	        #c020_SearchEmptyElement:
	            
	            REGION c020_SearchEmptyElement
	                //Action
	                FOR #n_EmptyElementIDX := #n_LowerBoundBuffer TO #n_UpperBoundBuffer DO
	                    IF #arrudt_InOutCarrierBuffer[#n_EmptyElementIDX].stPayload.nBarcode = 0
	                    THEN
	                        #n_EmptyElementIDXSave := #n_EmptyElementIDX;
	                        #arrudt_InOutCarrierBuffer[#n_EmptyElementIDX].stPayload := #udt_DataMESSave;
	                        #udt_InOut_HandshakeDataMES.str_Status.xNewDataSaved := True;
	                        #udt_InOut_HandshakeDataMES.str_Status.xReadingNewData := False;
	                        EXIT;
	                    END_IF;
	                    
	                END_FOR;
	                //Transition
	                IF #udtIn_DataMES.stPayload.nBarcode > 0
	                THEN
	                    #n_StepBufferMES := #c030_Finish;
	                END_IF;
	            END_REGION ;
	            
	        #c030_Finish:
	            REGION c030_Finish
	                // Action
	                
	                //Transition
	                IF NOT #udt_InOut_HandshakeDataMES.str_Ctrl.xNewDataAvaible
	                THEN
	                    #n_StepBufferMES := #c040_Reset;
	                END_IF;
	            END_REGION
	            
	        #c040_Reset:
	            REGION c040_Reset
	                //Action
	                #udt_InOut_HandshakeDataMES.str_Status.xReadingNewData := False;
	                #udt_InOut_HandshakeDataMES.str_Status.xNewDataSaved := False;
	                #udt_InOut_HandshakeDataMES.str_Status.xDataIncorrect := False;
	                #n_EmptyElementIDXSave := 0;
	                
	                //Transition
	                #n_StepBufferMES := #c000_Wait;
	            END_REGION
	    END_CASE;
	END_REGION
	
	(* REGION Fill Up Buffer
	    // Virtuellen Puffer mit Daten der MES befüllen.
	    // Daten werden zwischengespeichert, damit das Shuttle nicht am Seperator auf das Telegram der MES warten muss.
	    // "stCarrier".bStatus X3 = short  X4 = long
	    // 
	    //Handshake erforderlich
	    //#xSucheStart
	    //
	    
	    
	    
	    
	    IF #xSucheStart AND NOT #xDSucheAbgeschlossen
	    THEN
	        #xIDGefunden := False;
	        #n_FreierIndex := 0;
	        
	        FOR #n_IDXSearchData := #n_LowerBound TO #n_UpperBound DO
	            IF #arrudt_InOutCarrierBuffer[#n_IDXSearchData].stPayload.nBarcode = #udtIn_DataMES.stPayload.nBarcode
	            THEN
	                #xIDGefunden := True;
	            ELSIF #arrudt_InOutCarrierBuffer[#n_IDXSearchData].stPayload.nBarcode= 0 AND #n_FreierIndex = 0
	            THEN
	                #n_FreierIndex := #n_IDXSearchData;
	            END_IF;
	        END_FOR;
	        
	        
	        IF #xIDGefunden THEN
	            #xIDBereitsVorhanden := True;
	            #xIDHinzugefügt := False;
	        ELSIF #n_FreierIndex > 0 THEN
	            #arrudt_InOutCarrierBuffer[#n_FreierIndex].stPayload.nBarcode := #udtIn_DataMES.stPayload.nBarcode;
	            #arrudt_InOutCarrierBuffer[#n_FreierIndex].stPayload.arActions[1] := #udtIn_DataMES.stPayload.arActions[1];
	            #xIDBereitsVorhanden := False;
	            #xIDHinzugefügt := True;
	        ELSE
	            //Kein PLatz frei
	            #xIDBereitsVorhanden := False;
	            #xIDHinzugefügt := False;
	        END_IF;
	        
	        
	        #xDSucheAbgeschlossen := True;
	        
	        
	        
	    ELSIF NOT #xSucheStart
	    THEN
	        // Rücksetzen
	        #xDSucheAbgeschlossen := False;
	        #xIDBereitsVorhanden := False;
	        #xIDHinzugefügt := False;
	    END_IF;
	    
	    
	END_REGION
	*)
	REGION Daten aus Buffer übertragen - EMBI geändert
	    FOR #n_DatenBufferIDX := #n_LowerBound TO #n_UpperBound DO
	        FOR #n_DatenJamArea := #n_LowerBoundBuffer TO #n_UpperBoundBuffer DO
	            IF #n_DatenJamArea >= #n_LowerBoundBuffer AND #n_DatenJamArea <= #n_UpperBoundBuffer
	                AND #n_DatenBufferIDX >= #n_LowerBound AND #n_DatenBufferIDX <= #n_UpperBound
	            THEN
	                IF #arrudt_InOutCarrierBuffer[#n_DatenJamArea].stPayload.nBarcode = #arrudt_InOutJAM_Conv1_2[#n_DatenBufferIDX].nBarcode
	                    AND (* NOT *) #arrudt_InOutJAM_Conv1_2[#n_DatenBufferIDX].bStatus.%X1 //Carrier nicht beladen
	                THEN
	                    IF #arrudt_InOutCarrierBuffer[#n_DatenJamArea].stPayload.arActions[1] = 'kurz'
	                    THEN
	                        #arrudt_InOutJAM_Conv1_2[#n_DatenBufferIDX].bStatus.%X3 := True; //Bit für Carrier kurz
	                    ELSIF #arrudt_InOutCarrierBuffer[#n_DatenJamArea].stPayload.arActions[1] = 'lang'
	                    THEN
	                        #arrudt_InOutJAM_Conv1_2[#n_DatenBufferIDX].bStatus.%X4 := True; //Bit für Carrier lang
	                        
	                    END_IF;
	                END_IF;
	            END_IF;
	        END_FOR;
	        
	        
	        
	    END_FOR;
	    
	    
	    
	END_REGION
	
	
	REGION Jam Area Daten überwachen
	    //Shuttle ohne Ziel suchen
	    IF #nIDWithoutDest = 0
	    THEN
	        FOR #n_JamAreaIDX := #n_LowerBound TO #n_UpperBound DO //EMBI
	            IF #arrudt_InOutJAM_Conv1_2[#n_JamAreaIDX].nDestination = 0
	                AND ((#arrudt_InOutJAM_Conv1_2[#n_JamAreaIDX].bStatus.%X1 AND (#arrudt_InOutJAM_Conv1_2[#n_JamAreaIDX].bStatus.%X3 OR #arrudt_InOutJAM_Conv1_2[#n_JamAreaIDX].bStatus.%X4)) OR
	                (NOT #arrudt_InOutJAM_Conv1_2[#n_JamAreaIDX].bStatus.%X1 AND (NOT #arrudt_InOutJAM_Conv1_2[#n_JamAreaIDX].bStatus.%X3 AND  NOT #arrudt_InOutJAM_Conv1_2[#n_JamAreaIDX].bStatus.%X4)))
	            THEN
	                #nIDWithoutDest := #arrudt_InOutJAM_Conv1_2[#n_JamAreaIDX].nBarcode;
	                #st_JamAreaCarrier.st_Data := #arrudt_InOutJAM_Conv1_2[#n_JamAreaIDX];
	                EXIT;
	            END_IF;
	  //          EXIT; //EMBI
	        END_FOR;
	        
	        
	    END_IF;
	    
	    
	END_REGION
	
	
	REGION Find Destination
	    //Ziel für Shuttle ohne Ziel vergeben
	    IF #st_JamAreaCarrier.st_Data.bStatus.%X3
	        AND #st_JamAreaCarrier.st_Data.bStatus.%X1
	        AND #st_JamAreaCarrier.st_Data.bStatus.%X0
	    THEN
	        #n_CarrierTyp := #c001_CarrierKurz;
	    ELSIF #st_JamAreaCarrier.st_Data.bStatus.%X4
	        AND #st_JamAreaCarrier.st_Data.bStatus.%X1
	        AND #st_JamAreaCarrier.st_Data.bStatus.%X0
	    THEN
	        #n_CarrierTyp := #c002_CarrierLang;
	    ELSIF NOT #st_JamAreaCarrier.st_Data.bStatus.%X1
	        AND NOT #st_JamAreaCarrier.st_Data.bStatus.%X4
	        AND NOT #st_JamAreaCarrier.st_Data.bStatus.%X3
	        AND #st_JamAreaCarrier.st_Data.bStatus.%X0
	    THEN
	        #n_CarrierTyp := #c003_CarrierLeer;
	    ELSIF (#st_JamAreaCarrier.st_Data.bStatus.%X1
	        AND NOT #st_JamAreaCarrier.st_Data.bStatus.%X4
	        AND NOT #st_JamAreaCarrier.st_Data.bStatus.%X3)
	        OR (NOT #st_JamAreaCarrier.st_Data.bStatus.%X1
	        AND (#st_JamAreaCarrier.st_Data.bStatus.%X3
	        OR #st_JamAreaCarrier.st_Data.bStatus.%X4))
	        OR NOT #st_JamAreaCarrier.st_Data.bStatus.%X0
	    THEN
	        #n_CarrierTyp := #c000_undefinert;
	    END_IF;
	    
	    IF NOT #xDestinationGranted
	    THEN
	        
	        CASE #n_CarrierTyp OF
	            #c000_undefinert:
	                ;
	            #c001_CarrierKurz:
	                REGION Carrier kurz
	                    REGION Block 3
	                        IF FALSE AND  NOT #st_AreaDisabledLevel2.str_Block3.xBlock3disabled //erstmal nicht machen - Embi Test
	                        THEN
	                            CASE #nIn_StorageMode OF
	                                    
	                                #c000_uneven:
	                                    REGION Uneven
	                                        //Blöcken werden ungleich gefüllt
	                                        FOR #n_Block23IDX := 1 TO 21 DO
	                                            IF #n_Block23IDX >= 1 AND #n_Block23IDX <= 21
	                                            THEN
	                                                IF NOT #st_AreaDisabledLevel2.str_Block3.xSection2301disabled AND #arrudt_InOutStorage231[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage231[#n_Block23IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage231[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage231[#n_Block23IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage231BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage231
	                                                    AND NOT #arrudt_InOutStorage231[#n_Block23IDX].stData.Config.bByte.%X3 //X3 = Linie für leere Carrier
	                                                    AND NOT #udt_InOutStorage231BlockData.xError
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 23100;
	                                                    // #udt_InOutStorage231BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block3.xSection2301disabled AND #arrudt_InOutStorage232[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage232[#n_Block23IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage232[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage232[#n_Block23IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage232BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage232
	                                                    AND NOT #arrudt_InOutStorage232[#n_Block23IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 23200;
	                                                    // #udt_InOutStorage232BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block3.xSection2302disabled AND #arrudt_InOutStorage233[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage233[#n_Block23IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage233[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage233[#n_Block23IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage233BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage233
	                                                    AND NOT #arrudt_InOutStorage233[#n_Block23IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 23300;
	                                                    // #udt_InOutStorage233BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block3.xSection2302disabled AND #arrudt_InOutStorage234[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage234[#n_Block23IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage234[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage234[#n_Block23IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage234BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage234
	                                                    AND NOT #arrudt_InOutStorage234[#n_Block23IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 23400;
	                                                    // #udt_InOutStorage234BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                    
	                                                END_IF;
	                                            END_IF;
	                                            IF #n_Block23IDX = 21 AND #st_JamAreaCarrier.st_Data.nBarcode = 0
	                                            THEN
	                                                #xInOutError := True;
	                                                #nInOutErrorID := #c020_KeinZielVerfuegbar;
	                                            END_IF;
	                                            
	                                        END_FOR;
	                                    END_REGION
	                                    
	                                    
	                            END_CASE;
	                        END_IF;
	                    END_REGION
	                    REGION Ebene 1
	                        REGION Block 1
	                            CASE #nIn_StorageMode OF
	                                #c000_uneven:
	                                    REGION Uneven
	                                        //Blöcken werden ungleich gefüllt
	                                        FOR #n_Block11IDX := 1 TO 21 DO
	                                            IF #n_Block11IDX >= 1 AND #n_Block11IDX <= 21
	                                            THEN
	                                                IF (* #arrudt_InOutStorage111[#n_Block11IDX].Status.nCount < #arrudt_InOutStorage111[#n_Block11IDX].Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage111[#n_Block11IDX].Status.nCount < #arrudt_InOutStorage111[#n_Block11IDX].Config.nCapacitySet
	                                                    AND #udt_InOutStorage111BlockData.nCountTotal < #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage111
	                                                    AND NOT #arrudt_InOutStorage111[#n_Block11IDX].Config.bByte.%X3
	                                                    AND NOT #udt_InOutStorage111BlockData.xError
	                                                    AND #udtIn_Lv1StorageRelease.b_StorageReleaseBlock1xx
	                                                    AND *)NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 13000;//11100; EMBIIIII
	                                                    // #udt_InOutStorage111BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF #arrudt_InOutStorage112[#n_Block11IDX].Status.nCount < #arrudt_InOutStorage112[#n_Block11IDX].Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage112[#n_Block11IDX].Status.nCount < #arrudt_InOutStorage112[#n_Block11IDX].Config.nCapacitySet
	                                                    AND #udt_InOutStorage112BlockData.nCountTotal < #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage112
	                                                    AND NOT #arrudt_InOutStorage112[#n_Block11IDX].Config.bByte.%X3
	                                                    AND #udtIn_Lv1StorageRelease.b_StorageReleaseBlock1xx
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 11200;
	                                                    // #udt_InOutStorage112BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF #arrudt_InOutStorage113[#n_Block11IDX].Status.nCount < #arrudt_InOutStorage113[#n_Block11IDX].Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage113[#n_Block11IDX].Status.nCount < #arrudt_InOutStorage113[#n_Block11IDX].Config.nCapacitySet
	                                                    AND #udt_InOutStorage113BlockData.nCountTotal < #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage113
	                                                    AND NOT #arrudt_InOutStorage113[#n_Block11IDX].Config.bByte.%X3
	                                                    AND #udtIn_Lv1StorageRelease.b_StorageReleaseBlock1xx
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 11300;
	                                                    // #udt_InOutStorage113BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF #arrudt_InOutStorage114[#n_Block11IDX].Status.nCount < #arrudt_InOutStorage114[#n_Block11IDX].Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage114[#n_Block11IDX].Status.nCount < #arrudt_InOutStorage114[#n_Block11IDX].Config.nCapacitySet
	                                                    AND #udt_InOutStorage114BlockData.nCountTotal < #udt_CapacityStorage.str_Level1.str_Block1.nCapacityStorage114
	                                                    AND NOT #arrudt_InOutStorage114[#n_Block11IDX].Config.bByte.%X3
	                                                    AND #udtIn_Lv1StorageRelease.b_StorageReleaseBlock1xx
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 11400;
	                                                    // #udt_InOutStorage114BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                    
	                                                END_IF;
	                                            END_IF;
	                                            IF #n_Block11IDX = 21 AND #st_JamAreaCarrier.st_Data.nBarcode = 0
	                                            THEN
	                                                #xInOutError := True;
	                                                #nInOutErrorID := #c020_KeinZielVerfuegbar;
	                                            END_IF;
	                                            
	                                        END_FOR;
	                                        
	                                        
	                                        ;
	                                    END_REGION
	                                    
	                            END_CASE;
	                            
	                            
	                            
	                            
	                            
	                        END_REGION
	                        
	                        REGION Block 2
	                            CASE #nIn_StorageMode OF
	                                #c000_uneven:
	                                    REGION Uneven
	                                        //Blöcken werden ungleich gefüllt
	                                        FOR #n_Block12IDX := 1 TO 21 DO
	                                            IF #n_Block12IDX >= 1 AND #n_Block12IDX <= 21
	                                            THEN
	                                                IF #arrudt_InOutStorage121[#n_Block12IDX].Status.nCount < #arrudt_InOutStorage121[#n_Block12IDX].Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage121[#n_Block12IDX].Status.nCount < #arrudt_InOutStorage121[#n_Block12IDX].Config.nCapacitySet
	                                                    AND #udt_InOutStorage121BlockData.nCountTotal < #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage121
	                                                    AND NOT #arrudt_InOutStorage121[#n_Block12IDX].Config.bByte.%X3
	                                                    AND NOT #udt_InOutStorage121BlockData.xError
	                                                    AND #udtIn_Lv1StorageRelease.b_StorageReleaseBlock2xx
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 12100;
	                                                    // #udt_InOutStorage121BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF #arrudt_InOutStorage122[#n_Block12IDX].Status.nCount < #arrudt_InOutStorage122[#n_Block12IDX].Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage122[#n_Block12IDX].Status.nCount < #arrudt_InOutStorage122[#n_Block12IDX].Config.nCapacitySet
	                                                    AND #udt_InOutStorage122BlockData.nCountTotal < #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage122
	                                                    AND NOT #arrudt_InOutStorage122[#n_Block12IDX].Config.bByte.%X3
	                                                    AND #udtIn_Lv1StorageRelease.b_StorageReleaseBlock2xx
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 12200;
	                                                    // #udt_InOutStorage122BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF #arrudt_InOutStorage123[#n_Block12IDX].Status.nCount < #arrudt_InOutStorage123[#n_Block12IDX].Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage123[#n_Block12IDX].Status.nCount < #arrudt_InOutStorage123[#n_Block12IDX].Config.nCapacitySet
	                                                    AND #udt_InOutStorage123BlockData.nCountTotal < #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage123
	                                                    AND NOT #arrudt_InOutStorage123[#n_Block12IDX].Config.bByte.%X3
	                                                    AND #udtIn_Lv1StorageRelease.b_StorageReleaseBlock2xx
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 12300;
	                                                    // #udt_InOutStorage123BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF #arrudt_InOutStorage124[#n_Block12IDX].Status.nCount < #arrudt_InOutStorage124[#n_Block12IDX].Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage124[#n_Block12IDX].Status.nCount < #arrudt_InOutStorage124[#n_Block12IDX].Config.nCapacitySet
	                                                    AND #udt_InOutStorage124BlockData.nCountTotal < #udt_CapacityStorage.str_Level1.str_Block2.nCapacityStorage124
	                                                    AND NOT #arrudt_InOutStorage124[#n_Block12IDX].Config.bByte.%X3
	                                                    AND #udtIn_Lv1StorageRelease.b_StorageReleaseBlock2xx
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 12400;
	                                                    // #udt_InOutStorage124BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                    
	                                                END_IF;
	                                            END_IF;
	                                            IF #n_Block12IDX = 21 AND #st_JamAreaCarrier.st_Data.nBarcode = 0
	                                            THEN
	                                                #xInOutError := True;
	                                                #nInOutErrorID := #c020_KeinZielVerfuegbar;
	                                            END_IF;
	                                            
	                                        END_FOR;
	                                        
	                                        
	                                        ;
	                                    END_REGION
	                                    
	                            END_CASE;
	                            
	                            
	                            
	                            
	                            
	                        END_REGION
	                        
	                        REGION Block 3
	                            CASE #nIn_StorageMode OF
	                                #c000_uneven:
	                                    REGION Uneven
	                                        //Blöcken werden ungleich gefüllt
	                                        FOR #n_Block13IDX := 1 TO 21 DO
	                                            IF #n_Block13IDX >= 1 AND #n_Block13IDX <= 21
	                                            THEN
	                                                IF #arrudt_InOutStorage131[#n_Block13IDX].Status.nCount < #arrudt_InOutStorage131[#n_Block13IDX].Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage131[#n_Block13IDX].Status.nCount < #arrudt_InOutStorage131[#n_Block13IDX].Config.nCapacitySet
	                                                    AND #udt_InOutStorage131BlockData.nCountTotal < #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage131
	                                                    AND NOT #arrudt_InOutStorage131[#n_Block13IDX].Config.bByte.%X3
	                                                    AND NOT #udt_InOutStorage131BlockData.xError
	                                                    AND #udtIn_Lv1StorageRelease.b_StorageReleaseBlock3xx
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 13100;
	                                                    // #udt_InOutStorage131BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF #arrudt_InOutStorage132[#n_Block13IDX].Status.nCount < #arrudt_InOutStorage132[#n_Block13IDX].Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage132[#n_Block13IDX].Status.nCount < #arrudt_InOutStorage132[#n_Block13IDX].Config.nCapacitySet
	                                                    AND #udt_InOutStorage132BlockData.nCountTotal < #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage132
	                                                    AND NOT #arrudt_InOutStorage132[#n_Block13IDX].Config.bByte.%X3
	                                                    AND #udtIn_Lv1StorageRelease.b_StorageReleaseBlock3xx
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 13200;
	                                                    // #udt_InOutStorage132BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF #arrudt_InOutStorage133[#n_Block13IDX].Status.nCount < #arrudt_InOutStorage133[#n_Block13IDX].Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage133[#n_Block13IDX].Status.nCount < #arrudt_InOutStorage133[#n_Block13IDX].Config.nCapacitySet
	                                                    AND #udt_InOutStorage133BlockData.nCountTotal < #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage133
	                                                    AND NOT #arrudt_InOutStorage133[#n_Block13IDX].Config.bByte.%X3
	                                                    AND #udtIn_Lv1StorageRelease.b_StorageReleaseBlock3xx
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 13300;
	                                                    // #udt_InOutStorage133BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF #arrudt_InOutStorage134[#n_Block13IDX].Status.nCount < #arrudt_InOutStorage134[#n_Block13IDX].Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage134[#n_Block13IDX].Status.nCount < #arrudt_InOutStorage134[#n_Block13IDX].Config.nCapacitySet
	                                                    AND #udt_InOutStorage134BlockData.nCountTotal < #udt_CapacityStorage.str_Level1.str_Block3.nCapacityStorage134
	                                                    AND NOT #arrudt_InOutStorage134[#n_Block13IDX].Config.bByte.%X3
	                                                    AND #udtIn_Lv1StorageRelease.b_StorageReleaseBlock3xx
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 13400;
	                                                    // #udt_InOutStorage134BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                    
	                                                END_IF;
	                                            END_IF;
	                                            IF #n_Block13IDX = 21 AND #st_JamAreaCarrier.st_Data.nBarcode = 0
	                                            THEN
	                                                #xInOutError := True;
	                                                #nInOutErrorID := #c020_KeinZielVerfuegbar;
	                                            END_IF;
	                                            
	                                        END_FOR;
	                                        
	                                        
	                                        ;
	                                    END_REGION
	                                    
	                            END_CASE;
	                            
	                            
	                            
	                            
	                            
	                        END_REGION
	                        
	                    END_REGION
	                    
	                    
	                END_REGION
	                
	                
	                ;
	            #c002_CarrierLang:
	                REGION Carrier lang
	                    REGION Block 1
	                        //Für Test!!!
	                        IF FALSE AND (NOT #st_AreaDisabledLevel2.str_Block1.xBlock1disabled)
	                        THEN
	                            CASE #nIn_StorageMode OF
	                                    
	                                #c000_uneven:
	                                    REGION Uneven
	                                        //Blöcken werden ungleich gefüllt
	                                        FOR #n_Block21IDX := 1 TO 21 DO
	                                            IF #n_Block21IDX >= 1 AND #n_Block21IDX <= 21
	                                            THEN
	                                                
	                                                
	                                                IF NOT #st_AreaDisabledLevel2.str_Block1.xSection2101disabled AND #arrudt_InOutStorage211[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage211[#n_Block21IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage211[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage211[#n_Block21IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage211BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage211
	                                                    AND NOT #arrudt_InOutStorage211[#n_Block21IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 21100;
	                                                    // #udt_InOutStorage211BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block1.xSection2101disabled AND #arrudt_InOutStorage212[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage212[#n_Block21IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage212[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage212[#n_Block21IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage212BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage212
	                                                    AND NOT #arrudt_InOutStorage212[#n_Block21IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 21200;
	                                                    // #udt_InOutStorage212BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block1.xSection2102disabled AND #arrudt_InOutStorage213[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage213[#n_Block21IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage213[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage213[#n_Block21IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage213BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage213
	                                                    AND NOT #arrudt_InOutStorage213[#n_Block21IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 21300;
	                                                    // #udt_InOutStorage213BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block1.xSection2102disabled AND #arrudt_InOutStorage214[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage214[#n_Block21IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage214[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage214[#n_Block21IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage214BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage214
	                                                    AND NOT #arrudt_InOutStorage214[#n_Block21IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 21400;
	                                                    // #udt_InOutStorage214BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                    
	                                                END_IF;
	                                                
	                                            END_IF;
	                                            IF #n_Block21IDX = 21 AND #st_JamAreaCarrier.st_Data.nBarcode = 0
	                                            THEN
	                                                #xInOutError := True;
	                                                #nInOutErrorID := #c020_KeinZielVerfuegbar;
	                                            END_IF;
	                                        END_FOR;
	                                    END_REGION
	                                #c001_even:
	                                    REGION Even
	                                        //Minimale Befüllung in der Linie ermitteln 
	                                        #nTempMinBefuellungBlock1 := #arrudt_InOutStorage211[1].stData.Status.nCount;
	                                        FOR #nTempLinieIDX := 2 TO 12 DO
	                                            IF #arrudt_InOutStorage211[#nTempLinieIDX].stData.Status.nCount < #nTempMinBefuellungBlock1 THEN
	                                                #nTempMinBefuellungBlock1 := #arrudt_InOutStorage211[#nTempLinieIDX].stData.Status.nCount;
	                                            END_IF;
	                                            IF #arrudt_InOutStorage212[#nTempLinieIDX].stData.Status.nCount < #nTempMinBefuellungBlock1 THEN
	                                                #nTempMinBefuellungBlock1 := #arrudt_InOutStorage212[#nTempLinieIDX].stData.Status.nCount;
	                                            END_IF;
	                                            IF #arrudt_InOutStorage213[#nTempLinieIDX].stData.Status.nCount < #nTempMinBefuellungBlock1 THEN
	                                                #nTempMinBefuellungBlock1 := #arrudt_InOutStorage213[#nTempLinieIDX].stData.Status.nCount;
	                                            END_IF;
	                                            IF #arrudt_InOutStorage214[#nTempLinieIDX].stData.Status.nCount < #nTempMinBefuellungBlock1 THEN
	                                                #nTempMinBefuellungBlock1 := #arrudt_InOutStorage214[#nTempLinieIDX].stData.Status.nCount;
	                                            END_IF;
	                                        END_FOR;
	                                        
	                                        
	                                        
	                                        
	                                        
	                                        FOR #n_Block21IDX := 1 TO 21 DO
	                                            IF #n_Block21IDX >= 1 AND #n_Block21IDX <= 21
	                                            THEN
	                                                
	                                                IF NOT #st_AreaDisabledLevel2.str_Block1.xSection2101disabled AND #arrudt_InOutStorage211[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage211[#n_Block21IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage211[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage211[#n_Block21IDX].stData.Config.nCapacitySet
	                                                    AND #arrudt_InOutStorage211[#n_Block21IDX].stData.Status.nCount = #nTempMinBefuellungBlock1
	                                                    AND #udt_InOutStorage211BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage211
	                                                    AND NOT #arrudt_InOutStorage211[#n_Block21IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 21100;
	                                                    // #udt_InOutStorage211BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block1.xSection2101disabled AND #arrudt_InOutStorage212[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage212[#n_Block21IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage212[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage212[#n_Block21IDX].stData.Config.nCapacitySet
	                                                    AND #arrudt_InOutStorage212[#n_Block21IDX].stData.Status.nCount = #nTempMinBefuellungBlock1
	                                                    AND #udt_InOutStorage212BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage212
	                                                    AND NOT #arrudt_InOutStorage212[#n_Block21IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 21200;
	                                                    // #udt_InOutStorage212BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block1.xSection2102disabled AND #arrudt_InOutStorage213[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage213[#n_Block21IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage213[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage213[#n_Block21IDX].stData.Config.nCapacitySet
	                                                    AND #arrudt_InOutStorage213[#n_Block21IDX].stData.Status.nCount = #nTempMinBefuellungBlock1
	                                                    AND #udt_InOutStorage213BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage213
	                                                    AND NOT #arrudt_InOutStorage213[#n_Block21IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 21300;
	                                                    // #udt_InOutStorage213BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block1.xSection2102disabled AND #arrudt_InOutStorage214[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage214[#n_Block21IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage214[#n_Block21IDX].stData.Status.nCount < #arrudt_InOutStorage214[#n_Block21IDX].stData.Config.nCapacitySet
	                                                    AND #arrudt_InOutStorage214[#n_Block21IDX].stData.Status.nCount = #nTempMinBefuellungBlock1
	                                                    AND #udt_InOutStorage214BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block1.nCapacityStorage214
	                                                    AND NOT #arrudt_InOutStorage214[#n_Block21IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 21400;
	                                                    // #udt_InOutStorage214BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                END_IF;
	                                            END_IF;
	                                            IF #n_Block21IDX = 21 AND #st_JamAreaCarrier.st_Data.nBarcode = 0
	                                            THEN
	                                                #xInOutError := True;
	                                                #nInOutErrorID := #c020_KeinZielVerfuegbar;
	                                            END_IF;
	                                        END_FOR;
	                                        
	                                    END_REGION
	                            END_CASE;
	                            
	                        END_IF;
	                    END_REGION
	                    
	                    REGION Block 2
	                        
	                   //     IF #st_AreaDisabledLevel2.str_Block1.xBlock1disabled AND NOT #st_AreaDisabledLevel2.str_Block2.xBlock2disabled
	                   //     THEN
	                            CASE #nIn_StorageMode OF
	                                    
	                                #c000_uneven:
	                                    REGION Uneven
	                                        //Blöcken werden ungleich gefüllt
	                                        FOR #n_Block22IDX := 1 TO 21 DO
	                                            IF #n_Block22IDX >= 1 AND #n_Block22IDX <= 21
	                                            THEN
	                                                IF NOT #st_AreaDisabledLevel2.str_Block2.xSection2201disabled AND #arrudt_InOutStorage221[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage221[#n_Block22IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage221[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage221[#n_Block22IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage221BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage221
	                                                    AND NOT #arrudt_InOutStorage221[#n_Block22IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 21400;
	                                                    // #udt_InOutStorage221BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block2.xSection2201disabled AND #arrudt_InOutStorage222[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage222[#n_Block22IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage222[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage222[#n_Block22IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage222BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage222
	                                                    AND NOT #arrudt_InOutStorage222[#n_Block22IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 21400;//22200;
	                                                    // #udt_InOutStorage222BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block2.xSection2202disabled AND #arrudt_InOutStorage223[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage223[#n_Block22IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage223[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage223[#n_Block22IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage223BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage223
	                                                    AND NOT #arrudt_InOutStorage223[#n_Block22IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 21400;//22300;
	                                                    // #udt_InOutStorage223BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block2.xSection2202disabled AND #arrudt_InOutStorage224[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage224[#n_Block22IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage224[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage224[#n_Block22IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage224BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage224
	                                                    AND NOT #arrudt_InOutStorage224[#n_Block22IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 21400;//22400;
	                                                    // #udt_InOutStorage224BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSE
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 21400;//22400;
	                                                    #xDestinationGranted := True;
	                                                END_IF;
	                                            END_IF;
	                                            IF #n_Block22IDX = 21 AND #st_JamAreaCarrier.st_Data.nBarcode = 0
	                                            THEN
	                                                #xInOutError := True;
	                                                #nInOutErrorID := #c020_KeinZielVerfuegbar;
	                                            END_IF;
	                                            
	                                        END_FOR;
	                                    END_REGION
	                                    
	                                    REGION Even
	                                        //Minimale Befüllung in der Linie ermitteln 
	                                        #nTempMinBefuellungBlock2 := #arrudt_InOutStorage221[1].stData.Status.nCount;
	                                        FOR #nTempLinieIDX := 2 TO 12 DO
	                                            IF #arrudt_InOutStorage221[#nTempLinieIDX].stData.Status.nCount < #nTempMinBefuellungBlock2 THEN
	                                                #nTempMinBefuellungBlock2 := #arrudt_InOutStorage221[#nTempLinieIDX].stData.Status.nCount;
	                                            END_IF;
	                                            IF #arrudt_InOutStorage222[#nTempLinieIDX].stData.Status.nCount < #nTempMinBefuellungBlock2 THEN
	                                                #nTempMinBefuellungBlock2 := #arrudt_InOutStorage222[#nTempLinieIDX].stData.Status.nCount;
	                                            END_IF;
	                                            IF #arrudt_InOutStorage223[#nTempLinieIDX].stData.Status.nCount < #nTempMinBefuellungBlock2 THEN
	                                                #nTempMinBefuellungBlock2 := #arrudt_InOutStorage223[#nTempLinieIDX].stData.Status.nCount;
	                                            END_IF;
	                                            IF #arrudt_InOutStorage224[#nTempLinieIDX].stData.Status.nCount < #nTempMinBefuellungBlock2 THEN
	                                                #nTempMinBefuellungBlock2 := #arrudt_InOutStorage224[#nTempLinieIDX].stData.Status.nCount;
	                                            END_IF;
	                                        END_FOR;
	                                        
	                                        
	                                        
	                                        
	                                        
	                                        FOR #n_Block22IDX := 1 TO 21 DO
	                                            IF #n_Block22IDX >= 1 AND #n_Block22IDX <= 21
	                                            THEN
	                                                IF NOT #st_AreaDisabledLevel2.str_Block2.xSection2201disabled AND #arrudt_InOutStorage221[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage221[#n_Block22IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage221[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage221[#n_Block22IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage221BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage221
	                                                    AND #arrudt_InOutStorage221[#n_Block22IDX].stData.Status.nCount = #nTempMinBefuellungBlock2
	                                                    AND NOT #arrudt_InOutStorage221[#n_Block22IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 22100;
	                                                    // #udt_InOutStorage221BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block2.xSection2201disabled AND #arrudt_InOutStorage222[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage222[#n_Block22IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage222[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage222[#n_Block22IDX].stData.Config.nCapacitySet
	                                                    AND #arrudt_InOutStorage222[#n_Block22IDX].stData.Status.nCount = #nTempMinBefuellungBlock2
	                                                    AND #udt_InOutStorage222BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage222
	                                                    AND NOT #arrudt_InOutStorage222[#n_Block22IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 22200;
	                                                    // #udt_InOutStorage222BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block2.xSection2202disabled AND #arrudt_InOutStorage223[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage223[#n_Block22IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage223[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage223[#n_Block22IDX].stData.Config.nCapacitySet
	                                                    AND #arrudt_InOutStorage223[#n_Block22IDX].stData.Status.nCount = #nTempMinBefuellungBlock2
	                                                    AND #udt_InOutStorage223BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage223
	                                                    AND NOT #arrudt_InOutStorage223[#n_Block22IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 22300;
	                                                    // #udt_InOutStorage223BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block2.xSection2202disabled AND #arrudt_InOutStorage224[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage224[#n_Block22IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage224[#n_Block22IDX].stData.Status.nCount < #arrudt_InOutStorage224[#n_Block22IDX].stData.Config.nCapacitySet
	                                                    AND #arrudt_InOutStorage224[#n_Block22IDX].stData.Status.nCount = #nTempMinBefuellungBlock2
	                                                    AND #udt_InOutStorage224BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block2.nCapacityStorage224
	                                                    AND NOT #arrudt_InOutStorage224[#n_Block22IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 22400;
	                                                    // #udt_InOutStorage224BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                    
	                                                END_IF;
	                                            END_IF;
	                                            IF #n_Block22IDX = 21 AND #st_JamAreaCarrier.st_Data.nBarcode = 0
	                                            THEN
	                                                #xInOutError := True;
	                                                #nInOutErrorID := #c020_KeinZielVerfuegbar;
	                                            END_IF;
	                                        END_FOR;
	                                    END_REGION
	                            END_CASE;
	                   //     END_IF;
	                    END_REGION
	                END_REGION
	                
	                
	                
	                ;
	            #c003_CarrierLeer:
	                REGION Carrier leer
	                    REGION Block 3
	                        
	                        IF NOT #st_AreaDisabledLevel2.str_Block3.xBlock3disabled
	                        THEN
	                            CASE #nIn_StorageMode OF
	                                    
	                                #c000_uneven:
	                                    REGION Uneven
	                                        //Blöcken werden ungleich gefüllt
	                                        #n_Block23IDX := 1;
	                                        FOR #n_Block23IDX := 1 TO 21 DO
	                                            IF #n_Block23IDX >= 1 AND #n_Block23IDX <= 21
	                                            THEN
	                                                IF NOT #st_AreaDisabledLevel2.str_Block3.xSection2301disabled
	                                                    AND (#arrudt_InOutStorage231[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage231[#n_Block23IDX].stData.Config.nCapacityMax)
	                                                    AND (#arrudt_InOutStorage231[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage231[#n_Block23IDX].stData.Config.nCapacitySet)
	                                                    AND (#udt_InOutStorage231BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage231)
	                                                    AND (#arrudt_InOutStorage231[#n_Block23IDX].stData.Config.bByte.%X3)
	                                                    AND NOT (#arrudt_InOutStorage231[#n_Block23IDX].stData.Status.bByte.%X2)
	                                                    AND (NOT #xDestinationGranted)
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 23100;
	                                                    // #udt_InOutStorage231BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block3.xSection2301disabled AND #arrudt_InOutStorage232[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage232[#n_Block23IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage232[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage232[#n_Block23IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage232BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage232
	                                                    AND #arrudt_InOutStorage232[#n_Block23IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 23200;
	                                                    // #udt_InOutStorage232BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block3.xSection2302disabled AND #arrudt_InOutStorage233[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage233[#n_Block23IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage233[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage233[#n_Block23IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage233BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage233
	                                                    AND #arrudt_InOutStorage233[#n_Block23IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 23300;
	                                                    // #udt_InOutStorage233BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block3.xSection2302disabled AND #arrudt_InOutStorage234[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage234[#n_Block23IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage234[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage234[#n_Block23IDX].stData.Config.nCapacitySet
	                                                    AND #udt_InOutStorage234BlockData.nCountTotal < #udt_CapacityStorage.str_Level2.str_Block3.nCapacityStorage234
	                                                    AND #arrudt_InOutStorage234[#n_Block23IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 23400;
	                                                    // #udt_InOutStorage234BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                    
	                                                END_IF;
	                                            END_IF;
	                                            IF #n_Block23IDX = 21 (* AND #st_JamAreaCarrier.st_Data.nBarcode = 0 *)
	                                            THEN
	                                                #xInOutError := True;
	                                                #nInOutErrorID := #c020_KeinZielVerfuegbar;
	                                            END_IF;
	                                            
	                                        END_FOR;
	                                    END_REGION
	                                #c001_even:
	                                    REGION Even
	                                        //Minimale Befüllung in der Linie ermitteln 
	                                        #nTempMinBefuellungBlock3 := #arrudt_InOutStorage231[1].stData.Status.nCount;
	                                        FOR #nTempLinieIDX := 2 TO 12 DO
	                                            IF #arrudt_InOutStorage231[#nTempLinieIDX].stData.Status.nCount < #nTempMinBefuellungBlock3 THEN
	                                                #nTempMinBefuellungBlock3 := #arrudt_InOutStorage231[#nTempLinieIDX].stData.Status.nCount;
	                                            END_IF;
	                                            IF #arrudt_InOutStorage232[#nTempLinieIDX].stData.Status.nCount < #nTempMinBefuellungBlock3 THEN
	                                                #nTempMinBefuellungBlock3 := #arrudt_InOutStorage232[#nTempLinieIDX].stData.Status.nCount;
	                                            END_IF;
	                                            IF #arrudt_InOutStorage233[#nTempLinieIDX].stData.Status.nCount < #nTempMinBefuellungBlock3 THEN
	                                                #nTempMinBefuellungBlock3 := #arrudt_InOutStorage233[#nTempLinieIDX].stData.Status.nCount;
	                                            END_IF;
	                                            IF #arrudt_InOutStorage234[#nTempLinieIDX].stData.Status.nCount < #nTempMinBefuellungBlock3 THEN
	                                                #nTempMinBefuellungBlock3 := #arrudt_InOutStorage234[#nTempLinieIDX].stData.Status.nCount;
	                                            END_IF;
	                                        END_FOR;
	                                        
	                                        
	                                        
	                                        
	                                        
	                                        FOR #n_Block23IDX := 1 TO 21 DO
	                                            IF #n_Block23IDX >= 1 AND #n_Block23IDX <= 21
	                                            THEN
	                                                
	                                                IF NOT #st_AreaDisabledLevel2.str_Block3.xSection2301disabled AND #arrudt_InOutStorage231[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage231[#n_Block23IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage231[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage231[#n_Block23IDX].stData.Config.nCapacitySet
	                                                    AND #arrudt_InOutStorage231[#n_Block23IDX].stData.Status.nCount = #nTempMinBefuellungBlock3
	                                                    AND #arrudt_InOutStorage231[#n_Block23IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 23100;
	                                                    // #udt_InOutStorage231BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block3.xSection2301disabled AND #arrudt_InOutStorage232[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage232[#n_Block23IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage232[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage232[#n_Block23IDX].stData.Config.nCapacitySet
	                                                    AND #arrudt_InOutStorage232[#n_Block23IDX].stData.Status.nCount = #nTempMinBefuellungBlock3
	                                                    AND #arrudt_InOutStorage232[#n_Block23IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 23200;
	                                                    // #udt_InOutStorage232BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block3.xSection2302disabled AND #arrudt_InOutStorage233[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage233[#n_Block23IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage233[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage233[#n_Block23IDX].stData.Config.nCapacitySet
	                                                    AND #arrudt_InOutStorage233[#n_Block23IDX].stData.Status.nCount = #nTempMinBefuellungBlock3
	                                                    AND #arrudt_InOutStorage233[#n_Block23IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 23300;
	                                                    // #udt_InOutStorage233BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                ELSIF NOT #st_AreaDisabledLevel2.str_Block3.xSection2302disabled AND #arrudt_InOutStorage234[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage234[#n_Block23IDX].stData.Config.nCapacityMax
	                                                    AND #arrudt_InOutStorage234[#n_Block23IDX].stData.Status.nCount < #arrudt_InOutStorage234[#n_Block23IDX].stData.Config.nCapacitySet
	                                                    AND #arrudt_InOutStorage234[#n_Block23IDX].stData.Status.nCount = #nTempMinBefuellungBlock3
	                                                    AND #arrudt_InOutStorage234[#n_Block23IDX].stData.Config.bByte.%X3
	                                                    AND NOT #xDestinationGranted
	                                                THEN
	                                                    #st_JamAreaCarrier.st_Data.nDestination := 23400;
	                                                    // #udt_InOutStorage234BlockData.nCountReserved += 1;
	                                                    #xDestinationGranted := True;
	                                                    EXIT;
	                                                END_IF;
	                                            END_IF;
	                                            IF #n_Block23IDX = 21 AND #st_JamAreaCarrier.st_Data.nBarcode = 0
	                                            THEN
	                                                #xInOutError := True;
	                                                #nInOutErrorID := #c020_KeinZielVerfuegbar;
	                                            END_IF;
	                                        END_FOR;
	                                        
	                                    END_REGION
	                            END_CASE;
	                        END_IF;
	                    END_REGION
	                END_REGION
	                ;
	        END_CASE;
	        
	    END_IF;
	    
	    
	    
	END_REGION
	
	REGION Transfer Buffer Data to Jam Area Data
	    
	    // Übergabe des festgelegten Ziels an das Shuttle
	    // Suche muss über Barcode erneut erfolgen, das sich der Datensatz im Array verschiebt ->Array Element nicht konstant
	    IF #xDestinationGranted AND #st_JamAreaCarrier.st_Data.nDestination > 0
	    THEN
	        
	        
	        FOR #nTempTransferDataIDX := #n_LowerBound TO #n_UpperBound DO
	            IF #nIDWithoutDest = #arrudt_InOutJAM_Conv1_2[#nTempTransferDataIDX].nBarcode
	                AND #arrudt_InOutJAM_Conv1_2[#nTempTransferDataIDX].bStatus.%X1
	            THEN
	                #arrudt_InOutJAM_Conv1_2[#nTempTransferDataIDX].nDestination := #st_JamAreaCarrier.st_Data.nDestination;
	                #st_JamAreaCarrier := #st_JamAreaCarrierClear;
	            ELSIF #nIDWithoutDest = #arrudt_InOutJAM_Conv1_2[#nTempTransferDataIDX].nBarcode
	                AND NOT #arrudt_InOutJAM_Conv1_2[#nTempTransferDataIDX].bStatus.%X1
	            THEN
	                #arrudt_InOutJAM_Conv1_2[#nTempTransferDataIDX].nDestination := #st_JamAreaCarrier.st_Data.nDestination;
	                #st_JamAreaCarrier := #st_JamAreaCarrierClear;
	                #nIDWithoutDest := 0;
	                #xDestinationGranted := False;
	                #st_JamAreaCarrier.st_Data.nDestination := 0;
	            END_IF;
	        END_FOR;
	        
	        //Löschen des Buffer Eintrags
	        FOR #nTempDeleteBufferData := #n_LowerBoundBuffer TO #n_UpperBoundBuffer DO
	            IF #nIDWithoutDest = #arrudt_InOutCarrierBuffer[#nTempDeleteBufferData].stPayload.nBarcode
	            THEN
	                #arrudt_InOutCarrierBuffer[#nTempDeleteBufferData] := #st_BufferClear;
	                #xDestinationGranted := False;
	                #nIDWithoutDest := 0;
	                #st_JamAreaCarrier.st_Data.nDestination := 0;
	            
	            END_IF;
	        END_FOR;
	        
	    END_IF;
	    
	    
	END_REGION
	
	
	REGION Error 
	    
	    //Quit setzt Error Word zurück
	    IF #xInQuit
	    THEN
	        #xInOutError := False;
	    END_IF;
	    
	    IF #xInOutError AND #nInOutErrorID = #c010_CarrierDatenFehlerhaft
	    THEN
	        #wsErrorMessage1 := WString#'Carrier';
	        #wsErrorMessage2 := DINT_TO_WSTRING(#st_JamAreaCarrier.st_Data.nBarcode);
	        #wsErrorMessage3 := WSTRING#'Daten nicht eindeutig';
	    ELSIF #xInOutError AND #nInOutErrorID = #c020_KeinZielVerfuegbar
	    THEN
	        #wsErrorMessage1 := WString#'Carrier';
	        #wsErrorMessage2 := DINT_TO_WSTRING(#st_JamAreaCarrier.st_Data.nBarcode);
	        #wsErrorMessage3 := WSTRING#'kein Ziel verfuegbar';
	    ELSIF #xInOutError AND #nInOutErrorID = #c000_KeinFehler
	    THEN
	        #wsErrorMessage1 := WString#'';
	        #wsErrorMessage2 := WString#'';
	        #wsErrorMessage3 := WSTRING#'';
	        
	    END_IF;
	    
	    #PrgAlarm_Failmessage(SIG := #xInOutError,
	                          TIMESTAMP := #tTempLocalTime,
	                          SD_1 := #wsIn_ObjectName,
	                          SD_2 := #wsErrorMessage1,
	                          SD_3 := #wsErrorMessage2,
	                          SD_4 := #nInOutErrorID);
	    
	    
	    
	    
	    
	    
	END_REGION
	
	
	
	
END_FUNCTION_BLOCK

