Re: about serial port communication and new operator
thank you
i have done with that
i used the event mechanism and it is working fine
CString CMainFrame::ReadCharByChar()
{
CString FromBoard;
DWORD dwEventMask;
DWORD dwSize=0;
if(!SetCommMask(hCom, EV_RXCHAR)) /* Setting Event Type */
{
MessageBox("Can not set the event");
CloseHandle(hCom);
return FromBoard;
}
if(WaitCommEvent(hCom, &dwEventMask, NULL)) /* Waiting For Event to
Occur */
{
if(dwEventMask & EV_RXCHAR)
{
char szBuf;
DWORD dwIncommingReadSize;
do
{
if(ReadFile(hCom, &szBuf, 1, &dwIncommingReadSize, NULL) != 0)
{
if(dwIncommingReadSize > 0)
{
dwSize += dwIncommingReadSize;
FromBoard += szBuf;
}
}
else
{
MessageBox("ReadFile Failed");
unsigned long error = ::GetLastError();
break;
}
if(szBuf == '\'')
break;
} while(dwIncommingReadSize > 0);
}
}
else
{
MessageBox("Event never happened");
CloseHandle(hCom);
return FromBoard;
}
return FromBoard;
}
is it right?
but now i am facing another problem.
this is when the first time when i open the port and wait for event and
then user does some event on board like reseting at that time i get the
data.
but afterwards
i need to send character "s" to board and in replay he will send me the
data
for that i am issuing a WriteFile call
but then after when i try to read in which i set the event by
if(!SetCommMask(hCom, EV_RXCHAR))
and will wait till
if(WaitCommEvent(hCom, &dwEventMask, NULL))
returns but it never returns.
but i will first read the document told by Mr.Scott McPhillips
i think it will solve my problem.
million thanks to both of you.
Regards
Harshal Shete