A
arrowlike
In a VC6 program, a mscomm32.ocx is added to the project and read the
binary incoming RS232 data stream (from a GPS receiver). I use another
commercial serial port debug program to send out a binary file through
com port, read and record the com port data into a disk file. After
file comparison, no error occurs. When the GPS receiver is connected,
my program drops or adds one or two bytes in each data block which is
about 200 bytes. The data block size is seldom correct.
I believe the receiver contains no error, coz it uses embedded MCU.
Then, anyone met the similar mistake before? Maybe CString type
converts one special byte into two bytes stealthily?
Many thank in advance.
The implementation code is listed below:
VARIANT variant_inp;
COleSafeArray safearray_inp;
LONG len,k;
BYTE rxdata[2048];
CString strtemp;
if(m_ctrlComm.GetCommEvent()==2)
{
variant_inp=m_ctrlComm.GetInput();
safearray_inp=variant_inp;
len=safearray_inp.GetOneDimSize();
for(k=0;k<len;k++)
safearray_inp.GetElement(&k,rxdata+k);
for(k=0;k<len;k++)
{
BYTE bt=*(char*)(rxdata+k);
strtemp.Format("%c",bt);
m_strRXData+=strtemp;
}
}
binary incoming RS232 data stream (from a GPS receiver). I use another
commercial serial port debug program to send out a binary file through
com port, read and record the com port data into a disk file. After
file comparison, no error occurs. When the GPS receiver is connected,
my program drops or adds one or two bytes in each data block which is
about 200 bytes. The data block size is seldom correct.
I believe the receiver contains no error, coz it uses embedded MCU.
Then, anyone met the similar mistake before? Maybe CString type
converts one special byte into two bytes stealthily?
Many thank in advance.
The implementation code is listed below:
VARIANT variant_inp;
COleSafeArray safearray_inp;
LONG len,k;
BYTE rxdata[2048];
CString strtemp;
if(m_ctrlComm.GetCommEvent()==2)
{
variant_inp=m_ctrlComm.GetInput();
safearray_inp=variant_inp;
len=safearray_inp.GetOneDimSize();
for(k=0;k<len;k++)
safearray_inp.GetElement(&k,rxdata+k);
for(k=0;k<len;k++)
{
BYTE bt=*(char*)(rxdata+k);
strtemp.Format("%c",bt);
m_strRXData+=strtemp;
}
}