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: 

Working with Binary data from the Gpib Read Function

I m using the gpib read command to recieve data from a gpib instrument. I already know the form of the binary data being sent back. I have programmed it in matlab before. I am haveing trouble parseing out the binary data I recieve. the basic form of the data is
#I immediately followed by 401 64 bit ieee floating point numbers. When I programmed this in matlab the code I used was of the form:
[a,count,msg]=fread(g2,2,'int8');
[a,count,msg]=fread(g2,401,'float64');
for those that don't know matlab code the command reads data from the instrument pointed to by the g2 handle. the number after the g2 above speicifies the number of values to read. And the last part the string in qoute specifies the way the binary data
is to be interepeted. the output arguments a count and msg are
a-your data
count-number of items succesfully read in
msg-error message
In the above two lines I use the variable a twice to capture the data. The first time a is set equal to '#I' everything inside the qoutes. The second time a is set equal to the actual data, in this case 401 64bit floating point numbers. I m convince that the flatten to string and unflatten from string function are the set meant to accomplish this task. But I haven't been able to find a good example of how to use these functions. Especially with an array.
Can some one please help me?
Thanks
Scourched
0 Kudos
Message 1 of 3
(3,131 Views)
I'm pretty sure what you're describing is a simple typecast in LabVIEW. You will want to strip off the #I first, using string manipulation functions. Then, you can wire the string into a "typecast" VI, and wire a double precision float constant to the top connector of the typecast (this tells the VI that you expect a 64 bit float output) and then you can read your resulting array of double precision floats on the output of the typecast. The typecast VI is found in All Functions >> Advanced >> Data Manipulation.

I've attached an example in LabVIEW 7.0 and also 7.1 format.

Scott B.
Applications Engineer
National Instruments
Download All
Message 2 of 3
(3,131 Views)
Thanks Scott. After I posted the article I eventually figured this out on my own.
0 Kudos
Message 3 of 3
(3,131 Views)