使用 c++ .in Linux 进行串行通信

serial communication using c++ .in Linux

本文关键字:通信 Linux c++ in 使用      更新时间:2023-10-16

我可以串行发送 1 字节字符类型数据。 现在我被困在发送浮点型数据上。 这是我串行发送数据的代码。

fd = open("/dev/ttyO1", O_RDWR | O_NOCTTY);
char byte_out[] = {0x47};
write(fd, byte_out, strlen(byte_out)+1);

如何串行写入(或发送)浮点类型数据。请帮助我.提前谢谢.

没有什么不同..你需要放置正确的浮点类型大小..

fd = open("/dev/ttyO1", O_RDWR | O_NOCTTY);
float float_out[] = {1.2342};
write(fd, (void *) float_out, sizeof(float));