COMMTIMEOUTS

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am developing a com port application and am having trouble getting the following command to receive all sent bytes

BOOL rc
COMMTIMEOUTS CommTimeOuts
CommTimeOuts.ReadIntervalTimeout = 1
CommTimeOuts.ReadTotalTimeoutMultiplier = 1
CommTimeOuts.ReadTotalTimeoutConstant = 5
CommTimeOuts.WriteTotalTimeoutConstant = 1
CommTimeOuts.WriteTotalTimeoutMultiplier = 1
hComm = CreateFile(m_ComPort,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING, 0,0)
SetCommTimeouts(hComm,&CommTimeOuts)
rc = ReadFile(hComm,&pDoc->caDeviceReadBuffer,sizeof(pDoc->caDeviceReadBuffer),&dwRead,0)

I don't seem to be able to control the read timeout durations, it seems to always timeout before all characters have been received

Thanks
George
 
George said:
I am developing a com port application and am having trouble getting the
following command to receive all sent bytes:
BOOL rc;
COMMTIMEOUTS CommTimeOuts;
CommTimeOuts.ReadIntervalTimeout = 1;
CommTimeOuts.ReadTotalTimeoutMultiplier = 1;
CommTimeOuts.ReadTotalTimeoutConstant = 5;
CommTimeOuts.WriteTotalTimeoutConstant = 1;
CommTimeOuts.WriteTotalTimeoutMultiplier = 1;
hComm = CreateFile(m_ComPort,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING, 0,0);
SetCommTimeouts(hComm,&CommTimeOuts);
rc = ReadFile(hComm,&pDoc->caDeviceReadBuffer,sizeof(pDoc->caDeviceReadBuffer),&d
wRead,0);

I don't seem to be able to control the read timeout durations, it seems to
always timeout before all characters have been received.

IMO, You should also do a SetupComm and a SetCommState between the
CreateFile and the ReadFile.

Without knowing something about what your data looks like and how big the
read buffer is, it's hard to say whether it's timing out prematurely.

I don't tend to find real applications where I set both RIT and RTTM/C,
though no doubt they exist - are you sure you're clear about their
functions?

Will
 
----- Will Dean wrote: ----


George said:
I am developing a com port application and am having trouble getting th
following command to receive all sent bytes
COMMTIMEOUTS CommTimeOuts
CommTimeOuts.ReadIntervalTimeout = 1
CommTimeOuts.ReadTotalTimeoutMultiplier = 1
CommTimeOuts.ReadTotalTimeoutConstant = 5
CommTimeOuts.WriteTotalTimeoutConstant = 1
CommTimeOuts.WriteTotalTimeoutMultiplier = 1
hComm = CreateFile(m_ComPort,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING 0,0)
ReadFile(hComm,&pDoc->caDeviceReadBuffer,sizeof(pDoc->caDeviceReadBuffer),&
wRead,0)
always timeout before all characters have been received

IMO, You should also do a SetupComm and a SetCommState between th
CreateFile and the ReadFile

Without knowing something about what your data looks like and how big th
read buffer is, it's hard to say whether it's timing out prematurely

I don't tend to find real applications where I set both RIT and RTTM/C
though no doubt they exist - are you sure you're clear about thei
functions

Wil

Thanks Will
After further testing the real problem seems to be that ReadFile cannot receive more that 4096 bytes for each call, no matter what larger number I specify in the nNumberOfBytesToRead parameter. I am tring to read 32768 bytes and I have found a work around by setting up an eight iteration for loop that reads 4096 bytes on each pass. The documentation defines the nNumberOfBytesToRead parameter as a DWORD that should be abel to hold value 32768
Georg
 
George said:
Thanks Will,
After further testing the real problem seems to be that ReadFile cannot
receive more that 4096 bytes for each call, no matter what larger number I
specify in the nNumberOfBytesToRead parameter. I am tring to read 32768
bytes and I have found a work around by setting up an eight iteration for
loop that reads 4096 bytes on each pass. The documentation defines the
nNumberOfBytesToRead parameter as a DWORD that should be abel to hold value
32768.

Have you called SetupComm?

Will
 
----- Will Dean wrote: ----

George said:
After further testing the real problem seems to be that ReadFile canno
receive more that 4096 bytes for each call, no matter what larger number
specify in the nNumberOfBytesToRead parameter. I am tring to read 3276
bytes and I have found a work around by setting up an eight iteration fo
loop that reads 4096 bytes on each pass. The documentation defines th
nNumberOfBytesToRead parameter as a DWORD that should be abel to hold valu
32768

Have you called SetupComm

Wil

Yes, with the following comman
rc = SetupComm(hComm,32768,32768)
Georg
 
It may be that you need to use

rc = SetupComm( hComm, 33000, 33000 );

i.e. you need to provide slightly bigger buffers than the maximum amount you
would like to read or write. This is not documented, but I discovered this
when I wrote a serial program.

My maximum was 4096, and I always ensured that the buffers were at least
4296, i.e. size + 200.

Best Regards
Julian N.
 
thanks Julian, that was the source of my problems
I added

rc = SetupComm( hComm, 32678, 32768)

and now things are working as desired
 
Back
Top