简体   繁体   中英

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. So labview program is sender and php program is receiver.

In labview program, the float array is type casted to string using type cast function block and sent as UDP packets. While receiving those packets using php, I am receiving some data which is not in readable format.

在此处输入图片说明

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.

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). The entry on How LabVIEW Stores Data in Memory shows the actual representation of a single-precision floating-point number ( 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.

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. Possible options there might include:

  • If network bandwidth is not an issue, use a standard text-based format such as 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. From Ton Plomp's comment, that might be correct for your current PHP code.
  • 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; 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.

Also the unreadable section of data could be header info added by the UDP function. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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