FUNCTION_BLOCK "FB_EventLog_Correction"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      xInTrigger : Bool;
      stInEventCorrectionInfo : "stEventCorrectionInfo";
   END_VAR

   VAR 
      fbPaEventLogCorrection {InstructionName := 'Program_Alarm'; LibVersion := '1.0'} : Program_Alarm;
      wStatus : Word;
      sLogMessage : String;
      sDelimiter : String[1] := ',';
      sFunction : String[10];
      xTriggerFlag : Bool;
   END_VAR

   VAR_TEMP 
      xError : Bool;
      tRunProgramAlarm : Bool;
   END_VAR


BEGIN
	REGION Call Logging Program Alarm
	    IF #xTriggerFlag XOR #xInTrigger THEN
	        
	        REGION Build Message
	            #sDelimiter := ';';
	            #sFunction := 'Korrektur';
	            
	            CASE #stInEventCorrectionInfo.nCorrectionType OF
	                0:
	                    #sLogMessage := CONCAT_STRING(IN1 := "FC_DateAsString"(),
	                                                  IN2 := #sDelimiter,
	                                                  IN3 := "FC_TimeAsString"(),
	                                                  IN4 := #sDelimiter,
	                                                  IN5 := #sFunction,
	                                                  IN6 := #sDelimiter,
	                                                  IN7 := 'Carrier(',
	                                                  IN8 := 'Barcode:',
	                                                  IN9 := #stInEventCorrectionInfo.sBarcode,
	                                                  IN10 := #sDelimiter,
	                                                  IN11 := 'JobNo:',
	                                                  IN12 := #stInEventCorrectionInfo.sJobNo,
	                                                  IN13 := #sDelimiter,
	                                                  IN14 := 'ProdNo:',
	                                                  IN15 := #stInEventCorrectionInfo.sProductNo,
	                                                  IN16 := #sDelimiter,
	                                                  IN17 := 'Dest:',
	                                                  IN18 := #stInEventCorrectionInfo.sDest,
	                                                  IN19 := ')',
	                                                  IN20 := ' aus HJ entfernt');
	                1:
	                    #sLogMessage := CONCAT_STRING(IN1 := "FC_DateAsString"(),
	                                                  IN2 := #sDelimiter,
	                                                  IN3 := "FC_TimeAsString"(),
	                                                  IN4 := #sDelimiter,
	                                                  IN5 := #sFunction,
	                                                  IN6 := #sDelimiter,
	                                                  IN7 := 'Carrier(',
	                                                  IN8 := 'Barcode:',
	                                                  IN9 := #stInEventCorrectionInfo.sBarcode,
	                                                  IN10 := #sDelimiter,
	                                                  IN11 := 'JobNo:',
	                                                  IN12 := #stInEventCorrectionInfo.sJobNo,
	                                                  IN13 := #sDelimiter,
	                                                  IN14 := 'ProdNo:',
	                                                  IN15 := #stInEventCorrectionInfo.sProductNo,
	                                                  IN16 := #sDelimiter,
	                                                  IN17 := 'Dest:',
	                                                  IN18 := #stInEventCorrectionInfo.sDest,
	                                                  IN19 := ')',
	                                                  IN20 := ' in ',
	                                                  IN21 := #stInEventCorrectionInfo.sLoc,
	                                                  IN22 := ' Pos ',
	                                                  IN23 := #stInEventCorrectionInfo.sPos,
	                                                  IN24 := ' entfernt und Rest nachgeschoben');
	                2:
	                    #sLogMessage := CONCAT_STRING(IN1 := "FC_DateAsString"(),
	                                                  IN2 := #sDelimiter,
	                                                  IN3 := "FC_TimeAsString"(),
	                                                  IN4 := #sDelimiter,
	                                                  IN5 := #sFunction,
	                                                  IN6 := #sDelimiter,
	                                                  IN7 := 'Carrier(',
	                                                  IN8 := 'Barcode:',
	                                                  IN9 := #stInEventCorrectionInfo.sBarcode,
	                                                  IN10 := #sDelimiter,
	                                                  IN11 := 'JobNo:',
	                                                  IN12 := #stInEventCorrectionInfo.sJobNo,
	                                                  IN13 := #sDelimiter,
	                                                  IN14 := 'ProdNo:',
	                                                  IN15 := #stInEventCorrectionInfo.sProductNo,
	                                                  IN16 := #sDelimiter,
	                                                  IN17 := 'Dest:',
	                                                  IN18 := #stInEventCorrectionInfo.sDest,
	                                                  IN19 := ')',
	                                                  IN20 := ' in ',
	                                                  IN21 := #stInEventCorrectionInfo.sLoc,
	                                                  IN22 := ' Pos ',
	                                                  IN23 := #stInEventCorrectionInfo.sPos,
	                                                  IN24 := ' durch Dummy ersetzt');
	                3:
	                    #sLogMessage := CONCAT_STRING(IN1 := "FC_DateAsString"(),
	                                                  IN2 := #sDelimiter,
	                                                  IN3 := "FC_TimeAsString"(),
	                                                  IN4 := #sDelimiter,
	                                                  IN5 := #sFunction,
	                                                  IN6 := #sDelimiter,
	                                                  IN7 := 'Carrier(',
	                                                  IN8 := 'Barcode:',
	                                                  IN9 := #stInEventCorrectionInfo.sBarcode,
	                                                  IN10 := #sDelimiter,
	                                                  IN11 := 'JobNo:',
	                                                  IN12 := #stInEventCorrectionInfo.sJobNo,
	                                                  IN13 := #sDelimiter,
	                                                  IN14 := 'ProdNo:',
	                                                  IN15 := #stInEventCorrectionInfo.sProductNo,
	                                                  IN16 := #sDelimiter,
	                                                  IN17 := 'Dest:',
	                                                  IN18 := #stInEventCorrectionInfo.sDest,
	                                                  IN19 := ')',
	                                                  IN20 := #sDelimiter,
	                                                  IN21 := ' in Hyper-Jam eingefuegt');
	            END_CASE;
	            
	        END_REGION
	        
	        #fbPaEventLogCorrection(SIG := #xInTrigger,
	                             SD_1 := #sLogMessage,
	                             Status => #wStatus,
	                             Error => #xError);
	    END_IF;
	END_REGION
	
	REGION Flags
	    #xTriggerFlag := #xInTrigger;
	END_REGION
END_FUNCTION_BLOCK

