From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

32 bit byte swap

Hello,

 

I'm trying to read data from Agilent OSA that output the data in 32 bit number through GPIB interface.

 

if the bytes are numberd as 0, 1 , 2, and 3 - I need to swap 0 and 3, 1 and 2.

 

that is: to start with 0/1/2/3 and to end with 3/2/1/0.

 

can someone help how to do that for each 32 bits?

0 Kudos
Message 1 of 8
(5,482 Views)

Can you give an example of the data message coming from the instrument?  My initial thought is to just use Unflatten From String with a U32 (or I32) as the data type and the Endianess set to Little Endian.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 8
(5,453 Views)

The data set is simply the trace of the OSA.

 

1001 numbers such as -45.26 for example.

0 Kudos
Message 3 of 8
(5,451 Views)

I attach an image of my proposed solution?

 

I found split and joing function for high and low byts or word - so I split, swap and rejoin in reverse.

 

what do you think?

0 Kudos
Message 4 of 8
(5,427 Views)

Ah, so it is just an array of SGL data coming from the instrument.  Here is what I propose


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 8
(5,422 Views)

none of the above works.

 

I'm very high exponnets numbes (E+8).

 

Any suggestions?

0 Kudos
Message 6 of 8
(5,232 Views)

Is that floating point constant that you show in your jpg a double or a single?

I can't see from the jpg but it makes a big difference in values.

greetings from the Netherlands
0 Kudos
Message 7 of 8
(5,192 Views)

@Albert.Geven wrote:

Is that floating point constant that you show in your jpg a double or a single?

I can't see from the jpg but it makes a big difference in values.


Let's clarify this a little more.  A SGL (Single Precision Floating Point) uses 32 bits to represent a number.  A DBL (Double Precision Floating Point) uses 64 bits.  So when you convert to your floating point, make sure you are using SGL, just like I did in my snippet earlier.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 8
(5,099 Views)