• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Programming for serial port

Chupa

Member
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

 
Back
Top