Receiving single bytes with MSComm
From: Me (me_at_right.her)
Date: 02/16/05
- Next message: Ajay Kalra: "Re: Welcome dialog in MFC doc/view?"
- Previous message: Kelvin: "Welcome dialog in MFC doc/view?"
- Next in thread: Joseph M. Newcomer: "Re: Receiving single bytes with MSComm"
- Reply: Joseph M. Newcomer: "Re: Receiving single bytes with MSComm"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Ajay Kalra: "Re: Welcome dialog in MFC doc/view?"
- Previous message: Kelvin: "Welcome dialog in MFC doc/view?"
- Next in thread: Joseph M. Newcomer: "Re: Receiving single bytes with MSComm"
- Reply: Joseph M. Newcomer: "Re: Receiving single bytes with MSComm"
- Messages sorted by: [ date ] [ thread ]