dingcai
驱动牛犊
驱动牛犊
  • 注册日期2004-11-08
  • 最后登录2010-04-26
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1266回复:2

急问怎样手动下载固件程序?

楼主#
更多 发布于:2005-01-16 22:29
我需要手动下载固件程序,用DeviceIoControl (hDevice,
   IOCTL_Ezusb_ANCHOR_DOWNLOAD,buffer, nactual,NULL, 0, &nBytes,    NULL);可是遇到的问题是下载后设备没有重枚举。有关代码如下。请各位帮我解答一些,我生成.bix文件的格式是hex2bix -m 0x0a8d -o usb.bix project1.hex.不知这样生成的对不?解决了一定送分。我急着要回家了。

void HostDlg::OnUsb8051Hold()
{       HANDLE hDevice=NULL;
BOOL   bResult = FALSE;
ULONG  nBytes;
        VENDOR_REQUEST_IN myRequest;
if (UsbOpenDriver (&hDevice, DeviceName) != TRUE)
{
MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK);
   return;
}
myRequest.bRequest = 0xA0;
    myRequest.wValue = 0x7F92;
    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);
 
CloseHandle(hDevice);
}
void HostDlg::OnUsb8051Reset()
{

HANDLE hDevice=NULL;
BOOL   bResult = FALSE;
ULONG  nBytes;

VENDOR_REQUEST_IN myRequest;
if (UsbOpenDriver (&hDevice, DeviceName) != TRUE)
{
MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK);
   return;
}

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);
  CloseHandle(hDevice);
}
void HostDlg::OnDownloadFile()
{
int nactual=0;
        const   int    MAX_FILE_SIZE=7000;
        unsigned char buffer[MAX_FILE_SIZE];
HANDLE  hDevice = NULL;
BOOLEAN bResult = FALSE;
        ULONG   nBytes;
CFile downfile;
        UpdateData(TRUE);
m_Usblist.AddString(m_filename);//m_filename是我编辑控件对应的//变量名,他对应的就是我的固件程序.bix文件。
  
     if(!downfile.Open(m_filename,CFile::modeRead))
{
AfxMessageBox("打开固件代码失败");
return;
}
else
{
    nactual=downfile.Read(buffer,  MAX_FILE_SIZE);


}

    if (UsbOpenDriver (&hDevice, DeviceName) != TRUE)
{
MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK);
   return;
}

    bResult = DeviceIoControl (hDevice,
                               IOCTL_Ezusb_ANCHOR_DOWNLOAD,
                               buffer,
                              nactual,
                               NULL,
                               0,
                               &nBytes,
                               NULL);
 
CloseHandle(hDevice);
downfile.Close();

}
                                                            
                                                            
                          
dingcai
驱动牛犊
驱动牛犊
  • 注册日期2004-11-08
  • 最后登录2010-04-26
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2005-01-16 22:39
中间有点写错了。void HostDlg::OnUsb8051Hold()
{       HANDLE hDevice=NULL;
BOOL   bResult = FALSE;
ULONG  nBytes;
        VENDOR_REQUEST_IN myRequest;
if (UsbOpenDriver (&hDevice, DeviceName) != TRUE)
{
MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK);
   return;
}
myRequest.bRequest = 0xA0;
    myRequest.wValue = 0x7F92;
    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);
 
CloseHandle(hDevice);
}
void HostDlg::OnUsb8051Reset()
{

HANDLE hDevice=NULL;
BOOL   bResult = FALSE;
ULONG  nBytes;

VENDOR_REQUEST_IN myRequest;
if (UsbOpenDriver (&hDevice, DeviceName) != TRUE)
{
MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK);
   return;
}

myRequest.bRequest = 0xA0;
    myRequest.wValue = 0x7F92;//这里应该是7F92。
    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);
  CloseHandle(hDevice);
}
void HostDlg::OnDownloadFile()
{
int nactual=0;
        const   int    MAX_FILE_SIZE=7000;
        unsigned char buffer[MAX_FILE_SIZE];
HANDLE  hDevice = NULL;
BOOLEAN bResult = FALSE;
        ULONG   nBytes;
CFile downfile;
        UpdateData(TRUE);
m_Usblist.AddString(m_filename);//m_filename是我编辑控件对应的//变量名,他对应的就是我的固件程序.bix文件。
  
     if(!downfile.Open(m_filename,CFile::modeRead))
{
AfxMessageBox("打开固件代码失败");
return;
}
else
{
    nactual=downfile.Read(buffer,  MAX_FILE_SIZE);


}

    if (UsbOpenDriver (&hDevice, DeviceName) != TRUE)
{
MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK);
   return;
}

    bResult = DeviceIoControl (hDevice,
                               IOCTL_Ezusb_ANCHOR_DOWNLOAD,
                               buffer,
                              nactual,
                               NULL,
                               0,
                               &nBytes,
                               NULL);
 
CloseHandle(hDevice);
downfile.Close();

}
dingcai
驱动牛犊
驱动牛犊
  • 注册日期2004-11-08
  • 最后登录2010-04-26
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2005-01-16 22:32
我的固件程序用控制面板download,可以实现设计的功能,说明固件应该没有问题吧。我用的是按2131qc。
我的qq:283044263。
游客

返回顶部