c_w_k Posted December 18, 2009 Report Share Posted December 18, 2009 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 Quote Link to comment
jcarmody Posted December 18, 2009 Report Share Posted December 18, 2009 [...]I'm wondering if I could use an INI file to set the 15 parameters instead of having the user enter everything manually? I do this all the time. Take a look at OpenG Read INI Cluster. Quote Link to comment
c_w_k Posted December 18, 2009 Author Report Share Posted December 18, 2009 After doing some research i'm able to answer my own question here's the link that I found... http://zone.ni.com/reference/en-XX/help/371361B-01/lvconcepts/creating_configuration_files/ thanks jcarmody for the link, didn't see your post before i posted back i was able to get it working. Quote Link to comment
jcarmody Posted December 18, 2009 Report Share Posted December 18, 2009 After doing some research i'm able to answer my own question 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 Quote Link to comment
Black Pearl Posted December 18, 2009 Report Share Posted December 18, 2009 To add some more pro's to the OpenG ini VIs: If you change the parameters you only need to change the cluster type def of these parameters, OpenG handles all the File stuff automagically. Felix Quote Link to comment
crelf Posted December 18, 2009 Report Share Posted December 18, 2009 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...) Quote Link to comment
Yair Posted December 20, 2009 Report Share Posted December 20, 2009 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. 1 Quote Link to comment
c_w_k Posted December 21, 2009 Author Report Share Posted December 21, 2009 Thanks for all the feedback on the OpenG INI vi's, I'm going to give them a shot now.... Quote Link to comment
c_w_k Posted December 21, 2009 Author Report Share Posted December 21, 2009 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 Quote Link to comment
Yair Posted December 21, 2009 Report Share Posted December 21, 2009 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). Quote Link to comment
Black Pearl Posted December 22, 2009 Report Share Posted December 22, 2009 You need the variant to data type function to convert it to the original cluster when you read it. To get the ini file you described, use two clusters named Section 1 and Section two and the you need two write Cluster/Read Cluster. Felix Quote Link to comment
Mark Smith Posted December 22, 2009 Report Share Posted December 22, 2009 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 Quote Link to comment
c_w_k Posted January 18, 2010 Author Report Share Posted January 18, 2010 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 Quote Link to comment
crelf Posted January 18, 2010 Report Share Posted January 18, 2010 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. Quote Link to comment
TG Posted February 3, 2010 Report Share Posted February 3, 2010 If your data should become more complex as in VIsa refs or DAQ refs then you may run into issues using the OPENG VI's for INI access. However, if you make some VI wrappers around these two guys you will never have problems. The MGI ones are absoultely rock solid stable. http://www.mooregoodideas.com/ReadWriteAnything.htm Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.