Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C STM32 HID如何发送小于64字节的数据包?_C_Usb_Stm32_Hid - Fatal编程技术网

C STM32 HID如何发送小于64字节的数据包?

C STM32 HID如何发送小于64字节的数据包?,c,usb,stm32,hid,C,Usb,Stm32,Hid,我正在使用带有“STM32_USB-FS-Device_Lib_V4.0.0”的STM32F103向PC发送数据。STM32中的发送功能是: void USB_Send(unsigned char *p,u8 len) { UserToPMABufferCopy(p, GetEPTxAddr(ENDP1), len); SetEPTxCount(ENDP1, len); SetEPTxValid(ENDP1); while(GetEPTxStatus(ENDP1

我正在使用带有“STM32_USB-FS-Device_Lib_V4.0.0”的STM32F103向PC发送数据。STM32中的发送功能是:

void USB_Send(unsigned char *p,u8 len)
{
    UserToPMABufferCopy(p, GetEPTxAddr(ENDP1), len);
    SetEPTxCount(ENDP1, len); 
    SetEPTxValid(ENDP1);
    while(GetEPTxStatus(ENDP1)!=EP_TX_NAK);
}

但奇怪的是,当len=64时,我编写的C#程序和下载的调试工具正确地接收数据。但是,如果你能检测到USB总线上的数据包,你似乎看到了总线的坏端——你有没有考虑过你的C#程序没有正确读取数据?如果后者阻塞直到接收到(至少)64字节呢?那些充满bug的旧ST库充满了惊喜。如果USB FS帧为64字节,设置64字节传输有什么问题?可能是windows中的最小数据包大小为64字节。我的意思是windows大小会等到收到的数据是64字节,然后才将整个64字节提供给用户应用程序。您是否可以尝试在两个事务中发送32个字节和32个字节,而不会造成显著延迟?检查是否在windows程序中以单个64字节块的形式接收这两个事务?
//Init code:
HIDP_CAPS capabilities = new HIDP_CAPS();
int hidCapsSucsess = HidP_GetCaps(ptrToPreParsedData, ref capabilities);  //HidP_GetCaps is a win API
SafeFileHandle handle_read = CreateFile(devicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);  //CreateFile is a win API
FileStream FS_read = new FileStream(handle_read, FileAccess.ReadWrite, capabilities.OutputReportByteLength, false);
//...
//Receive code:
public byte[] read()
{
    byte[] readBuf = new byte[capabilities.OutputReportByteLength];
    FS_read.Read(readBuf, 0, capabilities.OutputReportByteLength);
    return readBuf;
}