Hi,
I have developed a application for sending a data through COM port(UART Communication), So for entering the data I have made one edit box ,It will get the text when the buttons are pressed.
So inside there will be timer which will be updating for every 25ms , so my application page also refreshing for every 25ms due to this I can't able to delete the characters in the edit box only when the COM port is open..., Without opening the COM port, If I run my application It is working fine and deleting characters.
The following is the PumpMessage code which is working fine for this issue in Visual Studio V6.0
But in VS 2005 , its not working.
void CUARTDlg::PumpMessages()
{
ASSERT(m_hWnd != NULL);
MSG msg;
while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(!IsDialogMessage(&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
COM port.........
void CKB600LRUpreDlg::ClickDasSmartbutton64()
{
DCB dcb;
dcb.BaudRate = 115200;
dcb.ByteSize = 8;
dcb.StopBits = 1;
dcb.Parity = 0;
dcb.fParity = 0;
dcb.fOutxCtsFlow = 0;
dcb.fOutxDsrFlow = 0;
dcb.fDsrSensitivity = 0;
dcb.fTXContinueOnXoff = FALSE;
dcb.fOutX = 0;
dcb.fInX = 0;
dcb.fNull = 0;
dcb.fErrorChar = 0;
dcb.fAbortOnError = 0;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
openPort(dcb,_T("COM2"));
AfxMessageBox(_T("Port Opened Successfully "));
tmr = SetTimer(ID_CLOCK_TIMER,20,NULL);
}
BOOL CKB600LRUpreDlg::openPort(DCB dcb, CString portName)
{
hPort = CreateFile(_T("\\\\.\\COM2"),GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
if (GetCommState(hPort,&dcb) == 0)
{
AfxMessageBox(_T("Get configuration port has problem."));
return FALSE;
}
if (SetCommState(hPort,&dcb) == 0)
{
AfxMessageBox(_T("Set configuration port has problem."));
return FALSE;
}
FlushFileBuffers( hPort );
PurgeComm (hPort, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
COMSTAT comStat;
DWORD dwErrorFlags;
ClearCommError ( hPort, &dwErrorFlags, &comStat );
return FALSE;
}
For Clear ......
void CKB600LRUpreDlg::ClickDasSmartbutton7()
{
if(Shift == 0)
{
int usCurPosS=0;
int pos = 0;
int istart = 0;
int iend = 0;
int &start = istart;
int &end = iend;
UpdateData(true);
m_edit.GetSel(istart,iend);
m_edit.GetSel(usCurPos,usCurPosS);
if(istart == iend)
{
if (usCurPos==0)
{
AfxMessageBox(_T("No Text Has Selected , Please Select The Text "));
m_edit.SetFocus();
return;
}
UpdateData(true);
m_edit.SetFocus();
m_edit.GetSel(usCurPos,usCurPosS);
m_edit.SetSel(usCurPos,usCurPos-1);
UpdateData(false);
}
else
{
m_edit.SetSel(istart,iend);
}
UpdateData(false);
m_edit.Clear();
m_edit.SetFocus();
}
else
{
int istart = 0;
int iend = 0;
int &start = istart;
int &end = iend;
UpdateData(true);
m_edit.GetSel(istart,iend);
m_edit.SetSel(0,iend);
UpdateData(false);
m_edit.Clear();
m_edit.SetFocus();
Shift=0;
}
}
For Key (Button) A
void CKB600LRUpreDlg::ClickDasSmartbutton2()
{
variable = 'B';
function();
}
void CKB600LRUpreDlg::function()
{
int length;
m_edit.GetWindowText(m_TxtSamplingFrequency);
if (usCurPos > m_edit.GetSel())
usCurPos = m_edit.GetSel();
m_TxtSamplingFrequency.Insert(usCurPos, variable);
m_edit.SetWindowText(m_TxtSamplingFrequency);
usCurPos++;
m_edit.SetSel(usCurPos,usCurPos);
length=m_TxtSamplingFrequency.GetLength();
if(length>32)
{
AfxMessageBox(_T("Maximum Text Limit Reached "));
m_edit.SetFocus();
return;
}
m_edit.SetFocus();
}