serial port communication problem
Hi guys, i have a problem with the serial port communication. I am trying to read from the serial port, but it appears that only 14 bytes can be read at once. This is probably the size of the serial port receive buffer.
I have a serial extension card in my pc which adds 2 serial ports. With a null modem cable i can send data from one serial port to the other.
Code:
m_SerialPort.SetCommMask(EV_RXCHAR);
if(m_SerialPort.WaitCommEvent(&dwEventMask, NULL))
{
unsigned char szBuf;
DWORD dwIncomingReadSize;
DWORD dwSize = 0;
int iByteCount = 0;
do
{
if(m_SerialPort.ReadData(&szBuf, 1, &dwIncomingReadSize) != 0)
{
if(dwIncomingReadSize > 0)
{
dwSize += dwIncomingReadSize;
m_pReceiveBuf[iByteCount] = szBuf;
iByteCount++;
}
}
else
{
// Handle error condition
}
}while( (dwIncomingReadSize > 0) && (iByteCount < RECEIVE_BUF_SIZE) );
*dwReceivedBytes = iByteCount;
}
If i send 20 bytes i want to read 20 bytes at the other side. Does anybody have a solution for this problem?
Re: serial port communication problem
It is completely unclear what m_SerialPort is and where and how you are using your code snippet.
You may want take a look at "Serial Communications in Win32" article and MTTTY sample in MSDN and J.Newcomer's essay Serial Port I/O
Re: serial port communication problem
Thanks for the link Victor, i am studying it. I am running into a little problem here. How is a shutdown event created? It is passed as one of the parameters to the thread and i cannot figure out where it is coming from.
Re: serial port communication problem
What serial port r u using RS232 or RS422? or the one which is present in all systems (COM)
Re: serial port communication problem
Hi,
have you checked with another side , i.e How many bytes sent actually ?
-Anant
Re: serial port communication problem
Thanks for the link Victor, i am studying it. I am running into a little problem here. How is a shutdown event created? It is passed as one of the parameters to the thread and i cannot figure out where it is coming from.