Thank you for the reply! my problem has been resolved. WindowCE does not support the overlapped I/O, the read and write needed to be in the separated thread. Also, to avoid the race condition, I used semaphore.
Liang
Question
Im trying to use the readfile
function to read data from a CDC device in the WinCE environment.
BOOL WINAPI ReadFile(
_In_ HANDLE hFile,
_Out_ LPVOID lpBuffer,
_In_ DWORD nNumberOfBytesToRead,
_Out_opt_ LPDWORD lpNumberOfBytesRead,
_Inout_opt_ LPOVERLAPPED lpOverlapped
);
I would like to know what is the size limit for the readbuf
. I am sending the block of 256 bytes of data for 100 times, the parameter lpNumberOfBytesRead
from the ReadFile
returns 173 bytes on the first try, and 0 all other 99 times. Please let me know what I am missing. Also what is the size limit for the 'writebuf'? below is code for the port open
BOOL PortOpen()
{
Close();
ComPort = INVALID_HANDLE_VALUE;
COMMTIMEOUTS ct;
ComPort=CreateFile (TEXT("COM1:"), GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);
if (ComPort != INVALID_HANDLE_VALUE) {
dcb.DCBlength = sizeof (dcb);
GetCommState (hLocal, &dcb);
dcb.BaudRate = 115200;
dcb.fParity = FALSE;
dcb.fNull = FALSE;
dcb.StopBits = ONESTOPBIT;
dcb.Parity = NOPARITY;
dcb.ByteSize = 8;
SetCommState (ComPort, &dcb);
ct.ReadIntervalTimeout = 0;
ct.ReadTotalTimeoutMultiplier = 0;
ct.ReadTotalTimeoutConstant = 0;
ct.WriteTotalTimeoutMultiplier = 0;
ct.WriteTotalTimeoutConstant = 0;
SetCommTimeouts (hLocal, &ct);
}
Liang
Solution 2
Thank you for the reply! my problem has been resolved. WindowCE does not support the overlapped I/O, the read and write needed to be in the separated thread. Also, to avoid the race condition, I used semaphore.
Liang
OTHER TIPS
Timeouts for the ReadFile operation can be configured using SetCommTimeouts API, are you sure that your code is not calling it? In that case the number of bytes returned can vary, depending on the different timeout parameters you set.