function Receive_Data(var Receive_Buffer:array of byte;Read_Len:integer):boolean;<br>var<br> Clear:Boolean;<br> dwnumberofbytesread:dword;<br> errorflag:dword;<br>begin<br> fillchar(Receive_Buffer,Read_Len,#0);<br> while true do<br> begin<br> Clear:=Clearcommerror(com_handle,errorflag,@Comstate);<br> if comstate.cbInQue>=read_len then<br> break;<br> if not clear then<br> begin<br> result:=false;<br> exit;<br> end ;<br> sleep(25);<br> end;<br> if Comstate.cbInQue=0 then<br> begin<br> result:=false;<br> exit;<br> end; <br> if comstate.cbInQue>0 then<br> begin<br> if (not readfile(com_handle,receive_buffer[0],read_len,dwnumberofbytesread,@read_os)) then<br> begin<br> result:=false;<br> exit;<br> end;<br> if dwnumberofbytesread>0 then<br> read_os.Offset:=read_os.Offset+dwnumberofbytesread;<br> end;<br> result:=true;<br>end;