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.

Recommended Answers

All 4 Replies

Did you forget to SET timeout parameters via SetCommTimeouts call?..

no I have used it also.

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

Well, the 1st snippet does not bear a relation to setting timeout for rsi_handle...

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.