CserialPort类的用法

打开串口:
         if (m_Comm.InitPort(this,3,115200,'n',8,1,EV_RXCHAR, 512))  //接收数据类型为     
                                                         //EV_RXCHAR,缓冲区大小为512
    {
        m_Comm.StartMonitoring();           //启动线程
        m_IsOpen = true;
    }
    else
    {
        AfxMessageBox("没有发现此串口或被占用");
    }

关闭串口:

    if(m_IsOpen)          //如果串口是打开的,则关闭串口
    {
        m_Comm.ClosePort();
    }

发送数据:
    if(!m_IsOpen)
    {
        AfxMessageBox(_T("串口没有打开!"));
    }
    else
    {
        m_Comm.WriteToPort(m_strSend);//发送字符串
    }

接收数据:
LRESULT CTestDlg::OnReceiveChar(UINT ch, LONG port)
{
    CString str;
    str.Format(_T("%c"),ch);
    m_edContext.SetSel(m_edContext.GetWindowTextLength(),m_edContext.GetWindowTextLength());
    m_edContext.ReplaceSel(str);
    return 0L;
}

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
  • 2021-04-26
  • 2021-11-26
  • 2022-01-03
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-02-09
  • 2021-04-13
  • 2021-09-05
相关资源
相似解决方案