Hi! Back in 2009 I learned a tiny little bit of LV 5.1 and wrote a simple VI to read an array of ints from a binary file and display it on an intensity graph:
I now need to re-create this functionality in LV 2016, but so much has changed that I don't even know where to begin. The basic functionality I need is this:
Can someone help me get started? Thanks!
C++-style file format follows, below:
long nType; //0 = float, 1 = word
float fPixelPeriod; //in nanoseconds
//new items for version 4
DWORD dwDataStart;//starting offset to the data = IMGSTRUCT
float fVmin; //minimum input voltage to AD
float fVmax; //maximum input voltage to AD
BOOL bCDSenabled; //TRUE if CDS was enabled;
Solved! Go to Solution.
use the ReadFromBinaryFile function, it supports all you need!
- you can select the datatype you want to read
- you can select how many items to read…
Just to give an idea:
Thanks! I was trying to read it in as an array, instead of reading it in as a stream of Singles or U16s and then resizing the array as you've shown. I have it working now!
After much trial and error I also figured out how to read the header and use the X, Y, and dwDataStart data to set up the file read and array parameters successfully.
There are just 2 features that I'd like to add, but that I can't figure out:
- use a case structure and have a ReadBinary function in each case
- use IndexArray when you want to index an array element...
Partial success! The Case structure worked as expected, and I can now choose either Type 1 or Type 0 files, and both graph properly.
I tried using an IndexArray to pick the Nth frame/page from a multi-frame file, but I'm getting garbage. Even a single-frame file displays incorrectly. This is supposed to look like the "Brother holding cat" photo, from above.
The VI is attached, and the binary data file is uploaded, here.
the error is in the ReshapeArray to a 3D array.
Using the known approach to reshape to a 2D array works fine on your example data:
(Note the subtle changes I made to your VI… What's the purpose of a single frame flat sequence here?)
Do some debugging: try to load a multi-frame file and to find the correct conversion settings…
Thanks! Yes, the multiple outputs from the IndexArray really cleans things up.
I'm still struggling with the reduction to a single frame. If I read in a multi-frame data file, don't I need to read it in as a 3D array and then extract the Nth page from that?
My goal is to be able to allow the user to page through the frames by fiddling with the Frame # control, without having to reload the file every time. Someday I'd like to actually be able to play them back in a loop, just like a video.
I'd put the whole thing in a frame because when I hook this up to the data acquisition system later I'll want to run this continuously in a loop, with another frame triggering the acquisition system to read 1 page of data from hardware and write new data to a file. Someday^2 I'll figure out to pass the data by pointer with a callback (instead of with a file), but that's for much later.
For now I just have to demonstrate rudimentary control and import. And, as you can tell, I know very little about LabVIEW!
I had the dimensions wired in the wrong order. Frame, Y, X works:
I'd tried this once before, but I also had the Frame index wrong; it's zero-based, so when I left the default at 1, it didn't work on my single-frame files, which led me to believe that the problem _wasn't_ the index ordering.
So I had to fix both errors simultaneously, which took a lot of trial and error.