FUNCTION_BLOCK "FB_SsccReading"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      stInSenEndMeasurement : "UDT_Sensor";
      xInCarrierReady : Bool;
      xInReadingDone : Bool;
      xInCarrierReleased : Bool;
   END_VAR

   VAR_OUTPUT 
      xOutDoneSSCCReading : Bool;
      xOutHandShake1 : Bool;
      xOutStartTest1 : Bool;
   END_VAR

   VAR 
      nState : Int := 10;
   END_VAR


BEGIN
	REGION _Sscc Reading _
	    CASE #nState OF
	        10:// STANDBY 
	            #xOutDoneSSCCReading := 0;
	            #xOutHandShake1 := 0;
	            #xOutStartTest1 := 0;
	            IF #xInCarrierReady THEN
	                #nState := 20;
	            END_IF;
	            
	        20:// reading 
	            #xOutStartTest1 := 1;
	            IF #xInReadingDone THEN
	                #xOutHandShake1 := 1;
	                #xOutStartTest1 := 0;
	                #nState := 30;
	            END_IF;
	            
	        30:// Waiting end sensor 
	            #xOutDoneSSCCReading := 1;
	            
	            IF #xInCarrierReleased THEN
	                #nState := 40;
	            END_IF;
	            
	        40:
	            #xOutDoneSSCCReading := 0;
	            IF #stInSenEndMeasurement.xDirectSensor THEN
	                #nState := 10;
	            END_IF;
	            
	    END_CASE;
	END_REGION
END_FUNCTION_BLOCK

