FUNCTION "FC_SHR_CyclePin" : Void
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      nInPosDiff : DInt;   // zykl. Differenz der Inkremente
      nInPosPitchPart : DInt;
      nInConvStations : Int;   // neu hinzugefügt, statt Konstante
      nInStationsMax : Int;   // neu hinzugefügt, statt Konstante
   END_VAR

   VAR_IN_OUT 
      stInOutConveyorStations : "stConveyorStations";
   END_VAR

   VAR_TEMP 
      nCounter : Int;
      stEmptyTrolley : "stCarrierPin";
      nLastStationPos : DInt;
      Temp_1 : DInt;
      Temp_2 : Bool;
   END_VAR


BEGIN
	// ****************************************
	// Zyklischer Aufruf für Online-Register
	// ****************************************
	
	// IF #stConveyorStations.nTrolleysOnline = 0 THEN
	//     ;//RETURN;
	// END_IF;
	
	#stInOutConveyorStations.stData.nPosActPart := #nInPosPitchPart;
	IF #nInPosDiff > 0 THEN
	    // Trolleys aus Stationen entfernen / Anzahl der Trolleys ermitteln
	    #stInOutConveyorStations.stData.nTrolleysOnline := 0;
	    FOR #nCounter := 1 TO #nInConvStations DO
	        
	        
	        // Wenn Trolley über letzte Station hinaus, dann löschen
	        IF (#stInOutConveyorStations.stData.nStations > 0) AND (#stInOutConveyorStations.stData.nStations <= #nInStationsMax) THEN
	            IF #stInOutConveyorStations.arTrolleysOnline[#nCounter].stPinValues.nPosAct > #stInOutConveyorStations.arStationsPos[#stInOutConveyorStations.stData.nStations].nPosIncr THEN
	                "FC_TSHR_AddAtEnd"(stInTrolley := #stInOutConveyorStations.arTrolleysOnline[#nCounter].stCarrier,
	                                   nOutCounter => #Temp_1,
	                                   xOutResult => #Temp_2,
	                                   arTSHR := "DB_HyperJam".stHyperJam.arCarrier); //TODO Zugriff über inout Schnittstelle...
	                #stInOutConveyorStations.arTrolleysOnline[#nCounter] := #stEmptyTrolley;
	            END_IF;
	        END_IF;
	        // Ansonsten online bleiben
	        IF #stInOutConveyorStations.arTrolleysOnline[#nCounter].stCarrier.bStatus.%X0 THEN
	            #stInOutConveyorStations.stData.nTrolleysOnline += 1;
	            #stInOutConveyorStations.arTrolleysOnline[#nCounter].stPinValues.nPosAct += #nInPosDiff;
	        END_IF;
	    END_FOR;
	END_IF;
END_FUNCTION

