下面是固件下载程序,就是原来的示例程序,没改过
BOOL CCYDEMODlg::OnDownloadFirmware(LPTSTR strdownloadfile,BOOL displaycharen)
{
// TODO: Add your control notification handler code here
HANDLE hDevice=NULL;
BOOL bResult = FALSE;
ULONG nBytes;
char DeviceName[256] = "";
// char tempbuff[256];
// char temp[256];
unsigned char buffer[MAX_BIX_SIZE];
int numreadfile = 0;
// int i;
HWND hdlg = NULL;
VENDOR_REQUEST_IN myRequest;
BOOL Downloadresult = FALSE;
m_strTestDisplay+="\r\n";
// Open the driver
if(!bOpenDriver(&hDevice,m_strName.GetBuffer(m_strName.GetLength())))
{
m_strTestDisplay+="No available device!\r\nPlease try again!\r\n";
UpdateData(FALSE);
return Downloadresult;
}
myRequest.bRequest = 0xA0;
myRequest.wValue = 0xE600;
myRequest.wIndex = 0x00;
myRequest.wLength = 0x01;
myRequest.bData = 1; //锁定
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!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;
} |