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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? usbtestdlg.cpp

?? 在PC上通過USB與C8051通信
?? CPP
字號:
// USBTestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "USBTest.h"
#include "USBIF.h"
#include "USBTestDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// USB driver definitions

#include <initguid.h>		// Required for GUID definition
DEFINE_GUID(GUID_INTERFACE_CYGNAL_INTERRUPT, 
0xdda31245, 0x1bfc, 0x4225, 0xb2, 0xb8, 0xea, 0xaa, 0xb2, 0xe3, 0x90, 0xb6);

#define CYGNAL_INT_WRITEPIPE	"PIPE01"
#define CYGNAL_INT_READPIPE	"PIPE00"

#define IOCTL_READINT			0x800	// User defined IO Control code
										// for reading the Interrupt Pipe
				

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CUSBTestDlg dialog

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

void CUSBTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUSBTestDlg)
	DDX_Control(pDX, IDC_AN1_METER, m_Analog_Meter1);
	DDX_Control(pDX, IDC_AN2_METER, m_Analog_Meter2);
	DDX_Control(pDX, IDC_BTN1_LED, m_ButtonLED1);
	DDX_Control(pDX, IDC_BTN2_LED, m_ButtonLED2);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CUSBTestDlg, CDialog)
	//{{AFX_MSG_MAP(CUSBTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUSBTestDlg message handlers

BOOL CUSBTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	m_bReadError = FALSE;
	m_bWriteError = FALSE;

	// 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
	
	// Custom Initialization follows:
	// Initialize handles
	hUSBRead, hUSBWrite = INVALID_HANDLE_VALUE;

	// LED's
	CWnd *pWndLedBtn1 = (CWnd *)GetDlgItem(IDC_BTN1_LED);
	m_ButtonLED1.SetLED(pWndLedBtn1,ID_LED_GREEN,ID_SHAPE_ROUND,500);
	m_ButtonLED1.SwitchOn();
	m_ButtonLED1.LedOff();

	CWnd *pWndLedBtn2 = (CWnd *)GetDlgItem(IDC_BTN2_LED);
	m_ButtonLED2.SetLED(pWndLedBtn2,ID_LED_GREEN,ID_SHAPE_ROUND,500);
	m_ButtonLED2.SwitchOn();
	m_ButtonLED2.LedOff();

	// Analog Meters
	CString sUnitPot = "Pot";
	m_Analog_Meter1.SetUnits(sUnitPot);
	m_Analog_Meter1.SetRange(0,255);
	m_Analog_Meter1.UpdateNeedle(0);
	CString sUnitTemp = "Temp";
	m_Analog_Meter2.SetUnits(sUnitTemp);
	m_Analog_Meter2.SetRange(0,255);
	m_Analog_Meter2.UpdateNeedle(0);

	// Establish USB connection
	hUSBRead = NULL;
	hUSBWrite = NULL;
	UsbIF.SetGUID(GUID_INTERFACE_CYGNAL_INTERRUPT);

	if (UsbIF.OpenUsbDevice())
	{
		// Get the read handle
		hUSBRead = UsbIF.open_file(CYGNAL_INT_READPIPE);
		if (hUSBRead == INVALID_HANDLE_VALUE)
		{
			CString sMessage;
			sMessage.Format("Error opening Read device: %s\n\nApplication is aborting.\nReset hardware and try again.",CYGNAL_INT_READPIPE);
			if (AfxMessageBox(sMessage,MB_OK|MB_ICONEXCLAMATION))
			{
				OnCancel();
			}
		}

		// Get the write handle
		hUSBWrite = UsbIF.open_file(CYGNAL_INT_WRITEPIPE);
		if (hUSBWrite == INVALID_HANDLE_VALUE)
		{
			CString sMessage;
			sMessage.Format("Error opening Write device: %s\n\nApplication is aborting.\nReset hardware and try again.",CYGNAL_INT_WRITEPIPE);
			if (AfxMessageBox(sMessage,MB_OK|MB_ICONEXCLAMATION))
			{
				OnCancel();
			}
		}

		// If both handles are valid, can start the timer
		if ( ((hUSBRead  != INVALID_HANDLE_VALUE) || (hUSBRead  != NULL)) &&
			 ((hUSBWrite != INVALID_HANDLE_VALUE) || (hUSBWrite != NULL)) )
		{
			SetTimer(1,100,NULL);
		}
	}
	else
	{
		if (AfxMessageBox("Error establishing USB connection.\n\nApplication is aborting.\nReset hardware and try again.",MB_OK|MB_ICONEXCLAMATION))
		{
			OnCancel();
		}
	}

	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CUSBTestDlg::OnOKExit() 
{
	KillTimer(1);	

	if ( hUSBWrite != NULL )
	{
		::CloseHandle(hUSBWrite);
		hUSBWrite = NULL;
	}
	
	if ( hUSBRead != NULL )
	{
		::CloseHandle(hUSBRead);
		hUSBRead = NULL;
	}

	

	CDialog::OnOK();
}

// Note: No cancel button exists on the dialog, but this function is used
// when dialog is terminated at customer request from message box input.
void CUSBTestDlg::OnCancel() 
{
	CloseConnection(); 
	CDialog::OnCancel();
}

void CUSBTestDlg::CloseConnection() 
{
	KillTimer(1);		

	if ( hUSBWrite != NULL )
	{
		::CloseHandle(hUSBRead);
		hUSBWrite = NULL;
	}
	
	if ( hUSBRead != NULL )
	{
		::CloseHandle(hUSBRead);
		hUSBRead = NULL;
	}
	
}

void CUSBTestDlg::OnTimer(UINT nIDEvent) 
{
	// Confirm an error hasn't already occurred
	if ( (m_bReadError == TRUE) || (m_bWriteError == TRUE) )
	{
		// Call base timer
		CDialog::OnTimer(nIDEvent);

		// Further processing not possible
		return;		
	}

	// Obtain current values of dialog editable items
	io_buffer.led1 = ((CButton*) GetDlgItem(IDC_CHECK_LED1))->GetCheck(); 
	io_buffer.led2 = ((CButton*) GetDlgItem(IDC_CHECK_LED2))->GetCheck(); 

	unsigned char B0 = ((CButton*) GetDlgItem(IDC_P1_B0))->GetCheck();
	unsigned char B1 = ((CButton*) GetDlgItem(IDC_P1_B1))->GetCheck();
	unsigned char B2 = ((CButton*) GetDlgItem(IDC_P1_B2))->GetCheck();
	unsigned char B3 = ((CButton*) GetDlgItem(IDC_P1_B3))->GetCheck();

	unsigned char P1 = ( (B3 << 3) | (B2 << 2) | (B1 << 1) | (B0) ) & 0x0F;
	io_buffer.port = P1; 

	unsigned long ulBytesSucceed;
	unsigned long ulBytesWriteRequest = (sizeof(USB_iobuf)-4);
	unsigned long ulBytesReadRequest = sizeof(USB_iobuf);

	// Perform USB Data Transfer
	// Write transfer packet
	WriteFile(hUSBWrite, &io_buffer, ulBytesWriteRequest, &ulBytesSucceed, NULL);
	if(ulBytesSucceed != ulBytesWriteRequest)
	{
		m_bWriteError = TRUE;	// Note: Set error flag immediately so that multiple 
								// message boxes do not queue up.
		CString sError;
		sError.Format("Error writing to USB.\nWrote %d of %d bytes.\n\nApplication is aborting.\nReset hardware and try again.", ulBytesSucceed, ulBytesWriteRequest);
		if (AfxMessageBox(sError,MB_OK|MB_ICONEXCLAMATION))
		{
			OnCancel();
			return;
		}
	}
	// Read transfer packet
	ReadFile(hUSBRead, &io_buffer, ulBytesReadRequest, &ulBytesSucceed, NULL);
	if( (ulBytesSucceed != ulBytesReadRequest) && (m_bReadError == FALSE) )
	{
		m_bReadError = TRUE;	// Note: Set error flag immediately so that multiple 
								// message boxes do not queue up.

		CString sError;
		sError.Format("Error reading from USB.\nRead %d of %d bytes.\n\nApplication is aborting.\nReset hardware and try again.", ulBytesSucceed, ulBytesReadRequest);
		if (AfxMessageBox(sError,MB_OK|MB_ICONEXCLAMATION))
		{
			OnCancel();
			return;
		}
	}
		
	// Make updates to dialog display items
	if (io_buffer.led1)
		m_ButtonLED1.LedOn();
	else
		m_ButtonLED1.LedOff();

	if (io_buffer.led2)
		m_ButtonLED2.LedOn();
	else
		m_ButtonLED2.LedOff();

// For debug purposes, can watch what comes back from driver.
//	TRACE3("L1:%02X, L2:%02X, P:%02X, ",io_buffer.led1,io_buffer.led2,io_buffer.port);
//	TRACE2("A1:%02X, A2:%02X\n",io_buffer.analog1,io_buffer.analog2);

	unsigned char P0 = io_buffer.port & 0x0F;
	((CButton*) GetDlgItem(IDC_P0_B0))->SetCheck(P0 & 0x01);  
	((CButton*) GetDlgItem(IDC_P0_B1))->SetCheck((P0 & 0x02) >> 1);  
	((CButton*) GetDlgItem(IDC_P0_B2))->SetCheck((P0 & 0x04) >> 2);  
	((CButton*) GetDlgItem(IDC_P0_B3))->SetCheck((P0 & 0x08) >> 3);  

	m_Analog_Meter1.UpdateNeedle(io_buffer.analog1);
	m_Analog_Meter2.UpdateNeedle(io_buffer.analog2);

	CDialog::OnTimer(nIDEvent);
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美三级资源在线| 亚洲欧美福利一区二区| 国产日韩精品一区二区三区 | 亚洲自拍欧美精品| 亚洲国产美女搞黄色| 免费观看在线综合色| 国产麻豆午夜三级精品| 97国产精品videossex| 色婷婷综合五月| 欧美一区二区美女| 国产欧美一区二区三区鸳鸯浴| 综合网在线视频| 午夜欧美视频在线观看 | 久久综合99re88久久爱| 久久久噜噜噜久噜久久综合| 中文字幕在线不卡| 免费不卡在线视频| 99热这里都是精品| 日韩欧美一区二区视频| 国产精品久久久爽爽爽麻豆色哟哟| 亚洲午夜久久久久久久久电影网| 激情六月婷婷久久| av在线不卡网| 在线播放中文字幕一区| 欧美国产一区二区| 天天色天天操综合| 成人精品视频一区| 欧美日韩精品欧美日韩精品| 久久午夜色播影院免费高清| 一区二区日韩电影| 国产一区二区精品久久| 欧美在线播放高清精品| 国产三级一区二区| 午夜精品久久久久久不卡8050| 国产成人精品免费在线| 欧美日韩精品一区二区三区蜜桃| 国产精品无码永久免费888| 日本成人超碰在线观看| 日本道免费精品一区二区三区| 亚洲精品一区二区三区四区高清| 亚洲成人免费在线| 97久久久精品综合88久久| 26uuu亚洲综合色| 亚洲电影你懂得| 97se亚洲国产综合自在线不卡| 久久影院视频免费| 天堂在线一区二区| 91精彩视频在线| 国产网红主播福利一区二区| 裸体歌舞表演一区二区| 欧美图区在线视频| 亚洲免费资源在线播放| 风间由美性色一区二区三区| 日韩一区二区电影在线| 亚洲在线视频免费观看| 99久久精品免费观看| 久久精品无码一区二区三区| 精品一区二区在线观看| 欧美一卡二卡三卡| 午夜激情一区二区| 欧美午夜视频网站| 一区二区在线观看视频在线观看| 99久久精品免费观看| 国产精品青草久久| 风间由美中文字幕在线看视频国产欧美| 日韩欧美卡一卡二| 日韩不卡一区二区三区 | 日本最新不卡在线| 欧美日韩在线不卡| 亚洲在线视频网站| 欧美日韩精品一区二区三区四区| 一区二区在线观看免费| 91免费小视频| 亚洲免费电影在线| 色综合天天天天做夜夜夜夜做| 中文字幕综合网| www.66久久| 亚洲区小说区图片区qvod| 99re这里都是精品| 亚洲综合免费观看高清在线观看| 色天天综合色天天久久| 亚洲综合色丁香婷婷六月图片| 欧美自拍偷拍一区| 亚洲444eee在线观看| 欧美在线视频日韩| 五月婷婷激情综合网| 欧美绝品在线观看成人午夜影视| 午夜a成v人精品| 日韩免费视频线观看| 国产一区二三区| 国产喷白浆一区二区三区| 成人av在线资源| 亚洲色图制服丝袜| 欧美三区免费完整视频在线观看| 五月婷婷综合网| 精品国产亚洲在线| 成人精品电影在线观看| 亚洲麻豆国产自偷在线| 欧美日韩成人在线| 九色|91porny| 国产精品久久久久影视| 欧美性猛交xxxx乱大交退制版 | 日韩美女一区二区三区| 国产精品一区二区在线播放| 国产精品天美传媒沈樵| 91福利在线看| 日本aⅴ亚洲精品中文乱码| 精品sm捆绑视频| 99精品视频一区二区三区| 亚洲大片精品永久免费| 精品国产a毛片| av电影在线观看一区| 午夜精品成人在线视频| 久久综合久久综合久久| 一本久久a久久免费精品不卡| 青青草视频一区| 日本一区二区三区四区在线视频| 色噜噜狠狠色综合欧洲selulu| 日本视频一区二区三区| 欧美国产欧美综合| 欧美最新大片在线看| 国产曰批免费观看久久久| 一区二区三区欧美在线观看| 亚洲精品一区二区三区四区高清| 91小视频免费看| 久久99精品国产.久久久久| 综合网在线视频| 欧美精品一区二区三区蜜桃视频 | 中文字幕日韩一区| 91精品一区二区三区久久久久久 | 亚洲精品乱码久久久久久久久 | 国产成a人亚洲精品| 亚洲va欧美va国产va天堂影院| 国产欧美一区二区精品忘忧草 | 爽好久久久欧美精品| 欧美国产亚洲另类动漫| 91精品久久久久久蜜臀| 99久久精品免费| 国产综合色产在线精品| 午夜精品福利一区二区蜜股av| 国产精品蜜臀在线观看| 日韩欧美在线网站| 日本道精品一区二区三区| 国产成人高清视频| 美女诱惑一区二区| 亚洲综合在线观看视频| 中文字幕av一区 二区| 日韩欧美精品在线| 欧美日韩五月天| 成人免费看视频| 激情综合一区二区三区| 午夜精品福利在线| 亚洲精品久久久久久国产精华液| 久久精品视频在线免费观看| 日韩女优制服丝袜电影| 欧美无砖砖区免费| 色综合久久88色综合天天| 国产成人精品免费| 韩国女主播一区| 日本一不卡视频| 亚洲成人手机在线| 一区二区三国产精华液| 亚洲色图清纯唯美| 久久精品这里都是精品| 精品久久久久一区| 日韩视频一区在线观看| 欧美猛男gaygay网站| 色老汉一区二区三区| 成人av网站在线观看| 国产精品66部| 国产麻豆9l精品三级站| 国产一区二区三区精品欧美日韩一区二区三区 | 一二三区精品福利视频| 中文字幕在线观看一区二区| 日本一二三不卡| 中文字幕乱码日本亚洲一区二区 | 成人久久18免费网站麻豆| 国产精品自在在线| 国产一区视频在线看| 男人的j进女人的j一区| 日本欧美大码aⅴ在线播放| 日日夜夜免费精品视频| 日韩成人一级片| 免费高清在线一区| 日本中文在线一区| 理论电影国产精品| 久久成人羞羞网站| 国产毛片一区二区| 丰满少妇久久久久久久| 成人黄色在线视频| www.色精品| 一本久久精品一区二区| 在线免费不卡视频| 欧美日韩中文国产| 91麻豆精品国产| 精品美女在线播放| 国产欧美日韩三级| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆| 亚洲丝袜自拍清纯另类| 一区二区三区不卡在线观看|