zoukankan      html  css  js  c++  java
  • CserialPort类的简单用法

    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;
    }
    
     
    发现自己的不足,善于利用找到的方法去扬长避短。行动起来。
  • 相关阅读:
    kvm介绍
    正式班D24
    正式班D23
    正式班D21
    正式班D20
    正式班D19
    正式班D18
    正式班D17
    正式班D16
    正式班D15
  • 原文地址:https://www.cnblogs.com/rechen/p/5087529.html
Copyright © 2011-2022 走看看