【问题标题】:How can I print a message stored in a buffer?如何打印存储在缓冲区中的消息?
【发布时间】:2020-11-21 08:08:42
【问题描述】:

我正在尝试编写一个名为 SerialSend 的函数,它会将环形缓冲区(名为 testbuff)的内容打印到我的控制台。这是我对 SerialSend 的定义。

void SerialSend (USInt* pusiBuffer, UDInt len, UDInt connectionId)
{
  USART_WriteByte(DEMO_USART, testbuff[i]); 
  i++;
  i %= DEMO_RING_BUFFER_SIZE;
}

调用时,SerialSend 打印 testbuff 中的第一个字符。如何让它打印缓冲区的其余内容?这是我调用 SerialSend 并且中断不起作用的 main 代码。

  while(i<17)
  {
    SerialSend(testbuff, 17, 0)  //Sends contents of testbuff to print in console
    if (i==16)
    {
      break;                     //Break isn't working, probably because i never hits 16 due to the ring
    }
  }

【问题讨论】:

    标签: while-loop console break uart


    【解决方案1】:

    原来我的环形缓冲区太小了,所以我将大小增加到 50 并像这样在 main 中编辑调用:

    while(1)
      {
        SerialSend(testbuff, 50, 0); //Sends contents of testbuff to print in console
        if (i==17)
        {
          break;
        }
      }
    

    testbuff 缓冲区包含我要打印的 17 个字符,因此当索引到达消息末尾时,if 语句用于中断。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-24
      • 2017-10-19
      • 1970-01-01
      • 1970-01-01
      • 2017-06-20
      • 2016-03-19
      相关资源
      最近更新 更多