To download NI software, including the products shown below, visit ni.com/downloads.
1. Overview
This example VI shows how to perform reading from a binary file in a producer-consumer design pattern, so that the data can be processed in smaller pieces, as determined by the user in the front panel.
2. Description
When you need to stream a great deal of data, more than you can store in memory, many times you will need to take the data from a file on disk. Now, if you want to loop this data the solution is rather simple.
All you need to do is determine how many reads will be required to iterate through the file given the file's size, the data type being read and the number of elements to read with each iteration. With this information you can simply perform the necessary number of iterations with a for loop. By placing the for loop inside a while loop and reseting the file position each time you enter the for loop you will be able to loop through the file.
The attached file does more than simply loop through the file, there is also logic for determining the number of iterations and a basic producer-consumer (data) design pattern.
This example reads the file in a loop indefinitely until the user stops the VI. For a more practical development, consider removing the producer while loop.
NOTE: You must change the data type of the elements to read in order to suit your needs. Go to the front panel, right click the Data Type to Read control, and select "Replace".
3. Requirements
4. Steps to Implement or Execute Code
5. Additional Information or References
**The code for this example has been edited to meet the new Community Example Style Guidelines.**
Description-Separate-2Regards,
Dan King
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.