Home > Software engineering >  MFC serial assistant program code can't understand... Ask for help...
MFC serial assistant program code can't understand... Ask for help...

Time:10-29

 

//global variable
Int LineHight [122].
Int LHTemp [120].
Cstrings DTemp;
Int LineNum=0;
Int NextTime.
Int RightLeftNum=0;
Int check='n';
Int gogo=0;
Int speed=9600;
Int TAB=0;
Cstrings FilePath="c: \ \ data. TXT".


//drawing function
//algorithm: use the LineTo function of 120 points line
Void CCommDlg: : OnPaint ()
{
Int hoc;
If (NextTime<600 & amp; & Stop==FALSE) hoc=600;
The else hoc=NextTime;
Cstrings TabStr="";
CPaintDC dc (this);//for drawing device context
Dc. GetNearestColor (RGB (0, 128));//device can display the closest crColor value
Dc. MoveTo (108250);//move to coordinate (108250)
If (NextTime<=600 & amp; & Stop==FALSE)//will points into lines
For (int I=0; i<(NextTime/5); I++)
{
Dc. LineTo (108 + 5 * (I), 250 - LineHight [I] * 5 + 99);//
}
The else
For (int I=0; i<121; I++)
{
Dc. LineTo (108 + 5 * (I), 250 - LineHight [I] * 5 + 99);
}
TabStr. The Format (" % d ", hoc/5-120);//X coordinate values corresponding to the time, make time corresponding data change
SetDlgItemText (IDC_TAB1 TabStr);
TabStr. The Format (" % d ", hoc/5-100);
SetDlgItemText (IDC_TAB2 TabStr);
TabStr. The Format (" % d ", hoc/5-80);
SetDlgItemText (IDC_TAB3 TabStr);
TabStr. The Format (" % d ", hoc/5-60);
SetDlgItemText (IDC_TAB4 TabStr);
TabStr. The Format (" % d ", hoc/5-40);
SetDlgItemText (IDC_TAB5 TabStr);
TabStr. The Format (" % d ", hoc/5-20);
SetDlgItemText (IDC_TAB6 TabStr);
TabStr. The Format (" % d ", hoc/5);
SetDlgItemText (IDC_TAB7 TabStr);
}


Void CCommDlg: : OnComm ()
{
If (stop) return;//if the suspension, do not accept the data
The VARIANT m_input1;//the VARIANT type variables, used to store the received data
COleSafeArray m_input2;;//safearray type variables
Long length, I;
BYTE data [600].//define type BYTE array
Cstrings STR.//define string
If (m_Comm. GetCommEvent ()==2)//receiving buffer in characters
{
M_input1=m_Comm. GetInput ();//reads data in the buffer to receive the data stored in the VARIANT type variable
M_input2=m_input1;//to the VARIANT type variables into ColeSafeArray type
Length=m_input2. GetOneDimSize ();//determine the data length
//. GetOneDimSize () returns the number of one dimensional array element, the one-dimensional array inside each element is an array type, deposit in order to the data in []
for(i=0; iM_input2. GetElement (& amp; I, the data + I);//convert data to BYTE array, there is data in [I],

for(i=0; i{
CFile file;
Cstrings tempstr;
BYTE a=* (char *) (data + I);
(data BYTE b=* (char *) + (+ + I));
Float=(float) a + c (float) (10) % b/10;
STR. The Format (" % 2.1 f ", c);//will c formatting
If (STR) GetLength () & lt; 5) STR="0" + STR;
STR=STR. Right (5);//five characters extracted from array
M_ReceiveData +=STR;//will just collect number added to edit box
LineHight [121]=a;


The Display ();//handling of data display before


//to save data to a file
If (m_ReceiveData GetLength () & gt;=600)//just 600 characters corresponding to 120 data
{
CStdioFile readfile;
Cstrings readstr readstr2;
If (readfile. Open (FilePath, CFile: : modeRead))
{
While (readfile. ReadString (readstr))//query, line by line until end-of-file
{
Readstr2 +=readstr;
}
Readfile. Close ();
}

If (file. Open (FilePath, CFile: : modeCreate | CFile: : modeReadWrite))
{
File. The Write (readstr2, readstr2 GetLength ());//the original data
File. The Write (m_ReceiveData, 600);//write new 120 data
File. The Close ();
M_ReceiveData=""; Cleaning the edit box//
break;
}
}
}
}
The UpdateData (FALSE);//update the content of the edit box
}
//to display data before processing: will the new years according to add to the left, the original moves to the right a
Void CCommDlg: : Display ()
{
If (NextTime & lt;=600 & amp; & Stop==FALSE)
{
LineHight NextTime/5=LineHight [121].
}
The else
{
For (int I=0; i<120; I++)
{
LineHight [I]=LineHight [I + 1);
}
LineHight [120]=LineHight [121].
}
NextTime=NextTime + 5;
This - & gt; Invalidate ().
return;
}

//the run between the three functions of the order? Is not the main function suddenly won't see the code,
//my question is dc. LineTo (108 + 5 * (I), 250 - LineHight [I] * 5 + 99);
//and BYTE a=* (char *) (data + I);
//BYTE b=* (char *) + (+ + I) (data);
//float=(float) a + c (float) (10) % b/10;
//STR. The Format (" % 2.1 f ", c);//will c formatting
//if (STR) GetLength () & lt; 5) STR="0" + STR;
//STR=STR. Right (5);//five characters extracted from array
//m_ReceiveData +=STR;//will just collect number added to edit box
//LineHight [121]=a;
//the two algorithms can't understand,,, I hope you can help me explain,

CodePudding user response:

Suggest the building Lord move this problem below the MFC section...

CodePudding user response:

Does the use of a mscom control

CodePudding user response:

reference 1st floor wenpinglaoyao response:
suggest move this problem to the building Lord MFC under section...


Thank you very much, has been moving ~

CodePudding user response:

COM communication protocol

CodePudding user response:

The
reference 4 floor mengzhisuoliu reply:
COM communication protocol


But to read out the value of the serial debugging assistant and I read it out inconsistencies in the ah,,

CodePudding user response:



Two things read numerical difference so much,,,

CodePudding user response:

It is recommended to use portmon auxiliary software debugging serial communication program,nullnull
  • Related