Well it’s hard for me to believe, but I’ve now been using National Instruments LabVIEW for six years. I started off with LabVIEW v7.1 and have used every version since (it’s now called LabVIEW 2010). So I’m definitely a fan. And yet, I’m still discovering new and more useful features on a fairly routine basis.
Just the other day I was looking for a convenient means to save a ton of front panel control values to a file (to allow the user to save their current program setup for later use). In the past, when saving program settings, I’ve used the Configuration File VIs, which make saving simple parameters very easy and neat (think header-based *.ini files). However, in this case I needed to save an obscenely large quantity of very variable data (numerics, strings, booleans, arrays, clusters, clusters of arrays, arrays of clusters, etc…). After a bit of Googling I found my answer, the magical Datalog VIs (located on the Programming → File I/O → Adv File Funcs → Datalog palette):
The Datalog VIs allow you to save clusters of any sort to a compact, record-based file. Of course, you aren’t required to make use of the record functionality, you can just store everything in a single record and then recall that record later. For instance, I packed the following mass of controls into a single datalog file with just a few simple blocks:
Reading from a datalog file is just as simple, you need only swap in a read block in place of the write block. Here’s a bit more on the Datalog blocks, taken from NI’s website:
A datalog file stores data as a sequence of identically structured records, similar to a spreadsheet, where each row represents a record. Each record in a datalog file must have the same data types associated with it. LabVIEW writes each record to the file as a cluster containing the data to store. However, the components of a datalog record can be any data type, which you determine when you create the file.
For example, you can create a datalog whose record data type is a cluster of a string and a number. Then, each record of the datalog is a cluster of a string and a number. However, the first record could be (“abc”,1), while the second record could be (“xyz”,7).
Using datalog files requires little manipulation, which makes writing and reading much faster. It also simplifies data retrieval because you can read the original blocks of data back as a record without having to read all records that precede it in the file. Random access is fast and easy with datalog files because all you need to access the record is the record number. LabVIEW sequentially assigns the record number to each record when it creates the datalog file.
So there you have it! If you’re looking for an easy way to store diverse data, the Datalog VIs may be your answer. Oh, and if you’ve got no clue what graphical programming with LabVIEW is all about, check out NI’s free 30-Day LabVIEW Trial. The trial is full-featured; the only catch is a small watermark placed in the lower right-hand corner of your VIs. But give it a shot! It takes a little getting used to if you’re a die-hard C programmer, but once you understand the basics, you’ll be churning out sophisticated programs in a fraction of the time required to type code.