(1)BOOL CTryDlg::OnInitDialog(){CDialog::OnInitDialog();ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL){CString strAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if (!strAboutMenu.IsEmpty()){pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);}}
// Set the icon for this dialog. The framework does this automatically// when the application's main window is not a dialogSetIcon(m_hIcon, TRUE); // Set big iconSetIcon(m_hIcon, FALSE); // Set small iconCString str;str="阿元串口收发测试程序";this->SetWindowText(str);m_ctrlComm.SetCommPort(3); //选择COM3m_ctrlComm.SetInputMode(1); //输入方式为二进制方式m_ctrlComm.SetInBufferSize(1024); //设置输入缓冲区大小m_ctrlComm.SetOutBufferSize(512); //设置输出缓冲区大小
//波特率9600,无校验,8个数据位,1个停止位m_ctrlComm.SetSettings("9600,n,8,1");
//参数1表示当串口接收缓冲区中有多于或者等于1个字符时将引发一个接收数据的OnOnCommMscomm1事件if(!m_ctrlComm.GetPortOpen())m_ctrlComm.SetPortOpen(1);m_ctrlComm.SetRThreshold(1);m_ctrlComm.SetInputLen(0); //设置当前接受区长度为0m_ctrlComm.GetInput(); //先预读缓冲区以清除残留数据
return TRUE; // return TRUE unless you set the focus to a control}
(2)void CTryDlg::OnOnCommMscomm1() //从串口接收数据并显示在接受编辑框中{VARIANT variant_inp;COleSafeArray safearray_inp;LONG len,k;BYTE rxdata[2048];CString strtemp;if(m_ctrlComm.GetCommEvent() == 2) //如果接收缓冲区内有字符{variant_inp = m_ctrlComm.GetInput(); //读缓冲区safearray_inp = variant_inp;len = safearray_inp.GetOneDimSize(); //得到有效数据长度for(k=0;k<len;k++)
{safearray_inp.GetElement(&k,rxdata+k); //转换为BYTE型数组}for(k=0;k<len;k++) //将数组转换为CString型数组{BYTE bt=*(char*)(rxdata+k); //字符型strtemp.Format("%c",bt);m_strEditRXDATA += strtemp; //加入接受编辑框对应字符}}UpdateData(0);}
(3)void CTryDlg::OnButtonManualsend(){UpdateData(1); //读取编辑框内容m_ctrlComm.SetOutput(COleVariant(m_strEditTXDATA)); //发送数据}
wanglei.rar_VC串口_wanglei
版权申诉
164 浏览量
2022-09-24
02:16:10
上传
评论
收藏 1KB RAR 举报
林当时
- 粉丝: 100
- 资源: 1万+
最新资源
- VID20240521070643.mp4
- Android系统原理与开发学习要点详解-培训课件.zip
- 部署yolov8的tensorrt模型支持检测分割姿态估计的C++源码+部署步骤.zip
- 以简单、易用、高性能为目标、开源的时序数据库,支持Linux及Windows, Time Series Database.zip
- python-leetcode面试题解之第198题打家劫舍-题解.zip
- python-leetcode面试题解之第191题位1的个数-题解.zip
- python-leetcode面试题解之第186题反转字符串中的单词II-题解.zip
- 一个基于python的web后端高性能开发框架,下载可用
- python-leetcode面试题解之第179题最大数-题解.zip
- python-leetcode面试题解之第170题两数之和III数据结构设计-题解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0