📄 ceserialtestdlg.cpp
字号:
// CESerialTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CESerialTest.h"
#include "CESerialTestDlg.h"
#include "CESerial.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CCESerial serial;
int serial_readthread=0;
/////////////////////////////////////////////////////////////////////////////
// CCESerialTestDlg dialog
CCESerialTestDlg::CCESerialTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCESerialTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCESerialTestDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCESerialTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCESerialTestDlg)
DDX_Control(pDX, IDC_SendMsg, m_eSendMsg);
DDX_Control(pDX, IDC_INFOLIST, m_lMsgList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCESerialTestDlg, CDialog)
//{{AFX_MSG_MAP(CCESerialTestDlg)
ON_BN_CLICKED(IDC_Send, OnSend)
ON_BN_CLICKED(IDC_Recv, OnRecv)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCESerialTestDlg message handlers
BOOL CCESerialTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
if(!serial.Open(_T("COM1:")))
ShowMessage(_T("Unable to open serial!"));
return TRUE; // return TRUE unless you set the focus to a control
}
void CCESerialTestDlg::OnSend()
{
TCHAR tch[100];
CString str;
memset(tch,0,200);
tch[0]=100;
m_eSendMsg.GetLine(0,tch);
str.Format(_T("Send: %s"),tch);
if(!serial.WriteData(tch,wcslen(tch)))
ShowMessage(_T("Send Error!"));
else
ShowMessage(str);
}
UINT ReadThread(LPVOID pParam)
{
TCHAR rbuf[128];
CString str;
CListBox *lbox;
lbox=(CListBox *)(pParam);
while(1)
{
memset(rbuf,0,256);
// if(serial.ReadDataWaiting()){
if(serial.ReadData(rbuf,128)){
str.Format(_T("Receive: %s"),rbuf);
lbox->AddString(str);
lbox->UpdateWindow();
}
// }
if(serial_readthread==0) break;
};
AfxEndThread(0);
return 0;
}
int click=0;
void CCESerialTestDlg::OnRecv()
{
click=(click++%2);
if(click==1){
serial_readthread=1;
AfxBeginThread(ReadThread,&m_lMsgList);
GetDlgItem(IDC_Recv)->SetWindowText(_T("Stop Receive"));
}
else{
serial_readthread=0;
GetDlgItem(IDC_Recv)->SetWindowText(_T("Begin Receive"));
}
}
void CCESerialTestDlg::ShowMessage(CString msg)
{
m_lMsgList.AddString(msg);
m_lMsgList.UpdateWindow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -