FUNCTION "FC_SHR_TargetSet_ReRoutePin" : Void
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      nInBarcodeNo : DInt;   // Barcode
      nInTarget : USInt;   // Ziel-Station f. Trolley bei My Theresa = 1
   END_VAR

   VAR_OUTPUT 
      xOutSuccess : Bool;
   END_VAR

   VAR_IN_OUT 
      stInOutConveyorStations : "stConveyorStations";
   END_VAR

   VAR_TEMP 
      nCounter : Int;   // Arraynummer bzw. Haken / Trolley
   END_VAR


BEGIN
	// // ****************************************
	// // Ändert Ziel für Barcode in Online-Register Station
	// // ****************************************
	
	IF #stInOutConveyorStations.stData.nTrolleysOnline = 0 THEN
	    RETURN;
	END_IF;
	// Passenden Eintrag finden
	FOR #nCounter := 1 TO ("cHooksSorterMaxPin") DO
	    IF #stInOutConveyorStations.arTrolleysOnline[#nCounter].stCarrier.nBarcode = #nInBarcodeNo THEN
	        EXIT;
	    END_IF;
	END_FOR;
	// Wenn Eintrag gefunden, dann eintragen.
	IF #nCounter < "cHooksSorterMaxPin" THEN
	    #stInOutConveyorStations.arTrolleysOnline[#nCounter].stCarrier.nDestination := #nInTarget;
	    // #stConveyorStations.arTrolleysOnline[#nCounter].stCarrData.xReRouteOverflow := TRUE; // brauchen wir bei ILS nicht (?), war speziell für Pin/Klinke
	    IF (#nInTarget > 0) AND (#nInTarget <= #stInOutConveyorStations.stData.nStations) THEN
	        #stInOutConveyorStations.arTrolleysOnline[#nCounter].stPinValues.nTargetPos := #stInOutConveyorStations.arStationsPos[#nInTarget].nPosIncr;
	        #xOutSuccess := 1;
	    END_IF;
	ELSE
	    #xOutSuccess := 0;
	END_IF;
END_FUNCTION

