亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? serialportdlg.cpp

?? 調(diào)用WinAPI函數(shù)進(jìn)行串口通信
?? CPP
字號(hào):
// SerialPortDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SerialPort.h"
#include "SerialPortDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSerialPortDlg dialog

CSerialPortDlg::CSerialPortDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSerialPortDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSerialPortDlg)
	m_sSendMsg = _T("");
	m_sShow = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSerialPortDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSerialPortDlg)
	DDX_Text(pDX, IDC_SEND_MSG, m_sSendMsg);
	DDX_Text(pDX, IDC_SHOW, m_sShow);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSerialPortDlg, CDialog)
	//{{AFX_MSG_MAP(CSerialPortDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(ID_SP_CONNECT, OnSpConnect)
	ON_BN_CLICKED(ID_SP_DISCONNECT, OnSpDisconnect)
	ON_BN_CLICKED(ID_SP_SETTINGS, OnSpSettings)
	ON_BN_CLICKED(ID_SP_SEND, OnSpSend)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSerialPortDlg message handlers

BOOL CSerialPortDlg::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
	m_bConnected=FALSE;
	m_pThread=NULL;
	m_sPort="COM1";
	m_nBaud=9600;
	m_nDataBits=8;
	m_sParity="None";
	m_sStopBits="1";
	m_nFlowCtrl=0;
	m_sSendMsg="";
	m_sShow="";

	GetDlgItem(ID_SP_DISCONNECT)->EnableWindow(m_bConnected);
	GetDlgItem(ID_SP_SEND)->EnableWindow(m_bConnected);
	memset(&m_osRead,0,sizeof(OVERLAPPED));
	memset(&m_osWrite,0,sizeof(OVERLAPPED));
	if(!(m_osRead.hEvent=CreateEvent(NULL,TRUE,TRUE,NULL))) return FALSE;
	if(!(m_osWrite.hEvent=CreateEvent(NULL,TRUE,TRUE,NULL))) return FALSE;
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSerialPortDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CSerialPortDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CSerialPortDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CSerialPortDlg::OnSpConnect() 
{
	// TODO: Add your control notification handler code here
	COMMTIMEOUTS TimeOuts;

	if(m_bConnected) return;
	m_hSPCom=CreateFile(m_sPort,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,NULL);
	if(m_hSPCom==INVALID_HANDLE_VALUE)
	{
		AfxMessageBox("Can't open connection!");
		return;
	}

	SetupComm(m_hSPCom,MAXBLOCK,MAXBLOCK);
	SetCommMask(m_hSPCom,EV_RXCHAR);
	TimeOuts.ReadIntervalTimeout=MAXDWORD;
	TimeOuts.ReadTotalTimeoutConstant=0;
	TimeOuts.ReadTotalTimeoutMultiplier=0;
	TimeOuts.WriteTotalTimeoutConstant=2000;
	TimeOuts.WriteTotalTimeoutMultiplier=50;
	SetCommTimeouts(m_hSPCom,&TimeOuts);

	if(ConfigConnection())
	{
		m_pThread=AfxBeginThread(SPCommProc,this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL);
		if(m_pThread==NULL)
		{
			CloseHandle(m_hSPCom);
			AfxMessageBox("Can't open connection!");
			return;
		}
		else{
			m_bConnected=TRUE;
			m_pThread->ResumeThread();
		}
	}
	else{
		CloseHandle(m_hSPCom);
		AfxMessageBox("Can't open connection!");
		return;
	}

	GetDlgItem(ID_SP_CONNECT)->EnableWindow(!m_bConnected);
	GetDlgItem(ID_SP_DISCONNECT)->EnableWindow(m_bConnected);
	GetDlgItem(ID_SP_SEND)->EnableWindow(m_bConnected);
}

void CSerialPortDlg::OnSpDisconnect() 
{
	// TODO: Add your control notification handler code here
	if(!m_bConnected) return;
	m_bConnected=FALSE;
	SetCommMask(m_hSPCom,0);
	WaitForSingleObject(m_pThread->m_hThread,INFINITE);
	m_pThread=NULL;
	CloseHandle(m_hSPCom);
	GetDlgItem(ID_SP_CONNECT)->EnableWindow(!m_bConnected);
	GetDlgItem(ID_SP_DISCONNECT)->EnableWindow(m_bConnected);
	GetDlgItem(ID_SP_SEND)->EnableWindow(m_bConnected);
}

void CSerialPortDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	if(m_bConnected) OnSpDisconnect();
	if(m_osRead.hEvent) CloseHandle(m_osRead.hEvent);
	if(m_osWrite.hEvent) CloseHandle(m_osWrite.hEvent);
	CDialog::OnCancel();
}

void CSerialPortDlg::OnSpSettings() 
{
	// TODO: Add your control notification handler code here
	CSetupDlg dlg;
	CString str;
	dlg.m_bConnected=m_bConnected;
	dlg.m_sPort=m_sPort;
	str.Format("%d",m_nBaud);
	dlg.m_sBaud=str;
	str.Format("%d",m_nDataBits);
	dlg.m_sDataBits=str;
	dlg.m_sParity=m_sParity;
	dlg.m_sStopBits=m_sStopBits;
	dlg.m_nFlowCtrl=m_nFlowCtrl;
	if(dlg.DoModal()==IDOK)
	{
		m_sPort=dlg.m_sPort;
		m_nBaud=atoi(dlg.m_sBaud);
		m_nDataBits=atoi(dlg.m_sDataBits);
		m_sParity=dlg.m_sParity;
		m_sStopBits=dlg.m_sStopBits;
		m_nFlowCtrl=dlg.m_nFlowCtrl;
		if(m_bConnected)
			if(!ConfigConnection()) AfxMessageBox("Can't realize the settings!");
	}
}

BOOL CSerialPortDlg::ConfigConnection()
{
	DCB dcb;
	if(!GetCommState(m_hSPCom,&dcb)) return FALSE;
	dcb.fBinary=TRUE;
	dcb.BaudRate=m_nBaud;
	dcb.ByteSize=m_nDataBits;
	dcb.fParity=TRUE;
	if(strcmp(m_sParity,"None")==0) dcb.Parity=NOPARITY;
	else if(strcmp(m_sParity,"Even")==0) dcb.Parity=EVENPARITY;
	else if(strcmp(m_sParity,"Odd")==0) dcb.Parity=ODDPARITY;
	if(strcmp(m_sStopBits,"1")==0) dcb.StopBits=ONESTOPBIT;
	else if(strcmp(m_sStopBits,"1.5")==0) dcb.StopBits=ONE5STOPBITS;
	else if(strcmp(m_sStopBits,"2")==0) dcb.StopBits=TWOSTOPBITS;
	dcb.fOutxCtsFlow=dcb.fRtsControl=(m_nFlowCtrl==1);
	dcb.fInX=dcb.fOutX=(m_nFlowCtrl==2);
	dcb.XonChar=XON;
	dcb.XoffChar=XOFF;
	dcb.XonLim=dcb.XoffLim=50;
	return SetCommState(m_hSPCom,&dcb);
}

DWORD CSerialPortDlg::ReadComm(char *buf, DWORD dwLength)
{
	DWORD length=0;
	COMSTAT ComStat;
	DWORD dwErrorFlags;
	ClearCommError(m_hSPCom,&dwErrorFlags,&ComStat);
	length=min(dwLength,ComStat.cbInQue);
	ReadFile(m_hSPCom,buf,length,&length,&m_osRead);
	return length;
}

DWORD CSerialPortDlg::WriteComm(char *buf, DWORD dwLength)
{
	DWORD length=dwLength;
	COMSTAT ComStat;
	DWORD dwErrorFlags;
	ClearCommError(m_hSPCom,&dwErrorFlags,&ComStat);
	WriteFile(m_hSPCom,buf,length,&length,&m_osWrite);
	if(GetLastError()==ERROR_IO_PENDING) GetOverlappedResult(m_hSPCom,&m_osWrite,&length,TRUE);
	else length=0;
	return length;
}

void CSerialPortDlg::OnSpSend() 
{
	// TODO: Add your control notification handler code here
	DWORD length;
	CString str;
	UpdateData(TRUE);
	length=WriteComm(m_sSendMsg.LockBuffer(),m_sSendMsg.GetLength());
	str.Format("本機(jī)發(fā)送數(shù)據(jù):\r\n");
	m_sShow+=str;
	m_sShow+=m_sSendMsg.Left(length);
	m_sShow+="\r\n\r\n";
	UpdateData(FALSE);
}

UINT SPCommProc(LPVOID pParam)
{
	OVERLAPPED os;
	DWORD dwMask,dwTrans;
	COMSTAT ComStat;
	DWORD dwErrorFlags;
	char buf[MAXBLOCK/4];
	DWORD length,i;
	CString str;

	CSerialPortDlg *pDlg=(CSerialPortDlg *)pParam;
	memset(&os,0,sizeof(OVERLAPPED));
	os.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
	if(os.hEvent==NULL)
	{
		AfxMessageBox("Can't create event object!");
		return -1;
	}

	while(pDlg->m_bConnected)
	{
		ClearCommError(pDlg->m_hSPCom,&dwErrorFlags,&ComStat);
		if(ComStat.cbInQue)
		{
			length=pDlg->ReadComm(buf,100);
			str.Format("本機(jī)收到數(shù)據(jù):\r\n");
			pDlg->m_sShow+=str;
			for(i=0;i<length;i++) pDlg->m_sShow+=buf[i];
			pDlg->m_sShow+="\r\n\r\n";
			pDlg->UpdateData(FALSE);
		}
		dwMask=0;
		if(!WaitCommEvent(pDlg->m_hSPCom,&dwMask,&os))
		{
			if(GetLastError()==ERROR_IO_PENDING)
				GetOverlappedResult(pDlg->m_hSPCom,&os,&dwTrans,TRUE);
			else{
				CloseHandle(os.hEvent);
				return -1;
			}
		}
	}
	CloseHandle(os.hEvent);
	return 0;
}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91香蕉国产在线观看软件| 国产精品精品国产色婷婷| 精品美女在线播放| 欧美刺激午夜性久久久久久久| 日韩女优电影在线观看| 国产欧美日韩在线视频| 亚洲欧美一区二区三区国产精品 | 日本一二三不卡| 中文字幕在线不卡| 亚洲va国产天堂va久久en| 日本成人中文字幕在线视频| 国产老妇另类xxxxx| 99久久久精品| 8v天堂国产在线一区二区| 久久精品一二三| 夜夜爽夜夜爽精品视频| 久久国产精品露脸对白| av在线不卡免费看| 欧美一区二区精品在线| 国产精品美女久久久久高潮| 亚洲3atv精品一区二区三区| 国产在线麻豆精品观看| 日本黄色一区二区| 久久综合色天天久久综合图片| 亚洲欧美色综合| 久久国产福利国产秒拍| 色嗨嗨av一区二区三区| 久久综合久久鬼色中文字| 亚洲女厕所小便bbb| 精品一区二区三区av| 色综合网色综合| 精品少妇一区二区三区日产乱码| 亚洲三级在线播放| 国产最新精品免费| 欧美日韩亚洲国产综合| 国产精品视频线看| 捆绑紧缚一区二区三区视频| 色屁屁一区二区| 久久久精品人体av艺术| 亚洲成人你懂的| 成人avav影音| 亚洲精品一区在线观看| 亚洲国产精品一区二区尤物区| 粉嫩av一区二区三区在线播放| 91精品国产综合久久福利软件 | 日本成人中文字幕| 色乱码一区二区三区88| 国产人成亚洲第一网站在线播放| 日本欧美久久久久免费播放网| 日本大香伊一区二区三区| 国产三级久久久| 激情综合色综合久久| 欧美精品免费视频| 亚洲欧美日韩国产成人精品影院 | 精品女同一区二区| 日韩和欧美一区二区三区| 色综合夜色一区| 国产精品久久二区二区| 国产乱码精品一区二区三区av| 日韩小视频在线观看专区| 五月婷婷久久综合| 欧美伊人精品成人久久综合97| 亚洲色欲色欲www在线观看| 福利一区二区在线观看| 久久免费国产精品 | 久久久777精品电影网影网 | 日韩一二三四区| 亚洲国产另类av| 欧美午夜精品久久久久久超碰| 亚洲视频一二三区| 99久久婷婷国产综合精品| 国产欧美一区二区在线| 国产伦精品一区二区三区免费 | 性久久久久久久久久久久| 欧美三级乱人伦电影| 亚洲综合色自拍一区| 色婷婷av一区二区三区之一色屋| 亚洲私人影院在线观看| 91在线一区二区三区| 日韩理论片网站| 99精品一区二区三区| 亚洲欧洲色图综合| 一本大道久久a久久综合| 亚洲欧美经典视频| 日本大香伊一区二区三区| 亚洲在线成人精品| 欧美日韩亚洲综合一区| 日本亚洲视频在线| 日韩欧美色综合| 激情小说欧美图片| 国产日韩三级在线| 99久久精品一区二区| 亚洲一级片在线观看| 欧美人动与zoxxxx乱| 日韩精品电影一区亚洲| 精品久久久久av影院| 国产精品一卡二卡| 国产精品国产三级国产aⅴ无密码 国产精品国产三级国产aⅴ原创 | 亚洲chinese男男1069| 欧美日本在线看| 日韩黄色在线观看| 国产亚洲综合在线| av电影一区二区| 亚洲一区二区三区视频在线| 制服丝袜中文字幕亚洲| 激情丁香综合五月| 国产精品二区一区二区aⅴ污介绍| 色综合久久久久综合99| 五月天视频一区| 欧美电影免费观看高清完整版在 | 一道本成人在线| 亚洲va国产va欧美va观看| 欧美va日韩va| caoporm超碰国产精品| 亚洲香肠在线观看| 精品国产sm最大网站免费看| 高潮精品一区videoshd| 尤物在线观看一区| 精品日韩一区二区| 99久久精品国产一区| 五月天婷婷综合| 国产精品丝袜久久久久久app| 在线观看免费亚洲| 久久超碰97中文字幕| 国产精品久久久久久妇女6080 | 美腿丝袜在线亚洲一区| 久久久www成人免费无遮挡大片| 99riav一区二区三区| 日韩专区欧美专区| 中文字幕精品在线不卡| 欧美亚洲一区二区在线| 国产精品一区免费视频| 亚洲精品中文在线观看| 欧美电影免费观看高清完整版| 成人免费黄色在线| 日韩二区三区四区| 国产精品欧美一区二区三区| 欧美肥妇bbw| 成人av影院在线| 日本美女一区二区三区视频| 亚洲欧美一区二区在线观看| 日韩一级片网站| 99re这里都是精品| 精品在线一区二区| 亚洲综合在线电影| 国产视频视频一区| 7777精品伊人久久久大香线蕉超级流畅 | 韩国视频一区二区| 一区二区三区波多野结衣在线观看| 91精品国产高清一区二区三区 | 久久人人爽人人爽| 欧美日韩国产精品自在自线| 粉嫩aⅴ一区二区三区四区| 日本v片在线高清不卡在线观看| 中文字幕在线不卡国产视频| 欧美精品一区二区蜜臀亚洲| 欧美性猛交xxxx黑人交| 99久久精品一区| 国产成人精品亚洲日本在线桃色| 午夜精品久久久久久| 亚洲天堂a在线| 国产欧美日韩亚州综合| 日韩欧美中文字幕一区| 69堂国产成人免费视频| 91久久久免费一区二区| 成人免费精品视频| 粉嫩一区二区三区性色av| 精品一二线国产| 免费看日韩a级影片| 岛国精品在线播放| 欧美精品在线观看一区二区| 亚洲乱码国产乱码精品精的特点 | 欧美成人精品高清在线播放| 欧美色爱综合网| 色综合久久天天| 成人黄色电影在线 | 欧美经典三级视频一区二区三区| 日韩西西人体444www| 91麻豆精品国产91| 欧美日韩日日骚| 欧美视频一区二区三区在线观看| 91亚洲大成网污www| 成人不卡免费av| 国产黄色91视频| 在线播放日韩导航| 欧美中文字幕一二三区视频| 91麻豆国产精品久久| 99久久99精品久久久久久| 国产精品综合在线视频| 国产一区二区美女| 麻豆传媒一区二区三区| 亚洲国产一区二区视频| 亚洲三级电影网站| 亚洲欧美欧美一区二区三区| 中国色在线观看另类| 国产精品久久久久aaaa| 国产精品系列在线| 国产精品久久久久四虎| 国产精品国产三级国产普通话三级 | 99久久er热在这里只有精品15|