![]() |
BEGIN_MESSAGE_MAP(CSerialPortClassDlg, CDialog) //{{AFX_MSG_MAP(CSerialPortClassDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_CLEAR_BUTTON, OnClearButton) ON_BN_CLICKED(IDC_SEND_BUTTON, OnSendButton) ON_MESSAGE(ON_COM_RECEIVE,OnCommRecv) //}}AFX_MSG_MAP END_MESSAGE_MAP() |
cnComm com; afx_msg void OnCommRecv(WPARAM wParam, LPARAM lParam); |
BOOL CSerialPortClassDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. 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 dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here com.Open(1); //打开串口1并使用默认设置 com.SetWnd(AfxGetMainWnd()->m_hWnd); //设置消息处理窗口 return TRUE; // return TRUE unless you set the focus to a control } |
//"发送"按钮函数(完成数据的发送功能) void CSerialPortClassDlg::OnSendButton() { // TODO: Add your control notification handler code here UpdateData(true); com.Write(m_send); //发送字符串 } |
void CSerialPortClassDlg::OnCommRecv(WPARAM wParam, LPARAM lParam) { UpdateData(true); //读取串口上的字符 char str[100]; com.ReadString(str, 100); m_recv += str; UpdateData(false); } |
责任编辑:小草