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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

reading 64-bit integers from file

I have a binary file that contains 64-bit integers (I guess what LV would consider U64 or I64) that I need to read into labview 7.1. I have read a great deal in the forums stating that there is no such way to do this in previous versions of Labview - messages from over two years ago. I hope that NI has finally programmed a way to deal with 64-bit integers considering the amount of discussion for them. Is there an easy way that I am missing to do this? I cannot read it as a double (although it is the same size).
0 Kudos
Message 1 of 12
(3,716 Views)
Hello dlbuhl,

I think LabView doesn't have an U64 or I64 datatype. You will have to program your own...
And reading should be easy: read in as U32 and combine the MSB and LSB to your datatype.
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 12
(3,713 Views)
This link
also has some good ideas for accessing 64 bit data from a DLL. Much of the information would also apply to your situation. The reading of the data is simply to do it as GerdW suggests and using a U32 twice. The rest of handling it in LabVIEW could use the suggestions in this link.

Hope that this helps,
Bob
Message 3 of 12
(3,698 Views)
this may seem a niave question... but how does one obtain the MSB and LSB of a number so they may be combined?

thanks, i will look into the other suggestions as well.
0 Kudos
Message 4 of 12
(3,689 Views)
First, you are talking about integers, so your problem is a lot easier; floats need a bit more work to combine (mantissa and exponent).

Your 64 bit integer is stored as 8 bytes, in either of the two following ways:

| MSB | | | | | | | LSB |

Or

| LSB | | | | | | | MSB |

This is dependant on what code wrote the data and whether the machine is big endian or little endian (insert religious war here).

Reading a 64 bit number into two 32 bit numbers results in the left half of the above bytes being in one location and the right half being in a second location. Here’s an example which will illustrate how to deal with this issue:

Assume that we have a two digit (base 10) number: 87
Lets say that I can only store one digit in a location, so I read in the 87 and store the 8 in variable “A” and the 7 in variable “B”.

A = 8
B = 7

To get the number back, you would have to multiply A by 10 (because this digit came from the 10’s column) and add it to “B”.

87 = A*10 + B

Your 64 bit problem is the same. Where “A” is the most significant bytes, and “B” is the least significant bytes. So:

64bit_value = A* (2^32) + B


Now, I’ve swept a bit under the rug, which is that you may have to byte swap to convert from big edian to little edian or visa versa.

Sheldon
Technical geek, engineer, research scientist, biodegradable...
Message 5 of 12
(3,677 Views)
As the link Bob pointed out says, you really do want to read the 64-bit integer as a double. This method will work for arrays and structures (clusters) as well, since platform-specific problems such as byte alignment will automatically be done for you. When you get it into LabVIEW, use the Type Cast primitive to change it to a cluster of two 32-bit integers.

If you want a good example of this, check out Can I Edit and Create Hierarchical Data Format (HDF5) files in LabVIEW?. The VIs in the examples use this method extensively to interface to the 64-bit HDF5 DLL. There is also quite a bit of 64-bit infrastructure code you can probably use.
0 Kudos
Message 6 of 12
(3,656 Views)
So I have tried all of your suggestions and to no avail have failed to obtain the correct number. I have attached a zip file of one of my recordings. The data format is as follows:

16384 byte ascii header, followed by a continuous loop of the following:
int64 timestamp
int32 channel number
int32 sampling freq
int32 number of valid samples
int16 array of 512 elements

I need to extract the int64 timestamp value - it should begin at 16384 bytes within the file, and occur every 8212 bytes. If any of you have a few minutes to devote to showing me how I can obtain these values, I will be forever in your debt! (and it may help other users trying to do something similar as well!).

Thanks!
0 Kudos
Message 7 of 12
(3,633 Views)
Hello dlbuhl,

try this.
I changed the offset in the file to 1036 (512*int16 + 3*int32 is 1036 bytes to me...).
The vi gets all timestamps as 2 U32 and displays them in hexadecimal format.
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 12
(3,631 Views)
Dear GerdW,

Thanks for the vi, but I still have a slight problem. The first number that I get from my c-script, which I know is the correct number, is 196,235,189. How can I get this number from the Hex number that your vi outputs? Sorry, I'm a bit a novice on this topic.

Best,
Derek
0 Kudos
Message 9 of 12
(3,626 Views)
Oh yes, and of course you are correct on the 1036... I still need my morning coffee 😉
0 Kudos
Message 10 of 12
(3,477 Views)