Home > Software engineering >  Stm32 kept sending a byte of data, and PC received written in MFC but show the code
Stm32 kept sending a byte of data, and PC received written in MFC but show the code

Time:11-01

Use MFC to write a serial port receiving function, in order to test, single chip microcomputer stm32 every two seconds to keep sending the same number, such as 0 x32, want to display in the receiving box, but each display is garbled, if in hexadecimal display is 8 hexadecimal code,
Set a breakpoint debugging, found that bt is successfully received, but is displayed in a cstrings gibberish, why?


The code is as follows:
 void uav ground control terminal Dlg: C: OnCommMscomm1 () 
{
//TODO: add message handler code here
The VARIANT VARIANT_Input;
COleSafeArray SafeArray_Input;
LONG len, k;
BYTE RXData [1024].
Cstrings strtemp;
If (m_mscom get_CommEvent ()==2)
{
VARIANT_Input=m_mscom. Get_Input ();//read buffer
SafeArray_Input=VARIANT_Input;//the VARIANT type variables into COleSafeArray type
Len=SafeArray_Input. GetOneDimSize ();
For (k=0; KSafeArray_Input. GetElement (& amp; K, RXData + k);//type into a BYTE array
For (k=0; K & lt; Len. K++)
{
Char bt=* (char *) (RXData + k);
Strtemp. The Format (_T (" % c ", bt));
M_EditReceive +=strtemp;//receive the edit box inside
}
M_EditReceive +="\ r \ n";
The UpdateData (false);

M_Edit. SetSel (1, 1);
This - & gt; SetDlgItemTextW (IDC_EDIT1 m_EditReceive);//will m_EditReceive content displayed to ID IDC_EDIT1 edit box at the end of the position of the
M_Edit. LineScroll (m_Edit. GetLineCount () - 1, 0).//the vertical scroll bar to scroll to the last
}


Checked for a long time and I don't know why, inquire, not very grateful!

CodePudding user response:

UNicode '2'=0 x0032; 2 bytes
See
Strtemp. The Format (_T (" % c ", bt));
The results of

CodePudding user response:

Char bt [2]={0};
Bt [0]=* (char *) (RXData + k);

CodePudding user response:

Set a breakpoint to check the raw data directly, if not consistent, may be inconsistent port parameters, such as length of baud rate, data bits, etc

CodePudding user response:

Or
WCHAR WCH=(WCHAR) bt;
  • Related