简体   繁体   English

如何通过TCP / IP通信Java和Labview,并发送浮点数据缓冲区?

[英]How to communicate Java and Labview through TCP/IP, and send data buffers of float point?

I am working on a university project, where I require communicating Java with Labview, bidirectional, and send and receive data in floating point, in data buffers, because the application in Labview generates data at high speed, but I temporarily store and send when the array has a size of 100. 我正在从事一个大学项目,在该项目中,我需要与Labview双向进行Java通信,并在数据缓冲区中以浮点形式发送和接收数据,因为Labview中的应用程序会高速生成数据,但是当数组的大小为100。

One of my difucultades is to convert data sent from Labview to Java format and viceversa. 我的难题之一是将Labview发送的数据转换为Java格式,反之亦然。

Thanks!! 谢谢!!

As far as I can see, you have two options: 据我所知,您有两个选择:

  1. Use a text base protocol (XML, JSON, something of your own) and just send the literal "1.3454". 使用基于文本的协议(XML,JSON,一些您自己的),然后发送原义“ 1.3454”。
    1. pro: it's probably human readable, which simplifies debugging/ asserting that the correct data is transferred. 优点:它可能是人类可读的,从而简化了调试/断言正确数据传输的过程。 It is also simpler to have different types of messages. 具有不同类型的消息也更简单。
    2. con: This may mean a loss of precision and definitely means some kind of overhead. 缺点:这可能意味着精度下降,并且肯定意味着某种开销。
  2. If you just have this one kind of data, you could also extract the bytes of the float and send them, so that the other end can read exactly four bytes and reconstruct the float. 如果仅具有这种数据,则还可以提取浮点数的字节并发送它们,以便另一端可以准确地读取四个字节并重建浮点数。
    1. pro : no overhead :没有开销
    2. con: There might be a problem with endianess. 缺点:耐力可能有问题。 I'm not sure if LabVIEW and Java handle all their data in a specific endian or if it depends on the hardware. 我不确定LabVIEW和Java是否以特定的字节序处理所有数据,还是取决于硬件。 You might need to reorder the read bytes before reassembling them back to a float. 您可能需要对读取的字节重新排序,然后再将它们重新组合为浮点型。 Also different kinds of messages can get more complicated. 同样,各种消息也会变得更加复杂。 On this best read the documentation on the TCP Read VI 最好阅读TCP Read VI上的文档

You can also mix both approaches: extract the bytes from the float, treat each byte as a character and assemble them as a string, which you put into your text based protocol. 您还可以混合使用两种方法:从浮点数中提取字节,将每个字节视为一个字符,然后将它们组装为字符串,然后将其放入基于文本的协议中。

考虑使用Labview标准的tcp-ip lib或websocket。

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

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