📄 usbdevicecommand.cpp
字号:
#include "stdafx.h"
#include "E2PROM_1581Dlg.h"
#include "UsbDeviceCommand.h"
#include "EasyISP1581.h"
UINT BulkReadPipe(void * pParam)
{
char temp [80],cc[80];
int nResult=0;
int nBytes = 0;
UINT totaltoTx=0, toTxNow=0, exitFlag=0;
THREADPARAM * threadParam;
CE2PROM_1581Dlg* testDlg;
HANDLE hDevice;
HANDLE hFile;
threadParam=(THREADPARAM *)pParam;
testDlg = threadParam->testDlg;
hDevice = ISP1581_OpenDev();
if(hDevice == INVALID_HANDLE_VALUE)
{
strcpy(temp, "Open device handle failed! Can't read from PIPE02.");
testDlg->MessageBox((LPCSTR)temp, "Test Error");
goto readexit;
}
hFile = ISP1581_OpenPipe("PIPE02");
if(hFile == INVALID_HANDLE_VALUE)
{
strcpy(temp, "Open driver failed! Can't read from PIPE02.");
testDlg->MessageBox((LPCSTR)temp, "Test Error");
ISP1581_CloseDev(hDevice);
goto readexit;
}
nResult=ISP1581_Vender_E2prom(hDevice,0x01,threadParam->startaddr,threadParam->length);
if(nResult!=0)
{
wsprintf (cc, "Requesting data transfer on ");
strcat( cc, "PIPE02");
strcat( cc, " failed! Aborted.");
testDlg->MessageBox((LPCSTR)cc, "Test Error");
ISP1581_ClosePipe(hFile);
ISP1581_CloseDev(hDevice);
goto readexit;
}
nBytes=ISP1581_Read(hFile,threadParam->buffer,threadParam->length,1000);
if (nBytes<=0)
{
wsprintf (cc, "Data transfer on ");
strcat( cc, "PIPE02");
strcat( cc, " failed! Aborted.");
testDlg->MessageBox((LPCSTR)cc, "Test Error");
}
else
{
testDlg->UpdateReadData();
}
ISP1581_ClosePipe(hFile);
ISP1581_CloseDev(hDevice);
readexit:
testDlg->EnableButton(true,true,true,true);
return 0;
}
UINT BulkWritePipe(void * pParam)
{
char temp [80],cc[80];
int nResult=0;
int nBytes = 0;
THREADPARAM * threadParam;
CE2PROM_1581Dlg* testDlg;
HANDLE hDevice;
HANDLE hFile;
threadParam=(THREADPARAM *)pParam;
testDlg = threadParam->testDlg;
hDevice = ISP1581_OpenDev();
if(hDevice == INVALID_HANDLE_VALUE)
{
strcpy(temp, "Open device handle failed! Can't write to PIPE03.");
testDlg->MessageBox((LPCSTR)temp, "Test Error");
goto writeexit;
}
hFile = ISP1581_OpenPipe("PIPE03");
if(hFile == INVALID_HANDLE_VALUE)
{
strcpy(temp, "Open driver failed! Can't write to PIPE03.");
testDlg->MessageBox((LPCSTR)temp, "Test Error");
ISP1581_CloseDev(hDevice);
goto writeexit;
}
nResult=ISP1581_Vender_E2prom(hDevice,0x00,threadParam->startaddr,threadParam->length);
if(nResult!=0)
{
wsprintf (cc, "Requesting data transfer on ");
strcat( cc, "PIPE03");
strcat( cc, " failed! Aborted.");
testDlg->MessageBox((LPCSTR)cc, "Test Error");
ISP1581_ClosePipe(hFile);
ISP1581_CloseDev(hDevice);
goto writeexit;
}
nBytes=ISP1581_Write(hFile,threadParam->buffer,threadParam->length,1000);
if (nBytes<=0)
{
wsprintf (cc, "Data transfer on ");
strcat( cc, "PIPE03");
strcat( cc, " failed! Aborted.");
testDlg->MessageBox((LPCSTR)cc, "Test Error");
}
ISP1581_ClosePipe(hFile);
ISP1581_CloseDev(hDevice);
writeexit:
testDlg->EnableButton(true,true,true,true);
return 0;
}
UINT ControlIn(void * pParam)
{
BOOLEAN bResult = FALSE;
ULONG nBytes = 0;
unsigned char version=0;
THREADPARAM * threadParam;
HANDLE hDevice;
CE2PROM_1581Dlg* testDlg;
threadParam=(THREADPARAM *)pParam;
testDlg = (CE2PROM_1581Dlg*)threadParam->testDlg;
if(ISP1581_Init()!=0)
{
testDlg->SetWindowText("No Board Attached ");
testDlg->EnableButton(false,false,false,false);
return 0;
}
hDevice = ISP1581_OpenDev();
if(hDevice == INVALID_HANDLE_VALUE)
{
testDlg->SetWindowText("No Board Attached ");
testDlg->EnableButton(false,false,false,false);
return 0;
}
if(ISP1581_Vender_Read(hDevice,version)==0)
{
if(version==0x21)
{
testDlg->SetWindowText(" DP-1581");
testDlg->EnableButton(true,false,true,false);
}
else if(version==0x22)
{
testDlg->SetWindowText(" USBPACK 2.0");
testDlg->EnableButton(true,false,true,false);
}
else
{
testDlg->SetWindowText("Unknown Board");
testDlg->EnableButton(false,false,false,false);
ISP1581_CloseDev(hDevice);
return 0;
}
}
else
{
testDlg->SetWindowText("No Board Attached ");
testDlg->EnableButton(false,false,false,false);
ISP1581_CloseDev(hDevice);
return 0;
}
ISP1581_CloseDev(hDevice);
testDlg->EnableButton(true,true,true,true);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -