08-14-2012 04:33 PM
Hi, I have several unsigned byte variables, and want to build them together as an array for future use in configuration saving. Could any one tell me which kind of array I should use? Or should I use "build array"?
Solved! Go to Solution.
08-14-2012 04:43 PM
Is your data multiple instances of some type of value or are you simply putting them into an array for convenience? If you are simply stuffing unrelated items into an array for convenience then don't do that. It will only serve to confuse anyone that comes along later to work on the code. Arrays should be collections of like data, not just unrelated things of the same data type. Also, if you are saving the data to a configuration file, do you want it to be human readable? Will people use and editor to make changes to the data? If so, then save your data in a meaningful way. In your case don't save 0 and 1 but rather save the value as "Enabled"/"Disabled". This is much easier for someone editing the file to understand. You can look at the examples that ship with LabVIEW for working with ini configuration files.
08-14-2012 04:59 PM
Hi Mark, thank you very much for your quick and detailed reply!And I will explain to you about my target then hope you can advise me more.
Like you see in the picture, I have a lot of items in front panel, and here I only showed one, its name is "enable". When we click on it, you can choose "ENABLE" or "DISABLE".
Currently what I have is a lot of related items (their function is independent). For example, I have three items, "enable1", "enable2" and "enable3". And all of them can be set as "ENABLE" or "DISABLE".
The final target is to put this array (or vector, or anything else you think the most suitable one) into the "save configuration file" diagram. I use the following picture as the template for "load the configuration". Could you tell me which is the best way to do? Thank you very much!
08-14-2012 05:07 PM - edited 08-14-2012 05:11 PM
I think you would be better off saving these items individually. It is a bit more work on the code side but it is much easier for a human to edit the file. Use a traditional ini file format such as:
[Application]
Station 1 = Enabled
Station 2 = Disabled
Logging = Enabled
Stop on Error = Yes
This is much more readable for a person. I recommend this sice you are saying this is a configuration file. Generally these will be open for editing by a person.
If you go with some criptic array format such as
Parameter = Enable, Enable, Disable, Enable
You can write a subVI that will return cluster containing your configuration settings. You would also write a similiar subVI for saving the parameters. This VI would also accept the cluster as an input.
the user will have no clue what they are setting or modifying.
Here are some examples of VIs I use to handle configuration files.
08-14-2012 05:28 PM
Thank you Mark, you are right, it should be better to use them individually. Since I am not familiar with configuration file programming, could you answer me some questions based on the following picture (it is a write to configuration diagram)?
If the ini file is created like this
[Application]
enable1 = Enabled
enable2 = Disabled
enable3 = Enabled
enable4 = Disabled
Stop on Error = Yes
(1) Since enable=00h, disable=01h, should I fill in the region "1", "2", "3" and "4" in the picture like "00","01", "00" and "01" for default value? If "1","2""3" and "4" are not for default value, what I suppose to put there?
(2) If I have changed the value on the panel and want to save updated configuration file, is this structure good enough?
Thank you very much!
08-15-2012 12:23 AM
If your only goal is to save and load control values on the FP, I would suggest going with an approach like this - https://decibel.ni.com/content/docs/DOC-15349
It takes a reference to each control and uses that to get its label and value and save them or load them. Note that because this example flattens the value to a string, the value in the file will probably not be human-readable, but it doesn't actually have to be. If you do want it to be, you can download the OpenG variant configuration file VIs and use that instead of the NI VI.
Also note that in that example I used a 3rd party tool (the JKI right-click framework) to quickly build the array of control references. You can do this yourself by right clicking each control, selecting Create>>Reference and then wiring those into Build Array. You can also get the references of all controls on the front panel using properties for the VI.
08-15-2012 07:37 AM - edited 08-15-2012 07:38 AM
Assuming you are using enums, I recommend using the Scan from String and Format String in order to convert from/to strings when reading from/saving to the config file.
08-15-2012 10:11 AM
Hi tst, I have read your example and it is very good! But I still have some questions about them.
(1) In your example to load and save, you also used "read and write controls to automatic config file", is that correct? Or they are independent?
(2) If question 1 is correct, does it mean I need to include "read and write controls to automatic config file" in my project folder, then modify my orignal main vi by adding similar code in "load and save example.vi"?
(3) I do not know how to change the path of ini file, I want to put this ini file in my project folder instead of default "labviewdata", how can I do it?
Thank you very much!
08-15-2012 12:05 PM
bhl3302 wrote:
(1) In your example to load and save, you also used "read and write controls to automatic config file", is that correct? Or they are independent?
(2) If question 1 is correct, does it mean I need to include "read and write controls to automatic config file" in my project folder, then modify my orignal main vi by adding similar code in "load and save example.vi"?
(3) I do not know how to change the path of ini file, I want to put this ini file in my project folder instead of default "labviewdata", how can I do it?
The example has two parts:
If you don't want to use the wrapper, you can use your own VI for this, like you suggested. What I often have is a VI which returns the path to the folder where the config files will be. If you want this folder to be in your project, you can use the Application Directory VI (I think it's in the file constants palette) which will return the folder of the project.
Note that in my example I put the files in the LV data folder because I don't want the user to touch the files and if you build an EXE you will probably have permissions problems when trying to write to a file in the Program Files folder.
08-20-2012 01:44 PM
Hi tst, i am still trying to use your methods to build my own. Yes I will make it an installation file and let the final users to save and load their configuration files. Do you have any suggestions now for me to build the code on your example's basis? Thank you!