如何正确显示十六进制数据包?

时间:2016-11-26 17:52:40

标签: c uart

我正在尝试在笔记本电脑和UART之间进行通信,我想显示此数据包:ccddeeff8899aabb4455667700112233327224 这是C代码:

dev_uart_ptr = uart_get_dev(1);
uint8_t rx_buffer[38];
dev_uart_ptr->uart_open(230400, 1, 0);
memset(rx_buffer, 0, sizeof(rx_buffer));

while(1)
{
    int rx_length = dev_uart_ptr->uart_read(rx_buffer,38);
    if (rx_length <38)
    {
        printf("\rx_buffer \n",rx_buffer);
    }
    else
        for(i=0;i<10;i++);
}

结果是

x_buffer
x_buffer
x_buffe
r
x_buffer
x_buffer
x_buffer

x_buffer
x_buffer
x_buffer

x_buffer
x_buffer
x_buffer
x
_buffer
x_buffer
x_buffer

如果我把

 while(1)
    {
        int rx_length = dev_uart_ptr->uart_read(rx_buffer,38);
        if (rx_length <38)
        {
            printf(rx_buffer);

        }
        else
            for(i=0;i<10;i++);
    }

我的结果是:

eff8899aabb445566770011223327224cb┼▄  
 ccddeeff8899aabb445566770011223327224
cb┼▄   ccddeeff8899aabb445566770011223
327224cb┼▄   ccddeeff8899aabb445566770
011223327224cb┼▄   ccddeeff8899aabb445
566770011223327224cb┼▄   ccddeeff8899a
abb445566770011223327224cb┼▄1223332722
4cb┼▄   cddeeff8899aabb445566770011223
3327224cb┼▄   cddeeff8899aabb445566770
0112233327224cb┼▄   cddeeff8899aabb445
5667700112233327224cb┼▄   cddeeff8899a
abb4455667700112233327224cb┼▄   cddeef
f8899aabb4455667700112233327224cb┼▄   
cddeeff8899aabb4455667700112233327224c
b┼▄   cddeeff8899aabb44556677001122333
27224cb┼▄   cddeeff8899aabb44556677001
12233327224cb┼▄   cddeeff8899aabb44556
67700112233327224cb┼▄   cddeeff8899aab
b4455667700112233327224cb┼▄   cddeeff8
899aabb4455667700112233327224cb┼▄   cd
deeff8899aabb4455667700112233327224cb┼
▄   cddeeff8899aabb4455667700112233327
224cb┼▄   cddeeff8899aabb4455667700112
233327224cb┼▄   cddeeff8899aabb4455667
700112233327224cb┼▄   cddeeff8899aabb4
455667700112233327224cb┼▄   cddeeff889
9aabb4455667700112233327224cb┼▄   cdde

首先,它工作正常,但现在我不知道问题出在哪里。如果你能帮助我,我将非常感激。

0 个答案:

没有答案