Home > Software engineering >  Operation not valid while the port is the opened!
Operation not valid while the port is the opened!

Time:10-29

Below is open the serial port code, debugging is displayed operation not valid while the port is the opened, how should solve? A great god, please give directions
 
Void CCommTestDlg: : OnBnClickedButtonOpen ()
{
//TODO: add the control notification handler code
If (m_mscomm get_PortOpen ())//if a serial port is open, the line close a serial port
{
M_mscomm. Put_PortOpen (FALSE);
}
M_mscomm. Put_PortOpen (3);//select COM3
M_mscomm. Put_InBufferSize (1024);//receive buffer
M_mscomm. Put_OutBufferSize (1024);//send buffer
M_mscomm. Put_InputLen (0);//set the current receiving data length is 0,, said all read
M_mscomm. Put_InputMode (1);//read and write data in a binary way
M_mscomm. Put_RThreshold (1);//receive buffer has more than 1 and 1 character, will trigger a receiving data OnComm events
M_mscomm. Put_Settings (_T (" 9600, n, 8, 1 "));//baud rate test 9600, 8 bits a stop bit
if(! M_mscomm. Get_PortOpen ())
{
M_mscomm. Put_PortOpen (TRUE);//open the serial port
AfxMessageBox (_T (" serial port 3 open success "));
}
The else
{
M_mscomm. Put_OutBufferCount (0);
AfxMessageBox (_T (" a serial port open 3 failure "));
}
}

CodePudding user response:

Their Debug mode order step debugging see which call failed?

CodePudding user response:

M_mscomm. Advance put_Settings to m_mscomm. Try before put_PortOpen

  • Related