FUNCTION "FC_SHR_CheckStationPin" : Void
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      nInStation : Int;
      xInTargetStation : Bool;
      nInConvStations : Int;   // neu hinzugefügt, statt Konstante
      nInStationsMax : Int;   // neu hinzugefügt, statt Konstante
   END_VAR

   VAR_OUTPUT 
      xOutStationHi : Bool;
      xOutStationNHi : Bool;
      xOutStationHiBefore : Bool;
      nOutBarcode : DInt;
      sOutBarcode : String;
   END_VAR

   VAR_IN_OUT 
      stInOutConveyorStations : "stConveyorStations";
   END_VAR

   VAR_TEMP 
      nCounter : Int;
      xStationHi : Bool;
   END_VAR


BEGIN
	// *************************************************************
	// Prüft ob Hanger aus dem Online-Register Station erreicht hat
	// *************************************************************
	
	IF #stInOutConveyorStations.stData.nTrolleysOnline = 0 OR
	    (#nInStation > #nInStationsMax) THEN
	    RETURN;
	END_IF;
	
	FOR #nCounter := 1 TO #nInConvStations DO
	    IF #stInOutConveyorStations.arTrolleysOnline[#nCounter].stCarrier.bStatus.%X0 AND                                                                                  // Teil vorhanden
	        ((#stInOutConveyorStations.arTrolleysOnline[#nCounter].stPinValues.nTarget = #nInStation) OR NOT #xInTargetStation) AND                                      // Zielstation GLEICH der eigenen Station
	        (#stInOutConveyorStations.arTrolleysOnline[#nCounter].stPinValues.nPosAct >= #stInOutConveyorStations.arStationsPos[#nInStation].nPosIncr) THEN
	        
	        #xStationHi := 1; //sagt Abwurf abbiegen
	        
	        IF #xStationHi THEN
	            #nOutBarcode := #stInOutConveyorStations.arTrolleysOnline[#nCounter].stCarrier.nBarcode;
	        END_IF;
	        EXIT;
	    ELSIF
	        #stInOutConveyorStations.arTrolleysOnline[#nCounter].stCarrier.bStatus.%X0 AND                                                                                  // Teil vorhanden
	        ((#stInOutConveyorStations.arTrolleysOnline[#nCounter].stPinValues.nTarget > #nInStation) OR NOT #xInTargetStation) AND                                      // Zielstation GRÖßER der eigenen Station
	        (#stInOutConveyorStations.arTrolleysOnline[#nCounter].stPinValues.nPosAct >= #stInOutConveyorStations.arStationsPos[#nInStation].nPosIncr) AND
	        (#stInOutConveyorStations.arTrolleysOnline[#nCounter].stPinValues.nPosAct < #stInOutConveyorStations.arStationsPos[#nInStation].nPosIncr + 150) THEN
	        
	        #xOutStationNHi := 1; //sagt Abwurf geradeaus
	        EXIT;
	    END_IF;
	END_FOR;
	#xOutStationHi := #xStationHi;
END_FUNCTION

