阅读:1137回复:0
fx2主机程序错误
用control panel下载了固件程序,为什么我用自己写的主机程序,点击get device,就重启呢,主机程序get device函数如下,vc:
BOOLEAN CUsbhostDlg::UsbOpenDriver (HANDLE *phDeviceHandle, PCHAR devname) { char completeDeviceName[64] = ""; char pcMsg[64] = ""; strcat (completeDeviceName,"\\\\.\\"); //strcat (completeDeviceName,devname); strcat (completeDeviceName,"Ezusb-0"); *phDeviceHandle = CreateFile(completeDeviceName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (*phDeviceHandle == INVALID_HANDLE_VALUE) return (FALSE); else return (TRUE); } void CUsbhostDlg::OnDeviceButton() { // TODO: Add your control notification handler code here USB_DEVICE_DESCRIPTOR output; HANDLE hDevice = NULL; BOOLEAN bResult = FALSE; ULONG nBytes; CString str; if (UsbOpenDriver (&hDevice, DeviceName) != TRUE) { MessageBox("无效设备,请重试!", "错误", MB_ICONERROR | MB_OK); hDevice = NULL; return; } if (hDevice != NULL) { bResult = DeviceIoControl (hDevice, IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR, NULL, 0, &output, sizeof(USB_DEVICE_DESCRIPTOR), &nBytes, NULL); } if (bResult==TRUE) { m_UsbList.AddString("USB Device Descriptor"); str.Format(_T("bLength:0x%x"),output.bLength); m_UsbList.AddString(str); str.Format(_T("bDescriptorType:0x%x"),output.bDescriptorType); m_UsbList.AddString(str); str.Format(_T("bcdUSB:0x%x"),output.bcdUSB); m_UsbList.AddString(str); str.Format(_T("bDeviceClass:0x%x"),output.bDeviceClass); m_UsbList.AddString(str); str.Format(_T("bDeviceSubClass:0x%x"),output.bDeviceSubClass); m_UsbList.AddString(str); str.Format(_T("bDeviceProtocol:0x%x"),output.bDeviceProtocol); m_UsbList.AddString(str); str.Format(_T("bMaxPacketSize0:0x%x"),output.bMaxPacketSize0); m_UsbList.AddString(str); str.Format(_T("idVendor:0x%x"),output.idVendor); m_UsbList.AddString(str); str.Format(_T("idProduct:0x%x"),output.idProduct); m_UsbList.AddString(str); str.Format(_T("bcdDevice:0x%x"),output.bcdDevice); m_UsbList.AddString(str); str.Format(_T("iManufacturer:0x%x"),output.iManufacturer); m_UsbList.AddString(str); str.Format(_T("iProduct:0x%x"),output.iProduct); m_UsbList.AddString(str); str.Format(_T("iSerialNumber:0x%x"),output.iSerialNumber); m_UsbList.AddString(str); str.Format(_T("bNumConfigurations:0x%x"),output.bNumConfigurations); m_UsbList.AddString(str); } else MessageBox("读取设备描述符失败!", "错误", MB_ICONERROR | MB_OK); CloseHandle (hDevice); } 麻烦各位大虾帮忙看看,谢谢了 |
|