FUNCTION_BLOCK "FB_PreMain"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_IN_OUT 
      stInOutControlUnitCabinetOF1 : "UDT_MainState";
      stInOutControlUnitCabinetOF2 : "UDT_MainState";
   END_VAR

   VAR 
      xAllMainContactorsOk { S7_SetPoint := 'True'} : Bool;
      xAllReadyToStartOF1 : Bool;
      xAllReadyToStartOF2 : Bool;
      xQuitNec : Bool;
      fbStateMainOF1 : "FB_StateMain";
      fbStateMainOF2 : "FB_StateMain";
      fbMonMotorProtectionUH01 : "FB_Monitoring";
      fbMonMotorProtectionUC011 : "FB_Monitoring";
      fbMonMotorProtectionUC0110 : "FB_Monitoring";
      fbMonMotorProtectionUC0111 : "FB_Monitoring";
      fbMonPhaseFailure : "FB_Monitoring";
      fbMonFuse24VUH01 : "FB_Monitoring";
      fbMonFuse24VUC011 : "FB_Monitoring";
      fbMonFuse400VUH01 : "FB_Monitoring";
      fbMonFuse400VUC011 : "FB_Monitoring";
      fbMonPressureUH01 : "FB_Monitoring";
      fbMonPressureUC011 : "FB_Monitoring";
      fbMonMainContactorsUH01 : "FB_Monitoring";
      fbMonMainContactorsUC0110 : "FB_Monitoring";
      fbMonMainContactorsUC0111 : "FB_Monitoring";
      fbMonMainContactorsUC011 : "FB_Monitoring";
      fbMonSafetyContactorsExternReserve : "FB_Monitoring";
      fbMonSafetyContactorsExternUC061 : "FB_Monitoring";
      fbMonFAS : "FB_Monitoring";   // IF from FACP "fire alarm" DI0034
      fbMonFPG_Open : "FB_Monitoring";   // Control from FPG
      fbMonFPG_Fault : "FB_Monitoring";   // Control from FPG
      fbMonFPG_Fire : "FB_Monitoring";   // Control from FPG
      fbMonRFID : "FB_Monitoring";
      fbMonTiltTeachBoom1 : "FB_Monitoring";
      fbMonTiltTeachBoom2 : "FB_Monitoring";
      fbMonDistanceFootTeachBoom1 : "FB_Monitoring";
      fbMonDistanceFootTeachBoom2 : "FB_Monitoring";
      fbMonCommFortnaWCS : "FB_Monitoring";
      arESTOPAck { S7_SetPoint := 'False'} : Array[0..15] of "FB_ESTOPhandling";
      tOnClarificationTime {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;
      Test : String;
      Result { S7_SetPoint := 'False'} : "UDT_Payload_GOHDRespM";
      xStart { S7_SetPoint := 'True'} : Bool;
      LStream_JsonDeserializer_Instance : "LStream_JsonDeserializer";
      typeElement { S7_SetPoint := 'False'} : Array[0..10] of "LStream_typeElement" := [(2, 'DecisionPoint', (), (), ()), (3, 'GIN', (), (), ()), (2, 'Barcode', (), (), ()), (1, 'Actions', (), (), true), ((), (), (), (), ()), ((), (), (), (), ()), ((), (), (), (), ()), ((), (), (), (), ()), ((), (), (), (), ()), ((), (), (), (), ()), ((), (), (), (), ())];
      Static_1 : Array[0..1023] of Byte;
      cnt : UInt;
      xReInit : Bool;
      fTrigReIntTime {InstructionName := 'F_TRIG'; LibVersion := '1.0'} : F_TRIG;
      tOfReIntTime {InstructionName := 'TOF_TIME'; LibVersion := '1.0'} : TOF_TIME;   // nach Hochfahren vergeht diese Zeit bis erstmalig Quit
   END_VAR

   VAR_TEMP 
      tDebug : Int;
      nIdx : USInt;
   END_VAR

   VAR CONSTANT 
      c_UH01 : Int := 0;   // Konstante für ESTOP
      c_UZ0101 : Int := 1;   // Konstante für ESTOP
      c_UZ0102 : Int := 2;   // Konstante für ESTOP
      c_UZ0103 : Int := 3;   // Konstante für ESTOP
      c_UZ0104 : Int := 4;   // Konstante für ESTOP
      c_UZ0110_1 : Int := 5;   // Konstante für ESTOP
      c_UZ0111_1 : Int := 6;   // Konstante für ESTOP
      c_UC011 : Int := 7;
      c_UH01_Extern : Int := 8;
      c_UC011_Extern : Int := 9;
   END_VAR


BEGIN
	// ------------------------------------------------
	// GLOBAL INFORMATION - do before other FB calls
	// ------------------------------------------------
	REGION *******PROVISORISCH********
	    //Um Frequenzumrichter zu quittieren
	    "DQ0135" := "SF0001";
	END_REGION
	
	REGION Reinitialisieren
	    #tOfReIntTime(IN := NOT #xReInit,
	                  PT := T#10s);
	    
	    IF NOT #xReInit THEN
	        #xReInit := TRUE;
	    END_IF;
	    
	    #fTrigReIntTime(CLK := #tOfReIntTime.Q);
	    
	END_REGION
	
	REGION CycleTime
	    // "DB_MachineGlobal".nLogicCycle := "DB_MachineGlobal".nLogicCycle + 1;
	    #tDebug := RD_SYS_T("DB_MachineGlobal".DTL_TimePLC);
	    // #fbCycleTime("DB_MachineGlobal".nPrevCycle);
	END_REGION
	
	REGION Alarmnummern zurücksetzen
	    IF "DB_MachineGlobal".Cold_Restart THEN
	        "DB_AlarmGlobal".nAlarmNoOffsetGlobal := 10;
	    END_IF;
	END_REGION
	
	REGION Monitoring
	    REGION UH01
	        REGION Motor Protection UH01
	            #fbMonMotorProtectionUH01.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonMotorProtectionUH01.stSettings.xSelfQuit := FALSE;
	            #fbMonMotorProtectionUH01(sInFctnName := 'Motorschutz',
	                                      sInPrefix := 'UH01',
	                                      sInAlarmMessage := 'Motorschutz UH01 ausgeloest',
	                                      sInSuffix := 'FC0057-FC0076',
	                                      wInTextListId_Function := 3,
	                                      wInTextListId_Message := 1,
	                                      xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                                      xInSignal := "FC0057" AND "FC0060" AND "FC0061" AND "FC0062" AND
	                                      "FC0063" AND "FC0064" AND "FC0065" AND "FC0066" AND "FC0067" AND
	                                      "FC0070" AND "FC0072" AND "FC0074" AND "FC0076",
	                                      InOutMachineState := #stInOutControlUnitCabinetOF1,
	                                      stOutHMI => "DB_Interface_HMI".stSystem.stMotorProtection.UH01);
	        END_REGION
	        REGION Phasen
	            #fbMonPhaseFailure.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonPhaseFailure.stSettings.xSelfQuit := FALSE;
	            #fbMonPhaseFailure(sInFctnName := 'Phasenausfall',
	                               sInPrefix := 'UH01',
	                               sInAlarmMessage := 'Phase UH01 ausgefallen',
	                               sInSuffix := 'DI0005',
	                               wInTextListId_Function := 6,
	                               wInTextListId_Message := 2,
	                               xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                               xInSignal := "DI0005",
	                               InOutMachineState := #stInOutControlUnitCabinetOF1,
	                               stOutHMI => "DB_Interface_HMI".stSystem.stPhase.UH01_400V);
	        END_REGION
	        REGION 24 V UH01
	            #fbMonFuse24VUH01.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonFuse24VUH01.stSettings.xSelfQuit := FALSE;
	            #fbMonFuse24VUH01(sInFctnName := 'Sicherungsfall',
	                              sInPrefix := 'UH01 24V',
	                              sInAlarmMessage := 'Sicherung UH01 ausgeloest',
	                              sInSuffix := 'DI0021-DI0024',
	                              wInTextListId_Function := 4,
	                              wInTextListId_Message := 3,
	                              xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                              xInSignal := "DI0021" AND "DI0022" AND "DI0023" AND "DI0024",
	                              InOutMachineState := #stInOutControlUnitCabinetOF1,
	                              stOutHMI => "DB_Interface_HMI".stSystem.stFuse.UH01_24V);
	        END_REGION
	        REGION 400 V UH01
	            #fbMonFuse400VUH01.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonFuse400VUH01.stSettings.xSelfQuit := FALSE;
	            #fbMonFuse400VUH01(sInFctnName := 'Sicherungsfall',
	                               sInPrefix := 'UH01 400V',
	                               sInAlarmMessage := 'Sicherung UH01 ausgeloest',
	                               sInSuffix := 'DI0006-DI0017',
	                               wInTextListId_Function := 4,
	                               wInTextListId_Message := 3,
	                               xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                               xInSignal := "DI0006" AND "DI0007" AND "DI0010" AND "DI0016" AND "DI0017",
	                               InOutMachineState := #stInOutControlUnitCabinetOF1,
	                               stOutHMI => "DB_Interface_HMI".stSystem.stFuse.UH01_400V);
	        END_REGION
	        REGION Druckluft UH01
	            #fbMonPressureUH01.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonPressureUH01.stSettings.xSelfQuit := FALSE;
	            #fbMonPressureUH01(sInFctnName := 'Druckluftueberwachung',
	                               sInPrefix := 'UH01',
	                               sInAlarmMessage := 'Druckluft UH01 zu niedrig',
	                               sInSuffix := 'BP0004',
	                               wInTextListId_Function := 5,
	                               wInTextListId_Message := 4,
	                               xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                               xInSignal := "BP0004",
	                               InOutMachineState := #stInOutControlUnitCabinetOF1,
	                               stOutHMI => "DB_Interface_HMI".stSystem.stPressure.UH01);
	        END_REGION
	        REGION Hauptschütze UH01
	            #fbMonMainContactorsUH01.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonMainContactorsUH01.stSettings.xSelfQuit := FALSE;
	            #fbMonMainContactorsUH01(sInFctnName := 'Hauptschuetzueberwachung',
	                                     sInPrefix := 'UH01',
	                                     sInAlarmMessage := 'Hauptschuetze Fehler',
	                                     sInSuffix := 'QA0610/QA0611',
	                                     wInTextListId_Function := 7,
	                                     wInTextListId_Message := 5,
	                                     xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                                     xInSignal := "DB_InterfaceSafety".stFromSafety.stMainContactorsUH01.xOk,
	                                     InOutMachineState := #stInOutControlUnitCabinetOF1,
	                                     stOutHMI => "DB_Interface_HMI".stSystem.stMainContactor.UH01);
	        END_REGION
	        REGION Safetyrelais UH01 Extern
	            #fbMonSafetyContactorsExternReserve.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonSafetyContactorsExternReserve.stSettings.xSelfQuit := FALSE;
	            #fbMonSafetyContactorsExternReserve(sInFctnName := 'Relaisueberwachung',
	                                                sInPrefix := 'UH01',
	                                                sInAlarmMessage := 'Relais Fehler',
	                                                sInSuffix := 'QA0612/QA0613',
	                                                wInTextListId_Function := 9,
	                                                wInTextListId_Message := 9,
	                                                xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                                                xInSignal := "DB_InterfaceSafety".stFromSafety.stSafetyContactorsExternReserve.xOk,
	                                                InOutMachineState := #stInOutControlUnitCabinetOF1,
	                                                stOutHMI => "DB_Interface_HMI".stSystem.stMainContactor.UH01ExternReserve);
	        END_REGION
	    END_REGION
	    
	    REGION UC011
	        REGION Motor Protection UC011
	            #fbMonMotorProtectionUC011.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonMotorProtectionUC011.stSettings.xSelfQuit := FALSE;
	            #fbMonMotorProtectionUC011(sInFctnName := 'Motorschutz',
	                                       sInPrefix := 'UC011',
	                                       sInAlarmMessage := 'Motorschutz UC011 ausgeloest',
	                                       sInSuffix := 'FC0140-FC0155',
	                                       wInTextListId_Function := 3,
	                                       wInTextListId_Message := 1,
	                                       xInQuitError := #stInOutControlUnitCabinetOF2.xQuitError OR "SF0117",
	                                       xInSignal := "FC0140" AND "FC0141" AND "FC0142" AND "FC0143" AND
	                                       "FC0144" AND "FC0145" AND "FC0146" AND "FC0147" AND
	                                       "FC0150" AND "FC0151" AND "FC0152" AND "FC0153" AND "FC0154" AND "FC0155",
	                                       InOutMachineState := #stInOutControlUnitCabinetOF2,
	                                       stOutHMI => "DB_Interface_HMI".stSystem.stMotorProtection.UC011);
	        END_REGION
	        REGION 24 V UC011
	            #fbMonFuse24VUC011.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonFuse24VUC011.stSettings.xSelfQuit := FALSE;
	            #fbMonFuse24VUC011(sInFctnName := 'Sicherungsfall',
	                               sInPrefix := 'UC011 24V',
	                               sInAlarmMessage := 'Sicherung UC011 ausgeloest',
	                               sInSuffix := 'DI0101-DI0102',
	                               wInTextListId_Function := 4,
	                               wInTextListId_Message := 3,
	                               xInQuitError := #stInOutControlUnitCabinetOF2.xQuitError OR "SF0117",
	                               xInSignal := "DI0101" AND "DI0102",
	                               InOutMachineState := #stInOutControlUnitCabinetOF2,
	                               stOutHMI => "DB_Interface_HMI".stSystem.stFuse.UC011_24V);
	        END_REGION
	        REGION 400 V UC011
	            #fbMonFuse400VUC011.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonFuse400VUC011.stSettings.xSelfQuit := FALSE;
	            #fbMonFuse400VUC011(sInFctnName := 'Sicherungsfall',
	                                sInPrefix := 'UC011 400V',
	                                sInAlarmMessage := 'Sicherung UC011 ausgeloest',
	                                sInSuffix := 'DI0100',
	                                wInTextListId_Function := 4,
	                                wInTextListId_Message := 3,
	                                xInQuitError := #stInOutControlUnitCabinetOF2.xQuitError OR "SF0117",
	                                xInSignal := "DI0100",
	                                InOutMachineState := #stInOutControlUnitCabinetOF2,
	                                stOutHMI => "DB_Interface_HMI".stSystem.stFuse.UC011_400V);
	        END_REGION
	        REGION Druckluft UC011
	            #fbMonPressureUC011.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonPressureUC011.stSettings.xSelfQuit := FALSE;
	            #fbMonPressureUC011(sInFctnName := 'Druckluftueberwachung',
	                                sInPrefix := 'UC011',
	                                sInAlarmMessage := 'Druckluft UC011 zu niedrig',
	                                sInSuffix := 'BP0107',
	                                wInTextListId_Function := 5,
	                                wInTextListId_Message := 4,
	                                xInQuitError := #stInOutControlUnitCabinetOF2.xQuitError OR "SF0117",
	                                xInSignal := "BP0107",
	                                InOutMachineState := #stInOutControlUnitCabinetOF2,
	                                stOutHMI => "DB_Interface_HMI".stSystem.stPressure.UC011);
	        END_REGION
	        REGION Hauptschütze UC011
	            #fbMonMainContactorsUC011.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonMainContactorsUC011.stSettings.xSelfQuit := FALSE;
	            #fbMonMainContactorsUC011(sInFctnName := 'Hauptschuetzueberwachung',
	                                      sInPrefix := 'UC011',
	                                      sInAlarmMessage := 'Hauptschuetze Fehler',
	                                      sInSuffix := 'QA0920/QA0921',
	                                      wInTextListId_Function := 7,
	                                      wInTextListId_Message := 5,
	                                      xInQuitError := #stInOutControlUnitCabinetOF2.xQuitError OR "SF0117",
	                                      xInSignal := "DB_InterfaceSafety".stFromSafety.stMainContactorsUC011.xOk,
	                                      InOutMachineState := #stInOutControlUnitCabinetOF2,
	                                      stOutHMI => "DB_Interface_HMI".stSystem.stMainContactor.UC011);
	        END_REGION
	        REGION Safetyrelais UC011 to UC061
	            #fbMonSafetyContactorsExternUC061.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonSafetyContactorsExternUC061.stSettings.xSelfQuit := FALSE;
	            #fbMonSafetyContactorsExternUC061(sInFctnName := 'Relaisueberwachung',
	                                              sInPrefix := 'UC011->UC061',
	                                              sInAlarmMessage := 'Relais Fehler',
	                                              sInSuffix := 'QA0922/QA0923',
	                                              wInTextListId_Function := 9,
	                                              wInTextListId_Message := 9,
	                                              xInQuitError := #stInOutControlUnitCabinetOF2.xQuitError,
	                                              xInSignal := "DB_InterfaceSafety".stFromSafety.stSafetyContactorsExternToUH06.xOk,
	                                              InOutMachineState := #stInOutControlUnitCabinetOF2,
	                                              stOutHMI => "DB_Interface_HMI".stSystem.stMainContactor.UC011toUC061);
	        END_REGION
	    END_REGION
	    
	    REGION UC0110
	        REGION Motor Protection UC0110
	            #fbMonMotorProtectionUC0110.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonMotorProtectionUC0110.stSettings.xSelfQuit := FALSE;
	            #fbMonMotorProtectionUC0110(sInFctnName := 'Motorschutz',
	                                        sInPrefix := 'UC0110',
	                                        sInAlarmMessage := 'Motorschutz UC0110 ausgeloest',
	                                        sInSuffix := 'FC0320-FC0321',
	                                        wInTextListId_Function := 3,
	                                        wInTextListId_Message := 1,
	                                        xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                                        xInSignal := "FC0320" AND "FC0321",
	                                        InOutMachineState := #stInOutControlUnitCabinetOF1,
	                                        stOutHMI => "DB_Interface_HMI".stSystem.stMotorProtection.UC0110);
	        END_REGION
	        REGION Hauptschütze UC0110
	            #fbMonMainContactorsUC0110.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonMainContactorsUC0110.stSettings.xSelfQuit := FALSE;
	            #fbMonMainContactorsUC0110(sInFctnName := 'Hauptschuetzueberwachung',
	                                       sInPrefix := 'UC0110',
	                                       sInAlarmMessage := 'Hauptschuetze Fehler',
	                                       sInSuffix := 'QA0660/QA0661',
	                                       wInTextListId_Function := 7,
	                                       wInTextListId_Message := 5,
	                                       xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                                       xInSignal := "DB_InterfaceSafety".stFromSafety.stMainContactorsUC0110.xOk,
	                                       InOutMachineState := #stInOutControlUnitCabinetOF1,
	                                       stOutHMI => "DB_Interface_HMI".stSystem.stMainContactor.UC0110);
	        END_REGION
	    END_REGION
	    REGION UC0111
	        REGION Motor Protection UC0111
	            #fbMonMotorProtectionUC0111.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonMotorProtectionUC0111.stSettings.xSelfQuit := FALSE;
	            #fbMonMotorProtectionUC0111(sInFctnName := 'Motorschutz',
	                                        sInPrefix := 'UC0111',
	                                        sInAlarmMessage := 'Motorschutz UC0111 ausgeloest',
	                                        sInSuffix := 'FC0380-FC0381',
	                                        wInTextListId_Function := 3,
	                                        wInTextListId_Message := 1,
	                                        xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                                        xInSignal := "FC0380" AND "FC0381",
	                                        InOutMachineState := #stInOutControlUnitCabinetOF1,
	                                        stOutHMI => "DB_Interface_HMI".stSystem.stMotorProtection.UC0111);
	        END_REGION
	        
	        
	        
	        REGION Hauptschütze UC0111
	            #fbMonMainContactorsUC0111.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonMainContactorsUC0111.stSettings.xSelfQuit := FALSE;
	            #fbMonMainContactorsUC0111(sInFctnName := 'Hauptschuetzueberwachung',
	                                       sInPrefix := 'UC0111',
	                                       sInAlarmMessage := 'Hauptschuetze Fehler',
	                                       sInSuffix := 'QA0662/QA0663',
	                                       wInTextListId_Function := 7,
	                                       wInTextListId_Message := 5,
	                                       xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                                       xInSignal := "DB_InterfaceSafety".stFromSafety.stMainContactorsUC0111.xOk,
	                                       InOutMachineState := #stInOutControlUnitCabinetOF1,
	                                       stOutHMI => "DB_Interface_HMI".stSystem.stMainContactor.UC0111);
	        END_REGION
	    END_REGION
	    
	    REGION Brandschutz Interface
	        REGION FAS
	            #fbMonFAS.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonFAS.stSettings.xSelfQuit := FALSE;
	            #fbMonFAS(sInFctnName := 'Feueralarm',
	                      sInPrefix := 'UH01/FAS',
	                      sInAlarmMessage := 'Feueralarm',
	                      sInSuffix := 'DI0034',
	                      wInTextListId_Function := 8,
	                      wInTextListId_Message := 6,
	                      xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError OR "SF0002",
	                      xInSignal := "DI0034",
	                      InOutMachineState := #stInOutControlUnitCabinetOF1,
	                      stOutHMI => "DB_Interface_HMI".stSystem.stFireControl.NoFireAlarmFAS);
	        END_REGION
	        
	        
	        REGION FPG open
	            #fbMonFPG_Open.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonFPG_Open.stSettings.xSelfQuit := FALSE;
	            #fbMonFPG_Open(sInFctnName := 'Feueralarm',
	                           sInPrefix := 'UC061->UC011/FD201',
	                           sInAlarmMessage := 'Tor nicht offen',
	                           sInSuffix := 'DI0112',
	                           wInTextListId_Function := 8,
	                           wInTextListId_Message := 7,
	                           xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError OR "SF0002",
	                           xInSignal := "DI0112",
	                           InOutMachineState := #stInOutControlUnitCabinetOF1,
	                           stOutHMI => "DB_Interface_HMI".stSystem.stFireControl.FPCOpened);
	        END_REGION
	        
	        
	        REGION FPG fault
	            #fbMonFPG_Fault.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonFPG_Fault.stSettings.xSelfQuit := FALSE;
	            #fbMonFPG_Fault(sInFctnName := 'Feueralarm',
	                            sInPrefix := 'UC061->UC011/FD201',
	                            sInAlarmMessage := 'Fehler',
	                            sInSuffix := 'DI0111',
	                            wInTextListId_Function := 8,
	                            wInTextListId_Message := 8,
	                            xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError OR "SF0002",
	                            xInSignal := "DI0111",
	                            InOutMachineState := #stInOutControlUnitCabinetOF1,
	                            stOutHMI => "DB_Interface_HMI".stSystem.stFireControl.NoFault);
	        END_REGION
	        
	        REGION FPG fire alarm
	            #fbMonFPG_Fire.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonFPG_Fire.stSettings.xSelfQuit := FALSE;
	            #fbMonFPG_Fire(sInFctnName := 'Feueralarm',
	                           sInPrefix := 'UC061->UC011/FD201',
	                           sInAlarmMessage := 'Feuer',
	                           sInSuffix := 'DI0110',
	                           wInTextListId_Function := 8,
	                           wInTextListId_Message := 6,
	                           xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError OR "SF0002",
	                           xInSignal := "DI0110",
	                           InOutMachineState := #stInOutControlUnitCabinetOF1,
	                           stOutHMI => "DB_Interface_HMI".stSystem.stFireControl.NoFireAlarmFPG);
	            
	            
	            
	        END_REGION
	        
	    END_REGION
	    
	    REGION MISC (nicht für AllReadyToStart)
	        REGION RFID
	            #fbMonRFID.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonRFID.stSettings.xSelfQuit := TRUE;
	            #fbMonRFID(sInFctnName := 'RFID',
	                       sInPrefix := 'UH01',
	                       sInSuffix := 'DI0042',
	                       wInTextListId_Function := 10000,
	                       wInTextListId_Message := 10000,
	                       xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                       xInSignal := "DI0042",
	                       InOutMachineState := #stInOutControlUnitCabinetOF1);
	        END_REGION
	        
	        REGION Loading Booms
	            #fbMonTiltTeachBoom1.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonTiltTeachBoom1.stSettings.xSelfQuit := TRUE;
	            #fbMonTiltTeachBoom1(sInFctnName := 'Boom',
	                                 sInPrefix := 'Boom 1',
	                                 sInSuffix := '',
	                                 wInTextListId_Function := 11000,
	                                 wInTextListId_Message := 11000,
	                                 xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                                 xInSignal := NOT "fbMain_DB".fbLoadingBoom1.fbTiltSensor.xOutTeachNec,
	                                 InOutMachineState := #stInOutControlUnitCabinetOF1);
	            
	            #fbMonTiltTeachBoom2.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonTiltTeachBoom2.stSettings.xSelfQuit := TRUE;
	            #fbMonTiltTeachBoom2(sInFctnName := 'Boom',
	                                 sInPrefix := 'Boom 2',
	                                 sInSuffix := '',
	                                 wInTextListId_Function := 11000,
	                                 wInTextListId_Message := 11000,
	                                 xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                                 xInSignal := NOT "fbMain_DB".fbLoadingBoom2.fbTiltSensor.xOutTeachNec,
	                                 InOutMachineState := #stInOutControlUnitCabinetOF1);
	            
	            #fbMonDistanceFootTeachBoom1.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonDistanceFootTeachBoom1.stSettings.xSelfQuit := TRUE;
	            #fbMonDistanceFootTeachBoom1(sInFctnName := 'Boom',
	                                         sInPrefix := 'Boom 1',
	                                         sInSuffix := '',
	                                         wInTextListId_Function := 11000,
	                                         wInTextListId_Message := 11001,
	                                         xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                                         xInSignal := NOT "fbMain_DB".fbLoadingBoom1.fbDistanceFoot.xOutTeachNec,
	                                         InOutMachineState := #stInOutControlUnitCabinetOF1);
	            
	            #fbMonDistanceFootTeachBoom2.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonDistanceFootTeachBoom2.stSettings.xSelfQuit := TRUE;
	            #fbMonDistanceFootTeachBoom2.stSettings.nErrorType := 1;
	            #fbMonDistanceFootTeachBoom2(sInFctnName := 'Boom',
	                                         sInPrefix := 'Boom 2',
	                                         sInSuffix := '',
	                                         wInTextListId_Function := 11000,
	                                         wInTextListId_Message := 11001,
	                                         xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                                         xInSignal := NOT "fbMain_DB".fbLoadingBoom2.fbDistanceFoot.xOutTeachNec,
	                                         InOutMachineState := #stInOutControlUnitCabinetOF1);
	            
	        END_REGION
	        
	        REGION TCP-Kommunikation
	            #fbMonCommFortnaWCS.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonCommFortnaWCS.stSettings.xSelfQuit := TRUE;
	            #fbMonCommFortnaWCS(sInFctnName := 'Kommunikationsfehler',
	                                sInPrefix := 'UH01',
	                                sInSuffix := 'Fortna WCS',
	                                wInTextListId_Function := 20000,
	                                wInTextListId_Message := 20000,
	                                xInQuitError := #stInOutControlUnitCabinetOF1.xQuitError,
	                                xInSignal := "FB_CommunicationWCSBL_DB".fbTeleHandler.xOutConnectionActive,
	                                InOutMachineState := #stInOutControlUnitCabinetOF1,
	                                stOutHMI => "DB_Interface_HMI".stSystem.stExternal.TCPFortnaWCS);
	            
	        END_REGION
	        
	        
	    END_REGION
	    
	END_REGION
	
	REGION AllReadyToStart
	    
	    REGION OF1
	        #xAllReadyToStartOF1 := #fbMonPhaseFailure.xOutOk AND
	        #fbMonFuse24VUH01.xOutOk AND
	        #fbMonFuse400VUH01.xOutOk AND
	        #fbMonPressureUH01.xOutOk AND
	        #fbMonMainContactorsUH01.xOutOk AND
	        #fbMonMainContactorsUC0110.xOutOk AND
	        #fbMonMainContactorsUC0111.xOutOk AND
	        #fbMonSafetyContactorsExternReserve.xOutOk AND
	        #fbMonSafetyContactorsExternUC061.xOutOk AND
	        #fbMonFAS.xOutOk AND
	        #fbMonFPG_Fire.xOutOk AND
	        #fbMonFPG_Fault.xOutOk AND
	        #fbMonFPG_Open.xOutOk;
	    END_REGION
	    
	    
	    REGION OF2
	        #xAllReadyToStartOF2 := #fbMonPhaseFailure.xOutOk AND
	        #fbMonFuse24VUC011.xOutOk AND
	        #fbMonFuse400VUC011.xOutOk AND
	        #fbMonPressureUC011.xOutOk AND
	        #fbMonMainContactorsUC011.xOutOk AND
	        #fbMonSafetyContactorsExternUC061.xOutOk AND
	        #fbMonFAS.xOutOk AND
	        #fbMonFPG_Fire.xOutOk AND
	        #fbMonFPG_Fault.xOutOk AND
	        #fbMonFPG_Open.xOutOk;
	    END_REGION
	    
	END_REGION
	
	REGION StateMain
	    
	    REGION OF1
	        #fbStateMainOF1.stSettings.xEnableStartUpWarning := TRUE;
	        #fbStateMainOF1.stSettings.tStartUpTime := T#5s;
	        #fbStateMainOF1(xInBtnMachineOn := "SF0001" OR "IBN".xEin,
	                        xInBtnMachineNotOff := "SF0000" AND "IBN".xAus,
	                        xInBtnTrigMot := "SF0002" OR "IBN".xQuit,
	                        xInBtnQuitError := "SF0002" OR "IBN".xQuit,
	                        xInAllReadyToStart := #xAllReadyToStartOF1,
	                        xInAllInExecute := TRUE,
	                        xInAllStarted := TRUE,
	                        xInSafetyActive := "DB_InterfaceSafety".stFromSafety.EStopMainOF1.Q,
	                        xInAllInSafeState := "DB_InterfaceSafety".stFromSafety.EStopMainOF1.Q,
	                        stInOutControlUnitCabinet := #stInOutControlUnitCabinetOF1,
	                        stInOutHMI := "DB_Interface_HMI".stStateMachine);
	    END_REGION
	    
	    REGION OF2
	        #fbStateMainOF2.stSettings.xEnableStartUpWarning := TRUE;
	        #fbStateMainOF2.stSettings.tStartUpTime := T#5s;
	        #fbStateMainOF2(xInBtnMachineOn := "SF0001" OR "IBN".xEin,
	                        xInBtnMachineNotOff := "SF0000" AND "IBN".xAus,
	                        xInBtnTrigMot := "SF0117" OR "IBN".xQuit,
	                        xInBtnQuitError := "SF0117" OR "IBN".xQuit,
	                        xInAllReadyToStart := #xAllReadyToStartOF2,
	                        xInAllInExecute := TRUE,
	                        xInAllStarted := TRUE,
	                        xInSafetyActive := "DB_InterfaceSafety".stFromSafety.EStopMainOF2.Q,
	                        xInAllInSafeState := "DB_InterfaceSafety".stFromSafety.EStopMainOF2.Q,
	                        stInOutControlUnitCabinet := #stInOutControlUnitCabinetOF2,
	                        stInOutHMI := "DB_Interface_HMI".stStateMachine);
	    END_REGION
	    
	END_REGION
	
	REGION Interface Safety
	    
	    REGION to Safety
	        
	        "DB_InterfaceSafety".stToSafety.xAckGlob := "IBN".xAckGlob OR #fTrigReIntTime.Q;
	        
	        "DB_InterfaceSafety".stToSafety.xMachineRunningOF1 := #stInOutControlUnitCabinetOF1.xRunning;
	        "DB_InterfaceSafety".stToSafety.xMachineStartingOF1 := #stInOutControlUnitCabinetOF1.xStarting;
	        "DB_InterfaceSafety".stToSafety.xMachineRunningOF2 := #stInOutControlUnitCabinetOF2.xRunning;
	        "DB_InterfaceSafety".stToSafety.xMachineStartingOF2 := #stInOutControlUnitCabinetOF2.xStarting;
	        
	        "DB_InterfaceSafety".stToSafety.xQuitButtonHss := "SF0002" OR "IBN".xQuit OR #stInOutControlUnitCabinetOF1.xQuitError OR #fTrigReIntTime.Q;
	        "DB_InterfaceSafety".stToSafety.xQuitButtonUZ0101 := "SF0031" OR #fTrigReIntTime.Q;
	        "DB_InterfaceSafety".stToSafety.xQuitButtonUZ0102 := "SF0033" OR #fTrigReIntTime.Q;
	        "DB_InterfaceSafety".stToSafety.xQuitButtonUZ0103 := "SF0043" OR #fTrigReIntTime.Q;
	        "DB_InterfaceSafety".stToSafety.xQuitButtonUZ0104 := "SF0054" OR #fTrigReIntTime.Q;
	        "DB_InterfaceSafety".stToSafety.xQuitButtonUC011 := "SF0117" OR "IBN".xQuit OR #stInOutControlUnitCabinetOF1.xQuitError OR #fTrigReIntTime.Q;
	        "DB_InterfaceSafety".stToSafety.stMainContactorsUH01.xFeedback := "DI0013";
	        "DB_InterfaceSafety".stToSafety.stMainContactorsUC0110.xFeedback := "DI0011";
	        "DB_InterfaceSafety".stToSafety.stMainContactorsUC0111.xFeedback := "DI0012";
	        "DB_InterfaceSafety".stToSafety.stMainContactorsUC011.xFeedback := "DI0106";
	        "DB_InterfaceSafety".stToSafety.stSafetyContactorsExternReserve.xFeedback := "DI0014";
	        "DB_InterfaceSafety".stToSafety.stSafetyContactorsExternToU06.xFeedback := "DI0114";
	    END_REGION
	    
	    
	    REGION from Safety
	        
	    END_REGION
	    
	END_REGION
	
	REGION Outputs
	    
	    REGION UH01
	        //LED Störung (Bei Ampel)
	        // "PF0000" := "fbMain_DB".fbLoadingBoom1.nOutState = 9999 OR "SF0003"; phase
	        
	        //LED Ein
	        "PF0001" := #stInOutControlUnitCabinetOF1.xRunning OR #stInOutControlUnitCabinetOF1.xStartUpWarning OR "SF0003";
	        
	        //LED Start nachStörung
	        "PF0002" := #arESTOPAck[#c_UH01].xOutLed (* OR NOT #xAllReadyToStart *)OR
	        (#fbMonMotorProtectionUH01.xOutAckReq AND "Clock_1Hz") OR
	        (#fbMonMotorProtectionUC0110.xOutAckReq AND "Clock_1Hz") OR
	        (#fbMonMotorProtectionUC0111.xOutAckReq AND "Clock_1Hz") OR
	        (#fbMonPhaseFailure.xOutAckReq AND "Clock_1Hz") OR
	        (#fbMonFuse24VUH01.xOutAckReq AND "Clock_1Hz") OR
	        (#fbMonFuse400VUH01.xOutAckReq AND "Clock_1Hz") OR
	        (#fbMonPressureUH01.xOutAckReq AND "Clock_1Hz") OR
	        ("fbMain_DB".fbLoadingBoom1.nOutState = 9999 AND "Clock_1Hz") OR
	        ("fbMain_DB".fbLoadingBoom2.nOutState = 9999 AND "Clock_1Hz") OR
	        ("fbMain_DB".TRO115.fbConvVario.fbFingerControl.xOutErrorRasterSensor) OR
	        ("DB_InterfaceSafety".stFromSafety.stMainContactorsUH01.xAckReq AND "Clock_1Hz") OR
	        ("DB_InterfaceSafety".stFromSafety.stMainContactorsUC0110.xAckReq AND "Clock_1Hz") OR
	        ("DB_InterfaceSafety".stFromSafety.stMainContactorsUC0111.xAckReq AND "Clock_1Hz") OR
	        ("DB_InterfaceSafety".stFromSafety.stMainContactorsUC011.xAckReq AND "Clock_1Hz") OR
	        ("DB_InterfaceSafety".stFromSafety.stSafetyContactorsExternReserve.xAckReq AND "Clock_1Hz") OR
	        ("DB_InterfaceSafety".stFromSafety.stSafetyContactorsExternToUH06.xAckReq AND "Clock_1Hz") OR
	        (#fbMonFAS.xOutAckReq AND "Clock_1Hz") OR
	        (#fbMonFPG_Fire.xOutAckReq AND "Clock_1Hz") OR
	        (#fbMonFPG_Fault.xOutAckReq AND "Clock_1Hz") OR
	        (#fbMonFPG_Open.xOutAckReq AND "Clock_1Hz") OR
	        "SF0003";
	        
	        //LED Druckluft
	        "PF0003" := #fbMonPressureUH01.xOutLedError OR "SF0003";
	        
	        //LED Motorschutz
	        "PF0004" := #fbMonMotorProtectionUH01.xOutLedError OR
	        #fbMonMotorProtectionUC0110.xOutLedError OR
	        #fbMonMotorProtectionUC0111.xOutLedError OR "SF0003";
	        
	        //LED Sicherung
	        "PF0005" := #fbMonFuse24VUH01.xOutLedError OR
	        #fbMonFuse400VUH01.xOutLedError OR "SF0003";
	        
	        //LED Brandfall
	        "PF0006" := "SF0003"
	        OR #fbMonFAS.xOutError
	        OR #fbMonFPG_Fire.xOutError
	        OR #fbMonFPG_Fault.xOutError
	        OR #fbMonFPG_Open.xOutError;
	        
	        //Motor-Freigabe 24V
	        // "DQ0035" := "DQ0033" := "DQ0031" := "DQ0027" := "DQ0025" := #fbMonFuse24VUH00.xOutOk;
	        
	        //Motor-Freigabe 400V
	        // (* "MM0024" := *) "MM0023" := "MM0022" := "MM0021" := "MM0020" := #stInOutControlUnitCabinet.xRunning AND #fbMonFuse400V.xOutOk AND "Main_Safety_RTG1_DB".ESTOP1_Main.Q;
	        
	        
	        //400 V Stützfuß
	        "MA0381" := "MA0321" := #stInOutControlUnitCabinetOF1.xRunning AND
	        "DB_InterfaceSafety".stFromSafety.EStopUZ0110.Q AND NOT "DB_InterfaceSafety".stFromSafety.EStopUZ0110.AckReq AND
	        "DB_InterfaceSafety".stFromSafety.EStopUZ0111.Q AND NOT "DB_InterfaceSafety".stFromSafety.EStopUZ0111.AckReq AND
	        "DB_InterfaceSafety".stFromSafety.EStopUH01.Q AND NOT "DB_InterfaceSafety".stFromSafety.EStopUH01.AckReq;
	        //"Main_Safety_RTG1_DB".ESTOP1_Bumper1.Q AND NOT "Main_Safety_RTG1_DB".ESTOP1_Bumper1.ACK_REQ;
	        
	        REGION Signalampel
	            //E-Stop Signalsäule
	            "PF0020" := NOT "DB_InterfaceSafety".stFromSafety.EStopMainOF1.Q OR "SF0003"
	            OR #fbMonFAS.xOutError
	            OR #fbMonFPG_Fire.xOutError
	            OR #fbMonFPG_Fault.xOutError
	            OR #fbMonFPG_Open.xOutError;
	            
	            //LED Störung + Signalsäule gelb
	            "PF0000" := "PF0021" :=
	            //#fbMonFireAlarm.xOutLedError OR
	            #fbMonMotorProtectionUH01.xOutLedError OR
	            #fbMonMotorProtectionUC0110.xOutLedError OR
	            #fbMonMotorProtectionUC0111.xOutLedError OR
	            #fbMonMotorProtectionUC011.xOutLedError OR
	            #fbMonPhaseFailure.xOutLedError OR
	            #fbMonFuse24VUH01.xOutLedError OR
	            #fbMonFuse24VUC011.xOutLedError OR
	            #fbMonFuse400VUH01.xOutLedError OR
	            #fbMonFuse400VUC011.xOutLedError OR
	            #fbMonPressureUH01.xOutLedError OR
	            #fbMonPressureUC011.xOutLedError OR
	            #fbMonMainContactorsUH01.xOutLedError OR
	            #fbMonMainContactorsUC0110.xOutLedError OR
	            #fbMonMainContactorsUC0111.xOutLedError OR
	            #fbMonMainContactorsUC011.xOutLedError OR
	            #fbMonSafetyContactorsExternReserve.xOutLedError OR
	            #fbMonSafetyContactorsExternUC061.xOutLedError OR
	            "fbMain_DB".fbLoadingBoom1.nOutState = 9999 OR
	            "fbMain_DB".fbLoadingBoom2.nOutState = 9999 OR
	            "fbMain_DB".fbLoadingBoom1.fbTiltSensor.xOutTeachNec OR
	            "fbMain_DB".fbLoadingBoom2.fbTiltSensor.xOutTeachNec OR
	            "fbMain_DB".fbLoadingBoom1.fbDistanceFoot.xOutTeachNec OR
	            "fbMain_DB".fbLoadingBoom2.fbDistanceFoot.xOutTeachNec OR
	            "SF0003";
	            
	            // System Ready
	            "PF0022" := #stInOutControlUnitCabinetOF1.xRunning OR
	            #stInOutControlUnitCabinetOF1.xStartUpWarning OR "SF0003";
	            
	            //Fehlerhafter MiniTrolley
	            REGION Timer für blaue Ampel
	                #tOnClarificationTime(IN := "fbMain_DB".TRO117.nState > 1000,
	                                      PT := T#86400s);
	            END_REGION
	            "PF0023" := ("fbMain_DB".TRO117.nState > 1000 AND (#tOnClarificationTime.ET <= T#600s)) OR
	            ("fbMain_DB".TRO117.nState > 1000 AND (#tOnClarificationTime.ET > T#600s AND #tOnClarificationTime.ET <= T#3600s) AND "Clock_1Hz") OR //zwischen 10 Min und 1 h
	            ("fbMain_DB".TRO117.nState > 1000 AND (#tOnClarificationTime.ET > T#3600s AND #tOnClarificationTime.ET <= T#18000s) AND "Clock_2Hz") OR "SF0003"; //OR //zwischen 1 h und 5 h
	            //("fbMain_DB".TRO117.nState > 1000 AND (#tOnClarificationTime.ET > T#18000s) AND "Clock_10Hz") OR "SF0003"; //ab 5 h
	            
	            //Anfahrwarnung
	            "PF0024" := (#stInOutControlUnitCabinetOF1.xStartUpWarning AND "Clock_1Hz") OR
	            (#stInOutControlUnitCabinetOF2.xStartUpWarning AND "Clock_1Hz");
	        END_REGION
	    END_REGION
	    
	    REGION UC011
	        
	        //Start nach Störung
	        "PF0117" := #arESTOPAck[#c_UC011].xOutLed OR
	        (#fbMonMotorProtectionUC011.xOutAckReq AND "Clock_1Hz") OR
	        (#fbMonPressureUC011.xOutAckReq AND "Clock_1Hz") OR
	        (#fbMonFuse24VUC011.xOutAckReq AND "Clock_1Hz") OR
	        (#fbMonFuse400VUC011.xOutAckReq AND "Clock_1Hz") OR
	        ("DB_InterfaceSafety".stFromSafety.stSafetyContactorsExternToUH06.xAckReq AND "Clock_1Hz") OR
	        ("fbMain_DB".TRO121.fbConvVario.fbFingerControl.xOutErrorRasterSensor AND "Clock_1Hz") OR
	        ("fbMain_DB".fbCarousel4204.xOutGridError AND "Clock_1Hz") OR "SF0003";
	        
	        //Druckluft
	        "PF0100" := #fbMonPressureUC011.xOutLedError OR "SF0003";
	        
	        //Motor Protection
	        "PF0101" := #fbMonMotorProtectionUC011.xOutLedError OR "SF0003";
	        
	        //Sicherung
	        "PF0102" := #fbMonFuse24VUC011.xOutLedError OR
	        #fbMonFuse400VUC011.xOutLedError OR "SF0003";
	        
	    END_REGION
	    
	    REGION UZ0101
	        
	        "PF0030" := #stInOutControlUnitCabinetOF1.xRunning OR #stInOutControlUnitCabinetOF1.xStartUpWarning OR "SF0003";
	        
	    END_REGION
	    
	    REGION UZ0102
	        
	        "PF0034" := #stInOutControlUnitCabinetOF1.xRunning OR #stInOutControlUnitCabinetOF1.xStartUpWarning OR "SF0003";
	        "PF0032" := ("fbMain_DB".TRO117.nState > 1000 AND TRUE) OR "SF0003"(* "fbMain_DB".fbPrioTRO102_116.TODO!! *);
	    END_REGION
	    
	    REGION UZ0103 6-fach Tableau LS1
	        //LED Ready
	        "PF0040" := #stInOutControlUnitCabinetOF1.xRunning OR
	        #stInOutControlUnitCabinetOF1.xStartUpWarning OR "SF0003";
	        
	        //LoadingBoom activated
	        //PF0044 in Main
	        
	        //LED Reset
	        "PF0043" := #arESTOPAck[#c_UZ0103].xOutLed OR #arESTOPAck[#c_UZ0110_1].xOutLed OR
	        ("fbMain_DB".fbLoadingBoom1.nOutState = 9999 AND "Clock_1Hz") OR
	        ("fbMain_DB".#fbConveyor0103.xOutGridError AND "Clock_1Hz") OR
	        ("fbMain_DB".#fbCarousel0104.xOutGridError AND "Clock_1Hz") OR
	        ("fbMain_DB".#fbConveyor0106.xOutGridError AND "Clock_1Hz") OR "SF0003";
	    END_REGION
	    
	    REGION UZ0104 6-fach Tableau LS2
	        //LED Ready
	        "PF0045" := #stInOutControlUnitCabinetOF1.xRunning OR
	        #stInOutControlUnitCabinetOF1.xStartUpWarning OR "SF0003";
	        
	        //LoadingBoom activated
	        //PF0055 in Main
	        
	        //LED Reset
	        "PF0054" := #arESTOPAck[#c_UZ0104].xOutLed OR #arESTOPAck[#c_UZ0111_1].xOutLed OR
	        ("fbMain_DB".fbLoadingBoom2.nOutState = 9999 AND "Clock_1Hz") OR
	        ("fbMain_DB".fbConveyor0107.xOutGridError AND "Clock_1Hz") OR
	        ("fbMain_DB".fbCarousel0108.xOutGridError AND "Clock_1Hz") OR
	        ("fbMain_DB".fbConveyor0110.xOutGridError AND "Clock_1Hz") OR "SF0003";
	    END_REGION
	    
	    REGION Ready-LEDs
	        "PF0120" := "PF0124" := "PF0126" := "PF0130" := #stInOutControlUnitCabinetOF1.xRunning OR #stInOutControlUnitCabinetOF1.xStartUpWarning OR "SF0003";
	        
	    END_REGION
	    
	    REGION Highway Tableaus
	        
	        REGION UZ1101
	            "PF0121" := ("fbMain_DB".TRO120.fbConvVario.fbFingerControl.xOutErrorRasterSensor AND "Clock_1Hz") OR
	            ("fbMain_DB".TRO127.fbConvVario.fbFingerControl.xOutErrorRasterSensor AND "Clock_1Hz") OR
	            ("fbMain_DB".TRO128.fbConvVario.fbFingerControl.xOutErrorRasterSensor AND "Clock_1Hz") OR
	            ("fbMain_DB".TRO123.fbConvVario.fbFingerControl.xOutErrorRasterSensor AND "Clock_1Hz") OR
	            ("fbMain_DB".fbCarousel4204.xOutGridError AND "Clock_1Hz") OR "SF0003";
	        END_REGION
	        
	        REGION UZ1103
	            "PF0125" := ("fbMain_DB".TRO126.fbConvVario.fbFingerControl.xOutErrorRasterSensor AND "Clock_1Hz") OR
	            ("fbMain_DB".TRO131.fbConvVario.fbFingerControl.xOutErrorRasterSensor AND "Clock_1Hz") OR "SF0003";
	        END_REGION
	        
	        REGION UZ1104 / UZ1105
	            "PF0131" := "PF0127" := ("fbMain_DB".TRO133.fbConvVario.fbFingerControl.xOutErrorRasterSensor AND "Clock_1Hz") OR
	            ("fbMain_DB".TRO134.fbConvVario.fbFingerControl.xOutErrorRasterSensor AND "Clock_1Hz") OR "SF0003";
	        END_REGION
	        
	    END_REGION
	    
	    
	END_REGION
	
	REGION NOT-Halt
	    
	    REGION UH01
	        #arESTOPAck[#c_UH01](sInAlarmFunction := 'HSS',
	                             sInAlarmDevice := 'UH01',
	                             sInAlarmMessage := 'Not-Halt aktiv',
	                             sInAlarmSuffix := 'PF0002',
	                             wInTextListId_Function := 0,
	                             wInTextListId_Message := 0,
	                             xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUH01.AckReq,
	                             xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUH01.Q,
	                             xInAckReqGlobal := #arESTOPAck[#c_UZ0101].xOutAckReq OR
	                             #arESTOPAck[#c_UC011].xOutAckReq OR
	                             #arESTOPAck[#c_UZ0102].xOutAckReq OR
	                             // #arESTOPAck[#c_UZ0103].xOutAckReq OR
	                             // #arESTOPAck[#c_UZ0104].xOutAckReq OR
	                             // #arESTOPAck[#c_UZ0111_1].xOutAckReq OR
	                             #arESTOPAck[#c_UZ0110_1].xOutAckReq OR
	                             #arESTOPAck[#c_UH01_Extern].xOutAckReq,
	                             xInSafetyNotOkGlobal := #arESTOPAck[#c_UZ0101].xOutSafetyNotOk OR
	                             #arESTOPAck[#c_UC011].xOutSafetyNotOk OR
	                             #arESTOPAck[#c_UZ0102].xOutSafetyNotOk OR
	                             // #arESTOPAck[#c_UZ0103].xOutSafetyNotOk OR
	                             // #arESTOPAck[#c_UZ0103].xOutSafetyNotOk OR
	                             // #arESTOPAck[#c_UZ0111_1].xOutSafetyNotOk OR
	                             #arESTOPAck[#c_UZ0110_1].xOutSafetyNotOk OR
	                             #arESTOPAck[#c_UH01_Extern].xOutSafetyNotOk,
	                             xInMainCabinet := TRUE,
	                             //        xOutLed => "PF0002",
	                             stInOutControlUnitCabinet := #stInOutControlUnitCabinetOF1,
	                             stInOutHmiEstopPanel := "DB_Interface_HMI".arEStops[#c_UH01]);
	    END_REGION
	    
	    REGION UH01 Extern Reserve
	        #arESTOPAck[#c_UH01_Extern](sInAlarmDevice := 'UH01_Ext',
	                                    sInAlarmSuffix := 'PF0002',
	                                    wInTextListId_Function := 20,
	                                    wInTextListId_Message := 20,
	                                    stInOutHmiEstopPanel := "DB_Interface_HMI".arEStops[#c_UH01_Extern],
	                                    stInOutControlUnitCabinet := #stInOutControlUnitCabinetOF1,
	                                    xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopExternUH01Reserve.AckReq,
	                                    xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopExternUH01Reserve.Q(* AND "DB_InterfaceSafety".stFromSafety.EStopUH01.Q *));
	        
	    END_REGION
	    
	    REGION UZ0101
	        #arESTOPAck[#c_UZ0101](sInAlarmFunction := 'Bedientableau',
	                               sInAlarmDevice := 'UZ0101',
	                               sInAlarmMessage := 'Not-Halt aktiv',
	                               sInAlarmSuffix := 'PF0031',
	                               wInTextListId_Function := 1,
	                               wInTextListId_Message := 0,
	                               stInOutHmiEstopPanel := "DB_Interface_HMI".arEStops[#c_UZ0101],
	                               stInOutControlUnitCabinet := #stInOutControlUnitCabinetOF1,
	                               xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0101.AckReq,
	                               xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0101.Q(* AND "DB_InterfaceSafety".stFromSafety.EStopUH01.Q *));
	        
	        "PF0031" := #arESTOPAck[#c_UZ0101].xOutLed OR
	        ("fbMain_DB".fbCarousel0101.xOutGridError AND "Clock_1Hz") OR "SF0003";
	        
	    END_REGION
	    
	    REGION UZ0102
	        #arESTOPAck[#c_UZ0102](sInAlarmFunction := 'Bedientableau',
	                               sInAlarmDevice := 'UZ0102',
	                               sInAlarmMessage := 'Not-Halt aktiv',
	                               sInAlarmSuffix := 'PF0033',
	                               wInTextListId_Function := 1,
	                               wInTextListId_Message := 0,
	                               stInOutHmiEstopPanel := "DB_Interface_HMI".arEStops[#c_UZ0102],
	                               stInOutControlUnitCabinet := #stInOutControlUnitCabinetOF1,
	                               xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0102.AckReq,
	                               xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0102.Q(* AND "DB_InterfaceSafety".stFromSafety.EStopUH01.Q *));
	        
	        "PF0033" := #arESTOPAck[#c_UZ0102].xOutLed OR
	        ("fbMain_DB".fbCarousel0102.xOutGridError AND "Clock_1Hz") OR "SF0003";
	        
	    END_REGION
	    
	    REGION UZ0103
	        //zwei ESTOPs teilen sich eine LED
	        #arESTOPAck[#c_UZ0103](sInAlarmFunction := 'Bedientableau',
	                               sInAlarmDevice := 'UZ0103',
	                               sInAlarmMessage := 'Not-Halt aktiv',
	                               sInAlarmSuffix := 'PF0043',
	                               wInTextListId_Function := 1,
	                               wInTextListId_Message := 0,
	                               stInOutHmiEstopPanel := "DB_Interface_HMI".arEStops[#c_UZ0103],
	                               stInOutControlUnitCabinet := #stInOutControlUnitCabinetOF1,
	                               xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0103.AckReq,
	                               xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0103.Q(* AND "DB_InterfaceSafety".stFromSafety.EStopUH01.Q *)(* , xOutLed => "PF0043" *));
	    END_REGION
	    
	    REGION UZ0104
	        //zwei ESTOPs teilen sich eine LED
	        #arESTOPAck[#c_UZ0104](sInAlarmFunction := 'Bedientableau',
	                               sInAlarmDevice := 'UZ0104',
	                               sInAlarmMessage := 'Not-Halt aktiv',
	                               sInAlarmSuffix := 'PF0054',
	                               wInTextListId_Function := 1,
	                               wInTextListId_Message := 0,
	                               stInOutHmiEstopPanel := "DB_Interface_HMI".arEStops[#c_UZ0104],
	                               stInOutControlUnitCabinet := #stInOutControlUnitCabinetOF1,
	                               xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0104.AckReq,
	                               xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0104.Q(* AND "DB_InterfaceSafety".stFromSafety.EStopUH01.Q *)(* ,xOutLed => "PF0054" *));
	    END_REGION
	    
	    REGION UZ0110_1
	        //zwei ESTOPs teilen sich eine LED
	        #arESTOPAck[#c_UZ0110_1](sInAlarmFunction := 'Bedientableau',
	                                 sInAlarmDevice := 'UZ0110_1',
	                                 sInAlarmMessage := 'Not-Halt aktiv',
	                                 sInAlarmSuffix := 'PF0043',
	                                 wInTextListId_Function := 1,
	                                 wInTextListId_Message := 0,
	                                 stInOutHmiEstopPanel := "DB_Interface_HMI".arEStops[#c_UZ0110_1],
	                                 stInOutControlUnitCabinet := #stInOutControlUnitCabinetOF1,
	                                 xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0110.AckReq,
	                                 xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0110.Q(* AND "DB_InterfaceSafety".stFromSafety.EStopUH01.Q *)(* ,xOutLed => "PF0043" *));
	        
	        //PF0043 weiter oben
	        
	    END_REGION
	    
	    REGION UZ0111_1
	        //zwei ESTOPs teilen sich eine LED
	        #arESTOPAck[#c_UZ0111_1](sInAlarmFunction := 'Bedientableau',
	                                 sInAlarmDevice := 'UZ0111_1',
	                                 sInAlarmMessage := 'Not-Halt aktiv',
	                                 sInAlarmSuffix := 'PF0054',
	                                 wInTextListId_Function := 1,
	                                 wInTextListId_Message := 0,
	                                 stInOutHmiEstopPanel := "DB_Interface_HMI".arEStops[#c_UZ0111_1],
	                                 stInOutControlUnitCabinet := #stInOutControlUnitCabinetOF1,
	                                 xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0111.AckReq,
	                                 xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0111.Q(* AND "DB_InterfaceSafety".stFromSafety.EStopUH01.Q *)(* ,xOutLed => "PF0054" *));
	        
	        //"PF0054" weiter oben
	        
	    END_REGION
	    
	    REGION UC011
	        
	        #arESTOPAck[#c_UC011](sInAlarmFunction := 'Unterverteiler',
	                              sInAlarmDevice := 'UC011',
	                              sInAlarmMessage := 'Not-Halt aktiv',
	                              sInAlarmSuffix := 'PF0117',
	                              wInTextListId_Function := 2,
	                              wInTextListId_Message := 0,
	                              xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUC011.AckReq,
	                              xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUC011.Q,
	                              xInAckReqGlobal := #arESTOPAck[#c_UC011].xOutAckReq,
	                              xInSafetyNotOkGlobal := #arESTOPAck[#c_UC011].xOutSafetyNotOk,
	                              xInMainCabinet := TRUE,
	                              stInOutHmiEstopPanel := "DB_Interface_HMI".arEStops[#c_UC011],
	                              stInOutControlUnitCabinet := #stInOutControlUnitCabinetOF2);
	        
	    END_REGION
	    
	    REGION UC011 Extern/UH06
	        #arESTOPAck[#c_UC011_Extern](sInAlarmDevice := 'UC011_Ext/UH06',
	                                     sInAlarmSuffix := 'PF0117',
	                                     wInTextListId_Function := 20,
	                                     wInTextListId_Message := 20,
	                                     stInOutHmiEstopPanel := "DB_Interface_HMI".arEStops[#c_UC011_Extern],
	                                     stInOutControlUnitCabinet := #stInOutControlUnitCabinetOF2,
	                                     xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopExternFromUH06.AckReq,
	                                     xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopExternFromUH06.Q);
	        
	    END_REGION
	    
	END_REGION
	
	REGION SCADA-Interface
	    "FB-OPC_UA_System-Stat_DB"(nInSystemStat := #fbStateMainOF1.nState, //State Main (Running, Idle, Stopped...)
	                               xInFireAlarm := (#fbMonFAS.xOutError OR #fbMonFPG_Fire.xOutError), // Nur Feueralarm
	                               xInSafetyStop := NOT "DB_InterfaceSafety".stFromSafety.EStopMainOF1.Q, // Not-Halt
	                               xInError := "DB_Interface_HMI".nActiveAlarms > 0, //Alle aktiven Meldungen über HMI Interface
	                               xInCommunicationError := #fbMonCommFortnaWCS.xOutError,
	                               nOutScadaStatus => "DB_Status".System.Status);
	END_REGION
END_FUNCTION_BLOCK

