
(* TODO: Add your comment here *)
FUNCTION_BLOCK ReadFileOnDisk
	IF(Execute = FALSE)THEN
		step := 0;
		Done := FALSE;
	END_IF;
	
	CASE step OF
		0:			
			IF(Execute = TRUE)THEN
				file_open.enable := TRUE;
				file_open.pDevice := ADR(file_device);
				file_open.pFile := ADR(file_path);
				file_open.mode := FILE_RW;
				file_open();
				IF(file_open.status = 0)THEN
					step := 1;
				ELSIF(file_open.status <> ERR_FUB_BUSY)THEN
					step := 69;		
				END_IF;
			END_IF;
		1: 
			file_read.enable := TRUE;
			file_read.ident := file_open.ident;
			file_read.offset := 0;
			file_read.pDest := data_adr;
			file_read.len := file_open.filelen;	
			file_read();
			IF(file_read.status = 0)THEN	
				step := 2;
				file_size := file_open.filelen;
			ELSIF(file_read.status <> ERR_FUB_BUSY)THEN
				step := 69;
			END_IF;
		2:
			file_close.enable := TRUE;
			file_close.ident := file_open.ident;
			file_close();
			IF(file_close.status = 0)THEN
				step := 3;
			ELSIF(file_close.status <> ERR_FUB_BUSY)THEN
				step := 69;
			END_IF;
		3:
			Done := TRUE;
	END_CASE		
END_FUNCTION_BLOCK
