Posted on 1997-09-07
I am having a bit of trouble using serial communications with C. I am using a Dell XM590 90Mhz with NT4 server and VC++ compiler. Although I am using the C++ compiler, I am writing in generic C and not using any MFC (that I'm aware of). I am trying to communicate with an RS232 compliant device (not a modem) on COM2. The puropse of this device is to simply sit and wait until it gets a radio signal from another source, then pass information to the computer based on that radio signal. I have verified that the device is working properly by hooking it to another computer and a generic testing program specifically made for this device.
I started out by opening the device with the CreateFile function. I then checked the status of the device by sending a command by ReadFile and WriteFile. So far, everything is working fine. The problem occurs while trying to wait for the radio signal. I set the comm mask to EV_RXCHAR, then use the WaitCommEvent function to wait for a character to arrive indicating that the radio signal has activated the device. This is failing miserably. Even though the comm mask is set, the WaitCommFunction fires on every comm event, seemingly even nonexistent ones. The code for this function looks something like this:
BOOL quit = FALSE;
HANDLE h = CreateFile(paramaters); /* opens the comm port.
WriteFileEx(paramaters); /*sets the device in command mode.
ReadFileEx(paramaters); /*reads the response verifying command mode
WriteFileEx(paramaters); /*set the device to data mode
ReadFileEx(paramaters); /*get the data mode response and clear the input buffer.
SetCommMask(h, EV_RXCHAR); /*set the comm mask to wait for an incoming character.
If(ReadFileBuffer == 0x0A) /*The code for incoming communication
ReadFileEx(parameters); /*Read the rest of the buffer and parse the data
I know this is rather vauge as source code goes, but I don't have the original code with me, and hopefully this gievs an idea of what I am trying to accomplish.