#include "stdio.h"
#include "string.h"
union Data
{
char str[4];//float占用4个字节所以给四个字符
float num;
};
int main()
{
union Data send_data,receive_data;
send_data.num=43.43;//通过串口发送43.43,只需要放入共用体里面,然后通过发送四个char 数据,下面是模拟的,还没试过在串口上。
receive_data.str[0]=send_data.str[0];
receive_data.str[1]=send_data.str[1];
receive_data.str[2]=send_data.str[2];
receive_data.str[3]=send_data.str[3];
printf("接收到的数据receive_data.num:%f\n",receive_data.num);
}
标签:示例,receive,浮点数,send,num,str,串口,data From: https://www.cnblogs.com/liehuo123/p/18011425