Receiving single bytes with MSComm

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Me (me_at_right.her)
Date: 02/16/05


Date: Wed, 16 Feb 2005 04:01:39 GMT

I got the transmit code working sending binary data for MSComm.

I have the following code for receiving a string of bytes.

bool CPSMDlg::GetChar()
{
  COleVariant myVar;
  int hr;
  long lLen = 0;
  BYTE *pAccess;
  char buffer[255];

  myVar.Attach (m_Comm.GetInput());

  hr = SafeArrayGetUBound (myVar.parray, 1, &lLen); // Get the length
  if (hr == S_OK)
  {
    lLen++; // upper bound is
zero based index
    hr = SafeArrayAccess (myVar.parray,(void**)&pAccess); // lock array so
you can access it
    if (hr == S_OK)
    {
      for (int i 0; i < lLen; i++) // Make a copy of
the data
         buffer[i] = pAccess[i];
      SafeArrayUnaccessData (myVar.parray); // unlock the
data
    }
  }
  // COleVariant cleans itself up
}

How do I receive single bytes one at a time since the device may only send 1
byte in response to commands????

Thanks
eddie@eddie1.net