Home > Software engineering >  VS2010 using Mscomm control, abnormal, when receiving data to answer?
VS2010 using Mscomm control, abnormal, when receiving data to answer?

Time:10-01

Void CRSDlg: : OnBnClickedButtonOpen ()
{
//TODO: add the control notification handler code
Cstrings STR, str1, n.//define string
GetDlgItemText (IDC_BUTTON_OPEN, STR);
The CWnd * h1.
H1=GetDlgItem (IDC_BUTTON_OPEN);//points to the space of caption
if(! M_mscom. Get_PortOpen ())
{
M_Comb2. GetLBText (m_Comb2. GetCurSel (), str1);//of the selected character, inside the str1
Str1=str1 + ', '+' n '+', '+' 8 '+', '+' 1 './/set the data format
M_mscom. Put_CommPort ((m_Comb1 GetCurSel () + 1));//select serial port
M_mscom. Put_InputMode (1);//set the input mode for binary mode
M_mscom. Put_Settings (str1);//set the baud rate
//m_mscom put_Settings (_T (" 9600, n, 8, 1 "));
M_mscom. Put_InputLen (1024);//set the current data receiving area length of 1024
M_mscom. Put_RThreshold (1);//buffer one character at a trigger event
M_mscom. Put_RTSEnable (1);//set the RT allows
M_mscom. Put_PortOpen (true);//open the serial port
If (m_mscom get_PortOpen ())
{
STR=_T (" close serial port ");
The UpdateData (true);
H1 - & gt; SetWindowText (STR);//change the name of the button to "close button"
}
}
The else
{
M_mscom. Put_PortOpen (false);
if(str!=_T (" open the serial port "))
{
STR=_T (" open the serial port ");
The UpdateData (true);
H1 - & gt; SetWindowText (STR);//change the button name to open the serial port
}
}
Void CRSDlg: : OnComm ()
{
The static unsigned int CNT=0;
The VARIANT variant_inp;
COleSafeArray safearryay_inp;
Long len, k;
Unsigned int data [1024]={0};
Byte rxdata [1024].
Cstrings stremp;
If (m_mscom get_CommEvent ()==2)
{
cnt++;
Variant_inp=m_mscom. Get_Input ();
Safearryay_inp=variant_inp;
Len=safearryay_inp. GetOneDimSize ();
For (k=0; K{
Safearryay_inp. GetElement (& amp; K, rxdata + k);
}
For (k=0; K{
Stremp. The Format (_T (" % c "), * (rxdata + k));
M_EditReceive +=stremp;
Cstrings temp=_T (" \ r \ n ");
M_EditReceive +=temp;
}
}
The UpdateData (FALSE);
}

Above is part of the code, crazy, always has a problem, and finally this problem, the program debugging, no problem, after running, open the serial port receiving data will prompt pictures show,
RS. Exe of 0 x7582845d (KernelBase. DLL) the most possible exceptions: Microsoft c + + exceptions: memory location 0 x00000000 [rethrow],
RS. Exe of 0 x7582845d (KernelBase. DLL) the most possible exceptions: Microsoft c + + exceptions: memory location 0 x003bd7d4 COleDispatchException,
Really don't know why? Please everyone a great god solve

CodePudding user response:

Debugged see where the problem?

CodePudding user response:

Catch, see what exceptions thrown by the first, and then the break with, and see where the problems step

CodePudding user response:

I met the same problem with you, I transfer data via bluetooth adapter serial port after receiving this question, can directly use the usb serial port receives the data, don't know whether you are using a bluetooth transmission is out of the question, I'm also thinking how to solve the problem of bluetooth receives this,

CodePudding user response:

Is there a map?
DECLARE_EVENTSINK_MAP
BEGIN_EVENTSINK_MAP
ON_EVENT
END_EVENTSINK_MAP

CodePudding user response:

Mscomm is vc6 era, believe you also very vexed the varient, with a third party class, several functions can solve problems at http://blog.csdn.net/sunnyloves/article/details/5575995

CodePudding user response:

Thank you, and find the problem, though, but the debug exe files on other computers are running well and no problems, I don't know why! This first

CodePudding user response:

I also met the same problem, how to solve?

CodePudding user response:

I also met the same problem, how to solve?

CodePudding user response:

I also met the same problem, how to solve?

CodePudding user response:

I am also can someone help to solve this problem

CodePudding user response:


Cstrings m_EditReceive stremp;

For (k=0; K{
BYTE bt=* (char *) (rxdata + k);//character
Stremp. The Format (" % 02 x ", bt);
M_EditReceive +=stremp;
}

CodePudding user response:

Collapsed in the pop-up dialog box, press the corresponding button to enter debugging press Alt + 7 key to view the Call Stack, namely "the Call Stack" from the inside to the following out of from the inner to outer function Call history, double-click a row to the cursor to the Call of the source code or assembly instruction, don't understand when double click on the next line, until we can read ,
Determine whether cross-border access, can be in after the last element of an array of the corresponding address set read and write data breakpoints, if the address corresponding to other variables interfere with the judgment, can be more declare an array element, and set the read and write data breakpoints on the corresponding address of the more elements,
 # include & lt; Time. H> 
#include
#include
Int main () {
Int a, b [11].//was b [10], to decide which words of cross-border, intentionally statement for b [11]

Srand ((unsigned int) time (NULL));//press F11 twice, such as yellow right arrow pointing to the bank, the debugging, the new breakpoint, new data breakpoints, address: & amp; B [10], byte count: 4, sure,
While (1) {//press F5, will stop in the following sentence, as a value of 10, b has been modified to corresponding to 0. [10]. One of the four,
B (11) (a=rand () %]=0;
Sleep (100);
B (11) (a=rand () %]=1;
Sleep (100);
B (11) (a=rand () %]=2;
Sleep (100);
B (11) (a=rand () %]=3;
Sleep (100);
B (11) (a=rand () %]=4;
Sleep (100);
}
return 0;
}

CodePudding user response:

reference 5 floor sunnyloves reply:
Mscomm is vc6 era, believe you also very vexed the varient, with a third party class, several functions can solve the problem, http://blog.csdn.net/sunnyloves/article/details/5575995


The building Lord if must use Mscomm can install a vc6