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(szCom,GENERIC_READ|GENERIC_WRITE,0,NULL ,OPEN_EXISTING,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, &CommTimeouts);
// set new values
CommTimeouts.ReadIntervalTimeout = 15;
CommTimeouts.ReadTotalTimeoutConstant = 250;
CommTimeouts.ReadTotalTimeoutMultiplier = 1;
CommTimeouts.WriteTotalTimeoutConstant = 250;
CommTimeouts.WriteTotalTimeoutMultiplier = 1;
bPort = SetCommTimeouts(hCom, &CommTimeouts);
return hCom;
}
"Chris Calzaretta" <cc*********@hotmail.com> wrote in message
news:u5**************@TK2MSFTNGP14.phx.gbl...
DO You have handshaking on>? i guess we need to know settings because if
your are doing some settings it should take care of this problem for you.
Such as your device is ready to send but your computer is not ready to
recceive you need to have RTS enabled if your device can handle it.
lots more settings what are yours
"Michael Chong" <mi*****@cyob.com.my> wrote in message
news:eW**************@tk2msftngp13.phx.gbl...I wrote a program that communicate with SerialComm. In every 300
milliseconds, my program continuously send & receive data via the serial
port once the program starts.
My program is once in a while, the serial port seems corrupted because
when
my data is sent, it doesn't go through the serial port, so as same to
receive process. In order to fix this, I have to close the port and
reopen the port again.
Why?!! Is there any way to fix this problem or I have to check for
corruption port, then I reopen the serial port again?
Thanks!
Michael