简体   繁体   English

在Linux中使用c ++进行串行通信

[英]serial communication using c++ .in Linux

i can send 1 byte char type data serially. 我可以串行发送1个字节的char类型数据。 now i am stuck with sending float type data . 现在我一直在发送浮点型数据。 here is my code for sending data serially . 这是我用于串行发送数据的代码。

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

how can i write(or send) float type data serially . 我如何串行写入(或发送)浮点型数据。 Please help me . 请帮我 。 thanks in advance . 提前致谢 。

Nothing different.. and you need to put the right size of the float type .. 没什么不同..并且您需要放置正确大小的浮点类型..

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM