LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Update Config File

Solved!
Go to solution

Hi everyone,

 

I faced recently something strange with Config File. In my Software, a key is updated according to a condition, but I noticed that the MyConfig.ini is not updated if it's not closed. I mean, in LabVIEW the file is opened and the data is written to it. But If I open the file in Windows, I see it's still not updated. If I close the file in LabVIEW, then it will be updated.

 

I am wondering, if this is right?

 

Sinan_Ismael_1-1630072053487.png

 

0 Kudos
Message 1 of 10
(3,505 Views)
Solution
Accepted by topic author Sinan_Ismael

Yes, read the detailed help for the Write Key VI.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 10
(3,498 Views)

@Sinan_Ismael wrote:

Hi everyone,

 

I faced recently something strange with Config File. In my Software, a key is updated according to a condition, but I noticed that the MyConfig.ini is not updated if it's not closed. I mean, in LabVIEW the file is opened and the data is written to it. But If I open the file in Windows, I see it's still not updated. If I close the file in LabVIEW, then it will be updated.

 

I am wondering, if this is right?

 

 

 


That sounds right to me... Usually Windows will lock a file when one program has it open. Then if another program tries to open that file it will get a sharing violation and Windows would usually pop up a box asking if the second program wants to open it in read only mode or open a copy of the file. 

 

 I am only guessing because I use XML for all my config files, but It's also possibly that file changes are not written to the file until it is closed. This could be a function of the LabVIEW config file VI's.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 10
(3,491 Views)

Yes, that is correct, only the close file will flush the changes from memory to file.

 

The close file even has an option to discard all the changes, it is possible only if it is flushing at close.

santo_13_0-1630076077613.png

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution
Message 4 of 10
(3,469 Views)

Just to add some details...

 

The Configuration File reference really just holds lookup tables.  As you add to the configuration, only those lookup tables are updated (in memory).  The file itself is only touched when opening (read the file to parse it and build the tables) and closing (replace the file using the contents in the tables).



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 10
(3,454 Views)

I tend to make my config file writes atomic because I don't want to deal with what happens if my code crashes before the changes were written.  I mean, I know I can include closing the config in the cleanup state, but it's usually unimportant to me to have the config file reference remain open, so why not "open, write, close" all at once.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 10
(3,433 Views)

I have rarely needed write to configuration files.  I will edit them in a text editor and read the configuration at application start up.  Granted, over the last couple of years, I have moved on to using XML and/or JSON for configuration data (more commonly JSON).  The main reason is I found I really needed a hierarchy for defining my instruments. 



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 10
(3,413 Views)

Yes, you are right.

 

Sinan_Ismael_0-1630911559285.png

 

0 Kudos
Message 8 of 10
(3,357 Views)

If you install the "Hidden Gems in vi.lib" tool from the VI Package Manager you will find a VI called LV Config Write String.vi in the Files menu. That VI will write the key to file instantly, but you will have to provide the value to write as a string.

 

Now if you open the Close Config File.vi you can see how it converts the file refnum to a queue and then within the Save Config File.vi it also calls it has a function that acts on that queue to generate the needed strings....which also allows you access to the Config to String.vi which shows you the type of the queue and how to extract the key value...So you have all you need to intervene in a number of ways here. You could combine the latter VI with the hidden gem one, or rewrite the Save Config File-subVI of close config file to do it.

0 Kudos
Message 9 of 10
(3,310 Views)

As I never see a reason to keep the reference to the config file alive, I just open it, do reads and/or writes to it, then close it all at once.  No need to hold the reference open and then have to worry about closing it, should something untoward happen.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 10
(3,297 Views)