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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? usbtestdlg.cpp

?? F320單片機實現于上位機USB接口通信的源代碼
?? CPP
字號:
// USBTestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "USBTest.h"
#include "USBTestDlg.h"
#include "SelectDialog.h"
#include "SiUSBXp.h"

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

#define TIMER_READWRITE		 (WM_USER+101)
/////////////////////////////////////////////////////////////////////////////
// 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);
	//}}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
	m_hUSBDevice = INVALID_HANDLE_VALUE;

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

	if (!GetDeviceList())
	{	
		AfxMessageBox("Error finding USB device. Aborting application",MB_OK|MB_ICONEXCLAMATION);
		OnCancel();
		return TRUE;
	}

	m_nDeviceNum = -1;

	if (!SelectDevice())
		return TRUE;

	// Set read write timeouts
	SI_SetTimeouts(1000, 1000);

	// Open device handle
	SI_STATUS status = SI_Open((DWORD)m_nDeviceNum, &m_hUSBDevice);

	if (status != SI_SUCCESS)
	{
		CString sMessage;
		sMessage.Format("Error opening device: %s\n\nApplication is aborting.\nReset hardware and try again.", m_sDeviceName);
		if (AfxMessageBox(sMessage,MB_OK|MB_ICONEXCLAMATION))
		{
			OnCancel();
			return TRUE;
		}
	}

	memset(&m_IObuffer, 0, sizeof(USB_iobuf));
	
	m_fontLogo.CreateFont(20, 0, 0, 0, 25, TRUE, FALSE,0,0,0,0,0,0, "宋體");
	
	SetTimer(TIMER_READWRITE,100,NULL);

	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
	{
		CPaintDC dc(this); // device context for painting
		
		CRect rectCleint;
		GetClientRect(&rectCleint);
		
		dc.SetBkMode(TRANSPARENT);
		
		CRect rectText;
		rectText.left = rectCleint.left;
		rectText.top = rectCleint.top;
		rectText.bottom = rectCleint.top + 80;
		rectText.right = rectCleint.left + 1000;
		
		CFont * OldFont = dc.SelectObject(&m_fontLogo);
		
		// draw text in DC
		COLORREF OldColor = dc.SetTextColor( ::GetSysColor( COLOR_3DHILIGHT));
		
		dc.DrawText( "銘朗科技—WWW.MLARM.COM", rectText + CPoint(1,1), DT_SINGLELINE | DT_LEFT | DT_VCENTER);
		dc.SetTextColor( ::GetSysColor( COLOR_3DSHADOW));
		dc.DrawText( "銘朗科技—WWW.MLARM.COM", rectText, DT_SINGLELINE | DT_LEFT | DT_VCENTER);
		
		// restore old text color
		dc.SetTextColor( OldColor);
		// restore old font
		dc.SelectObject(OldFont);
		
		//	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(TIMER_READWRITE);	

//	SI_Close(m_hUSBDevice);

	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() 
{
	KillTimer(TIMER_READWRITE);		
	
//	SI_Close(m_hUSBDevice); 
	
	CDialog::OnCancel();
}


void CUSBTestDlg::OnTimer(UINT nIDEvent) 
{
	if(nIDEvent != TIMER_READWRITE) return;
	
	SI_STATUS status = SI_SUCCESS;

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

	unsigned char B0 = ((CButton*) GetDlgItem(IDC_P1_B4))->GetCheck();
	unsigned char B1 = ((CButton*) GetDlgItem(IDC_P1_B3))->GetCheck();
	unsigned char B2 = ((CButton*) GetDlgItem(IDC_P1_B2))->GetCheck();
	unsigned char B3 = ((CButton*) GetDlgItem(IDC_P1_B1))->GetCheck();
	unsigned char B4 = ((CButton*) GetDlgItem(IDC_P1_B0))->GetCheck();
	
	unsigned char P1 = ( (B4 << 4) | (B3 << 3) | (B2 << 2) | (B1 << 1) | (B0) ) & 0x1F;
	m_IObuffer.adc0 = P1; 

	DWORD dwBytesSucceed = 0;
	DWORD dwBytesWriteRequest = (sizeof(USB_iobuf));
	DWORD dwBytesReadRequest = (sizeof(USB_iobuf));

	// Init. before write
	dwBytesSucceed = 0;

	// Perform USB Data Transfer
	// Write transfer packet
	status = SI_Write(m_hUSBDevice, &m_IObuffer, dwBytesWriteRequest, &dwBytesSucceed);

	if (dwBytesSucceed != dwBytesWriteRequest || status != SI_SUCCESS)
	{
		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.", dwBytesSucceed, dwBytesWriteRequest);
		if (AfxMessageBox(sError,MB_OK|MB_ICONEXCLAMATION))
		{
			OnCancel();
			return;
		}
	}

	// Init. before read
	dwBytesSucceed = 0;

	memset(&m_IObuffer, 0, sizeof(USB_iobuf));

	// Read transfer packet
	status = SI_Read(m_hUSBDevice, &m_IObuffer, dwBytesReadRequest, &dwBytesSucceed);

	if (((dwBytesSucceed != dwBytesReadRequest) && (m_bReadError == FALSE)) || status != SI_SUCCESS)
	{
		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.", dwBytesSucceed, dwBytesReadRequest);
		if (AfxMessageBox(sError,MB_OK|MB_ICONEXCLAMATION))
		{
			OnCancel();
			return;
		}
	}
		
	// Make updates to dialog display items
	unsigned char P0 = m_IObuffer.key & 0x0F;
	((CButton*) GetDlgItem(IDC_P0_B3))->SetCheck((~P0 & 0x01));  
	((CButton*) GetDlgItem(IDC_P0_B2))->SetCheck(((~P0 & 0x02) >> 1));  
	((CButton*) GetDlgItem(IDC_P0_B1))->SetCheck(((~P0 & 0x04) >> 2));  
	((CButton*) GetDlgItem(IDC_P0_B0))->SetCheck(((~P0 & 0x08) >> 3));  
	
	m_Analog_Meter1.UpdateNeedle(m_IObuffer.adc0/10.0);
	m_Analog_Meter2.UpdateNeedle(m_IObuffer.temp);

	CDialog::OnTimer(nIDEvent);
}


BOOL CUSBTestDlg::GetDeviceList()
{
	DWORD	dwNumDevices = 0;
	SI_DEVICE_STRING	devStr;

	SI_STATUS status = SI_GetNumDevices(&dwNumDevices);

	if (status == SI_SUCCESS)
	{
		for (DWORD d = 0; d < dwNumDevices; d++)
		{
			status = SI_GetProductString(d, devStr, SI_RETURN_SERIAL_NUMBER);

			if (status == SI_SUCCESS)
			{
				CString str = devStr;
				m_DeviceList.push_back(str);
			}
		}
	}
	else
	{
		return FALSE;
	}

	return TRUE;
}


BOOL CUSBTestDlg::SelectDevice()
{
	// ask for selection
	CSelectDialog dlg;
	dlg.Initialize(&m_DeviceList);
	if (dlg.DoModal() != IDOK)
		return FALSE;
	m_nDeviceNum = dlg.m_deviceIndex;
	m_sDeviceName = dlg.m_deviceList[dlg.m_deviceIndex];

	return TRUE;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91麻豆精品国产91久久久使用方法| 亚洲丶国产丶欧美一区二区三区| 亚洲色图丝袜美腿| 免费成人在线影院| 91黄色免费网站| 中文字幕乱码一区二区免费| 日欧美一区二区| 在线免费不卡视频| 国产日韩精品一区二区浪潮av| 视频一区视频二区中文| 91在线云播放| 欧美国产一区二区在线观看| 免费日韩伦理电影| 在线观看免费一区| 亚洲欧洲综合另类在线| 成人av网站在线| 久久精品一区八戒影视| 九九视频精品免费| 精品国产一区二区三区四区四| 五月天激情综合网| 欧美三日本三级三级在线播放| 成人欧美一区二区三区| www.欧美.com| 中文字幕日本不卡| 91小视频在线| 亚洲毛片av在线| 欧美性感一区二区三区| 亚洲你懂的在线视频| 色综合中文综合网| 亚洲欧洲www| 国产成人亚洲综合a∨猫咪| 精品成人a区在线观看| 精东粉嫩av免费一区二区三区| 欧美一级生活片| 精品无人区卡一卡二卡三乱码免费卡 | 久草精品在线观看| 精品盗摄一区二区三区| 国模娜娜一区二区三区| 国产欧美一二三区| 成人久久视频在线观看| 亚洲人精品一区| 欧美日韩在线电影| 麻豆成人免费电影| 久久久www成人免费毛片麻豆| 懂色中文一区二区在线播放| 国产精品麻豆视频| 欧美性videosxxxxx| 日韩精彩视频在线观看| 26uuu另类欧美亚洲曰本| 粉嫩13p一区二区三区| 伊人一区二区三区| 制服.丝袜.亚洲.中文.综合| 国产在线精品国自产拍免费| 中文一区二区在线观看| 91美女片黄在线观看91美女| 亚洲第一激情av| 26uuu国产日韩综合| 91女厕偷拍女厕偷拍高清| 五月天久久比比资源色| 国产亚洲精品bt天堂精选| 99精品桃花视频在线观看| 婷婷开心久久网| 国产香蕉久久精品综合网| 色综合天天狠狠| 麻豆精品视频在线观看视频| 亚洲欧美在线aaa| 欧美日韩国产高清一区二区三区| 国产在线一区观看| 亚洲一区二区三区精品在线| 欧美草草影院在线视频| 色婷婷亚洲精品| 精品亚洲国内自在自线福利| 亚洲精品综合在线| 精品88久久久久88久久久| 色综合天天在线| 激情综合亚洲精品| 亚洲一线二线三线视频| 国产视频一区二区在线| 欧美久久一二区| av男人天堂一区| 狠狠v欧美v日韩v亚洲ⅴ| 亚洲一区在线观看网站| 国产三级一区二区| 欧美精品在欧美一区二区少妇| 成人在线视频一区| 国产曰批免费观看久久久| 亚洲国产一区视频| 亚洲美女视频一区| 中文av一区特黄| 精品国产污网站| 欧美日本国产视频| 色吧成人激情小说| 91免费观看视频| 国产91对白在线观看九色| 久久国产精品99精品国产| 亚洲成人777| 艳妇臀荡乳欲伦亚洲一区| 中文字幕在线免费不卡| 久久亚洲综合色| 精品福利在线导航| 久久综合视频网| 久久久综合激的五月天| 精品久久久久久综合日本欧美| 欧美性大战久久| 日本久久一区二区三区| 91社区在线播放| 91日韩在线专区| 欧美在线视频日韩| 欧美亚一区二区| 欧美日韩国产bt| 欧美福利视频一区| 91精品国产91久久久久久一区二区 | 亚洲视频免费在线观看| 国产欧美精品区一区二区三区 | 欧美日韩和欧美的一区二区| 色婷婷亚洲综合| 色88888久久久久久影院按摩| 91网站最新地址| 色婷婷精品久久二区二区蜜臂av | 欧美亚洲综合另类| 欧美日韩在线亚洲一区蜜芽| www日韩大片| 精品国产免费视频| 欧美mv日韩mv| 国产午夜精品久久久久久久| 中文字幕 久热精品 视频在线| 国产精品欧美精品| 一区二区三区产品免费精品久久75| 亚洲欧美激情插| 亚洲国产cao| 老司机精品视频线观看86 | 91视频91自| 欧美色涩在线第一页| 欧美日韩国产美女| 91精品国产入口在线| 久久久五月婷婷| 成人免费一区二区三区在线观看| 一区二区三区国产| 奇米精品一区二区三区在线观看一 | 91碰在线视频| 欧美日韩国产色站一区二区三区| 精品国产一二三区| 综合欧美亚洲日本| 男人的天堂亚洲一区| 处破女av一区二区| 欧美丰满少妇xxxbbb| 久久久99久久| 亚洲一二三区在线观看| 国产麻豆精品视频| 欧美三日本三级三级在线播放| 欧美精品一区二区不卡| 亚洲欧美成aⅴ人在线观看 | 日韩女优av电影| 椎名由奈av一区二区三区| 蜜臀国产一区二区三区在线播放| 床上的激情91.| 日韩欧美国产系列| 亚洲私人黄色宅男| 国产一区高清在线| 欧美三片在线视频观看| 国产日产精品一区| 日本大胆欧美人术艺术动态| 91女人视频在线观看| 久久精品一级爱片| 日日欢夜夜爽一区| 91久久精品一区二区| 久久久蜜桃精品| 青草国产精品久久久久久| 色婷婷综合中文久久一本| 久久综合网色—综合色88| 天天色天天操综合| 91性感美女视频| 国产精品素人视频| 国产麻豆成人精品| 日韩三级.com| 亚洲成人福利片| 色噜噜久久综合| 国产精品亲子乱子伦xxxx裸| 国产一区视频在线看| 91精品国产91久久综合桃花 | 国产福利精品一区二区| 欧美日本一道本在线视频| 中文字幕制服丝袜一区二区三区 | 久久丁香综合五月国产三级网站| 欧美午夜一区二区三区免费大片| 国产精品妹子av| 成人美女在线观看| 国产精品久久久久久久久晋中| 国产福利电影一区二区三区| 精品日韩在线一区| 久久99国产精品麻豆| 日韩三级中文字幕| 免费成人美女在线观看.| 这里只有精品99re| 天天影视网天天综合色在线播放| 欧美亚洲综合另类| 五月激情综合婷婷| 日韩欧美www| 国产一区二区日韩精品| 久久久久久久久久电影|