Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages
Started by Jeff
Wed, 14 Jun 2006 15:39
COM Port Issue
Author: Jeff
Date: Wed, 14 Jun 2006 15:39
Date: Wed, 14 Jun 2006 15:39
15 lines
1529 bytes
1529 bytes
We've got a program that communicates via an ASCII protocol through the COM port on the computer. We obtain a handle to the port and use file I/O to interact with the buffer. The problem we're having is that we can't test the buffer for data without pulling the data out of the buffer. The code below is a segment that is done to see if data has been returned, but ReadFile() pulls out the data in the buffer. Is there a way to test for data in the buffer without pulling it out? Err_Ret_Code = (ReadFile(TShComm, InBuff, 10, &dwBytesRead, NULL)); if (InBuff[0] == '\0') //If no data is returned then return -1 Err_Ret_Code = -1; Thanks, Jeff
Re: COM Port Issue
Author: Remy Lebeau (TeamB)
Date: Wed, 14 Jun 2006 16:55
Date: Wed, 14 Jun 2006 16:55
34 lines
2000 bytes
2000 bytes
"Jeff" <Jeff@nospam.com> wrote in message
news:44902db2@newsgroups.borland.com...
> The problem we're having is that we can't test the buffer for
> data without pulling the data out of the buffer.
Yes, you can. Look at SetCommMask() and WaitCommEvent() so your reading can
be driven off of COM port events. When data is available, you will get
EV_RXCHAR events. Microsoft has a very detailed article on MSDN about how
to properly read from a COM port using COM event masks and error handling.
> Is there a way to test for data in the buffer without pulling it out?
Not specifically, no.
> Err_Ret_Code = (ReadFile(TShComm, InBuff, 10, &dwBytesRead, NULL));
> if (InBuff[0] == '\0') //If no data is returned then return -1
That is not the correct way to know if data ws put into a buffer. You
should be checking the dwBytesRead value instead:
if( ReadFile(TShComm, InBuff, 10, &dwBytesRead, NULL) )
{
if( dwBytesRead )
// there is data in the buffer
else
// there is no data in the buffer
}
else
// error in reading
Gambit
Re: COM Port Issue
Author: JD
Date: Wed, 14 Jun 2006 20:19
Date: Wed, 14 Jun 2006 20:19
11 lines
1085 bytes
1085 bytes
"Jeff" <Jeff@nospam.com> wrote: > > [...] Is there a way to test for data in the buffer without > pulling it out? Yes. Use the win32 API ClearCommError. The bytes available will be returned in the cbInQue member of the COMSTAT structure. ~ JD
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads