LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

EXE Embedded Data

Hey all,

          I'm trying to make an exe that saves some data right before it's built.  I've started with the Pre-Build Action vi, but I can't seem to find a way to save data.  I'd like, if possible, to have the data be connected to the exe in some way, and I'd rather not have to worry about another file.  The data will only be written when building, and afterwards it just needs to be able to read it, but I can't think of anything other than just a file.  Is there anyway to kind of embed a file into an exe?  Or is there a better way to do this?  Any help would be greatly appreciated!

0 Kudos
Message 1 of 5
(1,543 Views)

When you build an executable, one of the options is called "Destination".  In there, it shows where the Top Level VI will go, and also shows an entry for "Support Directory", which is (I think, by default) a folder called "Data".  In my Project, the Top Level VI is located at the "top" of the Folder holding the Project (that is, at the same level as the .lvproj file).  I put a folder called "Data" in the Project Folder.  So write the Pre-Built Action to put all files that you want to read when the Executable starts (or when you run the Top-Level VI before you build the Executable, just to see if the code works) into this Data folder.  You can find it easily by using the File constant "Application Directory" as the Folder and "Data" as the sub-folder name -- the "magic" is that when in Development Mode (i.e. when you run your code from within LabVIEW to test that it works, it uses the Data sub-folder that you put in your Project folder, but when you run the "built" version, it uses the Data folder that you asked it to create in the folder holding the Executable.  So in Development mode, when you run the Pre-Build action, it puts data into the Data Folder that ends up being in the "right place" in the Built folder.

 

I hope this is reasonably clear.

 

Bob Schor

0 Kudos
Message 2 of 5
(1,511 Views)

Hi Ethan,

 

One way of embedding data in an exe is to have a subVI with a single byte array indicator wired to an output. The pre-build step would then populate that byte array using some VI scripting and save that data as the default value. You can then call that subVI to read the embedded data in your main program. I've attached a small example which includes the pre-build step below.

 

enbedded-data-pre-build.png

0 Kudos
Message 3 of 5
(1,501 Views)

I was actually trying to do something like this before but couldn't seem to get it to stick.  It was odd becaues it worked when I ran the VI normally but when I tried to have it as the Pre build action, it never did anything. Also, what is that VI you're using that has the FP and Array inputs?  Maybe that's my problem.  Thanks!

0 Kudos
Message 4 of 5
(1,435 Views)

@EthanHenry wrote:

Also, what is that VI you're using that has the FP and Array inputs?  Maybe that's my problem.  Thanks!


That's "Traverse for GObjects".  If you go to your LabVIEW options and enable VI scripting in the "VI server" section, then in the "Application control" palette there will be a new sub-palette for VI scripting, and it and a few other helpful VIs will be there.  The main thing it does is that it looks for whatever you tell it to look for on the VI reference passed in to it (in this case, an Array control on the front panel... the code here will work as long as there is only one match).

 

As to why it didn't work when you tried it, post your code!  Best guess would be that you missed a step without realizing it.

0 Kudos
Message 5 of 5
(1,426 Views)