Programming for serial port

Chupa

Member
Aug 28, 2000
155
0
0
Hi,
I'm trying to write a program that accesses a device on COM1, reads data
from it, and stores it. I am running Win 2k, for what its worth.
My problem is in the ReadFile statement. For some reason, my program
will run fine for a bit, I can type in characters and the device will
respond, and then the program will lock up. The function it always locks
up on is the ReadFile function. The way I call it is: ReadFile(hComm,
InBuff, 1, &dwBytesRead, NULL);, where hComm is the comm handler defined
as:
hComm = CreateFile("COM1",
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
0,
0);
ctmoNew.ReadTotalTimeoutConstant = 10;
ctmoNew.ReadTotalTimeoutMultiplier = 0;
ctmoNew.WriteTotalTimeoutMultiplier = 0;
ctmoNew.WriteTotalTimeoutConstant = 10;
SetCommTimeouts(hComm, &ctmoNew);

dcbCommPort.DCBlength = sizeof(DCB);
GetCommState(hComm, &dcbCommPort);
BuildCommDCB("9600,N,8,1", &dcbCommPort);
SetCommState(hComm, &dcbCommPort);

I have tried various times for the timeouts but nothing works. I think
one of the things I need to do is to turn on CTS/RTS flow control. What
do I need to add to the BuildCommDCB statement to do this?
Thanks for your help,
-Rob