首页 > 其他 > 详细

CserialPort类的简单用法

时间:2015-12-30 01:50:09      阅读:240      评论:0      收藏:0      [点我收藏+]
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;
}

 

 

CserialPort类的简单用法

原文:http://www.cnblogs.com/rechen/p/5087529.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!