Jump to content

Using an ini file in my labVIEW vi


c_w_k

Recommended Posts

Hello,

I've been learning labVIEW over the past year so I have lots of questions....

Currently I have a simple vi that takes in 15 parameters (the parameters only need to change if the user is connecting to a different device). I'm wondering if I could use an INI file to set the 15 parameters instead of having the user enter everything manually?

I don't have much experience with INI files either so if anyone can help me or point me in the direction of a good tutorial on this I would appreciate it greatly. Sorry if I haven't included enough information, if anyone needs extra info in order to help me out please ask.

Thanks

CK

Link to comment

After doing some research i'm able to answer my own question biggrin.gif

here's the link that I found...

http://zone.ni.com/r...guration_files/

thanks jcarmody for the link, didn't see your post before i posted back i was able to get it working.

The advantage I see with the OpenG VI is that you don't need to program all of the sections/tags, just make a cluster and it'll read everything for you. It's just as easy on the other end to write everything back.

Have fun.

Jim

Link to comment

One thing we often do get the text from all the controls on a FP and use the OpenG INI VIs to save their values to a file on exit. Then on software start load all the values from the file into all the FP controls. It's a great way to have the software remember where it was. (I'd love to post the code, but it's in our internal reuse repository - IP protected - should be pretty easy to recreate though...)

Link to comment

should be pretty easy to recreate though...

Quite easy, and in fact you don't even need the OpenG VIs, since you can just build an array of reference and then iterate over them and use the variant Value property flattened to a string. Then you just need a VI for saving and a VI for loading and you're set. Whenever you want to add a control, you just create a reference for it and add that to the array.

  • Like 1
Link to comment

Okay, so I'm trying the OpenG vi for this....

Right now I'm just using a simple ini that consist of :

[section1]

key1=123

key2=456

key3=789

[section2]

key1=1000

key2=2000

key3=3000

In my labVIEW code on the block diagram I have the path of the INI going to the "Open Config Data.vi" which connects to the "Read INI Cluster"......Do I need to actually create a cluster in labVIEW that contains everything in the INI file?(Currently I do and have that feeding into the "Read INI Cluster" vi. I'm not sure exactly what I should be doing on this part. I have the output of the "Read INI Cluster" set as a "INI Formatted Cluster" indicator.....on my labVIEW program I can see all of the values but they look like this: "->123 instead of just looking like: 123 I'm not sure how I can separate these values out by themselves either....so for instance, if I only want to use "key1".....if I were able to unbundle by name then i could do it...but i'm not seeing that option.

I've attached of the block diagram as well as the output that i am getting on the front panel.

Thanks for any help

CK

post-15930-126142795892_thumb.jpg

Link to comment

You don't need to manually create the INI file. The package has two relevant VIs - the read VI (which you used in your example) and the write VI. If you wire your cluster into the write VI, an INI file with all the data will be created. When you want to load the data from the file, you wire the cluster into the input (like you did), which allows the VI to know what to look for in the file and how to build its variant output. You then wire the variant result and the cluster into the Variant to Data primitive and you have your cluster back. Now you can unbundle whatever you want out of it.

What's nice about this is that you can later add elements to the cluster and the VI will still be able to load older INI files you saved (as long as you don't change the names of the controls in the cluster).

Link to comment

I'll throw out another option here - I have found the "Read Anything" and "Write Anything" VI's from MGI to be extremely easy to use for simple ini operations. All you have to do is create the cluster (a type def is best) with the controls you want to write to and read from file. Wire the cluster to the "Anything" input of the "Write Anything" VI and run the VI. There's your ini file. To read the file, wire your type def'd cluster to the "Type Of Anything" control on the "Read Anything" VI and then use the Variant To Data function to convert the returned variant to the original cluster

The VIs are free at

http://www.mooregoodideas.com/File/index.html

Mark

Link to comment
  • 4 weeks later...

I know its been a while, I was finally able to spend some time looking at this and was able to get it to work, thanks to everyone who mentioned the Open G library and who gave pointers on how to use it.

I've attached a screen shot of my code...

I have an INI file (CK.ini) that I want to read in from a file, I create a cluster that matches section1 of my ini file, then wire that cluster to the Read VI, then I wire the variant outcome of the Read VI to the Variant To Data (also need to wire the cluster to this)...then I have my original cluster back. (Thanks Yair)then I just unbundle the cluster.

-CK

post-15930-126384917026_thumb.jpg

Link to comment
I have an INI file (CK.ini) that I want to read in from a file, I create a cluster that matches section1 of my ini file, then wire that cluster to the Read VI, then I wire the variant outcome of the Read VI to the Variant To Data (also need to wire the cluster to this)...then I have my original cluster back. (Thanks Yair)then I just unbundle the cluster.

thumbup1.gif

Link to comment
  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.