if(m_sComm.GetPortOpen())//如果串口打开则关闭
{
m_sComm.SetPortOpen(false);
}m_sComm.SetCommPort(1);//设置com1m_sComm.SetInputMode(1);
m_sComm.SetSettings("9600,n,8,1");
m_sComm.SetRThreshold(1);
m_sComm.SetInBufferSize(1024);
m_sComm.SetOutBufferSize(1024);if(!m_sComm.GetPortOpen())
{
m_sComm.SetPortOpen(TRUE);//执行到此处出现问题了提示是"the device is not open"
}                         //然后我捕获的异常号是:3634780,请教了.

解决方案 »

  1.   

    if(m_Com.GetPortOpen())
    m_Com.SetPortOpen(FALSE); m_Com.SetCommPort(1);//select com1
    if(!m_Com.GetPortOpen())
    m_Com.SetPortOpen(TRUE);//open serial port
    else{
    AfxMessageBox("cannot open serial port!");
    return;
    }
    m_Com.SetSettings("9600,n,8,1");//baudrate 9600,no parity bit,8 data bits,1 stop bit m_Com.SetInputMode(1);//1:fetch the data by binary
    m_Com.SetRThreshold(1);
    //1 denote that,when there is one or more characters in the receiving buffer,it will cause an OnComm event.
    m_Com.SetInputLen(0);//set the length of current receiving section with zero
    m_Com.GetInput();//clear the left data from the buffer
      

  2.   

    用try
    {
    }
    catch(colediapatchexcetion *e)
    {
    CString tt;
    tt.format("error number: %d,error message: %s",e->m_Wcode,e->discription);
    messagebox(tt);
    }
    把这个异常抓住,看看是什么异常,然后对应得去解决。上面得函数可能写得不对,自己改一下去