bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_VENDOR_REQUEST,
&myRequest,
sizeof(VENDOR_REQUEST_IN),
NULL,
0,
&nBytes,
NULL);
if (bResult!=TRUE)
{
m_strTestDisplay+="Error!Can't lock USB chip\r\n";
CloseHandle(hDevice);
return Downloadresult;
}
else {
m_strTestDisplay+="Success!\r\nUSB chip has been locked!\r\n";
}
UpdateData(FALSE);
CFile MyFile;
if (!MyFile.Open(strdownloadfile,CFile::modeRead,NULL))
{
MessageBox("Can't open the config file!","Config Error",MB_ICONERROR);
CloseHandle(hDevice);
return Downloadresult;
}
else
{
MyFile.Read(buffer,MAX_BIX_SIZE); //读取文件
numreadfile = MAX_BIX_SIZE;
CString strfilelength;
strfilelength.Format("The config file size is %d Bytes\r\n",numreadfile);
m_strTestDisplay+=strfilelength;
UpdateData(FALSE);
}
MyFile.Close();
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_ANCHOR_DOWNLOAD,
buffer,
numreadfile,
NULL,
0,
&nBytes,
NULL);
if (bResult!=TRUE)
{
m_strTestDisplay+="Error!\r\nDownlod config file Fail!\r\n";
}
else
{
m_strTestDisplay+="Success!\r\nConfig file has been downloaded\r\n";
}
UpdateData(FALSE);
myRequest.bRequest = 0xA0;
myRequest.wValue = 0xE600;
myRequest.wIndex = 0x00;
myRequest.wLength = 0x01;
myRequest.bData = 0; //复位
myRequest.direction = 0x00;
bResult = DeviceIoControl (hDevice,
IOCTL_Ezusb_VENDOR_REQUEST,
&myRequest,
sizeof(VENDOR_REQUEST_IN),
NULL,
0,
&nBytes,
NULL);
if (bResult!=TRUE)
m_strTestDisplay+="Error!\r\nReset USB chip fail!\r\n";
else {
m_strTestDisplay+="Success!\r\nUSB chip has been reset\r\n";
Downloadresult = TRUE;
}
UpdateData(FALSE);
CloseHandle(hDevice);
return Downloadresult;
} |