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

📄 usbdevicecommand.cpp

📁 51单片机众多优秀的开发源程序:ZLG7290例程*ZLG7290汇编例程*蜂鸣器音乐例程*蜂鸣器响例程*读EEPROM并显示例程*16×2LCD模块例程*128×64点阵LCD模块例程*直连KEY和
💻 CPP
字号:

#include "stdafx.h"

#include "TimeAndKeyDlg.h"
#include "UsbDeviceCommand.h"
#include "EasyISP1581.h"


UINT BulkReadPipe(void * pParam) 
{  

	int nResult=0;
	int nBytes = 0;
	UINT totaltoTx=0, toTxNow=0, exitFlag=0;
	THREADPARAM * threadParam;
	CTimeAndKeyDlg* testDlg;
	HANDLE hFile;
	
	threadParam=(THREADPARAM *)pParam;
	testDlg = threadParam->testDlg;
					

	while(threadParam->bInThread&&testDlg->m_nboard)
	{
		Sleep(1);
		hFile = ISP1581_OpenPipe("PIPE00");
		
		if(hFile == INVALID_HANDLE_VALUE) 
		{
//			Sleep(300);
//			continue;
			break;
		}
		nBytes=ISP1581_Read(hFile,threadParam->buffer,4);
		ISP1581_ClosePipe(hFile);
		if(testDlg->m_nboard==0)
			break;
		if(nBytes>0)
			testDlg->UpdateReadData();
/*		else
		{
			testDlg->MessageBox("Reading data failed!","Test error");
			break;
		}
*/	}

	threadParam->bInThread=false;
    return 0; 	
} 

UINT BulkWritePipe(void * pParam) 
{  
    char temp [80],cc[80];
	int nResult=0;
	int nBytes = 0;
	THREADPARAM * threadParam;
	CTimeAndKeyDlg* testDlg;
	HANDLE hFile;

	threadParam=(THREADPARAM *)pParam;
	testDlg = threadParam->testDlg;


	hFile = ISP1581_OpenPipe("PIPE01");
	if(hFile == INVALID_HANDLE_VALUE) 
	{
		strcpy(temp, "Open driver failed! Can't write to PIPE01.");
		testDlg->MessageBox((LPCSTR)temp, "Test Error");
		goto writeexit;
	}

		
	nBytes=ISP1581_Write(hFile,threadParam->buffer,8,50);

	if (nBytes<=0) 
	{
		wsprintf (cc, "Data transfer on ");
		strcat( cc, "PIPE01");
		strcat( cc, " failed! Aborted.");
		testDlg->MessageBox((LPCSTR)cc, "Test Error");			
	}

	ISP1581_ClosePipe(hFile);

writeexit:
	return 0; 
} 

UINT ControlIn(void * pParam)
{ 
	
    BOOLEAN bResult = FALSE;
    ULONG nBytes = 0;
	unsigned char version=0;
	THREADPARAM * threadParam;
	CTimeAndKeyDlg* testDlg;
	
	threadParam=(THREADPARAM *)pParam;
	testDlg = (CTimeAndKeyDlg*)threadParam->testDlg;
	
	if(testDlg->m_nboard)
	{
		testDlg->m_devhandle = ISP1581_OpenDev();
		if(testDlg->m_devhandle!=INVALID_HANDLE_VALUE)
		{
			ISP1581_CloseDev(testDlg->m_devhandle);
			return 0;
		}
	}
	testDlg->m_nboard=0;
	testDlg->m_readparam.hThread=NULL;
	if(ISP1581_Init()!=0)
	{
		testDlg->SetWindowText("No Board Attached ");
		testDlg->EnableButton(false);
		return 0;
	}
	testDlg->m_devhandle = ISP1581_OpenDev();
	if(testDlg->m_devhandle == INVALID_HANDLE_VALUE)
	{
		testDlg->SetWindowText("No Board Attached ");
		testDlg->EnableButton(false);
		return 0;		
	}

	if(ISP1581_Vender_Read(testDlg->m_devhandle,version)==0)
	{
		if(version==0x21)
		{
			testDlg->SetWindowText("   DP-1581");
		}
		else if(version==0x22)
		{
			testDlg->SetWindowText("   USBPACK 2.0");
		}
		else
		{
			testDlg->SetWindowText("Unknown Board");
			testDlg->EnableButton(false);
			ISP1581_CloseDev(testDlg->m_devhandle);
			return 0;
		}
	}
	else
	{
		testDlg->SetWindowText("No Board Attached ");
		testDlg->EnableButton(false);
		ISP1581_CloseDev(testDlg->m_devhandle);
		return 0;
	}
	
	testDlg->EnableButton(true);
	testDlg->m_nboard=1;
	ISP1581_CloseDev(testDlg->m_devhandle);
	
	testDlg->m_readparam.bInThread=true;
	CWinThread *wt=AfxBeginThread(BulkReadPipe,&(testDlg->m_readparam));
	testDlg->m_readparam.hThread=wt->m_hThread;

	return 0;
}

⌨️ 快捷键说明

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