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: 

how to read binary files wrt specific BYTE size and length??

Hello Everyone,

                            I have a project I want to accomplish. I have a binary file, and I would like to read the data and print on wfm in a specific order and size.

  1. The data is 16 bit binary type , and needs to be read in chunks of 2 bytes.
  2. i have 30 bytes of sample 1.
  3. followed by 2 bytes of sample 2.
  4. followed by another 2 bytes of sample 3.
  5. steps 2-4 should be repeated 10 times and then i should read sample 4 which is of 2 bytes.....

How should I do it?? I don't have any VI build... all i have is the example VI...

 

can anyone pleasehelp me???

 

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 1 of 9
(4,016 Views)

You mentioned an example VI, but did not include it...

 

The Read Binary File function can read data in whatever format you tell it, but wiring an appropriate constant of the specific datatype to the ... "data type" input. You can also tell it how many of those numbers to read by wiring an appropriate value to the ... "count" input. To read in sequence, just chain them up in sequence. The file pointer will get moved after each read.

0 Kudos
Message 2 of 9
(4,006 Views)

smercurio_fc, please see the attached VI, i am confused how to make sure that the file pointer  gets moved ... can you make some changes in the VI and post it please???

Now on LabVIEW 10.0 on Win7
Download All
0 Kudos
Message 3 of 9
(3,997 Views)

That VI does not read the data based on your specifications. It's specifying to read floating point numbers. That's why it doesn't work. Did you look at the example I posted? It shows you how to do it. Just adapt it based on what you said earlier for your datatypes and how many number you need to read. It's not that difficult. Try.

0 Kudos
Message 4 of 9
(3,993 Views)

smercurio_fc, check the VI i attached... I am not sure if i have done it correctly, I have introduced a for loop which would run for 10 times, so that the steps 2-4 run for 10 times...

 

Is it a correct way of doing it/??/

 

I haven't yet done what is to be done after repeating the steps 2-4 for 10 times...

 

***how can i make the reading of binary values is both time and byte dependent???*** example, the first 30 bytes were recorded at 100hz, the next 2 bytes were recorded at 10hz,

so while reading,i have to make sure I am reading at the same frequency.. ?? correct???

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 5 of 9
(3,982 Views)

What is the purpose of the while loop? Is there a reason to read the file again after you've read out its contents?

 

You need to clarify some statements you made. You said:

 


  1. The data is 16 bit binary type , and needs to be read in chunks of 2 bytes.
  2. i have 30 bytes of sample 1.

 

I don't understand item 2. If you have data that's 16-bit in size then what does "I have 30 bytes of sample 1" mean? Does this mean you have 15 values? Or did you mean you have 30 different values of sample 1?

 

If the values are 16-bit why are you wiring an I8 constant to the read functions?

 

You also said

 


 

  1. followed by 2 bytes of sample 2.
  2. followed by another 2 bytes of sample 3.
  3. steps 2-4 should be repeated 10 times and then i should read sample 4 which is of 2 bytes.....

 

Why are you repeating steps 2-4 10 times? Is this supposed to be 10 channels? Is it something else? What does the .... mean at the end?

 

What are you trying to do with the graphs? Right now all they will show are the values of the bytes, which don't tell you anything since you previously stated you have 16-bit values, not 8-bit values.

 

Are the values scaled values?

 


***how can i make the reading of binary values is both time and byte dependent???*** example, the first 30 bytes were recorded at 100hz, the next 2 bytes were recorded at 10hz,

so while reading,i have to make sure I am reading at the same frequency.. ?? correct???


I have no idea what you mean by this. You just values in the file. If you're trying to display some sort of waveform then you need to create a waveform datatype and provide it the timing information for the data that you're reading.

 

0 Kudos
Message 6 of 9
(3,963 Views)

smercurio_fc, sorry for the confusion, i will try my best to explain...

1. No, i don;t have to read the file again, once it has read, I used while loop just to see the data updating (i press run, and before i can visualize i have the waveforms; i can get rid of the while loop)

 

2. I have 30 different values of 1 sample. actually, the data is cmg from tri-axial accelerometer; each axis is of 10 bytes(hence 3*10 = 30bytes)

 

3. I am repeating the steps 2-4 10 times because the data was written into the binary file after 10 times sampling the sensors(if first 3 samples are read @ 1000hz, sample 4 was read at 1000/10 = 100hz)

 

4. I am using the graphs to interpret the values, that's it. The values are already scaled when they were wrote to the binary file, I have to simply interpret it.

 

I have made some changes in the VI, now i am reading only the first 30bytes, that too, in chunks of 10-10-10 bytes, and plotting the 3 samples simultaneously on a waveform chart. (will approach 1 sensor/sample at a time) and running the loop for 10 times. I have changed I8 to I16 now.

 

Please let me know if it makes sense to you now.

 

 

 

P.S. each sample is a sensor data.

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 7 of 9
(3,955 Views)

did anyone get a chance to run the program/?

can some1 please help me out??

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 8 of 9
(3,924 Views)

Hi,

 

Perhaps its an issue with your file position? 

 

set file position.png

 

Patrick Corcoran
Application Engineering Specialist | Control
National Instruments

0 Kudos
Message 9 of 9
(3,889 Views)