注册 登录
编程论坛 VC++/MFC

自己刚编写的打开串口的程序,运行时点击打开串口的按键时出现 Debug Assertion Failed! Line:563

xtumaning 发布于 2015-04-14 10:20, 1651 次点击
代码
void CMy413Dlg::OnBtnOpencom()
{
    /// TODO: Add your control notification handler code here
    CSerialPort g_SerialPort;
    CString str;
    GetDlgItemText(IDC_EDIT_COM,str);
    int i = atoi(str);
    GetDlgItemText(IDC_BTN_OPENCOM,str);
    if (str == "打开串口")
    {
        //打开串口
        if(g_SerialPort.InitPort(this,1,1000000,'N',8,1,EV_RXFLAG | EV_RXCHAR,512))
        {
            g_SerialPort.StartMonitoring();
            m_bPortOpened = TRUE;
            SetDlgItemText(IDC_BTN_OPENCOM,"关闭串口");
            m_Icon.SetIcon(m_hIconOn);
        }
        else
            MessageBox("没有发现串口或被占用","提示");
    }
    else
    {
        g_SerialPort.ClosePort();
        m_bPortOpened = FALSE;
        SetDlgItemText(IDC_BTN_OPENCOM,"打开串口");
        m_Icon.SetIcon(m_hIconOFF);
    }//*/
  
     
}
0 回复
1