0

I have implemented ReadFile function for reading data through SerialPort.When the other end is responding correctely my program is working fine.
Sometimes when I dont get data from the other end my program hangs.For this I have implemented timeouts for Readfile function.
But It doesnt seem to be working.

My initial timeout settings are :

COMMTIMEOUTS noblock;
		GetCommTimeouts(rsi_handle, &noblock);
		noblock.ReadIntervalTimeout         = 5;
		noblock.ReadTotalTimeoutConstant    = 1;
		noblock.ReadTotalTimeoutMultiplier  = 1;
		noblock.WriteTotalTimeoutConstant   = 1;
		noblock.WriteTotalTimeoutMultiplier = 1;

my readfile function read a single character in a loop until it gets a last character which is checked correctely.

if (ReadFile(rsi_handle,&c,1, &dwByteCount_r, NULL) == 0)
	{
		printf("Uart read Failed\n");
		return 1;//failure
	}

I am not getting the read failed message also.
can anyone help me on this.I have tried even increasing the "ReadTimeOutMultiplier" and "ReadTimeOutConstant" values also.But in vain.

2
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by abhi.nalluri
0

no I have used it also.

if (SetCommTimeouts(H_handle, &noblock) == 0)
error();
0

Here I am just trying to get the default values.
But my problem s solved.I just gave a try creating a thread.Its working fine

Thanks a lot.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.