|
-
March 27th, 2007, 09:44 AM
#1
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?
Time is fun when you're having flies 
-
March 27th, 2007, 10:10 AM
#2
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
-
March 28th, 2007, 02:24 AM
#3
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.
Time is fun when you're having flies 
-
March 28th, 2007, 02:28 AM
#4
Re: serial port communication problem
What serial port r u using RS232 or RS422? or the one which is present in all systems (COM)
Dan
-
March 28th, 2007, 02:34 AM
#5
Re: serial port communication problem
Hi,
have you checked with another side , i.e How many bytes sent actually ?
-Anant
"Devise the simplest possible solution that solves the problems"
-
March 28th, 2007, 04:54 AM
#6
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.
Time is fun when you're having flies 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|