Background: 我是Linux专家,在Windows方面经验很少 . 我正在为具有2个接口的USB设备开发Windows驱动程序 . 我的驱动程序应打开下面显示的第二个接口,并与中断OUT和IN endpoints 通信 .

Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              3 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1

我能够使用此接口的String描述符来跟踪此接口 . 我按照以下方法进行沟通

我打开一个Write和一个Read处理程序

// Get a handle for writing Output reports.
WriteHandle=CreateFile(detailData->DevicePath,
    GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
    (LPSECURITY_ATTRIBUTES)NULL,OPEN_EXISTING,0,NULL);

//Get a handle to the device for the overlapped ReadFiles.
ReadHandle=CreateFile(detailData->DevicePath,
    GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,(LPSECURITY_ATTRIBUTES)NULL,
    OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL);

我试着像这样推送数据

if(WriteFile(WriteHandle,buf,n,&BytesWritten,NULL)==FALSE) printf("Error sending output report\n");
if(ReadFile(ReadHandle,bufI,n,&NumberOfBytesRead,(LPOVERLAPPED) &HIDOverlapped)==FALSE) printf("Error receiving input report\n");

Question: 这不起作用 . 我看到的问题是,如果用作WriteFile函数参数的buf数组中的数据全是零,我看到数据传输 . 我很惊讶好像我把buf初始化为

buf[0] = 0x80;
buf[1] = 0x00;
buf[2] = 0xDB;

或者除零之外的任何其他数据然后没有传输并且打印错误消息 . 另请注意,调用函数时,n = 65,BytesWritten = 0 . 我已经确认使用硬件USB嗅探器传输零 .

有人能指出我哪里出错了?有没有比使用文件读写更好的方法来与Windows中断 endpoints 进行通信?