Home > other >  MFC used to receive MSComm with derivative according to the communication protocol conversion has be
MFC used to receive MSComm with derivative according to the communication protocol conversion has be

Time:11-06

This is the control response code, but in the end all of the output is zero, don't know where there is an error!
If (m_mscom get_CommEvent ()==2)
{
Cstrings STR.
Char chrBuffer [1024].
Long k;
Unsigned short usLength=0, usCnt=0;
The VARIANT InputData=https://bbs.csdn.net/topics/m_mscom.get_Input ();
COleSafeArray fs.
Fs=InputData;

For (k=0; K & lt; Fs. GetOneDimSize (); K++)
{
Fs. GetElement (& amp; K, chrBuffer + k);
UsLength=fs. GetOneDimSize ();
Memcpy (& amp; ChrBuffer, & amp; The fs, usLength);//may be wrong here, but can not find a solution to
The switch (chrBuffer [1])
{
Case 0 x50:
Memcpy (& amp; StcTime, & amp; ChrBuffer [2], 8);
break;
Case 0 x51:
Memcpy (& amp; StcAcc, & amp; ChrBuffer [2], 8);
break;
}

}

Cstrings str_T;
Str_T. The Format (_T (" Time: d - 20% - % d % d % d: % d: %, 3 f \ r \ n "), (short) stcTime. UcYear, (short) stcTime. UcMonth,
(short) stcTime ucDay, (short) stcTime. UcHour, (short) stcTime. UcMinute, (float) stcTime. UcSecond + (float) stcTime. UsMiliSecond/1000);
Cstrings str_A;
Str_A. The Format (_T (" Acc: %. 3 f %. 3 f %. 3 f \ r \ n "), (float) stcAcc. A [0]/* 16, 32768 (float) stcAcc. A [1]/* 16, 32768 (float) stcAcc. [2] a/32768 * 16);


M_EditRev +=str_T;
M_EditRev +=str_A;
The UpdateData (false);//the data displayed in the screen corresponding controls,
}

}

CodePudding user response:

Memcpy (& amp; ChrBuffer, & amp; The fs, usLength);
//chrBuffer is an array, remove the front & amp;
//fs is a structure? Take the fs. Data [] and so on