Can you help me to explain a question about serial port and resolve the problem.
Can you help me to explain a question about serial port and resolve the
problem. Thanks in advance.
I'm puzzled about one thing about serial port, My software communicates
with
several chip microprocessors on serial port under win2000 platform. it
works as follow:
I,Set Markparity, II,Send Number of a chip microprocessor, III,Set
Spaceparity, IV,then send command to receive data from the chip
microprocessor.
In order to make it works, I have to insert Sleep(n ms) between II and
III, or can not receive any bytes from the chip microprocessor.
the source code is about:
.....
DCB dcb;
// get current DCB settings
if (!GetCommState(hComm, &dcb))
{
return FALSE;
}
// update DCB rate, byte size, parity, and stop bits size
dcb.BaudRate = 2400;
dcb.ByteSize = 8;
dcb.Parity = MARKPARITY;
dcb.StopBits = 1;
dcb.fParity = TRUE;
// set new state
if (!SetCommState(hComm, &dcb))
{
return FALSE;
}
//send cmd to connect to a chip microprocessor
BYTE cTbNo = 0X0A;
if (!TransmitCommChar(hComm, cTbNo))
{
return FALSE;
}
//sleep 5 ms
Sleep(5);
if (!GetCommState(hComm, &dcb))
{
return FALSE;
}
// update DCB rate, byte size, parity, and stop bits size
dcb.BaudRate = 2400;
dcb.ByteSize = 8;
dcb.Parity = SPACEPARITY;
dcb.StopBits = 1;
dcb.fParity = TRUE;
// set new state
if (!SetCommState(hComm, &dcb))
{
return FALSE;
}
//send cmd
BYTE cCmd = 0XCD;
if (!TransmitCommChar(hComm, cCmd))
{
return FALSE;
}
....
Thanks in advance.
Best Regards,
|