简体   繁体   English

使用php将Labview程序接收的类型转换数组转换为float数组

[英]Converting the type casted array received from Labview program into float array using php

I have a program in labview which is sending UDP packets and using a php program I am receiving those packets. 我在labview中有一个程序正在发送UDP数据包,并使用php程序接收这些数据包。 So labview program is sender and php program is receiver. 因此,labview程序是发送方,而php程序是接收方。

In labview program, the float array is type casted to string using type cast function block and sent as UDP packets. 在labview程序中,使用类型转换功能块将float数组类型转换为字符串,并作为UDP数据包发送。 While receiving those packets using php, I am receiving some data which is not in readable format. 当使用php接收那些数据包时,我正在接收一些不是可读格式的数据。

在此处输入图片说明

I have tried converting the string array into float array using array_map ('floatval', $array).. But still the values are not coming in the readable format. 我试过使用array_map('floatval',$ array)将字符串数组转换为float数组。但是,这些值仍然不是可读格式。

Please help me to solve this issue. 请帮我解决这个问题。

The LabVIEW help for Type Cast points you at the document on flattened data which mentions that the representation is big-endian (most significant byte first). LabVIEW帮助Type Cast将您指向扁平化数据的文档,其中提到该表示形式为big-endian(最高有效字节在前)。 The entry on How LabVIEW Stores Data in Memory shows the actual representation of a single-precision floating-point number ( SGL ): LabVIEW如何在内存存储数据的条目显示了单精度浮点数( SGL )的实际表示形式:

SGL表示

Now that you know what LabVIEW is sending, your question becomes how to decode this in PHP - if you can't solve this yourself, I suggest asking a new question. 既然您知道了LabVIEW将发送的内容,那么您的问题就变成了如何在PHP中对其进行解码-如果您自己无法解决此问题,建议您提出一个新问题。

If you can change the LabVIEW code, you could alter the format in which the data is sent so as to make it easier to decode at the other end. 如果您可以更改LabVIEW代码,则可以更改数据发送的格式,以使其更易于在另一端解码。 Possible options there might include: 可能的选项可能包括:

  • If network bandwidth is not an issue, use a standard text-based format such as JSON 如果网络带宽不是问题,请使用基于文本的标准格式,例如JSON
  • If JSON is too big but you can afford eight bytes per value, convert to DBL - using a conversion 'bullet' from the numeric palette - before flattening to string, then reorder the bytes of the string to little-endian at the LabVIEW end. 如果JSON太大,但每个值只能提供8个字节,则在展平为字符串之前,使用数字调色板中的转换“项目符号”将其转换为DBL ,然后在LabVIEW端将字符串的字节重新排序为little-endian。 From Ton Plomp's comment, that might be correct for your current PHP code. 从Ton Plomp的评论来看,这对于您当前的PHP代码可能是正确的。
  • If you really can't afford more than four bytes per value, but the range of your data values is not too wide, you could scale them to an integer value ( U32 or I32 ) before flattening; 如果您确实不能为每个值提供四个以上的字节,但是数据值的范围不太宽,则可以在展平之前将它们缩放为整数值( U32I32 ); again, that might be easier to decode at the other end. 同样,在另一端可能更容易解码。

Note that although the data format you get from Type Cast and/or Flatten to String is documented and historically has been stable, I don't think it's absolutely guaranteed not to change between LabVIEW versions. 请注意,尽管您记录了从类型转换和/或展开到字符串的数据格式,并且历史上一直保持稳定,但我不保证绝对不会在LabVIEW版本之间进行更改。

Also the unreadable section of data could be header info added by the UDP function. 数据的不可读部分也可以是UDP函数添加的标头信息。 You may be able to parse that data and discard. 您也许可以解析该数据并丢弃。

Another thing to try is to read the UDP Rx data in Labview and compare to the Tx data to try and identify what is going on. 要尝试的另一件事是在Labview中读取UDP Rx数据,并与Tx数据进行比较以尝试确定正在发生的情况。

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

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