⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 +

📁 Visual C++串口通信开发入门与编程实践
💻
字号:
    CCommtestDlg dlg;
    m_pMainWnd=&dlg;
    dlg.DoModal();
      m_hIcon=AfxGetAPP()->Loadlcon
m_ListBox[0].SubclassDlgItem(IDC_LIST1, this); //生成列表框,编辑框
................  //另3个列表框,编辑框也如此编写
m_Edit[0].SubclassDlgItem(IDC_EDITI, this);
................  //另3个列表框,编辑框也如此编写
for (int i; 0; i < 4; i++)
{
  if (m_Ports[i].InitPort(this, i + 1, i ==  = 0 ? 9600 : 19200))
  //初始化配置对话框
    m_Ports[i].StartMonitoring();
  else
  {
    m_Edit[i].SetWindowText("NOT FOUND");
    m_Edit[i].EnableWindow(FALSE);
    m_ListBox[i].EnableWindow(FALSE);
  }
}
void CCommtestdlg::OnSendButtonlButton1()
{
  char but[100];
  memset(&buf, 0, sizeof(buf));
  GetDlgItemText(IDC_ EDIT1, buf, sizeof(buf)); //得到编辑框中内容
  if (strcmp("NOT FOUND", buf == 0)
     return ;
  if (((CButton*)
    GetdlgItem(IDC_CHECK1))->GetCheck()) //得到检查框
  buf[strlen(buf)] = 13; m_Ports[0].WriteToPort(buf);
    //写数据到COM口
}
if (port <= 0 || port > 4)
  return  - 1;
if (ch == 13 && ((CButton*)GetDlgItem(IDC_ CHECKS + port - 1))
  ->GetCheck())
{
  m_ListBox[port - 1].AddString(m_strReceived[port - 1]);
  m_ListBox[port - 1].SetSel(m_ListBox[port - 1].GetCount() - 1,
    TRUE);
  (m_strReceived[port - 1]).Empty();
}

else if (((CButton*)GetdlgItem(IDC_CHECKS + port - 1))->GetCheck())
  m_strReceived[port - 1] += (char)ch;
else
{
  CString string;
  string += (char)ch;
  m_ListBox[port - 1].AddString(string);
  m_ListBox[port - 1].SetSel(m_ListBox[port - 1].GetCount() - 1,
    TRUE);
}
if (port <= 0 || port > 4)
  return  - 1;
CString string;
string = "Clear To Send";
m_ListBox[port - 1].AddString(string);
m_ListBox[port - 1].SetSel(m_ListBox[port - 1].GetCowit() - 1,
  TRUE);
m_ListBox[0].ResetContent();
char buf[50];
CFileDialog m_mapwayopen(TRUE, NULL, NULL, NULL,
  "txt文件(*.txt)|*.txt||");
CString m_wayfilename;
CFile m_nWayFile;
if (m_mapwayopen.DoModal() == IDOK)
{
  m_wayfilename = m_mapwayopen.GetPathName();
  m_nWayFile.Open(m_wayfilename, CFile::modeRead);
  m_wayfilename += '\0';
  SetDlgItemText(IDC_EDIT1, m_wayfilename); //得到编辑框中内容
  int len = m_nWayFile.Read(buf, 50);
  while (len)
  {
    m_Ports[0].WriteTbPort(buf);
    len = m_nWayFile.Read(buf, 50);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -