LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Byte swapping Double Floats from an HP Device

Folks,

I'm trying to dump the cal coefficients from an HP 8751A RF network analyzer.   I'm using VISA across the GPIB.  The highest precision data is available in 64-bit doubles.  Unfortunately, it is in Big-Endian Motorola format.  I've studied the "Floating Point Modifiers" for the CVI "Fmt" command, but it appears that the Fmt command only allows byte swapping for Integer data using the "o" modifier (e.g. o1234, etc).  Is there an elegant way to swap the incoming Big-Endian bytes (all eight of 'em) to properly read in a double float?  I imagine that there is.  I can't be the first guy to want to pull a double from an older HP device.

I noticed that HP provided a lower resolution little-endian 32-bit float format to solve this type of issue with the 8751A.  Unfortunately, the lower precision of the 4-byte floats causes unacceptable error for reflection measurements (i.e. 30-40 db vice 70-80 db S11 measurements).

Thanks, calvin
0 Kudos
Message 1 of 6
(3,249 Views)
You get that the data as a string, to convert it to a double you (probably) use typecast.
The lastest version of Unflatten from string (8.5) has an endianness input option.

that should do the trick.

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 2 of 6
(3,238 Views)
If you don't have the latest version of LabVIEW, Type Cast to an array of U8s, use Index Array and Replace Array Subset to reverse the order of the bytes, then Type Cast back to a DBL.  Alternately, you can Type Cast to a cluster of two U32s, run a Swap Bytes and Swap Words operation on them (use the cluster directly), swap the order of the integers, then typecast to a DBL.  I don't know which would be faster or more memory efficient.

When doing things like this, it helps to think about the binary representation of the elements you are trying to operate on.  LabVIEW has a fairly complete set of binary level operations which, fortunately, don't get used very often.  However, they are there and very useful in this kind of situation.  Be careful when you use Type Cast that the inputs and outputs have the same size.  You can get weird memory errors if you don't follow this rule (one of the few places in LabVIEW where this is true).
0 Kudos
Message 3 of 6
(3,208 Views)


Modifiers" for the CVI "Fmt" command, but it appears that the Fmt command only allows byte swapping for Integer data using

It looks like he's using CVI and posted to the wrong board.
0 Kudos
Message 4 of 6
(3,203 Views)

If using CVI, you can use a series of masks and shifts to get each byte, then reassemble in the correct order.  Example:

10101010 00000000 AND 11111111 00000000, then shift the result 8 bits to the right, will give the MSByte.  Get the LSByte using AND, no shift required.  Then shift the LSByte to the left by 8 bits and AND with previous MSByte.  It is tedious but it will work.

- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 6
(3,182 Views)
Yes, thanks guys - I erroneously cross-posted to this board after getting kicked around by the system a bit.  I did learn something about unflatten from string though for LV!

Thanks for the idea using the byte swapping bit AND with shift.  I was thinking about perhaps reading in 8 chars, flipping them around LSB to MSB, forming a char pointer to the first byte, and then typecasting the pointer as an 8 byte double.  That might work.

Calvin

0 Kudos
Message 6 of 6
(3,154 Views)