I have a console test app to verify a legacy unit which responds over an old fashioned RS232 Serial line. It's a simple manual setup which requires a button push on the box in response to a buzzer signal sent from the controlling PC. This is a simple setup but a serious application, it's used in seismic surveying to mark the deployment of sonar devices on an ocean bottom cable.
The system sends out its "within window" beep on the RTS line and then listens on the CTS line for a change of state caused by the button press on the external box to verify deployment of the next device. The box simply generates a 5ms negative going pulse on the CTS line representing an OFF state to an ON state, (it's RS232 so OFF is a +ve voltage and ON is a -ve one so it needs to be a +ve to -ve transistion which gets detected).
I'm using this code:
if (WaitCommEvent(hComm, &dwEvent, NULL)) {
.....if (dwEvent & EV_CTS) {
..........DWORD dwCommStatus = 0;
..........GetCommModemStatus(hComm, &dwCommStatus);
..........if (MS_CTS_ON & dwCommStatus) {
...............printf("\n CTS change detected. CTS test terminating.\n");
...............//DO STUFF!
..........}
.....}
}
I have no problem with the coding to get a response, the app responds to the pulse reliably so hardware seems fine. My problem is that I seem to have something hanging around in the system which causes oddities after the initial response. I had wondered if the Modem Status firstly responds to the correct falling edge but then also generates another secondary response due to the rising edge which would not be set for MS_CTS_ON. I am wondering if I may have to set something to remove the rising edge response otherwise that secondary response is left in the buffer so my software responds to it immediately the next call to GetCommModemStatus() is made. Of course that would givew a FALSE response to "if (MS_CTS_ON & dwCommStatus) {}"
Is there a possibility there is anything in all of this rambling?
The system sends out its "within window" beep on the RTS line and then listens on the CTS line for a change of state caused by the button press on the external box to verify deployment of the next device. The box simply generates a 5ms negative going pulse on the CTS line representing an OFF state to an ON state, (it's RS232 so OFF is a +ve voltage and ON is a -ve one so it needs to be a +ve to -ve transistion which gets detected).
I'm using this code:
if (WaitCommEvent(hComm, &dwEvent, NULL)) {
.....if (dwEvent & EV_CTS) {
..........DWORD dwCommStatus = 0;
..........GetCommModemStatus(hComm, &dwCommStatus);
..........if (MS_CTS_ON & dwCommStatus) {
...............printf("\n CTS change detected. CTS test terminating.\n");
...............//DO STUFF!
..........}
.....}
}
I have no problem with the coding to get a response, the app responds to the pulse reliably so hardware seems fine. My problem is that I seem to have something hanging around in the system which causes oddities after the initial response. I had wondered if the Modem Status firstly responds to the correct falling edge but then also generates another secondary response due to the rising edge which would not be set for MS_CTS_ON. I am wondering if I may have to set something to remove the rising edge response otherwise that secondary response is left in the buffer so my software responds to it immediately the next call to GetCommModemStatus() is made. Of course that would givew a FALSE response to "if (MS_CTS_ON & dwCommStatus) {}"
Is there a possibility there is anything in all of this rambling?