标签:
UART串口有一个缺点,就是发送和接受是一个字节一个字节的接收,如果发送的浮点数那可怎么办啊?
double *p; p = &data;
unsigned char *q; q = (unsigned char *)p;
for(i=0;i<8;i++) { send(*(q+i)); }
#include "stdafx.h" #define MAX_LENTH 8 union U1 { char s[MAX_LENTH]; double d; }; union U2 { char s[MAX_LENTH]; double d; }; int _tmain(int argc, _TCHAR* argv[]) { U1 u1; U2 u2; int i=0; u1.d = 2.111; u2.d = 3.00; printf("u1.d = %lf\n",u1.d); printf("u2.d = %lf\n",u2.d); printf("Send Data..."); for(i=0;i<MAX_LENTH;i++) { u2.s[i] = u1.s[i]; } printf("u2.d = %lf\n",u2.d); while(getchar()==‘q‘); return 0; }
方法一简直就是浪费脑力啊!
vs2010结果
标签:
原文地址:http://www.cnblogs.com/simonlin/p/5037449.html