I am not very good in C++ problem and this is my codes below. I do not know
whether I got handshaking involve in my code. Could you guys let me know?
HANDLE OpenComm(char *lpszPort, int nBaud, char *nParity, int nData, int
nStop)
{
HANDLE hCom;
LPDCB lpDcb;
char szCom[10];
memset(szCom, 0, sizeof(szCom));
strcpy(szCom, "\\.\\COM") ;
strcat(szCom, lpszPort);
strcat(szCom, ":");
lpDcb = new(DCB);
//create port handle
hCom =
CreateFile(szCo m,GENERIC_READ| GENERIC_WRITE,0 ,NULL,OPEN_EXIS TING,FILE_FLAG_ O
VERLAPPED,NULL) ;
//failed coz invalid handle provided
if (hCom == INVALID_HANDLE_ VALUE)
{
hCom = NULL;
}
//fail to get port state
if (!GetCommState( hCom,lpDcb))
{
hCom = NULL;
}
//set setting [COM1: baud=9600 parity=N data=8 stop=1]
char strTemp[50];
memset(strTemp, 0, sizeof(strTemp) );
sprintf(strTemp , "baud=%d parity=%s data=%d stop=%d", nBaud, nParity,
nData, nStop);
if (!BuildCommDCB( strTemp,lpDcb))
{
hCom = NULL;
}
if (!SetCommState( hCom,lpDcb))
{
hCom = NULL;
}
// set communication timeouts
// get default values
BOOL bPort;
COMMTIMEOUTS CommTimeouts;
bPort = GetCommTimeouts (hCom, &CommTimeout s);
// set new values
CommTimeouts.Re adIntervalTimeo ut = 15;
CommTimeouts.Re adTotalTimeoutC onstant = 250;
CommTimeouts.Re adTotalTimeoutM ultiplier = 1;
CommTimeouts.Wr iteTotalTimeout Constant = 250;
CommTimeouts.Wr iteTotalTimeout Multiplier = 1;
bPort = SetCommTimeouts (hCom, &CommTimeout s);
return hCom;
}