FUNCTION_BLOCK "FB_Main"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_IN_OUT 
      stInOutControlUnitCabinet : "UDT_MainState";
   END_VAR

   VAR 
      fbCarousel4003 : "FB_Conveyor";
   END_VAR
   VAR RETAIN
      arCognexInterface { S7_SetPoint := 'False'} : Array[1.."cNoScanner"] of "stCognexInterface";
   END_VAR
   VAR 
      stCognexInterfaceDummy : "stCognexInterface";   // Als Platzhalter benutzen für TRO ohne Barcode-Leser
      stBarcodeReaderDummy : "UDT_BarcodeReader";
      TRO400 { S7_SetPoint := 'False'} : "FB_ILS_MTRO_Vario";
      TRO401 { S7_SetPoint := 'False'} : "FB_ILS_MTRO_Vario";
      TRO402 : "FB_ILS_MTRO_1Sep";
      TRO403 { S7_SetPoint := 'False'} : "FB_ILS_MTRO_Vario";
      TRO404 : "FB_ILS_MTRO_1Sep";
      TRO405 { S7_SetPoint := 'False'} : "FB_ILS_MTRO_1Sep1Swi";
      TRO406 : "FB_ILS_MTRO_1Sep";
      TRO407 : "FB_ILS_MTRO_1Sep1Swi";
      TRO408 : "FB_ILS_MTRO_Vario";
      TRO409 : "FB_ILS_MTRO_1Sep";
      TRO410 : "FB_ILS_MTRO_1Sep1Swi";
      TRO411 : "FB_ILS_MTRO_Vario";
      TRO412 : "FB_ILS_MTRO_1Sep";
      TRO413 : "FB_ILS_MTRO_1Sep1Swi";
      TRO414 { S7_SetPoint := 'False'} : "FB_ILS_MTRO_Vario";
      TRO415 : "FB_ILS_MTRO_1Sep";
      TRO416 : "FB_ILS_MTRO_1Sep";
      TRO417 : "FB_ILS_MTRO_1Sep";
      TRO418 : "FB_ILS_MTRO_Vario";
      TRO419 : "FB_ILS_MTRO_1Sep";
      TRO420 : "FB_ILS_MTRO_Vario";
      TRO421 : "FB_ILS_MTRO_Vario_workStation";
      TRO422 : "FB_ILS_MTRO_Vario_workStation";
      TRO423 : "FB_ILS_MTRO_Vario_workStation";
      TRO424 : "FB_ILS_MTRO_1Sep";
      fbBarcodeReaderBX4103 : "FB_BarcodeReaderCognex";
      xStartScan4103 : Bool;
      xHandshakeScanb4103 : Bool;
      nBarcodeReaderBX4103_Result : DInt;
      fbBarcodeReaderBX4105 : "FB_BarcodeReaderCognex";
      xStartScan4105 : Bool;
      xHandshakeScan4105 : Bool;
      nBarcodeReaderBX4105_Result : DInt;
      fbBarcodeReaderBX4107 : "FB_BarcodeReaderCognex";
      xStartScan4107 : Bool;
      xHandshakeScan4107 : Bool;
      nBarcodeReaderBX4107_Result : DInt;
      xReInit : Bool;
      rTrigReInit {InstructionName := 'R_TRIG'; LibVersion := '1.0'; S7_SetPoint := 'False'} : R_TRIG;
      "rTrig_Workstation 1" {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
      "rTrig_Workstation 2" {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
      "rTrig_Workstation 3" {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
   END_VAR

   VAR_TEMP 
      nActCar : Int;
      nActNo : Int;
      nNiu : DInt;
      stGenerateCarrier : "stCarrier";
      nCounter1 : DInt;
      xResult1 : Bool;
      nIdx : Int;
      nIdx2 : Int;
      nFound : Int;
      stEmptyCarrier : "stCarrier";
      stEmptyCarrierData : "stJamData";
      arCarrierPlaceHolder : Array[1..1] of "stCarrier";   // Platzhalter
      stJamDataPlaceHolder : "stJamData";
      stHMISwitchPlaceholder : "UDT_UnloadingStation";
      idx : Int;
      arEmptyStorageLine_1 : Int;
      arEmptyStorageLine : Array[1..1] of "stCarrier";
      t_automatik : Bool;
      arDummyEventCorrectionInfo : Array[0..1] of "stEventCorrectionInfo";
      tmpLaneStatus : Array[0..4] of String;
      arStCarrierLeaveControl : Array[1..1] of "stCarrier";
      stJamDataLeaveControl : "stJamData";
      arCarrier4010 : Array[1..1] of "stCarrier";   // Platzhalter
      stJamData4010 : "stJamData";
   END_VAR


BEGIN
	REGION Reinitialisieren
	    IF NOT #xReInit THEN
	        #xReInit := TRUE;
	    END_IF;
	    
	    #rTrigReInit(CLK := #xReInit);
	    
	    IF #rTrigReInit.Q THEN
	        
	        #TRO400.nState := "DB_GLOB_TroState".arTroState["cMainTro400"];
	        #TRO401.nState := "DB_GLOB_TroState".arTroState["cMainTro401"];
	        #TRO402.nState := "DB_GLOB_TroState".arTroState["cMainTro402"];
	        #TRO403.nState := "DB_GLOB_TroState".arTroState["cMainTro403"];
	        #TRO404.nState := "DB_GLOB_TroState".arTroState["cMainTro404"];
	        #TRO405.nState := "DB_GLOB_TroState".arTroState["cMainTro405"];
	        #TRO406.nState := "DB_GLOB_TroState".arTroState["cMainTro406"];
	        #TRO407.nState := "DB_GLOB_TroState".arTroState["cMainTro407"];
	        #TRO408.nState := "DB_GLOB_TroState".arTroState["cMainTro408"];
	        #TRO409.nState := "DB_GLOB_TroState".arTroState["cMainTro409"];
	        #TRO410.nState := "DB_GLOB_TroState".arTroState["cMainTro410"];
	        #TRO411.nState := "DB_GLOB_TroState".arTroState["cMainTro411"];
	        #TRO412.nState := "DB_GLOB_TroState".arTroState["cMainTro412"];
	        #TRO413.nState := "DB_GLOB_TroState".arTroState["cMainTro413"];
	        #TRO414.nState := "DB_GLOB_TroState".arTroState["cMainTro414"];
	        #TRO415.nState := "DB_GLOB_TroState".arTroState["cMainTro415"];
	        #TRO416.nState := "DB_GLOB_TroState".arTroState["cMainTro416"];
	        #TRO417.nState := "DB_GLOB_TroState".arTroState["cMainTro417"];
	        #TRO418.nState := "DB_GLOB_TroState".arTroState["cMainTro418"];
	        #TRO419.nState := "DB_GLOB_TroState".arTroState["cMainTro419"];
	        #TRO420.nState := "DB_GLOB_TroState".arTroState["cMainTro420"];
	        #TRO421.nState := "DB_GLOB_TroState".arTroState["cMainTro421"];
	        #TRO422.nState := "DB_GLOB_TroState".arTroState["cMainTro422"];
	        #TRO423.nState := "DB_GLOB_TroState".arTroState["cMainTro423"];
	        #TRO424.nState := "DB_GLOB_TroState".arTroState["cMainTro424"];
	        
	    END_IF;
	END_REGION
	
	REGION Automatik
	    #t_automatik := "DB_InterfaceSafety".stFromSafety.stMainContactorsUH04.Q;//#stInOutControlUnitCabinet.xRunning AND NOT #stInOutControlUnitCabinet.xStarting AND "DB_InterfaceSafety".stFromSafety.EStopMain.Q;
	END_REGION
	
	REGION Conveyors  
	    REGION KR-M4003 (Carousel)
	        #fbCarousel4003.xInRequestRun :=
	        "fbPreMain_DB".fbStateMain.nConveyorStartUpCounter = 100 OR
	        #stInOutControlUnitCabinet.xRestart OR
	        #TRO404.xOutCarouselReq OR
	        #TRO405.xOutCarouselReq1 OR
	        #TRO406.xOutCarouselReq OR
	        #TRO407.xOutCarouselReq1 OR
	        #TRO409.xOutCarouselReq OR
	        #TRO410.xOutCarouselReq1 OR
	        #TRO412.xOutCarouselReq OR
	        #TRO413.xOutCarouselReq1 OR
	        #TRO415.xOutCarouselReq OR
	        #TRO416.xOutCarouselReq OR
	        #TRO424.xOutCarouselReq OR 
	        #TRO417.xOutCarouselReq;
	        
	        #fbCarousel4003.Settings.tEnergySafeTime := "cTimeEnergySafe" + t#20s;
	        #fbCarousel4003.Settings.xGridActive := TRUE;
	        #fbCarousel4003.Settings.sMotorProtectName := 'FC0060';
	        #fbCarousel4003.Settings.sGridSenName := 'BG3432';
	        #fbCarousel4003(xInEnabled := "cTodoTRUE",
	                        xInGridSen := "DB_Inputs".Sensors["cInBG3432"].xDirectSensor,
	                        xInGridQuit := "SF0002",
	                        xInAutomaticMode := #t_automatik,
	                        xInMotorProtectionMonitoring := "FC0060",
	                        xOutPowerContactor => "MA0060",
	                        stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                        stInOutInterfaceHMI := "DB_Interface_HMI".stConveyors.stCarousel.stCar4003);
	    END_REGION
	END_REGION
	
	REGION TROs
	    
	    REGION TRO 400 (Vario) // Loaded to AMR
	        #TRO400.stInSeparator1.Settings.nSeparatorNo := "cSep400.1";
	        #TRO400.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO400.stInSeparator1.Settings.tHandlingTime := t#400ms;
	        #TRO400.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO400.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO400.stInSeparator1.Settings.xPluggedJam := FALSE;
	        #TRO400.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO400.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO400.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3260"];
	        
	        #TRO400.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO400.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO400.stInVario.stSenFinger := "DB_Inputs".Sensors["cInBG3262"]; //Finger in Pos
	        #TRO400.stInVario.stSenLastPos := "DB_Inputs".Sensors["cInBG3240"]; // Conveyor full
	        #TRO400.stInVario.stSenJam := "DB_Inputs".Sensors["cInBG3243"]; // Jam detector
	        #TRO400.stInVario.stSenCarrInPos := "DB_Inputs".Sensors["cInBG3261"]; // MT in Pos
	        
	        #TRO400.stInVario.Settings.xContinousEmptying := FALSE;
	        #TRO400.stInVario.Settings.tWaitForJog := T#300ms;
	        #TRO400.stInVario.Settings.tConvEmpty := T#40000ms;//T#8000ms;
	        #TRO400.stInVario.Settings.nCountCarrier := 1;
	        #TRO400.stInVario.Settings.tWaitForStop := T#3s;
	        
	        #TRO400.stInVario.Settings.tCarrierInPosDelay := t#1200ms;
	        #TRO400.stInVario.Settings.tCarrierInPosEdgeDelay := t#100ms;
	        
	        #TRO400.stInVario.Settings.tRasterHigh := T#5s;
	        #TRO400.stInVario.Settings.tRasterLow := T#5s;
	        
	        #TRO400.stInPriorityManager.xReleaseOk := TRUE; //keine Vorfahrtsregelung notwendig
	        
	        #TRO400.stInSettings.xIsBorner := TRUE;
	        #TRO400(nInMainTroNo := "cMainTro400",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInReset := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO400,
	                xInMotorProtection := "FC0070",
	                xInAutomatic := #t_automatik,
	                arInOutJamEntr := "DB_JamArea4000".stJam4000_1.arCarrier,
	                stInOutJamEntr := "DB_JamArea4000".stJam4000_1.stData,
	                arInOutJamFinger := "DB_JamArea4001".stJam4001_1.arCarrier,
	                stInOutJamFinger := "DB_JamArea4001".stJam4001_1.stData,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO400,
	                xOutStopper => "MB3260",
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro400"],
	                xOutVarioMotor => "MA0070");
	    END_REGION
	    
	    REGION TRO 401 (Vario)
	        #TRO401.stInSeparator1.Settings.nSeparatorNo := "cSep401.1";
	        #TRO401.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO401.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO401.stInSeparator1.Settings.tHandlingTime := t#400ms;
	        #TRO401.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO401.stInSeparator1.Settings.xPluggedJam := FALSE;
	        #TRO401.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO401.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO401.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3242"];
	        
	        #TRO401.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO401.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO401.stInVario.Settings.xContinousEmptying := FALSE;
	        #TRO401.stInVario.Settings.tWaitForJog := T#350ms;
	        #TRO401.stInVario.Settings.tConvEmpty := T#50000ms;
	        #TRO401.stInVario.Settings.nCountCarrier := 1;
	        #TRO401.stInVario.Settings.tWaitForStop := T#3s;
	        
	        #TRO401.stInVario.Settings.tCarrierInPosDelay := t#1200ms;
	        #TRO401.stInVario.Settings.tCarrierInPosEdgeDelay := t#100ms;
	        
	        #TRO401.stInVario.Settings.tRasterHigh := T#5s;
	        #TRO401.stInVario.Settings.tRasterLow := T#5s;
	        
	        #TRO401.stInVario.stSenFinger := "DB_Inputs".Sensors["cInBG3244"]; //Pusher Dog in Pos
	        #TRO401.stInVario.stSenLastPos := "DB_Inputs".Sensors["cInBG3245"]; // Conveyor full
	        #TRO401.stInVario.stSenJam := "DB_Inputs".Sensors["cInBG3246"]; // Jam detector
	        #TRO401.stInVario.stSenCarrInPos := "DB_Inputs".Sensors["cInBG3241"]; // MT in Pos
	        
	        #TRO401.stInPriorityManager.xReleaseOk := TRUE; //keine Vorfahrtsregelung notwendig
	        
	        #TRO401(nInMainTroNo := "cMainTro401",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInReset := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO401,
	                xInMotorProtection := "FC0071",
	                xInAutomatic := #t_automatik,
	                arInOutJamEntr := "DB_JamArea4001".stJam4001_1.arCarrier,
	                stInOutJamEntr := "DB_JamArea4001".stJam4001_1.stData,
	                arInOutJamFinger := "DB_JamArea4001".stJam4001_2.arCarrier,
	                stInOutJamFinger := "DB_JamArea4001".stJam4001_2.stData,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO401,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                xOutStopper => "MB3242",
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro401"],
	                xOutVarioMotor => "MA0071");
	        
	        
	    END_REGION
	    
	    REGION TRO 402 (1Sep) (Vor Brandschutztor)
	        #TRO402.stInSeparator1.Settings.nSeparatorNo := "cSep402.1";
	        #TRO402.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO402.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO402.stInSeparator1.Settings.tHandlingTime := t#400ms;
	        #TRO402.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO402.stInSeparator1.Settings.xPluggedJam := TRUE;
	        #TRO402.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO402.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO402.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3247"];
	        #TRO402.stInSenJam2 := "DB_Inputs".Sensors["cInBG3423"];
	        
	        #TRO402.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO402.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO402.stInPriorityManager.xReleaseOk := "cTodoTRUE";
	        
	        #TRO402(nInMainTroNo := "cMainTro402",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInCancel := "cTodoFalse",
	                xInCarouselRun := TRUE, //Gefälle
	                xInRelease := "DB_TRO_Test".TRO402,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                arInOutJamEntr1 := "DB_JamArea4001".stJam4001_2.arCarrier,
	                stInOutJamEntr1 := "DB_JamArea4001".stJam4001_2.stData,
	                arInOutJamExit2 := "DB_JamArea4002".stJam4002_1.arCarrier,
	                stInOutJamExit2 := "DB_JamArea4002".stJam4002_1.stData,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro402"],
	                xOutStopper1 => "MB3247",
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO402);
	        
	    END_REGION
	    
	    REGION TRO 403 (Vario)
	        #TRO403.stInSeparator1.Settings.nSeparatorNo := "cSep403.1";
	        #TRO403.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO403.stInSeparator1.Settings.tHandlingTime := t#400ms;
	        #TRO403.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO403.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO403.stInSeparator1.Settings.xPluggedJam := FALSE;
	        #TRO403.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO403.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO403.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3420"];
	        
	        #TRO403.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO403.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO403.stInVario.stSenFinger := "DB_Inputs".Sensors["cInBG3421"]; //Finger in Pos
	        #TRO403.stInVario.stSenLastPos := "DB_Inputs".Sensors["cInBG3390"]; // Conveyor full
	        #TRO403.stInVario.stSenJam := "DB_Inputs".Sensors["cInBG3387"]; // Jam detector
	        #TRO403.stInVario.stSenCarrInPos := "DB_Inputs".Sensors["cInBG3426"]; // MT in Pos
	        
	        #TRO403.stInVario.Settings.xContinousEmptying := FALSE;
	        #TRO403.stInVario.Settings.tWaitForJog := T#400ms;
	        #TRO403.stInVario.Settings.tConvEmpty := t#20s;//T#8000ms;
	        #TRO403.stInVario.Settings.nCountCarrier := 1;
	        #TRO403.stInVario.Settings.tWaitForStop := T#3s;
	        
	        #TRO403.stInVario.Settings.tCarrierInPosDelay := t#1200ms;
	        #TRO403.stInVario.Settings.tCarrierInPosEdgeDelay := t#100ms;
	        
	        #TRO403.stInVario.Settings.tRasterHigh := T#5s;
	        #TRO403.stInVario.Settings.tRasterLow := T#5s;
	        
	        #TRO403.stInPriorityManager.xReleaseOk := TRUE; //keine Vorfahrtsregelung notwendig
	        
	        #TRO403(nInMainTroNo := "cMainTro403",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInReset := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO403,
	                xInMotorProtection := "FC0073",
	                xInAutomatic := #t_automatik,
	                arInOutJamEntr := "DB_JamArea4002".stJam4002_1.arCarrier,
	                stInOutJamEntr := "DB_JamArea4002".stJam4002_1.stData,
	                arInOutJamFinger := "DB_JamArea4002".stJam4002_2.arCarrier,
	                stInOutJamFinger := "DB_JamArea4002".stJam4002_2.stData,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO403,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro403"],
	                xOutStopper => "MB3420",
	                xOutVarioMotor => "MA0073");
	        
	    END_REGION
	    
	    REGION TRO 404 (1Sep)
	        
	        #TRO404.stInSeparator1.Settings.nSeparatorNo := "cSep404.1";
	        #TRO404.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO404.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO404.stInSeparator1.Settings.tHandlingTime := t#400ms;
	        #TRO404.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO404.stInSeparator1.Settings.xPluggedJam := TRUE;
	        #TRO404.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO404.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO404.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3386"];
	        #TRO404.stInSenJam2 := "DB_Inputs".Sensors["cInBG3367"];
	        
	        IF "DB_JamArea4002".stJam4002_2.arCarrier[1].nBarcode > 0 THEN
	            "DB_JamArea4002".stJam4002_2.arCarrier[1].bStatus.%X1 := TRUE; //Wir nehmen erstmal an, dass alles, was vom Highway kommt, beladen ist. TRO405 kontrolliert nach
	        ELSE
	            "DB_JamArea4002".stJam4002_2.arCarrier[1].bStatus.%X1 := FALSE;
	        END_IF;
	        
	        #TRO404.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO404.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO404(stInPriorityManager := "DB_Prozessdaten".stPriorityManager.udt_TRO404.TroIn,
	                stOutPriorityManager => "DB_Prozessdaten".stPriorityManager.udt_TRO404.TroOut,
	                nInMainTroNo := "cMainTro404",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInCancel := "cTodoFalse",
	                xInCarouselRun := #fbCarousel4003.xOutConveyorFullSpeed,
	                xInRelease := NOT "FB_CallAMRManagement_DB".Lfb_AMRManagement.xOutStopFeed,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                arInOutJamEntr1 := "DB_JamArea4002".stJam4002_2.arCarrier,
	                stInOutJamEntr1 := "DB_JamArea4002".stJam4002_2.stData,
	                arInOutJamExit2 := "DB_JamArea4003".stJam4003_8.arCarrier,
	                stInOutJamExit2 := "DB_JamArea4003".stJam4003_8.stData,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro404"],
	                xOutStopper1 => "MB3386",
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO404);
	    END_REGION
	    REGION TEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	        // "DB_JamArea4003".stJam4003_1.arCarrier[1].nDestination := "cDestLeaveAmr";
	    END_REGION
	    
	    REGION TRO 405 (1Sep1Switch) + Scanner (BX4100) + Behangskontrolle
	        //TYP ÄNDERN MIT PART SENSOR LOGIK!!!!!!
	        #TRO405.stInSeparator1.Settings.nSeparatorNo := "cSep405.1";
	        #TRO405.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO405.stInSeparator1.Settings.tTrailingTime := t#0ms;
	        #TRO405.stInSeparator1.Settings.tHandlingTime := t#0ms;
	        #TRO405.stInSeparator1.Settings.xPluggedJam := TRUE;
	        #TRO405.stInSeparator1.Settings.xPluggedPart := TRUE;
	        #TRO405.stInSeparator1.Settings.xPluggedScanner := TRUE;
	        #TRO405.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3360"];
	        #TRO405.stInSeparator1.stSenPart := "DB_Inputs".Sensors["cInBG3361"];
	        #TRO405.stInSenJam2 := "DB_Inputs".Sensors["cInBG3362"];
	        #TRO405.stInSenJam3 := "DB_Inputs".Sensors["cInBG3301"];
	        
	        #TRO405.stInSwitch1.Settings.nSwitchNo := "cSwi405.1";
	        #TRO405.stInSwitch1.Settings.xPluggedExSen3 := FALSE;
	        #TRO405.stInSwitch1.Settings.xPluggedExSen4 := FALSE;
	        #TRO405.stInSwitch1.Settings.tTransitEx := T#5s;
	        #TRO405.stInSwitch1.Settings.nTo1Destinations := 3; //Info nötig für HMI
	        
	        #TRO405.stInBarcodeReader.Settings.xActivateCheckASCI := TRUE;
	        #TRO405.stInBarcodeReader.Settings.tTimeout := T#5s;
	        
	        #arCognexInterface["cScannerBX4100"].xInCamTriggerReady := "bx4100-TriggerReady";
	        #arCognexInterface["cScannerBX4100"].xInCamTriggerAck := "bx4100-TriggerAck";
	        #arCognexInterface["cScannerBX4100"].xInCamResultsAvailable := "bx4100-Results Available";
	        #arCognexInterface["cScannerBX4100"].xInCamGeneralFault := "bx4100-General Fault";
	        #arCognexInterface["cScannerBX4100"].hwInCamInspectionResults := "BX4100~Ergebnisse_–_64_Bytes_1";
	        
	        #stJamData4010.Config.nCapacitySet := 1;
	        
	        #TRO405.stInPriorityManagerDir1.xReleaseOk := TRUE; //Keine Vorfahrtsregelung notwendig
	     //   #TRO405.stInSettings.bSepType.%X1 := TRUE;
	        #TRO405.stInSettings.bSepType.%X2 := TRUE;
	        #TRO405(nInMainTroNo := "cMainTro405",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInCancel := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO405,
	                xInCarouselRun1 := #fbCarousel4003.xOutConveyorFullSpeed,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO405,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #arCognexInterface["cScannerBX4100"],
	                arInOutJamEntr1 := "DB_JamArea4003".stJam4003_1.arCarrier,
	                stInOutJamEntr1 := "DB_JamArea4003".stJam4003_1.stData,
	                arInOutJamExit2 := #arCarrier4010, //"DB_JamArea4010".stJam4010_1.arCarrier,
	                stInOutJamExit2 := #stJamData4010, //"DB_JamArea4010".stJam4010_1.stData,
	                arInOutJamExit3 := "DB_JamArea4003".stJam4003_2.arCarrier,
	                stInOutJamExit3 := "DB_JamArea4003".stJam4003_2.stData,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro405"],
	                xOutStopper1 => "MB3360",
	                xOutSw1ExTo3 => "MB3362");
	        
	        IF #TRO405.nState = 1400 THEN
	            IF #TRO405.xTrolleyWithPart AND "DB_JamArea4003".stJam4003_1.arCarrier[1].nDestination = "cDestLeaveAmr" THEN
	                "DB_JamArea4003".stJam4003_1.arCarrier[1].nDestination := "cDestStayAmr";
	         //    ELSE
	            
	           // "DB_JamArea4003".stJam4003_1.arCarrier[1].nDestination := "cDestLeaveAmr";
	            ELSIF #TRO405.xTrolleyWoPart THEN //auskommentiert für test mit leercarriern
	                "DB_JamArea4003".stJam4003_1.arCarrier[1].nDestination := "cDestLeaveAmr" ; //leave
	            END_IF;
	        END_IF;
	        
	        "bx4100-TriggerEnable" := #arCognexInterface["cScannerBX4100"].xOutCamTriggerEnable;
	        "bx4100-Trigger" := #arCognexInterface["cScannerBX4100"].xOutCamTrigger;
	        "bx4100-ResultsAck" := #arCognexInterface["cScannerBX4100"].xOutCamResultsAck;
	        
	        REGION Carr_Glob_Correction            
	            "FC_CARR_GLOB_CORRECTION"(xInStart := #TRO405.xOutCorrection, //Führe Korrektur aus
	                                      nInBarcodeScan := #TRO405.nBarcodeResult,
	                                      nInStation := 0,
	                                      arOutEventLogInfo => #arDummyEventCorrectionInfo,
	                                      InOutCarrierExpect := "DB_JamArea4003".stJam4003_1.arCarrier[1]);
	        END_REGION
	        
	        REGION Direction
	            "FC_Direction"(nInSwitchNo := "cSwi405.1",
	                           nOutDirection => #TRO405.nInDirection,
	                           InOutCarrier := "DB_JamArea4003".stJam4003_1.arCarrier[1]);
	            
	        END_REGION
	        
	        REGION Loaded MT: Send DReqM to Fortna WCS
	            IF #TRO405.xOutNewScan AND "DB_Test".xCommuActive THEN
	                
	                #tmpLaneStatus[0] := "FC_Get_LaneStatus"(stInOutJamData := "DB_JamArea4004"."stJam4004_1".stData,
	                                                         stInOutWorkStation := "DB_Prozessdaten".stWorkStations.stMPS1);
	                #tmpLaneStatus[1] := "FC_Get_LaneStatus"(stInOutJamData := "DB_JamArea4006"."stJam4006_1".stData,
	                                                         stInOutWorkStation := "DB_Prozessdaten".stWorkStations.stMPS2);
	                #tmpLaneStatus[2] := "FC_Get_LaneStatus"(stInOutJamData := "DB_JamArea4008"."stJam4008_1".stData,
	                                                         stInOutWorkStation := "DB_Prozessdaten".stWorkStations.stMPS3);
	                
	                "FC_Send_GOHDReqM"(sInPLCID := "cPLCID",
	                                   xInSSCCReq := FALSE,
	                                   xInLengthReq := FALSE,
	                                   xInDockDoorReq := FALSE,
	                                   xInLaneStatusReq := TRUE,
	                                   nInBarcode := #TRO405.nOutScanResult,
	                                   sInSSCC := '',
	                                   sInDecisionPoint := 'GOH.Decant.01', //todo
	                                   sInDockDoor := '',
	                                   sInLengthInfo := '',
	                                   arInLaneStatus := #tmpLaneStatus,
	                                   nInLaneCnt := 3,
	                                   FIFO := "DB_LGF_FIFO_CommWCSBL",
	                                   BUFFER := "DB_Buffer_CommunicationWCSBL".BUFFER,
	                                   nInOutSequenceNumber:="DB_CommunicationParameters".nSeqNumWESDeviceHub);
	            END_IF;
	        END_REGION
	        
	        REGION Provisorium - Zielvorgabe
	            IF "DB_Test".nBatchCounter > 5 THEN
	                "DB_Test".nBatchCounter := 1;
	                "DB_Test".nTargetTest += 1;
	                IF "DB_Test".nTargetTest > 3 THEN
	                    "DB_Test".nTargetTest := 1;
	                END_IF;
	            END_IF;
	            
	            IF #TRO405.nState = 1500 AND #TRO405.fbSeparator1.xOutTrolleyReleasedEdge AND "DB_JamArea4003".stJam4003_1.arCarrier[1].bStatus.%X0 AND "DB_JamArea4003".stJam4003_1.arCarrier[1].nDestination <> "cDestLeaveAmr"(* AND "DB_JamArea4003".stJam4003_1.arCarrier[1].bStatus.%X1 *) THEN //Nur beladene ankündigen
	                "DB_Handshake".udtIn_TeleDataFromMES.stPayload.nBarcode := #TRO405.nOutScanResult;
	                
	                IF "DB_Test".nTargetTest = 1 THEN
	                    "DB_Handshake".udtIn_TeleDataFromMES.stPayload.arActions[0] := '1';
	                    "DB_Handshake".udtIn_TeleDataFromMES.stPayload.arActions[1] := '1';
	                ELSIF "DB_Test".nTargetTest = 2 THEN
	                    "DB_Handshake".udtIn_TeleDataFromMES.stPayload.arActions[0] := '2';
	                    "DB_Handshake".udtIn_TeleDataFromMES.stPayload.arActions[1] := '2';
	                ELSIF "DB_Test".nTargetTest = 3 THEN
	                    "DB_Handshake".udtIn_TeleDataFromMES.stPayload.arActions[0] := '3';
	                    "DB_Handshake".udtIn_TeleDataFromMES.stPayload.arActions[1] := '3';
	                END_IF;
	                
	                // "DB_Handshake".udtIn_TeleDataFromMES.stPayload.arActions[0] := INT_TO_CHAR(IN := "DB_Test".nTargetTest);
	                // "DB_Handshake".udtIn_TeleDataFromMES.stPayload.arActions[1] := INT_TO_CHAR(IN := "DB_Test".nTargetTest);
	                
	                "DB_Test".nBatchCounter += 1;
	                
	                "DB_Handshake".udt_HandshakeMESStorage.str_Ctrl.xNewDataAvaible := TRUE;
	            END_IF;
	            
	            IF "DB_Handshake".udt_HandshakeMESStorage.str_Status.xNewDataSaved
	            THEN
	                "DB_Handshake".udt_HandshakeMESStorage.str_Ctrl.xNewDataAvaible := FALSE;
	            END_IF;
	            
	        END_REGION ;
	        
	(*        IF #TRO405.xOutBookedDir2 AND "DB_Test".xCommuActive THEN
	            "FC_Send_GOHDUM"(sInPLCID := "cPLCID",
	                             nInBarcode := #TRO405.stOutLastCarrier.nBarcode,
	                             sInDecisionPoint := 'GOH.Decant.01',
	                             sInActionTaken := '1', 
	                             nReasonCode := 1,
	                             FIFO := "DB_LGF_FIFO_CommWCSBL",
	                             BUFFER := "DB_Buffer_CommunicationWCSBL".BUFFER,
	                             nInOutSequenceNumber := "DB_CommunicationParameters".nSeqNumWCSBL);
	        END_IF; *)
	        
	        
	    END_REGION
	    
	    
	    REGION TRO 406 (1Sep) + Scanner (BX4101)
	        
	        #TRO406.stInSeparator1.Settings.nSeparatorNo := "cSep406.1";
	        #TRO406.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Medium";
	        #TRO406.stInSeparator1.Settings.tTrailingTime := t#0ms;
	        #TRO406.stInSeparator1.Settings.tHandlingTime := t#0ms;
	        #TRO406.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO406.stInSeparator1.Settings.xPluggedJam := TRUE;
	        #TRO406.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO406.stInSeparator1.Settings.xPluggedScanner := TRUE;
	        #TRO406.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3300"];
	        #TRO406.stInSenJam2 := "DB_Inputs".Sensors["cInBG3303"];
	        
	        #TRO406.stInBarcodeReader.Settings.xActivateCheckASCI := TRUE;
	        #TRO406.stInBarcodeReader.Settings.tTimeout := T#5s;
	        
	        #arCognexInterface["cScannerBX4101"].xInCamTriggerReady := "bx4101-TriggerReady";
	        #arCognexInterface["cScannerBX4101"].xInCamTriggerAck := "bx4101-TriggerAck";
	        #arCognexInterface["cScannerBX4101"].xInCamResultsAvailable := "bx4101-Results Available";
	        #arCognexInterface["cScannerBX4101"].xInCamGeneralFault := "bx4101-General Fault";
	        #arCognexInterface["cScannerBX4101"].hwInCamInspectionResults := "BX4101~Ergebnisse_–_64_Bytes_1";
	        
	        #TRO406.stInPriorityManager.xReleaseOk := TRUE; //keine Vorfahrtsregelung notwendig
	        
	       
	        
	        #TRO406(nInMainTroNo := "cMainTro406",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInCancel := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO406, //todo:Dieser TRO kann aufhören etwas loszuschicken, wenn alle Stationen voll sind, weil wir dann nur noch sinnlos rotieren und immer wieder probieren
	                xInCarouselRun := #fbCarousel4003.xOutConveyorFullSpeed,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #arCognexInterface["cScannerBX4101"],
	                arInOutJamEntr1 := "DB_JamArea4003".stJam4003_2.arCarrier,
	                stInOutJamEntr1 := "DB_JamArea4003".stJam4003_2.stData,
	                arInOutJamExit2 := "DB_JamArea4003".stJam4003_3.arCarrier,
	                stInOutJamExit2 := "DB_JamArea4003".stJam4003_3.stData,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO406,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro406"],
	                xOutStopper1 => "MB3300");
	        
	        "bx4101-TriggerEnable" := #arCognexInterface["cScannerBX4101"].xOutCamTriggerEnable;
	        "bx4101-Trigger" := #arCognexInterface["cScannerBX4101"].xOutCamTrigger;
	        "bx4101-ResultsAck" := #arCognexInterface["cScannerBX4101"].xOutCamResultsAck;
	        
	        REGION Carr_Glob_Correction            
	            "FC_CARR_GLOB_CORRECTION"(xInStart := #TRO406.xOutCorrection, //Führe Korrektur aus
	                                      nInBarcodeScan := #TRO406.nBarcodeResult,
	                                      nInStation := 0,
	                                      arOutEventLogInfo => #arDummyEventCorrectionInfo,
	                                      InOutCarrierExpect := "DB_JamArea4003".stJam4003_2.arCarrier[1]);
	        END_REGION
	        
	        REGION AMR Management Schnittstelle
	            IF #TRO406.xOutNewScan THEN
	                "DB_Handshake".str_TROScan.udt_InTro406Scan.nBarcode := #TRO406.nOutScanResult;
	            END_IF;
	            
	            IF #TRO406.nState = 2000 OR #TRO406.nState = 1500 THEN
	                "DB_Handshake".str_TROs.udt_TRO406.udt_State.xReady := TRUE;
	            ELSE
	                "DB_Handshake".str_TROs.udt_TRO406.udt_State.xReady := FALSE;
	            END_IF;
	        END_REGION
	        
	    END_REGION
	    
	    REGION TRO 407 (1Sep1Switch) + Scanner (BX4102)
	        #TRO407.stInSeparator1.Settings.nSeparatorNo := "cSep407.1";
	        #TRO407.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO407.stInSeparator1.Settings.tTrailingTime := t#0ms;
	        #TRO407.stInSeparator1.Settings.tHandlingTime := t#0ms;
	        #TRO407.stInSeparator1.Settings.xPluggedJam := TRUE;
	        #TRO407.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO407.stInSeparator1.Settings.xPluggedScanner := TRUE;
	        #TRO407.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3304"];
	        #TRO407.stInSenJam2 := "DB_Inputs".Sensors["cInBG3311"];
	        #TRO407.stInSenJam3 := "DB_Inputs".Sensors["cInBG3322"];
	        
	        #TRO407.stInSwitch1.Settings.nSwitchNo := "cSwi407.1";
	        #TRO407.stInSwitch1.Settings.xPluggedExSen3 := FALSE;
	        #TRO407.stInSwitch1.Settings.xPluggedExSen4 := FALSE;
	        #TRO407.stInSwitch1.Settings.tTransitEx := T#5s;
	        #TRO407.stInSwitch1.Settings.nTo1Destinations := 3; //Info nötig für HMI
	        
	        #TRO407.stInBarcodeReader.Settings.xActivateCheckASCI := TRUE;
	        #TRO407.stInBarcodeReader.Settings.tTimeout := T#5s;
	        
	        #arCognexInterface["cScannerBX4102"].xInCamTriggerReady := "bx4102-TriggerReady";
	        #arCognexInterface["cScannerBX4102"].xInCamTriggerAck := "bx4102-TriggerAck";
	        #arCognexInterface["cScannerBX4102"].xInCamResultsAvailable := "bx4102-Results Available";
	        #arCognexInterface["cScannerBX4102"].xInCamGeneralFault := "bx4102-General Fault";
	        #arCognexInterface["cScannerBX4102"].hwInCamInspectionResults := "BX4102~Ergebnisse_–_64_Bytes_1";
	        
	        #TRO407.stInSettings.xPrioDir2 := TRUE;
	        #TRO407(stInPriorityManagerDir2 := "DB_Prozessdaten".stPriorityManager.udt_TRO407.TroIn,
	                stOutPriorityManagerDir2 => "DB_Prozessdaten".stPriorityManager.udt_TRO407.TroOut,
	                nInMainTroNo := "cMainTro407",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInCancel := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO407,
	                xInCarouselRun1 := #fbCarousel4003.xOutConveyorFullSpeed,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO407,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #arCognexInterface["cScannerBX4102"],
	                arInOutJamEntr1 := "DB_JamArea4003".stJam4003_3.arCarrier,
	                stInOutJamEntr1 := "DB_JamArea4003".stJam4003_3.stData,
	                arInOutJamExit2 := "DB_JamArea4004".stJam4004_1.arCarrier,
	                stInOutJamExit2 := "DB_JamArea4004".stJam4004_1.stData,
	                arInOutJamExit3 := "DB_JamArea4003".stJam4003_4.arCarrier,
	                stInOutJamExit3 := "DB_JamArea4003".stJam4003_4.stData,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro407"],
	                xOutStopper1 => "MB3304",
	                xOutSw1ExTo3 => "MB3306");
	        
	        "bx4102-TriggerEnable" := #arCognexInterface["cScannerBX4102"].xOutCamTriggerEnable;
	        "bx4102-Trigger" := #arCognexInterface["cScannerBX4102"].xOutCamTrigger;
	        "bx4102-ResultsAck" := #arCognexInterface["cScannerBX4102"].xOutCamResultsAck;
	        
	        REGION Carr_Glob_Correction            
	            "FC_CARR_GLOB_CORRECTION"(xInStart := #TRO407.xOutCorrection, //Führe Korrektur aus
	                                      nInBarcodeScan := #TRO407.nBarcodeResult,
	                                      nInStation := 0,
	                                      arOutEventLogInfo => #arDummyEventCorrectionInfo,
	                                      InOutCarrierExpect := "DB_JamArea4003".stJam4003_3.arCarrier[1]);
	        END_REGION
	        
	        REGION Direction
	            "FC_Direction"(nInSwitchNo := "cSwi407.1",
	                           nOutDirection => #TRO407.nInDirection,
	                           InOutCarrier := "DB_JamArea4003".stJam4003_3.arCarrier[1]);
	        END_REGION
	        
	        REGION Recirce
	            IF #TRO407.nState = 2400 AND #TRO407.fbStateManager.tOutTimeInStep > T#15s THEN //Steckt in CheckJam fest, weil kein Platz in der Station + Zeit vergangen
	                "DB_JamArea4003".stJam4003_3.arCarrier[1].nDestination := "cDestRecirc"; // Ziel zum Rotieren um nicht zu Blockieren
	                #TRO407.nState := 2000; //Hole nochmal die Direction 
	            END_IF;
	            
	        END_REGION
	        
	        REGION Send DUM to Fortna WCS
	            IF #TRO407.xOutBookedDir1 THEN
	                "FC_Send_GOHDUM"(sInPLCID := "cPLCID",
	                                 nInBarcode := #TRO407.stOutLastCarrier.nBarcode,
	                                 sInDecisionPoint := 'GOH.Decant.01',
	                                 sInActionTaken := '2', //todo? Am besten eine Konstantentabelle anlegen aus Infos von Spezifikation
	                                 nReasonCode := 1, //todo?
	                                 FIFO := "DB_LGF_FIFO_CommWCSBL",
	                                 BUFFER := "DB_Buffer_CommunicationWCSBL".BUFFER,
	                                 nInOutSequenceNumber := "DB_CommunicationParameters".nSeqNumWCSBL);
	            END_IF;
	            
	            
	        END_REGION
	        
	        
	    END_REGION
	    
	    REGION TRO 408 (Vario) 
	        #TRO408.stInSeparator1.Settings.nSeparatorNo := "cSep408.1";
	        #TRO408.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO408.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO408.stInSeparator1.Settings.tHandlingTime := t#200ms;
	        #TRO408.stInSeparator1.Settings.tJam := "TimeForSepJam";
	
	        #TRO408.stInSeparator1.Settings.xPluggedJam := FALSE;
	        #TRO408.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO408.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO408.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3310"];
	        
	        #TRO408.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO408.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO408.stInVario.Settings.xContinousEmptying := FALSE;
	        #TRO408.stInVario.Settings.tWaitForJog := T#400ms;
	        #TRO408.stInVario.Settings.tConvEmpty := t#15000ms;//T#8000ms;
	        #TRO408.stInVario.Settings.nCountCarrier := 1;
	        #TRO408.stInVario.Settings.tWaitForStop := T#3s;
	        #TRO408.stInVario.Settings.tCarrierInPosDelay := t#1200ms;
	        
	        #TRO408.stInVario.stSenFinger := "DB_Inputs".Sensors["cInBG3312"]; //Finger in Pos
	        #TRO408.stInVario.stSenLastPos := "DB_Inputs".Sensors["cInBG3313"]; // Conveyor full
	        #TRO408.stInVario.stSenJam := "DB_Inputs".Sensors["cInBG3327"]; // Jam
	        #TRO408.stInVario.stSenCarrInPos := "DB_Inputs".Sensors["cInBG3316"]; // MT in Position
	        
	        #TRO408.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO408.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO408.stInVario.Settings.tCarrierInPosDelay := t#1200ms;
	        #TRO408.stInVario.Settings.tCarrierInPosEdgeDelay := t#100ms;
	        
	        #TRO408.stInPriorityManager.xReleaseOk := TRUE; //braucht keine Vorfahrtsregelung
	        
	        #TRO408(nInMainTroNo := "cMainTro408",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInReset := "cTodoFalse",
	                xInMotorProtection := "FC0061",
	                xInAutomatic := #t_automatik,
	                xInRelease := "DB_TRO_Test".TRO408,
	                arInOutJamEntr := "DB_JamArea4004".stJam4004_1.arCarrier,
	                stInOutJamEntr := "DB_JamArea4004".stJam4004_1.stData,
	                arInOutJamFinger := "DB_JamArea4004".stJam4004_2.arCarrier,
	                stInOutJamFinger := "DB_JamArea4004"."stJam4004_2".stData,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO408,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro408"],
	                xOutStopper => "MB3310",
	                xOutVarioMotor => "MA0061");
	        
	       
	    END_REGION
	    
	    REGION TRO 409 (1Sep)
	        #TRO409.stInSeparator1.Settings.nSeparatorNo := "cSep409.1";
	        #TRO409.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO409.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO409.stInSeparator1.Settings.tHandlingTime := t#200ms;
	        #TRO409.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO409.stInSeparator1.Settings.xPluggedJam := TRUE;
	        #TRO409.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO409.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO409.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3321"];
	        #TRO409.stInSenJam2 := "DB_Inputs".Sensors["cInBG3322"];
	        
	        #TRO409.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO409.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO409(stInPriorityManager := "DB_Prozessdaten".stPriorityManager.udt_TRO409.TroIn,
	                stOutPriorityManager => "DB_Prozessdaten".stPriorityManager.udt_TRO409.TroOut,
	                nInMainTroNo := "cMainTro409",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInCancel := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO409,
	                xInCarouselRun := #fbCarousel4003.xOutConveyorFullSpeed,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                arInOutJamEntr1 := "DB_JamArea4005"."stJam4005_1".arCarrier,
	                stInOutJamEntr1 := "DB_JamArea4005".stJam4005_1.stData,
	                arInOutJamExit2 := "DB_JamArea4003".stJam4003_4.arCarrier,
	                stInOutJamExit2 := "DB_JamArea4003".stJam4003_4.stData,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO409,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro409"],
	                xOutStopper1 => "MB3321");
	        
	    END_REGION
	    
	    REGION TRO 410 (1Sep1Switch) + Scanner (BX4104)
	        
	        #TRO410.stInSeparator1.Settings.nSeparatorNo := "cSep410.1";
	        #TRO410.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO410.stInSeparator1.Settings.tTrailingTime := t#0ms;
	        #TRO410.stInSeparator1.Settings.tHandlingTime := t#0ms;
	        #TRO410.stInSeparator1.Settings.xPluggedJam := TRUE;
	        #TRO410.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO410.stInSeparator1.Settings.xPluggedScanner := TRUE;
	        #TRO410.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3363"];
	        #TRO410.stInSenJam2 := "DB_Inputs".Sensors["cInBG3371"];
	        #TRO410.stInSenJam3 := "DB_Inputs".Sensors["cInBG3382"];
	        
	        #TRO410.stInSwitch1.Settings.nSwitchNo := "cSwi410.1";
	        #TRO410.stInSwitch1.Settings.xPluggedExSen3 := FALSE;
	        #TRO410.stInSwitch1.Settings.xPluggedExSen4 := FALSE;
	        #TRO410.stInSwitch1.Settings.tTransitEx := T#5s;
	        #TRO410.stInSwitch1.Settings.nTo1Destinations := 3; //Info nötig für HMI
	        
	        #TRO410.stInBarcodeReader.Settings.xActivateCheckASCI := TRUE;
	        #TRO410.stInBarcodeReader.Settings.tTimeout := T#5s;
	        
	        #arCognexInterface["cScannerBX4104"].xInCamTriggerReady := "bx4104-TriggerReady";
	        #arCognexInterface["cScannerBX4104"].xInCamTriggerAck := "bx4104-TriggerAck";
	        #arCognexInterface["cScannerBX4104"].xInCamResultsAvailable := "bx4104-Results Available";
	        #arCognexInterface["cScannerBX4104"].xInCamGeneralFault := "bx4104-General Fault";
	        #arCognexInterface["cScannerBX4104"].hwInCamInspectionResults := "BX4104~Ergebnisse_–_64_Bytes_1";
	        
	        #TRO410.stInSettings.xPrioDir2 := TRUE;
	        
	        #TRO410(stInPriorityManagerDir2 := "DB_Prozessdaten".stPriorityManager.udt_TRO410.TroIn,
	                stOutPriorityManagerDir2 => "DB_Prozessdaten".stPriorityManager.udt_TRO410.TroOut,
	                nInMainTroNo := "cMainTro410",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInCancel := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO410,
	                xInCarouselRun1 := #fbCarousel4003.xOutConveyorFullSpeed,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO410,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #arCognexInterface["cScannerBX4104"],
	                arInOutJamEntr1 := "DB_JamArea4003".stJam4003_4.arCarrier,
	                stInOutJamEntr1 := "DB_JamArea4003".stJam4003_4.stData,
	                arInOutJamExit2 := "DB_JamArea4006".stJam4006_1.arCarrier,
	                stInOutJamExit2 := "DB_JamArea4006".stJam4006_1.stData,
	                arInOutJamExit3 := "DB_JamArea4003".stJam4003_5.arCarrier,
	                stInOutJamExit3 := "DB_JamArea4003".stJam4003_5.stData,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro410"],
	                xOutStopper1 => "MB3363",
	                xOutSw1ExTo3 => "MB3366");
	        
	        
	        "bx4104-TriggerEnable" := #arCognexInterface["cScannerBX4104"].xOutCamTriggerEnable;
	        "bx4104-Trigger" := #arCognexInterface["cScannerBX4104"].xOutCamTrigger;
	        "bx4104-ResultsAck" := #arCognexInterface["cScannerBX4104"].xOutCamResultsAck;
	        
	        REGION Carr_Glob_Correction            
	            "FC_CARR_GLOB_CORRECTION"(xInStart := #TRO410.xOutCorrection, //Führe Korrektur aus
	                                      nInBarcodeScan := #TRO410.nBarcodeResult,
	                                      nInStation := 0,
	                                      arOutEventLogInfo => #arDummyEventCorrectionInfo,
	                                      InOutCarrierExpect := "DB_JamArea4003".stJam4003_4.arCarrier[1]);
	        END_REGION
	        
	        REGION Direction
	            "FC_Direction"(nInSwitchNo := "cSwi410.1",
	                           nOutDirection => #TRO410.nInDirection,
	                           InOutCarrier := "DB_JamArea4003".stJam4003_4.arCarrier[1]);
	        END_REGION
	        
	        REGION Recirce
	            IF #TRO410.nState = 2400 AND #TRO410.fbStateManager.tOutTimeInStep > T#15s THEN //Steckt in CheckJam fest, weil kein Platz in der Station + Zeit vergangen
	                "DB_JamArea4003".stJam4003_4.arCarrier[1].nDestination := "cDestRecirc"; // Ziel zum Rotieren um nicht zu Blockieren
	                #TRO410.nState := 2000; //Hole nochmal die Direction 
	            END_IF;
	            
	        END_REGION
	        
	        REGION Send DUM to Fortna WCS
	            IF #TRO410.xOutBookedDir1 THEN
	                "FC_Send_GOHDUM"(sInPLCID := "cPLCID",
	                                 nInBarcode := #TRO410.stOutLastCarrier.nBarcode,
	                                 sInDecisionPoint := 'GOH.Decant.01',
	                                 sInActionTaken := '3', //todo? Am besten eine Konstantentabelle anlegen aus Infos von Spezifikation
	                                 nReasonCode := 1, //todo?
	                                 FIFO := "DB_LGF_FIFO_CommWCSBL",
	                                 BUFFER := "DB_Buffer_CommunicationWCSBL".BUFFER,
	                                 nInOutSequenceNumber := "DB_CommunicationParameters".nSeqNumWCSBL);
	            END_IF;
	            
	            
	        END_REGION
	        
	    END_REGION
	    
	    REGION TRO 411 (Vario)
	        #TRO411.stInSeparator1.Settings.nSeparatorNo := "cSep411.1";
	        #TRO411.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO411.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO411.stInSeparator1.Settings.tHandlingTime := t#400ms;
	        #TRO411.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO411.stInSeparator1.Settings.xPluggedJam := FALSE;
	        #TRO411.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO411.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO411.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3370"];
	        
	        #TRO411.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO411.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO411.stInVario.Settings.xContinousEmptying := FALSE;
	        #TRO411.stInVario.Settings.tWaitForJog := T#400ms;
	        #TRO411.stInVario.Settings.tConvEmpty := T#15000ms;
	        #TRO411.stInVario.Settings.nCountCarrier := 1;
	        #TRO411.stInVario.Settings.tWaitForStop := T#3s;
	
	        
	        #TRO411.stInVario.Settings.tCarrierInPosDelay := t#1200ms;
	        #TRO411.stInVario.Settings.tCarrierInPosEdgeDelay := t#100ms;
	        
	        #TRO411.stInVario.stSenFinger := "DB_Inputs".Sensors["cInBG3372"]; // Finger in Pos
	        #TRO411.stInVario.stSenLastPos := "DB_Inputs".Sensors["cInBG3373"]; // Conveyor full
	        #TRO411.stInVario.stSenJam := "DB_Inputs".Sensors["cInBG3396"]; // Jam
	        #TRO411.stInVario.stSenCarrInPos := "DB_Inputs".Sensors["cInBG3376"]; // Mt in Position;
	        
	        #TRO411.stInPriorityManager.xReleaseOk := TRUE; //braucht keine Vorfahrtsregelung
	        
	        #TRO411(nInMainTroNo := "cMainTro411",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInReset := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO411,
	                xInMotorProtection := "FC0063",
	                xInAutomatic := #t_automatik,
	                arInOutJamEntr := "DB_JamArea4006".stJam4006_1.arCarrier,
	                stInOutJamEntr := "DB_JamArea4006".stJam4006_1.stData,
	                arInOutJamFinger := "DB_JamArea4006".stJam4006_2.arCarrier,
	                stInOutJamFinger := "DB_JamArea4006".stJam4006_2.stData,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO411,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro411"],
	                xOutStopper => "MB3370",
	                xOutVarioMotor => "MA0063");
	        
	        (* REGION Barcode-Reader BX4105
	            #arCognexInterface["cScannerBX4105"].xInCamTriggerReady := "bx4105-TriggerReady";
	            #arCognexInterface["cScannerBX4105"].xInCamTriggerAck := "bx4105-TriggerAck";
	            #arCognexInterface["cScannerBX4105"].xInCamResultsAvailable := "bx4105-Results Available";
	            #arCognexInterface["cScannerBX4105"].xInCamGeneralFault := "bx4105-General Fault";
	            #arCognexInterface["cScannerBX4105"].hwInCamInspectionResults := "BX4105~Ergebnisse_–_64_Bytes_1";
	            
	            #fbBarcodeReaderBX4105.stInSettings.xActivateCheckASCI := TRUE;
	            #fbBarcodeReaderBX4105.stInSettings.tTimeout := T#5s; //T#5s  zum Testen
	            
	            IF #fbBarcodeReaderBX4105.xOutReadyForNewScan AND "DB_Inputs".Sensors["cInBG3374"].xDirectEdgePos THEN
	                #xHandshakeScan4105 := FALSE;
	                #xStartScan4105 := TRUE;
	            END_IF;
	            
	            IF #fbBarcodeReaderBX4105.xOutReadingDone THEN
	                #nBarcodeReaderBX4105_Result := LINT_TO_DINT(#fbBarcodeReaderBX4105.#nOutBarcode);
	                #xHandshakeScan4105 := TRUE;
	                #xStartScan4105 := FALSE;
	            END_IF;
	            
	            #fbBarcodeReaderBX4105(xInHWError := false, // todo
	                                   xInStartReading := #xStartScan4105,
	                                   xInHandshakeDone := #xHandshakeScan4105,
	                                   stInOutInterface := #arCognexInterface["cScannerBX4105"],
	                                   stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                                   stInOutHMI := #stBarcodeReaderDummy);
	            
	            "bx4105-TriggerEnable" := #arCognexInterface["cScannerBX4105"].xOutCamTriggerEnable;
	            "bx4105-Trigger" := #arCognexInterface["cScannerBX4105"].xOutCamTrigger;
	            "bx4105-ResultsAck" := #arCognexInterface["cScannerBX4105"].xOutCamResultsAck;
	            
	        END_REGION *)
	        
	        
	    END_REGION
	    
	    REGION TRO 412 (1Sep)
	        #TRO412.stInSeparator1.Settings.nSeparatorNo := "cSep412.1";
	        #TRO412.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO412.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO412.stInSeparator1.Settings.tHandlingTime := t#200ms;
	        #TRO412.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO412.stInSeparator1.Settings.xPluggedJam := TRUE;
	        #TRO412.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO412.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO412.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3381"];
	        #TRO412.stInSenJam2 := "DB_Inputs".Sensors["cInBG3382"];
	        
	        #TRO412.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO412.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO412(stInPriorityManager := "DB_Prozessdaten".stPriorityManager.udt_TRO412.TroIn,
	                stOutPriorityManager => "DB_Prozessdaten".stPriorityManager.udt_TRO412.TroOut,
	                nInMainTroNo := "cMainTro412",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInCancel := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO412,
	                xInCarouselRun := #fbCarousel4003.xOutConveyorFullSpeed,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                arInOutJamEntr1 := "DB_JamArea4007".stJam4007_1.arCarrier,
	                stInOutJamEntr1 := "DB_JamArea4007".stJam4007_1.stData,
	                arInOutJamExit2 := "DB_JamArea4003".stJam4003_5.arCarrier,
	                stInOutJamExit2 := "DB_JamArea4003".stJam4003_5.stData,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO412,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro412"],
	                xOutStopper1 => "MB3381");
	    END_REGION
	    
	    REGION TRO 413(1Sep1Switch)+Scanner(BX4106)
	        
	        #TRO413.stInSeparator1.Settings.nSeparatorNo := "cSep413.1";
	        #TRO413.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO413.stInSeparator1.Settings.tTrailingTime := t#0ms;
	        #TRO413.stInSeparator1.Settings.tHandlingTime := t#0ms;
	        #TRO413.stInSeparator1.Settings.xPluggedJam := TRUE;
	        #TRO413.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO413.stInSeparator1.Settings.xPluggedScanner := TRUE;
	        #TRO413.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3430"];
	        #TRO413.stInSenJam2 := "DB_Inputs".Sensors["cInBG3431"];
	        #TRO413.stInSenJam3 := "DB_Inputs".Sensors["cInBG3450"];
	        
	        #TRO413.stInSwitch1.Settings.nSwitchNo := "cSwi413.1";
	        #TRO413.stInSwitch1.Settings.xPluggedExSen3 := FALSE;
	        #TRO413.stInSwitch1.Settings.xPluggedExSen4 := FALSE;
	        #TRO413.stInSwitch1.Settings.tTransitEx := T#5s;
	        #TRO413.stInSwitch1.Settings.nTo1Destinations := 3; //Info nötig für HMI
	        
	        #TRO413.stInBarcodeReader.Settings.xActivateCheckASCI := TRUE;
	        #TRO413.stInBarcodeReader.Settings.tTimeout := T#5s;
	        
	        #arCognexInterface["cScannerBX4106"].xInCamTriggerReady := "bx4106-TriggerReady";
	        #arCognexInterface["cScannerBX4106"].xInCamTriggerAck := "bx4106-TriggerAck";
	        #arCognexInterface["cScannerBX4106"].xInCamResultsAvailable := "bx4106-Results Available";
	        #arCognexInterface["cScannerBX4106"].xInCamGeneralFault := "bx4106-General Fault";
	        #arCognexInterface["cScannerBX4106"].hwInCamInspectionResults := "BX4106~Ergebnisse_–_64_Bytes_1";
	        
	        #TRO413.stInSettings.xPrioDir2 := TRUE;
	        #TRO413(stInPriorityManagerDir2 := "DB_Prozessdaten".stPriorityManager.udt_TRO413.TroIn,
	                stOutPriorityManagerDir2 => "DB_Prozessdaten".stPriorityManager.udt_TRO413.TroOut,
	                nInMainTroNo := "cMainTro413",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInCancel := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO413,
	                xInCarouselRun1 := #fbCarousel4003.xOutConveyorFullSpeed,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO413,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #arCognexInterface["cScannerBX4106"],
	                arInOutJamEntr1 := "DB_JamArea4003".stJam4003_5.arCarrier,
	                stInOutJamEntr1 := "DB_JamArea4003".stJam4003_5.stData,
	                arInOutJamExit2 := "DB_JamArea4008".stJam4008_1.arCarrier,
	                stInOutJamExit2 := "DB_JamArea4008"."stJam4008_1".stData,
	                arInOutJamExit3 := "DB_JamArea4003".stJam4003_6.arCarrier,
	                stInOutJamExit3 := "DB_JamArea4003".stJam4003_6.stData,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro413"],
	                xOutStopper1 => "MB3430",
	                xOutSw1ExTo3 => "MB3432");
	        
	        "bx4106-TriggerEnable" := #arCognexInterface["cScannerBX4106"].xOutCamTriggerEnable;
	        "bx4106-Trigger" := #arCognexInterface["cScannerBX4106"].xOutCamTrigger;
	        "bx4106-ResultsAck" := #arCognexInterface["cScannerBX4106"].xOutCamResultsAck;
	        
	        REGION Carr_Glob_Correction            
	            "FC_CARR_GLOB_CORRECTION"(xInStart := #TRO413.xOutCorrection, //Führe Korrektur aus
	                                      nInBarcodeScan := #TRO413.nBarcodeResult,
	                                      nInStation := 0,
	                                      arOutEventLogInfo => #arDummyEventCorrectionInfo,
	                                      InOutCarrierExpect := "DB_JamArea4003".stJam4003_5.arCarrier[1]);
	        END_REGION
	        
	        REGION Direction
	            "FC_Direction"(nInSwitchNo := "cSwi413.1",
	                           nOutDirection => #TRO413.nInDirection,
	                           InOutCarrier := "DB_JamArea4003".stJam4003_5.arCarrier[1]);
	            
	        END_REGION
	        
	        REGION Recirce
	            IF #TRO413.nState = 2400 AND #TRO413.fbStateManager.tOutTimeInStep > T#15s THEN //Steckt in CheckJam fest, weil kein Platz in der Station + Zeit vergangen
	                "DB_JamArea4003".stJam4003_5.arCarrier[1].nDestination := "cDestRecirc"; // Ziel zum Rotieren um nicht zu Blockieren
	                #TRO413.nState := 2000; //Hole nochmal die Direction 
	            END_IF;
	            
	        END_REGION
	        
	        REGION Send DUM to Fortna WCS
	            IF #TRO413.xOutBookedDir1 THEN
	                "FC_Send_GOHDUM"(sInPLCID := "cPLCID",
	                                 nInBarcode := #TRO413.stOutLastCarrier.nBarcode,
	                                 sInDecisionPoint := 'GOH.Decant.01',
	                                 sInActionTaken := '4', //todo? Am besten eine Konstantentabelle anlegen aus Infos von Spezifikation
	                                 nReasonCode := 1, //todo?
	                                 FIFO := "DB_LGF_FIFO_CommWCSBL",
	                                 BUFFER := "DB_Buffer_CommunicationWCSBL".BUFFER,
	                                 nInOutSequenceNumber := "DB_CommunicationParameters".nSeqNumWCSBL);
	            END_IF;
	            
	            
	        END_REGION
	        
	    END_REGION
	    
	    REGION TRO 414 (Vario) 
	        #TRO414.stInSeparator1.Settings.nSeparatorNo := "cSep414.1";
	        #TRO414.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO414.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO414.stInSeparator1.Settings.tHandlingTime := t#200ms;
	        #TRO414.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO414.stInSeparator1.Settings.xPluggedJam := FALSE;
	        #TRO414.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO414.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO414.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3440"];
	        
	        #TRO414.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO414.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO414.stInVario.Settings.xContinousEmptying := FALSE;
	        #TRO414.stInVario.Settings.tWaitForJog := T#400ms;
	        #TRO414.stInVario.Settings.tConvEmpty := T#15000ms;
	        #TRO414.stInVario.Settings.nCountCarrier := 1;
	        #TRO414.stInVario.Settings.tWaitForStop := T#3s;
	        
	        #TRO414.stInVario.Settings.tCarrierInPosDelay := t#1200ms;
	        #TRO414.stInVario.Settings.tCarrierInPosEdgeDelay := t#100ms;
	        
	        #TRO414.stInVario.stSenFinger := "DB_Inputs".Sensors["cInBG3442"]; //Finger in Pos
	        #TRO414.stInVario.stSenLastPos := "DB_Inputs".Sensors["cInBG3443"]; // Conveyor full
	        #TRO414.stInVario.stSenCarrInPos := "DB_Inputs".Sensors["cInBG3446"]; // Carr in Pos
	        #TRO414.stInVario.stSenJam := "DB_Inputs".Sensors["cInBG3437"]; // Jam
	        
	        #TRO414.stInPriorityManager.xReleaseOk := TRUE; //braucht keine Vorfahrtsregelung
	        
	        #TRO414(nInMainTroNo := "cMainTro414",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInReset := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO414,
	                xInMotorProtection := "FC0065",
	                xInAutomatic := #t_automatik,
	                arInOutJamEntr := "DB_JamArea4008".stJam4008_1.arCarrier,
	                stInOutJamEntr := "DB_JamArea4008".stJam4008_1.stData,
	                arInOutJamFinger := "DB_JamArea4008".stJam4008_2.arCarrier,
	                stInOutJamFinger := "DB_JamArea4008".stJam4008_2.stData,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO414,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro414"],
	                xOutStopper => "MB3440",
	                xOutVarioMotor => "MA0065");
	                // xOutVarioMotor2 => "MA0066");
	        
	        (* REGION Barcode-Reader BX4107
	            #arCognexInterface["cScannerBX4107"].xInCamTriggerReady := "bx4107-TriggerReady";
	            #arCognexInterface["cScannerBX4107"].xInCamTriggerAck := "bx4107-TriggerAck";
	            #arCognexInterface["cScannerBX4107"].xInCamResultsAvailable := "bx4107-Results Available";
	            #arCognexInterface["cScannerBX4107"].xInCamGeneralFault := "bx4107-General Fault";
	            #arCognexInterface["cScannerBX4107"].hwInCamInspectionResults := "BX4107~Ergebnisse_–_64_Bytes_1";
	            
	            #fbBarcodeReaderBX4107.stInSettings.xActivateCheckASCI := TRUE;
	            #fbBarcodeReaderBX4107.stInSettings.tTimeout := T#5s; //T#5s  zum Testen
	            
	            IF #fbBarcodeReaderBX4107.xOutReadyForNewScan AND "DB_Inputs".Sensors["cInBG3444"].xDirectEdgePos THEN
	                #xHandshakeScan4107 := FALSE;
	                #xStartScan4107 := TRUE;
	            END_IF;
	            
	            IF #fbBarcodeReaderBX4107.xOutReadingDone THEN
	                #nBarcodeReaderBX4107_Result := LINT_TO_DINT(#fbBarcodeReaderBX4107.#nOutBarcode);
	                #xHandshakeScan4107 := TRUE;
	                #xStartScan4107 := FALSE;
	            END_IF;
	            
	            #fbBarcodeReaderBX4107(xInHWError := false, // todo
	                                   xInStartReading := #xStartScan4107,
	                                   xInHandshakeDone := #xHandshakeScan4107,
	                                   stInOutInterface := #arCognexInterface["cScannerBX4107"],
	                                   stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                                   stInOutHMI := #stBarcodeReaderDummy);
	            
	            "bx4107-TriggerEnable" := #arCognexInterface["cScannerBX4107"].xOutCamTriggerEnable;
	            "bx4107-Trigger" := #arCognexInterface["cScannerBX4107"].xOutCamTrigger;
	            "bx4107-ResultsAck" := #arCognexInterface["cScannerBX4107"].xOutCamResultsAck;
	            
	        END_REGION *)
	        
	        
	    END_REGION
	    
	    REGION TRO 415 (1Sep)
	        #TRO415.stInSeparator1.Settings.nSeparatorNo := "cSep415.1";
	        #TRO415.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO415.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO415.stInSeparator1.Settings.tHandlingTime := t#200ms;
	        #TRO415.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO415.stInSeparator1.Settings.xPluggedJam := TRUE;
	        #TRO415.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO415.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO415.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3451"];
	        #TRO415.stInSenJam2 := "DB_Inputs".Sensors["cInBG3450"];
	        
	        #TRO415.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO415.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO415(stInPriorityManager := "DB_Prozessdaten".stPriorityManager.udt_TRO415.TroIn,
	                stOutPriorityManager => "DB_Prozessdaten".stPriorityManager.udt_TRO415.TroOut,
	                nInMainTroNo := "cMainTro415",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInCancel := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO415,
	                xInCarouselRun := #fbCarousel4003.xOutConveyorFullSpeed,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                arInOutJamEntr1 := "DB_JamArea4009".stJam4009_1.arCarrier,
	                stInOutJamEntr1 := "DB_JamArea4009".stJam4009_1.stData,
	                arInOutJamExit2 := "DB_JamArea4003".stJam4003_6.arCarrier,
	                stInOutJamExit2 := "DB_JamArea4003".stJam4003_6.stData,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO415,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro415"],
	                xOutStopper1 => "MB3451");
	        
	    END_REGION
	    
	    REGION TRO 416 (1Sep) + Beladeprüfung
	        
	        #TRO416.stInSeparator1.Settings.nSeparatorNo := "cSep416.1";
	        #TRO416.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO416.stInSeparator1.Settings.tTrailingTime := t#0ms;
	        #TRO416.stInSeparator1.Settings.tHandlingTime := t#0ms;
	        #TRO416.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO416.stInSeparator1.Settings.xPluggedJam := TRUE;
	        #TRO416.stInSeparator1.Settings.xPluggedPart := FALSE;  
	        #TRO416.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO416.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3435"];
	        #TRO416.stInSenJam2 := "DB_Inputs".Sensors["cInBG3433"];
	        
	        #TRO416.stInPriorityManager.xReleaseOk := TRUE; //braucht keine Vorfahrtsregelung
	        
	        IF "DB_JamArea4003".stJam4003_6.arCarrier[1].bStatus.%X0 AND "DB_JamArea4003".stJam4003_6.arCarrier[1].nDestination <> "cDestRecirc" THEN
	            "DB_JamArea4003".stJam4003_6.arCarrier[1].nDestination := "cDestLeaveAmr";
	        END_IF;
	        
	        #TRO416(nInMainTroNo := "cMainTro416",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInCancel := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO416,
	                xInCarouselRun := #fbCarousel4003.xOutConveyorFullSpeed,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                arInOutJamEntr1 := "DB_JamArea4003".stJam4003_6.arCarrier,
	                stInOutJamEntr1 := "DB_JamArea4003".stJam4003_6.stData,
	                arInOutJamExit2 := "DB_JamArea4003".stJam4003_7.arCarrier,
	                stInOutJamExit2 := "DB_JamArea4003".stJam4003_7.stData,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO416,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro416"],
	                xOutStopper1 => "MB3435");
	        
	        
	    END_REGION
	    
	    REGION TRO 417 (1Sep)
	        
	        #TRO417.stInSeparator1.Settings.nSeparatorNo := "cSep417.1";
	        #TRO417.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Long";
	        #TRO417.stInSeparator1.Settings.tTrailingTime := t#0ms;
	        #TRO417.stInSeparator1.Settings.tHandlingTime := t#0ms;
	        #TRO417.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO417.stInSeparator1.Settings.xPluggedJam := TRUE;
	        #TRO417.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO417.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO417.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3383"];
	        #TRO417.stInSenJam2 := "DB_Inputs".Sensors["cInBG3367"];
	        
	        #TRO417(stInPriorityManager := "DB_Prozessdaten".stPriorityManager.udt_TRO417.TroIn,
	                stOutPriorityManager => "DB_Prozessdaten".stPriorityManager.udt_TRO417.TroOut,
	                nInMainTroNo := "cMainTro417",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInCancel := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO417,
	                xInCarouselRun := #fbCarousel4003.xOutConveyorFullSpeed,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                arInOutJamEntr1 := "DB_JamArea4003".stJam4003_7.arCarrier,
	                stInOutJamEntr1 := "DB_JamArea4003".stJam4003_7.stData,
	                arInOutJamExit2 := "DB_JamArea4003".stJam4003_8.arCarrier,
	                stInOutJamExit2 := "DB_JamArea4003".stJam4003_8.stData,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO417,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro417"],
	                xOutStopper1 => "MB3383");
	        
	    END_REGION
	    
	    REGION TRO 418 (Vario)
	        
	        #TRO418.stInSeparator1.Settings.nSeparatorNo := "cSep418.1";
	        #TRO418.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO418.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO418.stInSeparator1.Settings.tHandlingTime := t#400ms;
	        #TRO418.stInSeparator1.Settings.tDelayToNextItem := T#5s;
	        #TRO418.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO418.stInSeparator1.Settings.xPluggedJam := FALSE;
	        #TRO418.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO418.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO418.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3391"];
	        
	        #TRO418.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO418.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO418.stInVario.Settings.xContinousEmptying := FALSE;
	        #TRO418.stInVario.Settings.tWaitForJog := T#300ms;
	        #TRO418.stInVario.Settings.tConvEmpty := T#20000ms;
	        #TRO418.stInVario.Settings.nCountCarrier := 1;
	        #TRO418.stInVario.Settings.tWaitForStop := T#3s;
	        
	        #TRO418.stInVario.Settings.tCarrierInPosDelay := t#1200ms;
	        
	        #TRO418.stInVario.Settings.tCarrierInPosEdgeDelay := t#100ms;
	        
	        #TRO418.stInVario.stSenFinger := "DB_Inputs".Sensors["cInBG3393"]; //Finger in Pos
	        #TRO418.stInVario.stSenLastPos := "DB_Inputs".Sensors["cInBG3425"]; // Conveyor full
	        #TRO418.stInVario.stSenJam := "DB_Inputs".Sensors["cInBG3264"]; // Jam detector 
	        #TRO418.stInVario.stSenCarrInPos := "DB_Inputs".Sensors["cInBG3392"]; // MT in Pos
	        
	        #TRO418.stInPriorityManager.xReleaseOk := TRUE; //braucht keine Vorfahrtsregelung
	        
	        #TRO418.stInSettings.xIsBorner := TRUE;
	        
	        #TRO418(nInMainTroNo := "cMainTro418",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInAutomatic := #t_automatik,
	                xInReset := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO418,
	                xInMotorProtection := "FC0074",
	                arInOutJamEntr := "DB_JamArea4010".stJam4010_1.arCarrier,
	                stInOutJamEntr := "DB_JamArea4010".stJam4010_1.stData,
	                arInOutJamFinger := "DB_JamArea4011".stJam4011_1.arCarrier,
	                stInOutJamFinger := "DB_JamArea4011".stJam4011_1.stData,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO418,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro418"],
	                xOutStopper => "MB3391",
	                xOutVarioMotor => "MA0074");
	        
	        
	        
	    END_REGION
	    
	    REGION !!!!!! TRO 419 (1Sep) GIBT NICHT MEHR!!!!!!!
	        
	        // #TRO419.stInSeparator1.Settings.nSeparatorNo := "cSep419.1";
	        // #TRO419.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        // #TRO419.stInSeparator1.Settings.tTrailingTime := t#0ms;
	        // #TRO419.stInSeparator1.Settings.tHandlingTime := t#0ms;
	        // #TRO419.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        // #TRO419.stInSeparator1.Settings.xPluggedJam := TRUE;
	        // #TRO419.stInSeparator1.Settings.xPluggedPart := FALSE;
	        // #TRO419.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        // #TRO419.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3424"];
	        // #TRO419.stInSenJam2 := "DB_Inputs".Sensors["cInBG3250"];
	        
	        // #TRO419.stInPriorityManager.xReleaseOk := TRUE; //braucht keine Vorfahrtsregelung
	        
	        // #TRO419(nInMainTroNo := "cMainTro419",
	        //         xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	        //         xInAllRdyToStart := TRUE,
	        //         xInCancel := "cTodoFalse",
	        //         xInRelease := "DB_TRO_Test".TRO419, // todooooo "DI0036" AND "DI0037", //Brandschutz tor offen + Brandschutztor kein Fehler (NC oder NO signal?)
	        //         xInCarouselRun := TRUE,
	        //         stInOutMachineState := #stInOutControlUnitCabinet,
	        //         stInOutCognexInterface := #stCognexInterfaceDummy,
	        //         arInOutJamEntr1 := "DB_JamArea4010".stJam4010_2.arCarrier,
	        //         stInOutJamEntr1 := "DB_JamArea4010".stJam4010_2.stData,
	        //         arInOutJamExit2 := "DB_JamArea4011".stJam4011_1.arCarrier,
	        //         stInOutJamExit2 := "DB_JamArea4011".stJam4011_1.stData,
	        //         stInOutHMI := "DB_Interface_HMI".stTRO.TRO419,
	        //         nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro419"],
	        //         xOutStopper1 => "MB3424");
	        
	    END_REGION
	    
	    REGION TRO 420 (Vario)
	        #TRO420.stInSeparator1.Settings.nSeparatorNo := "cSep420.1";
	        #TRO420.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO420.stInSeparator1.Settings.tHandlingTime := t#400ms;
	        #TRO420.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO420.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO420.stInSeparator1.Settings.xPluggedJam := FALSE;
	        #TRO420.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO420.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO420.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3250"];
	        
	        #TRO420.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO420.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO420.stInVario.stSenFinger := "DB_Inputs".Sensors["cInBG3253"]; //Finger in Pos
	        #TRO420.stInVario.stSenLastPos := "DB_Inputs".Sensors["cInBG3256"]; // Conveyor full
	        #TRO420.stInVario.stSenJam := "DB_Inputs".Sensors["cInBG3251"]; // Jam detector, fehlt!
	        #TRO420.stInVario.stSenCarrInPos := "DB_Inputs".Sensors["cInBG3255"]; // MT in Pos
	        
	        #TRO420.stInVario.Settings.xContinousEmptying := FALSE;
	        #TRO420.stInVario.Settings.tWaitForJog := T#300ms;
	        #TRO420.stInVario.Settings.tConvEmpty := T#50000ms;
	        #TRO420.stInVario.Settings.nCountCarrier := 1;
	        #TRO420.stInVario.Settings.tWaitForStop := T#3s;
	        
	        #TRO420.stInVario.Settings.tCarrierInPosDelay := t#1200ms;
	        #TRO420.stInVario.Settings.tCarrierInPosEdgeDelay := t#100ms;
	        
	        #TRO420.stInPriorityManager.xReleaseOk := TRUE; //braucht keine Vorfahrtsregelung
	        
	        #stJamDataLeaveControl.Config.nCapacitySet := 1;
	        
	        #TRO420(nInMainTroNo := "cMainTro420",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInAutomatic := #t_automatik,
	                xInReset := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO420,
	                xInMotorProtection := "FC0072",
	                arInOutJamEntr := "DB_JamArea4011".stJam4011_1.arCarrier,
	                stInOutJamEntr := "DB_JamArea4011".stJam4011_1.stData,
	                arInOutJamFinger := #arStCarrierLeaveControl,//JAM Übergabe CPU UH01!
	                stInOutJamFinger := #stJamDataLeaveControl,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO420,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro420"],
	                xOutStopper => "MB3250",
	                xOutVarioMotor => "MA0072");
	        
	    END_REGION
	    
	    REGION TRO 421 (Vario)
	        #TRO421.stInSeparator1.Settings.nSeparatorNo := "cSep421.1";
	        #TRO421.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO421.stInSeparator1.Settings.tHandlingTime := t#200ms;
	        #TRO421.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO421.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO421.stInSeparator1.Settings.xPluggedJam := FALSE;
	        #TRO421.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO421.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO421.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3326"];
	        
	        #TRO421.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO421.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO421.stInVario.stSenFinger := "DB_Inputs".Sensors["cInBG3315"]; //Finger in Pos
	        #TRO421.stInVario.stSenLastPos := "DB_Inputs".Sensors["cInBG3317"]; // Conveyor full
	        #TRO421.stInVario.stSenCarrInPos := "DB_Inputs".Sensors["cInBG3324"]; // MT in Position
	        #TRO421.stInVario.stSenJam := "DB_Inputs".Sensors["cInBG3320"]; // Jam Detector
	        
	        // #TRO421.stInVario.stSenUnloadPos := "DB_Inputs".Sensors["cInBG3314"]; //Unload Position
	        // #TRO421.stInVario.xButton := "SF0025"; // Release Button
	        
	        #TRO421.stInVario.Settings.xContinousEmptying := FALSE;
	        #TRO421.stInVario.Settings.tWaitForJog := T#400ms;
	        #TRO421.stInVario.Settings.tConvEmpty := T#30000ms;
	        #TRO421.stInVario.Settings.nCountCarrier := 1;
	        #TRO421.stInVario.Settings.tWaitForStop := T#3s;
	        
	        #TRO421.stInVario.Settings.xJamSenDelayActive := TRUE;
	        #TRO421.stInVario.Settings.tJamSenDelay := T#2s;
	        
	        #TRO421.stInVario.Settings.tCarrierInPosDelay := t#1200ms;
	        #TRO421.stInVario.Settings.tCarrierInPosEdgeDelay := t#100ms;
	        
	        #TRO421.stInPriorityManager.xReleaseOk := TRUE; //braucht keine Vorfahrtsregelung
	        
	        #TRO421.fbConvVario.xBeladenError := "DB_Inputs".Sensors["cInBG3325"].xDirectSensor;
	        
	        #TRO421(nInMainTroNo := "cMainTro421",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInAutomatic := #t_automatik,
	                xInReset := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO421,
	                xInMotorProtection := "FC0062",
	                stInStationSensor:="DB_Inputs".Sensors["cInBG3314"],
	                xInReleaseStation:= #"rTrig_Workstation 1".CLK,
	                arInOutJamEntr := "DB_JamArea4004".stJam4004_2.arCarrier,
	                stInOutJamEntr := "DB_JamArea4004".stJam4004_2.stData,
	                arInOutJamFinger := "DB_JamArea4005".stJam4005_1.arCarrier,
	                stInOutJamFinger := "DB_JamArea4005".stJam4005_1.stData,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO421,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro421"],
	                xOutStopper => "MB3326",
	                xOutVarioMotor => "MA0062");
	        
	        
	        
	        REGION Barcode-Reader BX4103
	            
	            #arCognexInterface["cScannerBX4103"].xInCamTriggerReady := "bx4103-TriggerReady";
	            #arCognexInterface["cScannerBX4103"].xInCamTriggerAck := "bx4103-TriggerAck";
	            #arCognexInterface["cScannerBX4103"].xInCamResultsAvailable := "bx4103-Results Available";
	            #arCognexInterface["cScannerBX4103"].xInCamGeneralFault := "bx4103-General Fault";
	            #arCognexInterface["cScannerBX4103"].hwInCamInspectionResults := "BX4103~Ergebnisse_–_64_Bytes_1";
	            
	            #fbBarcodeReaderBX4103.stInSettings.xActivateCheckASCI := TRUE;
	            #fbBarcodeReaderBX4103.stInSettings.tTimeout := T#5s; //T#5s  zum Testen
	            
	            #TRO421.fbConvVario.xReadyForScan := #fbBarcodeReaderBX4103.xOutReadyForNewScan;
	            #TRO421.fbConvVario.xReadingDone := #fbBarcodeReaderBX4103.xOutReadingDone;
	            
	            (* IF #TRO421.fbConvVario.xStartScanBarcode(* "DB_Inputs".Sensors["cInBG3314"].xDirectEdgePos *)THEN
	                #xHandshakeScanb4103 := FALSE;
	                #xStartScan4103 := TRUE;
	            END_IF; *)
	            
	            IF #fbBarcodeReaderBX4103.xOutReadingDone THEN
	                #TRO421.nBarcodeReader_Result := LINT_TO_DINT(#fbBarcodeReaderBX4103.#nOutBarcode);
	               (* #xHandshakeScanb4103 := NOT #TRO421.fbConvVario.xSationStop (* TRUE *);
	                #xStartScan4103 := FALSE; *)
	            END_IF;
	            
	            #fbBarcodeReaderBX4103(xInHWError := false, // todo
	                                   xInStartReading := #TRO421.fbConvVario.xStartScanBarcode,
	                                   xInHandshakeDone := #TRO421.fbConvVario.xHandShakeScan,
	                                   stInOutInterface := #arCognexInterface["cScannerBX4103"],
	                                   stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                                   stInOutHMI := #stBarcodeReaderDummy);
	            
	            "bx4103-TriggerEnable" := #arCognexInterface["cScannerBX4103"].xOutCamTriggerEnable;
	            "bx4103-Trigger" := #arCognexInterface["cScannerBX4103"].xOutCamTrigger;
	            "bx4103-ResultsAck" := #arCognexInterface["cScannerBX4103"].xOutCamResultsAck;
	            
	        END_REGION
	        
	        
	        
	        REGION Release and Reset Buttons
	            
	            #TRO421.fbConvVario.xResetBeladen := "SF0053";
	            "PF0053" := #TRO421.fbConvVario.xResetLed OR "SF0003";
	            
	            #"rTrig_Workstation 1"(CLK := "SF0025"); //Release Button Workstation 1
	            
	        END_REGION
	        
	    END_REGION
	    
	    REGION TRO 422 (Vario)
	        #TRO422.stInSeparator1.Settings.nSeparatorNo := "cSep422.1";
	        #TRO422.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO422.stInSeparator1.Settings.tHandlingTime := t#200ms;
	        #TRO422.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO422.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO422.stInSeparator1.Settings.xPluggedJam := FALSE;
	        #TRO422.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO422.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO422.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3397"];
	        
	        #TRO422.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO422.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO422.stInVario.stSenFinger := "DB_Inputs".Sensors["cInBG3375"]; //Finger in Pos
	        #TRO422.stInVario.stSenLastPos := "DB_Inputs".Sensors["cInBG3377"]; // Conveyor full
	        #TRO422.stInVario.stSenCarrInPos := "DB_Inputs".Sensors["cInBG3384"]; // MT in Position
	        #TRO422.stInVario.stSenJam := "DB_Inputs".Sensors["cInBG3380"]; // Jam detector
	        
	        // #TRO422.stInVario2.stSenUnloadPos := "DB_Inputs".Sensors["cInBG3374"]; //Unload Position
	        // #TRO422.stInVario2.xButton := "SF0026"; // Release Button
	        
	        #TRO422.stInVario.Settings.xContinousEmptying := FALSE;
	        #TRO422.stInVario.Settings.tWaitForJog := T#400ms;
	        #TRO422.stInVario.Settings.tConvEmpty := T#30000ms;
	        #TRO422.stInVario.Settings.nCountCarrier := 1;
	        #TRO422.stInVario.Settings.tWaitForStop := T#3s;
	        
	        #TRO422.stInVario.Settings.tCarrierInPosDelay := t#1200ms;
	        #TRO422.stInVario.Settings.tCarrierInPosEdgeDelay := t#100ms;
	        
	        #TRO422.stInVario.Settings.xJamSenDelayActive := TRUE;
	        #TRO422.stInVario.Settings.tJamSenDelay := T#2s;
	        
	        #TRO422.stInPriorityManager.xReleaseOk := TRUE; //braucht keine Vorfahrtsregelung
	        #TRO422.fbConvVario.xBeladenError := "DB_Inputs".Sensors["cInBG3385"].xDirectSensor;
	        
	        #TRO422(nInMainTroNo := "cMainTro422",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInAutomatic := #t_automatik,
	                xInReset := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO422,
	                xInMotorProtection := "FC0064",
	                stInStationSensor:="DB_Inputs".Sensors["cInBG3374"],
	                xInReleaseStation:=#"rTrig_Workstation 2".CLK,
	                arInOutJamEntr := "DB_JamArea4006".stJam4006_2.arCarrier,
	                stInOutJamEntr := "DB_JamArea4006".stJam4006_2.stData,
	                arInOutJamFinger := "DB_JamArea4007".stJam4007_1.arCarrier,
	                stInOutJamFinger := "DB_JamArea4007".stJam4007_1.stData,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO422,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro422"],
	                xOutStopper => "MB3397",
	                xOutVarioMotor => "MA0064");
	        
	        
	        REGION Release AND Reset Buttons
	            
	            #TRO422.fbConvVario.xResetBeladen := "SF0055";
	            "PF0055" := #TRO422.fbConvVario.xResetLed OR "SF0003";
	            // TO DO
	            #"rTrig_Workstation 2"(CLK := "SF0026"); //Release Button Workstation 2
	            
	        END_REGION
	        
	        REGION Barcode-Reader BX4105
	            
	            #arCognexInterface["cScannerBX4105"].xInCamTriggerReady := "bx4105-TriggerReady";
	            #arCognexInterface["cScannerBX4105"].xInCamTriggerAck := "bx4105-TriggerAck";
	            #arCognexInterface["cScannerBX4105"].xInCamResultsAvailable := "bx4105-Results Available";
	            #arCognexInterface["cScannerBX4105"].xInCamGeneralFault := "bx4105-General Fault";
	            #arCognexInterface["cScannerBX4105"].hwInCamInspectionResults := "BX4105~Ergebnisse_–_64_Bytes_1";
	            
	            
	            #fbBarcodeReaderBX4105.stInSettings.xActivateCheckASCI := TRUE;
	            #fbBarcodeReaderBX4105.stInSettings.tTimeout := T#5s; //T#5s  zum Testen
	            
	            #TRO422.fbConvVario.xReadyForScan := #fbBarcodeReaderBX4105.xOutReadyForNewScan;
	            #TRO422.fbConvVario.xReadingDone := #fbBarcodeReaderBX4105.xOutReadingDone;
	            
	            (* IF #TRO421.fbConvVario.xStartScanBarcode(* "DB_Inputs".Sensors["cInBG3314"].xDirectEdgePos *)THEN
	                #xHandshakeScanb4103 := FALSE;
	                #xStartScan4103 := TRUE;
	            END_IF; *)
	            
	            IF #fbBarcodeReaderBX4105.xOutReadingDone THEN
	                #TRO422.nBarcodeReader_Result := LINT_TO_DINT(#fbBarcodeReaderBX4105.#nOutBarcode);
	                (* #xHandshakeScanb4103 := NOT #TRO422.fbConvVario.xSationStop (* TRUE *);
	                 #xStartScan4103 := FALSE; *)
	            END_IF;
	            
	            #fbBarcodeReaderBX4105(xInHWError := false, // todo
	                                   xInStartReading := #TRO422.fbConvVario.xStartScanBarcode,
	                                   xInHandshakeDone := #TRO422.fbConvVario.xHandShakeScan,
	                                   stInOutInterface := #arCognexInterface["cScannerBX4105"],
	                                   stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                                   stInOutHMI := #stBarcodeReaderDummy);
	            
	            "bx4105-TriggerEnable" := #arCognexInterface["cScannerBX4105"].xOutCamTriggerEnable;
	            "bx4105-Trigger" := #arCognexInterface["cScannerBX4105"].xOutCamTrigger;
	            "bx4105-ResultsAck" := #arCognexInterface["cScannerBX4105"].xOutCamResultsAck;
	            
	        END_REGION
	        
	        
	        
	       
	        
	        
	        
	    END_REGION
	    
	    REGION TRO 423 (Vario)
	        #TRO423.stInSeparator1.Settings.nSeparatorNo := "cSep423.1";
	        #TRO423.stInSeparator1.Settings.tTrailingTime := "cTimeSepTrailing";
	        #TRO423.stInSeparator1.Settings.tHandlingTime := t#200ms;
	        #TRO423.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO423.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO423.stInSeparator1.Settings.xPluggedJam := FALSE;
	        #TRO423.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO423.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO423.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3436"];
	        
	        #TRO423.stInSeparator1.Settings.tSenFree := T#1200ms;
	        #TRO423.stInSeparator1.Settings.tSenWait := T#4300ms;
	        
	        #TRO423.stInVario.stSenFinger := "DB_Inputs".Sensors["cInBG3445"]; //Finger in Pos
	        #TRO423.stInVario.stSenLastPos := "DB_Inputs".Sensors["cInBG3447"]; // Conveyor full
	        #TRO423.stInVario.stSenCarrInPos := "DB_Inputs".Sensors["cInBG3454"]; // MT in Position
	        #TRO423.stInVario.stSenJam := "DB_Inputs".Sensors["cInBG3431"]; // Jam detector
	        
	        // #TRO414.stInVario2.stSenUnloadPos := "DB_Inputs".Sensors["cInBG3444"]; //Unload Position
	        // #TRO414.stInVario2.xButton := "SF0027"; // Release Button
	        
	        #TRO423.stInVario.Settings.xContinousEmptying := FALSE;
	        #TRO423.stInVario.Settings.tWaitForJog := T#400ms;
	        #TRO423.stInVario.Settings.tConvEmpty := T#30000ms;
	        #TRO423.stInVario.Settings.nCountCarrier := 1;
	        #TRO423.stInVario.Settings.tWaitForStop := T#3s;
	        
	        #TRO423.stInVario.Settings.tCarrierInPosDelay := t#1200ms;
	        #TRO423.stInVario.Settings.tCarrierInPosEdgeDelay := t#100ms;
	        
	        #TRO423.stInVario.Settings.xJamSenDelayActive := TRUE;
	        #TRO423.stInVario.Settings.tJamSenDelay := T#2s;
	        
	        #TRO423.stInPriorityManager.xReleaseOk := TRUE; //braucht keine Vorfahrtsregelung
	        #TRO423.fbConvVario.xBeladenError := "DB_Inputs".Sensors["cInBG3455"].xDirectSensor;
	        
	        #TRO423(nInMainTroNo := "cMainTro423",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInAutomatic := #t_automatik,
	                xInReset := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO423,
	                xInMotorProtection := "FC0066",
	                stInStationSensor:="DB_Inputs".Sensors["cInBG3444"],
	                xInReleaseStation:=#"rTrig_Workstation 3".CLK,
	                arInOutJamEntr := "DB_JamArea4008".stJam4008_2.arCarrier,
	                stInOutJamEntr := "DB_JamArea4008".stJam4008_2.stData,
	                arInOutJamFinger := "DB_JamArea4009".stJam4009_1.arCarrier,
	                stInOutJamFinger := "DB_JamArea4009".stJam4009_1.stData,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO423,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro423"],
	                xOutStopper => "MB3436",
	                xOutVarioMotor => "MA0066");
	        
	        REGION Barcode-Reader BX4107
	            
	            #arCognexInterface["cScannerBX4107"].xInCamTriggerReady := "bx4107-TriggerReady";
	            #arCognexInterface["cScannerBX4107"].xInCamTriggerAck := "bx4107-TriggerAck";
	            #arCognexInterface["cScannerBX4107"].xInCamResultsAvailable := "bx4107-Results Available";
	            #arCognexInterface["cScannerBX4107"].xInCamGeneralFault := "bx4107-General Fault";
	            #arCognexInterface["cScannerBX4107"].hwInCamInspectionResults := "BX4107~Ergebnisse_–_64_Bytes_1";
	            
	            
	            #fbBarcodeReaderBX4107.stInSettings.xActivateCheckASCI := TRUE;
	            #fbBarcodeReaderBX4107.stInSettings.tTimeout := T#5s; //T#5s  zum Testen
	            
	            #TRO423.fbConvVario.xReadyForScan := #fbBarcodeReaderBX4107.xOutReadyForNewScan;
	            #TRO423.fbConvVario.xReadingDone := #fbBarcodeReaderBX4107.xOutReadingDone;
	            
	            (* IF #TRO421.fbConvVario.xStartScanBarcode(* "DB_Inputs".Sensors["cInBG3314"].xDirectEdgePos *)THEN
	                #xHandshakeScanb4103 := FALSE;
	                #xStartScan4103 := TRUE;
	            END_IF; *)
	            
	            IF #fbBarcodeReaderBX4107.xOutReadingDone THEN
	                #TRO423.nBarcodeReader_Result := LINT_TO_DINT(#fbBarcodeReaderBX4107.#nOutBarcode);
	                (* #xHandshakeScanb4103 := NOT #TRO422.fbConvVario.xSationStop (* TRUE *);
	                 #xStartScan4103 := FALSE; *)
	            END_IF;
	            
	            #fbBarcodeReaderBX4107(xInHWError := false, // todo
	                                   xInStartReading := #TRO423.fbConvVario.xStartScanBarcode,
	                                   xInHandshakeDone := #TRO423.fbConvVario.xHandShakeScan,
	                                   stInOutInterface := #arCognexInterface["cScannerBX4107"],
	                                   stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                                   stInOutHMI := #stBarcodeReaderDummy);
	            
	            "bx4107-TriggerEnable" := #arCognexInterface["cScannerBX4107"].xOutCamTriggerEnable;
	            "bx4107-Trigger" := #arCognexInterface["cScannerBX4107"].xOutCamTrigger;
	            "bx4107-ResultsAck" := #arCognexInterface["cScannerBX4107"].xOutCamResultsAck;
	            
	        END_REGION
	        
	        
	        
	        REGION Release AND Reset  Buttons
	            // TO DO
	            #TRO423.fbConvVario.xResetBeladen := "SF0057";
	            "PF0057" := #TRO423.fbConvVario.xResetLed OR "SF0003";
	            #"rTrig_Workstation 3"(CLK := "SF0027"); //Release Button Workstation 2
	            
	        END_REGION
	        
	        
	    END_REGION
	    
	    REGION TRO 424 (1Sep) vor Behangskontrolle
	        
	        #TRO424.stInSeparator1.Settings.nSeparatorNo := "cSep424.1";
	        #TRO424.stInSeparator1.Settings.tDelayToNextItem := "TimeForSepWaiting_Short";
	        #TRO424.stInSeparator1.Settings.tTrailingTime := t#0ms;
	        #TRO424.stInSeparator1.Settings.tHandlingTime := t#0ms;
	        #TRO424.stInSeparator1.Settings.tJam := "TimeForSepJam";
	        #TRO424.stInSeparator1.Settings.xPluggedJam := TRUE;
	        #TRO424.stInSeparator1.Settings.xPluggedPart := FALSE;
	        #TRO424.stInSeparator1.Settings.xPluggedScanner := FALSE;
	        #TRO424.stInSeparator1.stSenInSep := "DB_Inputs".Sensors["cInBG3400"];
	        #TRO424.stInSenJam2 := "DB_Inputs".Sensors["cInBG3360"];
	        
	        #TRO424.stInPriorityManager.xReleaseOk := TRUE; //keine Vorfahrtsregelung notwendig
	        
	        #TRO424(nInMainTroNo := "cMainTro424",
	                xInSftyOk := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                xInAllRdyToStart := TRUE,
	                xInCancel := "cTodoFalse",
	                xInRelease := "DB_TRO_Test".TRO424,
	                xInCarouselRun := #fbCarousel4003.xOutConveyorFullSpeed,
	                stInOutMachineState := #stInOutControlUnitCabinet,
	                stInOutCognexInterface := #stCognexInterfaceDummy,
	                arInOutJamEntr1 := "DB_JamArea4003".stJam4003_8.arCarrier,
	                stInOutJamEntr1 := "DB_JamArea4003".stJam4003_8.stData,
	                arInOutJamExit2 := "DB_JamArea4003".stJam4003_1.arCarrier,
	                stInOutJamExit2 := "DB_JamArea4003".stJam4003_1.stData,
	                stInOutHMI := "DB_Interface_HMI".stTRO.TRO424,
	                nOutStateLast => "DB_GLOB_TroState".arTroState["cMainTro424"],
	                xOutStopper1 => "MB3400");
	        
	        
	    END_REGION
	    
	END_REGION
END_FUNCTION_BLOCK

