Tisme
January 16th, 2003, 08:22 PM
I have an application that sends piles of data down the com line to an external device, and for the most part it works fine.
The external device can at any time send a CTRL_S message to the application that tells it to suspend sending data until a CTRL_Q is sent.
The app will in fact stop sending data until it receives the CTRL_Q signal. No new data is sent to the i/o port.
But, there can (and invariably is) data still stored in the i/o device that will be sent down the line to the external device. Is there any way that upon receiving the CTRL_S signature, that my app can force the hardware to not send what's in it's buffer.
(The problem arises because the external device sends a CTRL_S when it's buffer is getting full to halt the data stream. Any data received after it sends the CTRL_S is either discarded, or causes bad things on the external device).
The routine responsible for sending the data:
BOOL ZComm::WriteFile(unsigned char ch)
{
m_nWritingNumber ++ ;
if ( !::WriteFile(h_File,&ch,1,m_pdw,&ov_Write))
{
DWORD dw;
if (GetLastError() == ERROR_IO_PENDING)
return GetOverlappedResult(h_File, // Handle to COMM port
&ov_Write,// Overlapped structure
&dw, // Stores number of bytes sent
TRUE); // Wait flag
return FALSE;
}
return TRUE;
}
I also use the functions:
ClearCommError
SetCommState
etc
to set up Comm port information.
Thanks for any advice, or pointers.
The external device can at any time send a CTRL_S message to the application that tells it to suspend sending data until a CTRL_Q is sent.
The app will in fact stop sending data until it receives the CTRL_Q signal. No new data is sent to the i/o port.
But, there can (and invariably is) data still stored in the i/o device that will be sent down the line to the external device. Is there any way that upon receiving the CTRL_S signature, that my app can force the hardware to not send what's in it's buffer.
(The problem arises because the external device sends a CTRL_S when it's buffer is getting full to halt the data stream. Any data received after it sends the CTRL_S is either discarded, or causes bad things on the external device).
The routine responsible for sending the data:
BOOL ZComm::WriteFile(unsigned char ch)
{
m_nWritingNumber ++ ;
if ( !::WriteFile(h_File,&ch,1,m_pdw,&ov_Write))
{
DWORD dw;
if (GetLastError() == ERROR_IO_PENDING)
return GetOverlappedResult(h_File, // Handle to COMM port
&ov_Write,// Overlapped structure
&dw, // Stores number of bytes sent
TRUE); // Wait flag
return FALSE;
}
return TRUE;
}
I also use the functions:
ClearCommError
SetCommState
etc
to set up Comm port information.
Thanks for any advice, or pointers.