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

📄 usbdevdlg.cpp

📁 针对at91sam7s64芯片实现和下位机之间的usb通讯
💻 CPP
字号:
// usbdevDlg.cpp : implementation file
//

#include "stdafx.h"
#include "usbdev.h"
#include "usbdevDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CUsbdevDlg dialog

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

void CUsbdevDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUsbdevDlg)
	DDX_Control(pDX, IDC_CLOSE, m_close);
	DDX_Control(pDX, IDC_OPEN, m_open);
	DDX_Control(pDX, IDC_READ, m_read);
	DDX_Control(pDX, IDC_SEND, m_send);
	DDX_Control(pDX, IDC_RXDATA, m_rx);
	DDX_Text(pDX, IDC_RXDATA, m_recieve);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CUsbdevDlg, CDialog)
	//{{AFX_MSG_MAP(CUsbdevDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_SEND, OnSend)
	ON_BN_CLICKED(IDC_READ, OnRead)
	ON_BN_CLICKED(IDC_CLOSE, OnClose)
	ON_BN_CLICKED(IDC_OPEN, OnOpen)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUsbdevDlg message handlers

BOOL CUsbdevDlg::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

	// TODO: Add extra initialization here
	m_send.EnableWindow(FALSE);
	m_read.EnableWindow(FALSE);
	m_close.EnableWindow(FALSE);
	SetDlgItemText(IDC_TXDATA,"1");
	SetDlgItemText(IDC_RXDATA,"0");
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CUsbdevDlg::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 CUsbdevDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CUsbdevDlg::OnSend() 
{
	// TODO: Add your control notification handler code here
	m_read.EnableWindow(TRUE);
	m_send.EnableWindow(FALSE);
	CString   str; 
	char *pbuf,ch;
	GetDlgItem(IDC_TXDATA)->GetWindowText(str);
	pbuf=(LPSTR)(LPCTSTR)str;
	ch=*pbuf;
	m_alvausb.doWrite(4,pbuf);	
}

void CUsbdevDlg::OnRead() 
{
	// TODO: Add your control notification handler code here
	m_read.EnableWindow(FALSE);
	m_send.EnableWindow(TRUE);
	CString str;	
	str=m_alvausb.doRead(1);
	SetDlgItemText(IDC_RXDATA,str);
}

void CUsbdevDlg::OnClose() 
{
	// TODO: Add your control notification handler code here
	m_alvausb.Close();
    DestroyWindow(); 
    OnClose(); 

//	m_close.EnableWindow(FALSE);
//	m_send.EnableWindow(FALSE);
//	m_read.EnableWindow(FALSE);
}

void CUsbdevDlg::OnOpen() 
{
	// TODO: Add your control notification handler code here
	m_close.EnableWindow(TRUE);
	m_open.EnableWindow(FALSE);
	m_send.EnableWindow(TRUE);
	m_alvausb.IniDevice();
	
}

⌨️ 快捷键说明

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