Serial read not working

I have some code that I wrote for Serial communication through a com port which has always worked for reading from and writing to a com port.  Now I am trying to communicate with 2 different com ports from 2 different threads and I'm having problems.  I making a test program to write to one com port (COM1)  and I want to see how long it takes to receive it from the other com port (COM7).  I am successfully writing to COM1 but I'm not receiving it at COM7.  My serial read and write functions look like:
BOOL CSerialComm::ReadCommBlock(LPSTR lpszBlock,int nMaxLength )
{
      DWORD dwLength      = 0;
      DWORD dwRead;
      OVERLAPPED osReader      = {0};

      if (m_bComOpen == true)
      {
            osReader.hEvent      = CreateEvent(NULL, TRUE, FALSE, NULL);
            if (osReader.hEvent == NULL)
            {
                  CloseHandle(osReader.hEvent);
                  return FALSE;
            }
            if (!ReadFile(hComm, lpszBlock, nMaxLength, &dwRead, &osReader))
            {
                  if (GetLastError()!= ERROR_IO_PENDING)      //read not delayed?
                  {      //Error in communication
                        CloseHandle(osReader.hEvent);
                        return FALSE;
                  }
            }
            else
            {      // read completed immediately
                  if (dwRead < 1)
                  {
                        CloseHandle(osReader.hEvent);
                        return FALSE;
                  }
                  else
                  {
                        CloseHandle(osReader.hEvent);
                        return TRUE;
                  }
            }
            CloseHandle(osReader.hEvent);
      }
      return FALSE;
} // end of ReadCommBlock()
BOOL CSerialComm::WriteCommBlock(LPSTR lpszBlock , DWORD dwBytesToWrite)
{
      OVERLAPPED osWrite      = {0};
      DWORD dwWritten;
      DWORD dwRes;
      bool bFlag;

      if (m_bComOpen == true)
      {
            // Create this write operation's OVERLAPPED structure's hEvent.
            osWrite.hEvent      = CreateEvent(NULL, TRUE, FALSE, NULL);
            if (osWrite.hEvent == NULL)
            {
                  CloseHandle(osWrite.hEvent);
                  return FALSE;
            }
            //  Issue write
            if (!WriteFile(hComm, lpszBlock, dwBytesToWrite, &dwWritten, &osWrite))
            {
                  if (GetLastError() != ERROR_IO_PENDING)
                  {
                        bFlag      = FALSE;
                  }
                  else // write is pending
                        dwRes      = WaitForSingleObject(osWrite.hEvent, INFINITE);
                  switch (dwRes)
                  {
                        // OVERLAPPED structure's event had been signaled
                  case WAIT_OBJECT_0:
                        if (!GetOverlappedResult(hComm, &osWrite, &dwWritten, FALSE))
                              bFlag      = FALSE;
                        else // Write operation completed successfully
                              bFlag      = TRUE;
                        break;
                  default:
                        bFlag      = FALSE;
                        break;
                  }
            }
            else
                  bFlag      = TRUE;
            CloseHandle(osWrite.hEvent);
      }
      return bFlag;
}

I thought one possibility is that I'm not doing to overlapping right because I wasn't and still not to sure of what I'm doing there.  Can someone help me get this working.  I know that it is possible to send a string through com port and read it on another com port on the same computer because I tried ( successfully ) to send a string throught windows' hyperterminal and receive it in another hyperterminal on the same computer.
dociebAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Why are you using 'OVERLAPPED' in the 1st place if you have multple threads anyway? Also, if you do it, be sure you also use it in your read function, e.g.

BOOL CSerialComm::ReadCommBlock(LPSTR lpszBlock,int nMaxLength )
{
     DWORD dwLength     = 0;
     DWORD dwRead;
     OVERLAPPED osReader     = {0};

     if (m_bComOpen == true)
     {
          osReader.hEvent     = CreateEvent(NULL, TRUE, FALSE, NULL);
          if (osReader.hEvent == NULL)
          {
               CloseHandle(osReader.hEvent);
               return FALSE;
          }
          if (!ReadFile(hComm, lpszBlock, nMaxLength, &dwRead, &osReader))
          {
               if (GetLastError()!= ERROR_IO_PENDING)     //read not delayed?
               {     //Error in communication
                    CloseHandle(osReader.hEvent);
                    return FALSE;
               }
          }
          else
          {     // read completed immediately
               if (dwRead < 1)
               {
                    CloseHandle(osReader.hEvent);
                    return FALSE;
               }
               else
               {

                    dwRes     = WaitForSingleObject(osWrite.hEvent, INFINITE);
                       switch (dwRes)
                       {
                            // OVERLAPPED structure's event had been signaled
                       case WAIT_OBJECT_0:
                            if (!GetOverlappedResult(hComm, &osReader, &dwRead, FALSE))
                                 bFlag     = FALSE;
                            else // Rad operation completed successfully
                                 bFlag     = TRUE;
                            break;
                       default:
                            bFlag     = FALSE;
                            break;
                       }
                    CloseHandle(osReader.hEvent);
                    return TRUE;
               }
          }
          CloseHandle(osReader.hEvent);
     }
     return FALSE;
} // end of ReadCommBlock()
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dociebAuthor Commented:
I thought I read somewhere that overlapped is needed when using multiple threads or is that just when multiple threads are accessing the same port.  If so, that makes since to me now.  Overlaping is for waiting for a port to be free.  Ok, well anywho.  I added the overlapping part like you mentioned and it seems to read the string now.
0
jkrCommented:
>>I thought I read somewhere that overlapped is needed when using multiple thread

No, not really. The concept of using 'OVERLAPPED' comes in handy when you have a pool of worker threads. or a highly async scenario. You can always use multiple threads without that.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.