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

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

?? cp210xtestdlg.cpp

?? cp2102 官方usb開發包
?? CPP
字號:
// CP210x TestDlg.cpp : implementation file
//
// by Novia Wijaya
// Created June 2, 2004
// Last Modified June 3, 2004

#include "stdafx.h"
#include "CP210xTest.h"
#include "CP210xTestDlg.h"
#include "SiUSBXp.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
bool m_Running = false;

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

/////////////////////////////////////////////////////////////////////////////
// CCP210xTestDlg dialog

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

void CCP210xTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCP210xTestDlg)
	DDX_Text(pDX, IDC_OUTPUT, m_output);
	DDX_Text(pDX, IDC_PORT_NUM, m_port_num);
	DDV_MinMaxUInt(pDX, m_port_num, 0, 256);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCP210xTestDlg, CDialog)
	//{{AFX_MSG_MAP(CCP210xTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(ID_EXIT, OnExit)
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_BN_CLICKED(IDC_UPDATE_DEVICE_LIST, OnUpdateDeviceList)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCP210xTestDlg message handlers

BOOL CCP210xTestDlg::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
	// Get devices, init. combo box with their names
	FillDeviceList();
	
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

/**
 * Quit the program
 */
void CCP210xTestDlg::OnExit() 
{
	CDialog::OnCancel();
}


void CCP210xTestDlg::FillDeviceList()
{
	SI_DEVICE_STRING	devStr;
	DWORD				dwNumDevices	= 0;
	CComboBox*			pDevList		= (CComboBox*)GetDlgItem(IDC_DEVICE_SELECT1);
	
	if (pDevList)
	{
		int numDevs = pDevList->GetCount();


		for (int i = 0; i < numDevs; i++)
		{
			pDevList->DeleteString(0);
		}

		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)
				{
					if (pDevList)				// Fill device list
						pDevList->AddString(devStr);					
				}
			}
		}

		pDevList->SetCurSel(0);
	}
}


/**
 * Start sending data between two devices if the port numbers specified are correct
 */
void CCP210xTestDlg::OnStart() 
{
	UpdateData(TRUE);
		
	if (!m_Running) 
	{
		m_Running = true;
		GetDlgItem(IDC_START)->SetWindowText("Running");
		GetDlgItem(IDC_OUTPUT)->SetWindowText("");

		// Get the CP210x device list
		CComboBox*	pDevList	= (CComboBox*)GetDlgItem(IDC_DEVICE_SELECT1);
		
		DCB dcbPortInitState, dcbPort;

		// Format our COM Port string
		CString COMPort;
		COMPort.Format("\\\\.\\COM%u", m_port_num);
		
		// Create the Handle to the COM Port
		HANDLE hDev = CreateFile(COMPort, GENERIC_READ | GENERIC_WRITE, 0, 0, 
									OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

		BeginWaitCursor();

		if(hDev == INVALID_HANDLE_VALUE)
			m_output = "Error: Invalid Handle Value for Device 1."; 
		else 
		{
			if (pDevList)
			{
				// Open selected device.
				if (pDevList->GetCurSel() >= 0)
				{
					DWORD device = pDevList->GetCurSel();
					SI_STATUS status = SI_Open(device, &m_hUSBDevice);

					// setup the COM Port
					if (status == SI_SUCCESS)
					{
						if(!PurgeComm(hDev, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR)) // device 1 fails
						{
							m_output = "Error: Failed to purge COM port for device 1.";
						}
						else
						{
							if(!GetCommState(hDev, &dcbPortInitState)) // com port fails to get its current state
							{
								m_output = "Error: Failed to get current state of com port.";
							}
							else 
							{
								dcbPort = dcbPortInitState;
								dcbPort.BaudRate = 57600;
								dcbPort.Parity = NOPARITY;
								dcbPort.ByteSize = 8;
								dcbPort.StopBits = ONESTOPBIT;
								if(!SetCommState(hDev, &dcbPort)) // fails to set port 1 state
								{
									m_output = "Error: Failed to set the state of com port.";
								}
								else 
								{
									// Clear the CP210x device's buffers
									status = SI_FlushBuffers(m_hUSBDevice, TRUE, TRUE);
									if (status != SI_SUCCESS)
										m_output = "Error: Failed to purge device.";
									// Set the CP210x device's baud rate 
									status = SI_SetBaudRate(m_hUSBDevice, 57600);
									if (status != SI_SUCCESS)
										m_output = "Error: Failed to set baud rate 57600 for device.";
									
									if(Transfer(&m_hUSBDevice, &hDev))
									{
										m_output = "Data transfered successfully.";
									}
									else
									{
										m_output = "Error: Failed to transfer data.";
									}
									// Closing the COM Port handle	
									if (hDev != INVALID_HANDLE_VALUE) CloseHandle(hDev);
									hDev = INVALID_HANDLE_VALUE;

								}
							}
						}
						// Close the CP210x device handle
						status = SI_Close(m_hUSBDevice);
						if (status != SI_SUCCESS)
							m_output = "Error: Error closing device.";
					}
					else
					{
						m_output = "Error: Failed open device.";
					}
				}
			}
		}
		m_Running = false;
		GetDlgItem(IDC_START)->SetWindowText("Start Data Transfer");
	}
	
	UpdateData(FALSE);		
}

/**
 * Perform write on device 1, read on device 2, write on device 2, and read on device 1.
 * Return true if the data is transfered successfully, false otherwise.
 */
bool CCP210xTestDlg::Transfer(HANDLE* hDev1, HANDLE* hDev2)
{
	BYTE dataSent[] = { 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
			  		0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,
					0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,
					0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,
					0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
					0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,
					0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,
					0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88 };

	BYTE dataRead[64];

	bool success = false;
	
	UINT timeout = 3000;
	DWORD toBeWritten = 64, toBeRead = 64;
	DWORD* written = (DWORD*)malloc(sizeof(DWORD));
	DWORD* read = (DWORD*)malloc(sizeof(DWORD));
	SI_STATUS status;

	status = SI_Write(*hDev1, (LPVOID)dataSent, toBeWritten, written);
	if(status != SI_SUCCESS)
	{
		MessageBox("Surprise Removal on Device 1 Write!");
	}
	else
		success = true;
	


	if(*written != toBeWritten)
		success = false;

	if(success) // continue to read the data from the other device if the previous write succeed
	{
		success = false;
		DelayMS(60);
		if(!ReadFile(*hDev2, dataRead, toBeRead, read, NULL))
		{
			MessageBox("Surprise Removal on Device 2 Read!");
			CloseHandle(*hDev2);
			*hDev2 = INVALID_HANDLE_VALUE;
		}
		else
			success = true;

		if(success)	// compare the data sent and received by the two devices if the read succeed
		{
			for(int i = 0; i < 64 && success; ++i)
			{
				if(dataSent[i] != dataRead[i])
					success = false;
			}
		}
	}

	if(success) // do the opposite direction if the previous transfer succeed
	{
		success = false;
		dataRead[64];
		*written = 0;
		*read = 0;

		if(!WriteFile(*hDev2, (LPCVOID)dataSent, toBeWritten, written, NULL))
		{
			MessageBox("Surprise Removal on Device 2 Write!");
			CloseHandle(*hDev2);
			*hDev2 = INVALID_HANDLE_VALUE;
		}
		else
			success = true;
		


		if(*written != toBeWritten)
			success = false;

		if(success) // continue to read the data from the other device if the previous write succeed
		{
			success = false;
			DelayMS(60);
			status = SI_Read(*hDev1, dataRead, toBeRead, read);
			if(status != SI_SUCCESS)
			{
				MessageBox("Surprise Removal on Device 1 Read!");
			}		
			else
				success = true;

			if(success)	// compare the data sent and received by the two devices if the read succeed
			{
				for(int i = 0; i < 64 && success; ++i)
				{
					if(dataSent[i] != dataRead[i])
						success = false;
				}
			}
		}
	}

	delete read;
	delete written;


	return success;
}

/**
 * To delay the program
 * @param delay The amount of delay time in milliseconds
 */
void CCP210xTestDlg::DelayMS(UINT delay)
{
	DWORD start, end;
	start = end = GetTickCount();

	// Wait for 'delay' milliseconds.
	while ((end - start) < delay)
	{
		end = GetTickCount();
	}
}

void CCP210xTestDlg::OnUpdateDeviceList() 
{
	// TODO: Add your control notification handler code here
	FillDeviceList();
	
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区三区四区不卡视频| 久久综合九色综合欧美98| 精品亚洲aⅴ乱码一区二区三区| 亚洲一区二区黄色| 亚洲黄色小视频| 亚洲精品一二三区| 一区二区三区不卡视频在线观看| 亚洲日本丝袜连裤袜办公室| 亚洲码国产岛国毛片在线| 亚洲三级在线观看| 一区二区三区产品免费精品久久75| 亚洲色图欧洲色图婷婷| 亚洲一区二区欧美| 免费观看在线综合| 国产精品综合网| 成人午夜在线视频| 91电影在线观看| 制服丝袜亚洲网站| 国产清纯在线一区二区www| 国产精品福利av| 亚洲综合色噜噜狠狠| 视频一区视频二区中文字幕| 麻豆精品在线看| 成人综合激情网| 欧美日韩亚洲丝袜制服| 欧美大片日本大片免费观看| 亚洲国产激情av| 夜夜精品视频一区二区| 久久er精品视频| 91蜜桃免费观看视频| 91精品国产免费| 国产精品理伦片| 日日摸夜夜添夜夜添精品视频| 国内精品国产成人| 91久久一区二区| 精品三级在线看| 伊人性伊人情综合网| 久久精品国产精品亚洲综合| 91色九色蝌蚪| 久久你懂得1024| 同产精品九九九| 成人精品国产一区二区4080| 91精品国产乱码久久蜜臀| 中文在线资源观看网站视频免费不卡| 一区二区激情视频| 不卡一卡二卡三乱码免费网站| 欧美理论电影在线| 亚洲免费资源在线播放| 久久精品国产免费看久久精品| 色婷婷综合久色| 久久久av毛片精品| 蜜臀精品一区二区三区在线观看 | 欧美日韩不卡一区二区| 国产日韩欧美a| 蜜桃av一区二区三区电影| 色综合久久综合网| 国产日韩欧美麻豆| 国产麻豆精品在线| 91精品国产一区二区三区蜜臀| 亚洲日本成人在线观看| 国产成人三级在线观看| 欧美大片一区二区三区| 日韩精品一级二级| 欧美性大战xxxxx久久久| 日韩理论片中文av| 波多野结衣欧美| 日本一区二区三区国色天香 | 久久免费的精品国产v∧| 亚洲va欧美va天堂v国产综合| aaa国产一区| 中文字幕欧美日韩一区| 国产一区二区在线视频| 久久综合色婷婷| 久久99久久99| 精品久久久久99| 久久精品国产**网站演员| 日韩欧美一区二区在线视频| 日韩精品国产欧美| 欧美大片免费久久精品三p| 美女视频网站久久| 久久亚洲私人国产精品va媚药| 久久99热99| 国产亚洲成av人在线观看导航| 国产传媒日韩欧美成人| 国产精品午夜免费| 91网站在线播放| 亚洲午夜激情网页| 在线观看91av| 国产精品一区二区久激情瑜伽| 欧美精品一区二区三区久久久| 在线观看日韩高清av| 一区二区三区成人| 91麻豆精品国产自产在线| 日本成人在线不卡视频| 26uuuu精品一区二区| 国产成人免费av在线| 亚洲欧美影音先锋| 欧美老肥妇做.爰bbww视频| 久久99这里只有精品| 国产精品国模大尺度视频| 在线观看日韩电影| 精品一区免费av| 中文字幕一区二区三区在线不卡| 色999日韩国产欧美一区二区| 亚洲妇女屁股眼交7| 久久精品亚洲一区二区三区浴池| 99国产精品久久久久| 日本午夜一本久久久综合| 久久精品视频免费观看| 欧美这里有精品| 国产一区免费电影| 亚洲国产精品久久久久婷婷884| 日韩欧美第一区| 91在线无精精品入口| 婷婷综合久久一区二区三区| 中文字幕精品—区二区四季| 欧美性大战久久久久久久蜜臀| 激情综合色播激情啊| 一区二区三区在线视频免费观看| 日韩精品一区二区三区视频播放 | 在线影院国内精品| 久草这里只有精品视频| 一区二区三区四区国产精品| www日韩大片| 91麻豆精品国产91久久久资源速度| 国产成人精品1024| 美女视频网站久久| 亚洲国产精品影院| 亚洲色图视频网| 国产日韩欧美一区二区三区综合| 欧美剧情电影在线观看完整版免费励志电影 | 日韩美女视频一区| 久久只精品国产| 日韩欧美一区在线| 777亚洲妇女| 91国偷自产一区二区三区成为亚洲经典 | 高清不卡一二三区| 精品亚洲欧美一区| 日韩av电影免费观看高清完整版 | 加勒比av一区二区| 首页亚洲欧美制服丝腿| 亚洲国产成人av网| 亚洲欧美电影院| 亚洲欧美另类久久久精品| 欧美激情一区在线观看| 26uuu精品一区二区| 精品国产伦理网| 精品久久久久一区| 日韩欧美不卡一区| 日韩区在线观看| 日韩一区二区麻豆国产| 正在播放亚洲一区| 制服丝袜av成人在线看| 3751色影院一区二区三区| 欧美猛男gaygay网站| 欧美日韩视频在线第一区 | 国产精品久久久久影院亚瑟| 精品盗摄一区二区三区| 久久综合丝袜日本网| 久久久国产综合精品女国产盗摄| www国产成人| 国产亚洲1区2区3区| 中文字幕一区二区三区精华液 | 香蕉av福利精品导航| 亚洲福利一区二区三区| 亚洲成av人在线观看| 日韩高清不卡一区二区三区| 青椒成人免费视频| 久久国产精品一区二区| 国产成人aaaa| 色妞www精品视频| 欧美丝袜自拍制服另类| 欧美日韩一区在线| 日韩精品中文字幕在线不卡尤物| 久久亚洲二区三区| 亚洲天堂久久久久久久| 午夜激情一区二区| 国产乱人伦偷精品视频不卡| 高清不卡一区二区| 在线观看日韩精品| 日韩欧美的一区二区| 国产精品―色哟哟| 亚洲综合色噜噜狠狠| 久久99精品久久久久| av电影在线观看不卡| 欧美精品一级二级三级| 国产偷国产偷亚洲高清人白洁| 亚洲欧美日韩电影| 久久精品国产亚洲高清剧情介绍| 丰满少妇在线播放bd日韩电影| 色婷婷av一区二区三区大白胸| 91精品国产91久久久久久一区二区 | 欧美在线免费视屏| 51精品久久久久久久蜜臀| 亚洲国产岛国毛片在线| 日韩高清不卡在线| 91网站视频在线观看| 欧美精品一区二区三区蜜桃视频| 国产在线精品一区在线观看麻豆| jvid福利写真一区二区三区|