后台:我是Linux专家,在Windows方面经验不足。我正在为具有2个接口的USB设备开发Windows驱动程序。我的驱动程序应打开下面显示的第二个接口,并与中断OUT和IN端点通信。
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");
问题:这不起作用。我看到的问题是,如果用作WriteFile函数参数的buf数组中的数据全是零,我看到数据传输。我很惊讶,好像我将buf初始化为
buf[0] = 0x80;
buf[1] = 0x00;
buf[2] = 0xDB;
或者除了零之外的任何其他数据,则没有传输并且打印错误消息。另请注意,调用函数时,n = 65,BytesWritten = 0。我已经确认使用硬件USB嗅探器传输零。
有人能指出我哪里出错了吗?有没有比使用文件读写更好的方法来与Windows中断端点进行通信?