FUNCTION_BLOCK "FB_Visu_AuslagernList"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      arrudt_AngeforderteCarrier { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Array[0..26964] of "udt_InfoRequestedCarrier";
   END_VAR

   VAR_OUTPUT 
      udt_JamListState : Array[0..14] of "udt_InfoRequestedCarrier";
      di_FirstIndex : DInt;
      di_LastIndex : DInt;
   END_VAR

   VAR_IN_OUT 
      i_ValidCount : Int := 0;
      udt_JamListCtrl : "udt_JamListCtrl";
   END_VAR

   VAR 
      MaxStart : Int;
      srcIndex : Int;
      Lrtrig_S_Increase1 {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
      Lrtrig_S_Increase15 {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
      Lrtrig_S_Decrease1 {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
      Lrtrig_S_Decrease15 {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
      Lrtrig_S_ScrollStart {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
      Lrtrig_S_ScrollEnd {InstructionName := 'R_TRIG'; LibVersion := '1.0'} : R_TRIG;
      i_IndexArrayBefüllen { S7_SetPoint := 'True'} : Int;
      udt_InfoRequestedCarrierClear { S7_SetPoint := 'False'} : "udt_InfoRequestedCarrier";
   END_VAR

   VAR CONSTANT 
      cMinArray : Int := 0;
      cMaxArray : Int := 14;
      cPage : DInt := 10;
   END_VAR


BEGIN
	REGION Info
	(* ------------------------------------------------------------------------------------------------
	   Modulname    : FB_Visu_AuslagernList
	   Date         : 16.10.2025              
	   Author       : Kannler Thomas / Automated-Intelligence
	   Info         : FB für das Scrollen/Durchtippen der Auslagerungsliste der angeforderten Carrier
	                           
	   ChangeLog:   : 
	   ---------------------------------------------------------------------------------------------- *)
	END_REGION
	
	REGION Flankenauswertung
	    #Lrtrig_S_Decrease1(CLK:=#udt_JamListCtrl.DecOne);
	    #Lrtrig_S_Increase1(CLK:=#udt_JamListCtrl.IncOne);
	    #Lrtrig_S_Decrease15(CLK:=#udt_JamListCtrl.DecTen);
	    #Lrtrig_S_Increase15(CLK:=#udt_JamListCtrl.IncTen);
	    #Lrtrig_S_ScrollStart(CLK:=#udt_JamListCtrl.ScrollStart);
	    #Lrtrig_S_ScrollEnd(CLK:=#udt_JamListCtrl.ScrollEnd);
	    
	END_REGION
	
	REGION Grenzen
	    //ValidCount
	    IF #i_ValidCount < 0 THEN
	        #i_ValidCount := 0;
	    END_IF;
	    
	    //Max Start
	    #MaxStart := #i_ValidCount;// - 10;  auskommentiert
	    
	    IF #MaxStart < 0 THEN
	        #MaxStart := 0;
	    END_IF;
	END_REGION
	
	REGION Buttons auswerten
	    IF #Lrtrig_S_ScrollStart.Q THEN
	        #udt_JamListCtrl.nIndex := 0;
	    ELSIF #Lrtrig_S_ScrollEnd.Q THEN
	        #udt_JamListCtrl.nIndex := #MaxStart;
	    ELSIF #Lrtrig_S_Decrease15.Q THEN
	        #udt_JamListCtrl.nIndex := #udt_JamListCtrl.nIndex - 15;
	    ELSIF #Lrtrig_S_Increase15.Q THEN
	        #udt_JamListCtrl.nIndex := #udt_JamListCtrl.nIndex + 15;
	    ELSIF #Lrtrig_S_Decrease1.Q THEN
	        #udt_JamListCtrl.nIndex := #udt_JamListCtrl.nIndex - 1;
	    ELSIF #Lrtrig_S_Increase1.Q THEN
	        #udt_JamListCtrl.nIndex := #udt_JamListCtrl.nIndex + 1;
	    ELSE
	        #udt_JamListCtrl.DecOne := FALSE;
	        #udt_JamListCtrl.DecTen := FALSE;
	        #udt_JamListCtrl.IncOne := FALSE;
	        #udt_JamListCtrl.IncTen := FALSE;
	        #udt_JamListCtrl.ScrollEnd := FALSE;
	        #udt_JamListCtrl.ScrollStart := FALSE;
	    END_IF;
	    
	END_REGION
	
	REGION Clamp
	    // Begrenzung nach Button-Eingabe
	    IF #udt_JamListCtrl.nIndex < 0 THEN
	        #udt_JamListCtrl.nIndex := 0;
	    END_IF;
	    
	    IF #udt_JamListCtrl.nIndex > #MaxStart THEN
	        #udt_JamListCtrl.nIndex := #MaxStart;
	    END_IF;
	    
	END_REGION
	
	REGION 15er-View füllen
	    //Befüllen des Arrays mit 15 Carriern anhand des Index 
	    FOR #i_IndexArrayBefüllen := #cMinArray TO #cMaxArray DO
	        #srcIndex := #udt_JamListCtrl.nIndex + #i_IndexArrayBefüllen + 1;
	        IF (#srcIndex >= 1) AND (#srcIndex <= #i_ValidCount) AND (#srcIndex <= 26964) THEN
	            #udt_JamListState[#i_IndexArrayBefüllen] := #arrudt_AngeforderteCarrier[#srcIndex];
	        ELSE
	            #udt_JamListState[#i_IndexArrayBefüllen] := #udt_InfoRequestedCarrierClear;
	        END_IF;
	    END_FOR;
	    
	END_REGION
	
END_FUNCTION_BLOCK

