|
我照着PC机示例程序写了一个PC程序,第一次打开PC程序下载FX2固件程序后能正常使用。关掉程序再打开,再下载固件程序,就不能向USB传输数据了,但如果不再次下载固件程序,程序使用是正常的。请问FX2在设备枚举和重枚举的时候有啥要注意的,导致我这种错误。
我觉得问题应该就是在FX2初始化,枚举重枚举那里。我FX2只要reset一下就全好了,不reset再下载固件程序就不行。但是我不清楚这部分该怎么做,可以多次下载固件程序不出错。是不是每次下载之前都要重新get_address之类的
下面是固件下载程序,就是原来的示例程序,没改过
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;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|