|
-
April 17th, 2003, 09:18 AM
#1
Select data from a ColeSafeArray and use it?
Hello again,
I am still trying to figure this out. I am using MSCOMM to receive data from a device and respond accordingly. I input the data into a ColeSafeArray like this:
case 2: // vbMSCommEvReceive
COleSafeArray svar = m_Comm.GetInput(); // get input, place into svar array
int nn = svar.GetOneDimSize(); //gives you number of bytes received as a check
void* pSrc; //pointer to pSrc,
svar.AccessData( &pSrc ); //retrieves pointer to array data, & is address of
LPBYTE pbtSrc=(LPBYTE)pSrc;
//Here each byte is assigned a value so that the sequence can be compared.
BYTE btTmp= pbtSrc[0];
BYTE btTmp2= pbtSrc[1];
BYTE btTmp3= pbtSrc[2];
BYTE btTmp4= pbtSrc[3];
//etc. and so on and so on
It is necessary for me to check two of the bytes (the third and fourth) in the received sequence for a proper CRC-16. However, I can’t figure out how to pass the third and fourth bytes to the function. Can anyone help?
Here is the source file of the CRC-16 calculator, which works fine if I could only pass this data to it:
#include "stdafx.h"
WORD calc_crc16(const BYTE* pBuffer, const int nLength)
{
static const WORD CRC16_TABLE[16] =
{
0x0000, 0xCC01, 0xD801, 0x1400,
0xF001, 0x3C00, 0x2800, 0xE401,
0xA001, 0x6C00, 0x7800, 0xB401,
0x5000, 0x9C01, 0x8801, 0x4400
};
register WORD wCrc = 0;
register WORD wTemp;
register int nIndex;
for(nIndex = 0; nIndex < nLength; nIndex++, pBuffer++)
{
/* lower 4 bits */
wTemp = CRC16_TABLE[wCrc & 0x000F];
wCrc = (wCrc >> 4) & 0x0FFF;
wCrc = wCrc ^ wTemp ^ CRC16_TABLE[*pBuffer & 0x000F];
/* upper 4 bits */
wTemp = CRC16_TABLE[wCrc & 0x000F];
wCrc = (wCrc >> 4) & 0x0FFF;
wCrc = wCrc ^ wTemp ^ CRC16_TABLE[(*pBuffer >> 4) & 0x000F];
}
return wCrc;
}
Thanks for looking!
Electroskill
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|