WinCE下的USB设备驱动,急需各位大哥相助!谢谢

mood8888   2007-3-3 11:38 楼主
我在跟踪USBDeviceAttach函数时,发现第三个参数LPCUSB_INTERFACE UsbInterface 为NULL,那是什么原因造成的呢?我知道UsbInterface表示USB设备的接口信息。是不是我将USB设备信息写到注册表时没有写对?

我的USB设备的信息如下:
Device Descriptor:
bcdUSB: 0x0200
bDeviceClass: 0x00
bDeviceSubClass: 0x00
bDeviceProtocol: 0x00
bMaxPacketSize0: 0x40(64)
idVendor: 0x3344
idProduct: 0x1122
bcdDevice: 0x0000
iManufacturer: 0x01
iProduct: 0x02
iSerialNumber: 0x03
bNumConfigurations: 0x01

ConnectionStatus: DeviceConnected
Current Configure Value: 0x01
Device Bus Speed: Full
Device Address: 0x02
Open Pipes: 0


#define LME_USB_VENDORID     0x3344
#define LME_USB_PRODUCTID     0x1122

#define DRIVER_SETTINGS \\
        sizeof(USB_DRIVER_SETTINGS), \\
        LME_USB_VENDORID,   \\
        LME_USB_PRODUCTID,   \\
        USB_NO_INFO,   \\
        USB_NO_INFO,   \\
        USB_NO_INFO,   \\
        USB_NO_INFO,   \\
        USB_NO_INFO,   \\
        USB_NO_INFO,   \\
        USB_NO_INFO

BOOL USBInstallDriver(LPCWSTR szDriverLibFile)
{
  BOOL bRc;

  const WCHAR wsUsbDeviceID[] = CLASS_NAME_SZ;
   WCHAR wsSubClassRegKey[sizeof(CLIENT_REGKEY_SZ)+16] = CLIENT_REGKEY_SZ;

  //Set lmeusb device descriptor
  USB_DRIVER_SETTINGS usbDriverSettings = { DRIVER_SETTINGS };

   DWORD dwPortStatusTimeout = GET_PORT_STATUS_TIMEOUT;
  DWORD dwDeviceIdTimeout   = GET_DEVICE_ID_TIMEOUT;
  DWORD dwSoftResetTimeout = SOFT_RESET_TIMEOUT;
  DWORD dwReadTimeoutMultiplier = READ_TIMEOUT_MULTIPLIER;
  DWORD dwReadTimeoutConstant   = READ_TIMEOUT_CONSTANT;
  DWORD dwWriteTimeoutMultiplier = WRITE_TIMEOUT_MULTIPLIER;
  DWORD dwWriteTimeoutConstant   = WRITE_TIMEOUT_CONSTANT;

   REG_VALUE_DESCR LmeusbKeyValues[] = {
       TEXT(\"Dll\"),   REG_SZ,   0, (PBYTE)(DRIVER_NAME),
       TEXT(\"Prefix\"), REG_SZ,   0, (PBYTE)(DEVICE_PREFIX),
    GET_PORT_STATUS_TIMEOUT_SZ, REG_DWORD, 0, (PUCHAR)(&dwPortStatusTimeout),
    GET_DEVICE_ID_TIMEOUT_SZ,   REG_DWORD, 0, (PUCHAR)(&dwDeviceIdTimeout),
    SOFT_RESET_TIMEOUT_SZ,     REG_DWORD, 0, (PUCHAR)(&dwSoftResetTimeout),
    READ_TIMEOUT_MULTIPLIER_SZ, REG_DWORD, 0, (PUCHAR)(&dwReadTimeoutMultiplier),
    READ_TIMEOUT_CONSTANT_SZ,   REG_DWORD, 0, (PUCHAR)(&dwReadTimeoutConstant),
    WRITE_TIMEOUT_MULTIPLIER_SZ, REG_DWORD, 0, (PUCHAR)(&dwWriteTimeoutMultiplier),
    WRITE_TIMEOUT_CONSTANT_SZ,   REG_DWORD, 0, (PUCHAR)(&dwWriteTimeoutConstant),
       NULL, 0, 0, NULL
  };

  //Register Unique Driver ID, [HKEY_LOCAL_MACHINE\\Drivers\\USB\\ClientDrivers\\LMEUSB_Class]
  bRc = RegisterClientDriverID(wsUsbDeviceID);
  if(!bRc) {
       DEBUGMSG(ZONE_ERR, (TEXT(\"RegisterClientDriverID error:%d\\n\"),GetLastError()));
       return FALSE;
   }

   //Register relative device info, [HKEY_LOCAL_MACHINE\\Drivers\\USB\\LoadClients\\DriverName]
   bRc = RegisterClientSettings(szDriverLibFile,wsUsbDeviceID,NULL,&usbDriverSettings);
  if (!bRc) {
       DEBUGMSG(ZONE_ERR, (TEXT(\"RegisterClientSettings error:%d\\n\"), GetLastError()));
       return FALSE;
   }

   //Set our default values to the register
  if (!GetSetKeyValues(wsSubClassRegKey , LmeusbKeyValues, TRUE, TRUE)) {
       MessageBox(NULL,_T(\"Wrong to Set Registry Values!!\"), _T(\"OK\"), MB_OK);
       return FALSE;
  }
   MessageBox(NULL, _T(\"Enter USBInstallDriver\"), _T(\"OK\"), MB_OK);

   return bRc;
}

回复评论 (1)

过了这么多年,还没有人回答吗,我最近也在学习WINCE USB相关知识 希望大佬们解答

点赞  2024-9-25 10:16
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复