LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

writes tag/value pair to a specific location inside .ini file

I am trying to write to .ini file. The tag/value pair need to be written to a location where the same tag exists. I tried this using Ini_PutRawString(). The location of new tag/value pair is written to the same location as previous tag with the same name. However, other data in the .ini file appears a little bit distorted.
 
Please advise.
 
 
0 Kudos
Message 1 of 11
(4,499 Views)
I never had problems with ini files so I cannot imagine what can be happening; can you detail a little more your sentence about distorsion in other parts of the ini file? Does this happens when you write that particular tag or always? Does this happen even if you write that tag only? Can you post an abstract of your code and a sample ini file before and after the modification?


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 11
(4,492 Views)

Be aware that these function panel routines strip out comments and any other unrecognised entries in the INI file. I tend to use the GetPrivateProfile... group of Windows API functions.

Kevin Snelling (CVI Certified developer)

 

0 Kudos
Message 3 of 11
(4,478 Views)
I insert tag DFSite1 into .ini file. The before and after is as attached. This happens everytime i insert the tag.
Download All
0 Kudos
Message 4 of 11
(4,443 Views)

Standard release of IniFile instrument splits too large lines into several lines as you can see in your file "after": this is clearly stated in the online help for Ini_PutString and Ini_PutRawString functions:

If the string is very long, the instrument driver will split it across multiple lines associated with the same tag name. This is done by generating new tag names, such as in:

<Tag Name> Line 0001 = "first part of line ........"
<Tag Name> Line 0002 = "second part of line ......."
<Tag Name> Line 0003 = "third part of line"

When you attempt to retrieve the string from the file by calling Ini_GetPointerToString, Ini_GetStringCopy, or Ini_GetStringIntoBuffer, you only need to enter the same Tag Name that you passed into this function. The instrument driver takes care of reconstructing the original single string from the multiple lines.

"very long" defaults to 80 characters and is not modifiable unless you create a modified copy of the instrument (it's defined in macro INI_NUM_CHARS_PER_LINE in inifile.c source file).

 

BTW I don't understand how you succeed in placing inside a ini file a text like

bearing = 1.12          ; bearing in decimal........

including the comment, unless the comment itself is part of the string. In this case, though, how you manage to store a string without surrounding quotes? Can you explain me? It could be useful sometimes to add comments; since now I managed it adding a field like itemComment = "comment string"

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 11
(4,431 Views)
I enter DFSite1 tag. Everthing before DFSite1 tag was already in the .ini file.
0 Kudos
Message 6 of 11
(4,429 Views)

Ok, so the instrument behaviour is this one:

  • An item simply read in ReadFromFile and written in WriteToFile without modifications maintain sorrounding quotes if it has and does not add them if it hasn't. This is true even if it exceeds 80 characters and is splitted into more rows
  • If you happen to use a PutString or PutRawString on that item, surrounding quotes are automatically added regardless the lenght of the item
  • In case you want to read a row with numeric values and a comment appended, you will receive an error (e.g. Ini_GetInt returns "Invalid integer number" error)

The strange thing is that a totally commented row should not be maintained over a WriteToFile as highlighted from Kevin, but I see that in your "after" file some commented rows are present...



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 11
(4,413 Views)
In CVI 8.5, we made the INI instrument preserve existing single-line comments. This was a consequence of user request 44JCHT00 and is mentioned in the CVI 8.5 readme. Roberto, I think this is why you are seeing the single-line comment maintained over a WriteToFile. Note that only lines begining with ; are considered single-line comments and preserved when written out.
0 Kudos
Message 8 of 11
(4,393 Views)
Thank you Mohan, I didn't focused on this new feature of 8.5 version: too much habit to previous versions features and too much literature to read on each upgrade! Smiley Wink


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 11
(4,391 Views)

I think there is another problem in your code.

In the before, the data were added using Ini_PutDouble() function, which is now overwritten with Ini_PutRawString(). The differnce results in  new " " quotes appearing in your text.

layosh 

0 Kudos
Message 10 of 11
(4,384 Views)