FUNCTION "FC_SHR_ExtractedHangerPin" : Void
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      xInUnloadingDone : Bool;   // trigger zum Offline Setzen des Trolleys
      nInBarcode : DInt;   // Arrayposition in arTrolleysOnline
      xInBypass : Bool;
   END_VAR

   VAR_IN_OUT 
      stInOutConveyorStations : "stConveyorStations";
      arInOutCarrier : Array[*] of "stCarrier";
   END_VAR

   VAR_TEMP 
      nCounter : Int;   // Arraynummer bzw. Haken / Trolley
      nTrolleyPosition : Int;
      stEmptyTrolley : "stCarrierPin";
      tempTrolley : "stCarrier";
      TempCounter : DInt;
      TempResult : Bool;
   END_VAR


BEGIN
	// ****************************************
	// Setzt im Online-Register den Hanger im Abwurf auf Not Online
	// ****************************************
	// Passenden Eintrag finden
	IF #xInUnloadingDone THEN
	    FOR #nCounter := 1 TO ("cHooksSorterMaxPin") DO
	        IF #stInOutConveyorStations.arTrolleysOnline[#nCounter].stCarrier.nBarcode = #nInBarcode THEN
	            EXIT;
	        END_IF;
	    END_FOR;
	    // Wenn Eintrag gefunden, dann eintragen.
	    IF #nCounter < "cHooksSorterMaxPin" THEN
	        // #arOutTrolleyShiftRegister.arTrolley[1] := #arInOutTrolleysOnline[#nCounter].stTrolleyLoad;
	        IF NOT #xInBypass THEN //Wenn der Carrier am Block vorbeifährt (Bypass) NICHT buchen *****NEU*****
	            #tempTrolley := #stInOutConveyorStations.arTrolleysOnline[#nCounter].stCarrier;
	            "FC_TSHR_AddAtEnd"(stInTrolley := #tempTrolley,
	                               nOutCounter => #TempCounter,
	                               xOutResult => #TempResult,
	                               arTSHR := #arInOutCarrier);
	        END_IF;
	        
	        IF NOT #TempResult
	            AND NOT #xInBypass //***NEU***
	        THEN
	             RETURN;
	         ELSE
	            // Leeren des Hangers am Abwurf
	            #stInOutConveyorStations.stData.nTrolleysOnline -= 1;
	            // Alles im Online-Register eins weiter schieben
	            FOR #nCounter := #nCounter TO ("cHooksSorterMaxPin" - 1) DO       // Weiterkopieren um eine Position
	                #stInOutConveyorStations.arTrolleysOnline[#nCounter] := #stInOutConveyorStations.arTrolleysOnline[#nCounter + 1];
	            END_FOR;
	            #stInOutConveyorStations.arTrolleysOnline["cHooksSorterMaxPin"] := #stEmptyTrolley;
	        END_IF;
	    END_IF;
	END_IF;
END_FUNCTION

