FUNCTION_BLOCK "FB_EventLog_Scan"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      xInTrigger : Bool;
      stInEventScanInfo : "stEventScanInfo";
   END_VAR

   VAR 
      fbPaEventLogScan {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: Program Alarm
	    IF #xTriggerFlag XOR #xInTrigger THEN
	        
	        REGION Meldetext
	            #sDelimiter := ';';
	            #sFunction := 'Scan';
	            
	            CASE #stInEventScanInfo.nScanType OF
	                0:  
	                    #sLogMessage := CONCAT_STRING(IN1 := "FC_DateAsString"(),
	                                                  IN2 := #sDelimiter,
	                                                  IN3 := "FC_TimeAsString"(),
	                                                  IN4 := #sDelimiter,
	                                                  IN5 := #sFunction,
	                                                  IN6 := #sDelimiter,
	                                                  IN7 := 'Carrier(',
	                                                  IN8 := 'Barcode:',
	                                                  IN9 := #stInEventScanInfo.sBarcode,
	                                                  IN10 := #sDelimiter,
	                                                  IN11 := 'JobNo:',
	                                                  IN12 := #stInEventScanInfo.sJobNo,
	                                                  IN13 := #sDelimiter,
	                                                  IN14 := 'ProdNo:',
	                                                  IN15 := #stInEventScanInfo.sProductNo,
	                                                  IN16 := #sDelimiter,
	                                                  IN17 := 'Dest:',
	                                                  IN18 := #stInEventScanInfo.sDest,
	                                                  IN19 := ')',
	                                                  IN20 := ' bei SC',
	                                                  IN21 := #stInEventScanInfo.sReaderId,
	                                                  IN22 := ' Mat.Nr. nicht lesbar');
	                  
	                1:
	                    #sLogMessage := CONCAT_STRING(IN1 := "FC_DateAsString"(),
	                                                  IN2 := #sDelimiter,
	                                                  IN3 := "FC_TimeAsString"(),
	                                                  IN4 := #sDelimiter,
	                                                  IN5 := #sFunction,
	                                                  IN6 := #sDelimiter,
	                                                  IN7 := 'Carrier(',
	                                                  IN8 := 'Barcode:',
	                                                  IN9 := #stInEventScanInfo.sBarcode,
	                                                  IN10 := '(erwartet)',
	                                                  IN11 := #sDelimiter,
	                                                  IN12 := 'JobNo:',
	                                                  IN13 := #stInEventScanInfo.sJobNo,
	                                                  IN14 := #sDelimiter,
	                                                  IN15 := 'ProdNo:',
	                                                  IN16 := #stInEventScanInfo.sProductNo,
	                                                  IN17 := #sDelimiter,
	                                                  IN18 := 'Dest:',
	                                                  IN19 := #stInEventScanInfo.sDest,
	                                                  IN20 := ')',
	                                                  IN21 := ' bei SC',
	                                                  IN22 := #stInEventScanInfo.sReaderId,
	                                                  IN23 := ' nicht lesbar');
	                2:
	                    #sLogMessage := CONCAT_STRING(IN1 := "FC_DateAsString"(),
	                                                  IN2 := #sDelimiter,
	                                                  IN3 := "FC_TimeAsString"(),
	                                                  IN4 := #sDelimiter,
	                                                  IN5 := #sFunction,
	                                                  IN6 := #sDelimiter,
	                                                  IN7 := 'Carrier(',
	                                                  IN8 := 'Barcode:',
	                                                  IN9 := #stInEventScanInfo.sBarcode,
	                                                  IN10 := #sDelimiter,
	                                                  IN11 := 'JobNo:',
	                                                  IN12 := #stInEventScanInfo.sJobNo,
	                                                  IN13 := #sDelimiter,
	                                                  IN14 := 'ProdNo:',
	                                                  IN15 := #stInEventScanInfo.sProductNo,
	                                                  IN16 := #sDelimiter,
	                                                  IN17 := 'Dest:',
	                                                  IN18 := #stInEventScanInfo.sDest,
	                                                  IN19 := ')',
	                                                  IN20 := ' bei SC',
	                                                  IN21 := #stInEventScanInfo.sReaderId,
	                                                  IN22 := ' neu hinzugefuegt');
	                3:
	                    #sLogMessage := CONCAT_STRING(IN1 := "FC_DateAsString"(),
	                                                  IN2 := #sDelimiter,
	                                                  IN3 := "FC_TimeAsString"(),
	                                                  IN4 := #sDelimiter,
	                                                  IN5 := #sFunction,
	                                                  IN6 := #sDelimiter,
	                                                  IN7 := 'Carrier(',
	                                                  IN8 := 'Barcode:',
	                                                  IN9 := #stInEventScanInfo.sBarcode,
	                                                  IN10 := #sDelimiter,
	                                                  IN11 := 'JobNo:',
	                                                  IN12 := #stInEventScanInfo.sJobNo,
	                                                  IN13 := #sDelimiter,
	                                                  IN14 := 'ProdNo:',
	                                                  IN15 := #stInEventScanInfo.sProductNo,
	                                                  IN16 := #sDelimiter,
	                                                  IN17 := 'Dest:',
	                                                  IN18 := #stInEventScanInfo.sDest,
	                                                  IN19 := ')',
	                                                  IN20 := ' bei SC',
	                                                  IN21 := #stInEventScanInfo.sReaderId,
	                                                  IN22 := ' unbekannter Carrier hinzugefuegt');
	               // Good Reads     
	                4:
	                    #sLogMessage := CONCAT_STRING(IN1 := "FC_DateAsString"(),
	                                                  IN2 := #sDelimiter,
	                                                  IN3 := "FC_TimeAsString"(),
	                                                  IN4 := #sDelimiter,
	                                                  IN5 := #sFunction,
	                                                  IN6 := #sDelimiter,
	                                                  IN7 := 'Carrier(',
	                                                  IN8 := 'Barcode:',
	                                                  IN9 := #stInEventScanInfo.sBarcode,
	                                                  IN10 := #sDelimiter,
	                                                  IN11 := 'JobNo:',
	                                                  IN12 := #stInEventScanInfo.sJobNo,
	                                                  IN13 := #sDelimiter,
	                                                  IN14 := 'ProdNo:',
	                                                  IN15 := #stInEventScanInfo.sProductNo,
	                                                  IN16 := #sDelimiter,
	                                                  IN17 := 'Dest:',
	                                                  IN18 := #stInEventScanInfo.sDest,
	                                                  IN19 := ')',
	                                                  IN20 := ' bei SC',
	                                                  IN21 := #stInEventScanInfo.sReaderId,
	                                                  IN22 := ' gelesen');
	                    
	            END_CASE;
	           
	        END_REGION
	        
	        #fbPaEventLogScan(SIG := #xInTrigger,
	                             SD_1 := #sLogMessage,
	                             Status => #wStatus,
	                             Error => #xError);
	    END_IF;
	END_REGION
	
	REGION Flanken
	    #xTriggerFlag := #xInTrigger;
	END_REGION
END_FUNCTION_BLOCK

