带字节的串行通信(0x00问题)

问题描述 投票:-1回答:1

使用串行通信进行USB CDC时出现问题。我正在嵌入式STM微控制器上工作,我想用pySerial传递二进制数据。

我想直接发送二进制代码,但此0x00阻止了我。我的问题是,当我想发送0x00字节时,下一个字节似乎被忽略了。

这是python脚本:

towrite = [ 0xFF, 0xx00 \xFF ] 
nbSend = s.write(b'\xFF\x00\xFF')
print(nbSend)                                 #Displaying 3 here, that means 3 bytes are successfully sended

然后嵌入脚本:

//Interrupt function that receive the data from serial com
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 6 */
  USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
  USBD_CDC_ReceivePacket(&hUsbDeviceFS);

  char buffer[64];

  sprintf(buffer,"Length=%lu / Word=%c%c%c ",(unsigned long)*Len,Buf[0],Buf[1],Buf[2]);
  debugPrintln(&huart2, buffer)  //Function to print on serial to debug
  //Here that print "Length=3 / Word=ÿ "


  return (USBD_OK);
  /* USER CODE END 6 */
}

如您所见,即使接收的字节数很好,也不会考虑第二个和最终字符(0x00、0xFF)...有什么建议吗?

使用串行通信进行USB CDC时出现问题。我正在开发嵌入式STM微控制器,我想通过pySerial传递二进制数据。我想直接发送二进制代码,但是...

python c stm32 pyserial cdc
1个回答
0
投票

这是调试不起作用,但是数据传输很好。

© www.soinside.com 2019 - 2024. All rights reserved.