LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

SriptFile Logic help

Sure: you just need to read the content of the file in memory with Ini_ReadFromFile immediately after creating the IniFile object. Next you can update its contents with Ini_Put statements and write the updated file to disk.


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?
Message 11 of 33
(1,839 Views)

do you mean in this format?

   

    GetProjectDir(directoryPathName);
    Ini_ReadFromFile (iniStationController, directoryPathName);
    Ini_Dispose(iniStationController);
    iniStationController=Ini_New( 0 );
    Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
    Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
    Ini_WriteToFile(iniStationController, iniFilePathName);
    //system("notepad Config.ini");

0 Kudos
Message 12 of 33
(1,834 Views)
yea this process i need help with, for some reason the ini_new   erases all my sections and input only the section I requested.
0 Kudos
Message 13 of 33
(1,838 Views)

darnell wrote:

do you mean in this format?

   

    GetProjectDir(directoryPathName);
    Ini_ReadFromFile (iniStationController, directoryPathName);
    Ini_Dispose(iniStationController);
    iniStationController=Ini_New( 0 );
    Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
    Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
    Ini_WriteToFile(iniStationController, iniFilePathName);
    //system("notepad Config.ini");


A little bit of logic would help...

 

    GetProjectDir(directoryPathName);
    Ini_ReadFromFile (iniStationController, directoryPathName);

How could you read from the file to IniFile object if you haven't created it yet?


    Ini_Dispose(iniStationController);

If by chance a IniFile object would exist, here you have destroyed it (together with the content read from disk!)


    iniStationController=Ini_New( 0 );

Ok, now the object (a brand new object) has been created, but filled with anything


    Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
    Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
    Ini_WriteToFile(iniStationController, iniFilePathName);

Here you are writing to disk only the 2 elements filled in those lines.

 

Correct logic:

 

    IniText   iniStationController = 0;

 

    // Other code here (af any)

    GetProjectDir(directoryPathName); 
    // Dispose an existing object, if any

    if (iniStationController > 0) Ini_Dispose(iniStationController);

    // Create a new object 

    iniStationController = Ini_New( 0 );

    // Fill with content from file on disk

    Ini_ReadFromFile (iniStationController, directoryPathName);

    // Update some field 

    Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
    Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
    // Write the updated content to disk

    Ini_WriteToFile(iniStationController, iniFilePathName);

    // Dispose the object after using it

    if (iniStationController > 0) Ini_Dispose(iniStationController);



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?
Message 14 of 33
(1,859 Views)

correct, I found out the problem, it happens everytime.  its like you do something real simple and straight point, but its hard to pin point the

the simple misstake you made. dont get me wrong your logic is correct to a certain , but when I you call the Ini_

 

 

    GetProjectDir(directoryPathName);
    MakePathname(directoryPathName,CONFIG_FILE2,iniFilePathName);
    Ini_Dispose(iniStationController);
    iniStationController=Ini_New( 0 );
    //Ini_ReadFromFile (iniStationController,directoryPathName);//////////////this line is the misstake, the second parameter should be iniFilePathName

    Ini_ReadFromFile (iniStationController,iniFilePathName);correct line
    Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
    Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
    Ini_WriteToFile(iniStationController, iniFilePathName);
    Ini_Dispose(iniStationController);
    //system("notepad Config.ini");
 

   now im going to put in my test , thanks roberto for your help

0 Kudos
Message 15 of 33
(1,855 Views)

    // Other code here (af any)

    GetProjectDir(directoryPathName); 
    // Dispose an existing object, if any

    if (iniStationController > 0) Ini_Dispose(iniStationController);///// can you explain the reason for the greater >0 check?

    // Create a new object 

    iniStationController = Ini_New( 0 );

    // Fill with content from file on disk//////// can you explain the fill with content with file on disk?

    Ini_ReadFromFile (iniStationController, directoryPathName);

    // Update some field 

    Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
    Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
    // Write the updated content to disk

    Ini_WriteToFile(iniStationController, iniFilePathName);

    // Dispose the object after using it

    if (iniStationController > 0) Ini_Dispose(iniStationController);//I guess my problem is understanding the dispose function!!!

 

      I just need a lil assistance. 

0 Kudos
Message 16 of 33
(1,855 Views)

 411, 32   Operands of > have illegal types 'IniText' and 'int'.

 

 

im getting this error 

 

 

when i use the this test

 

    if(iniStationController > 0)
    {
        Ini_Dispose(iniStationController);
    }
 

0 Kudos
Message 17 of 33
(1,850 Views)

    // Other code here (af any)

    GetProjectDir(directoryPathName); 

    // Dispose an existing object, if any

    if (iniStationController > 0) Ini_Dispose(iniStationController);

///// can you explain the reason for the greater >0 check?

Sorry, my fault: variable is initialized to 0 and populated by Ini_New, which either returns NULL or a valid handle (iniText variables are really a pointer to an object in memory). The correct instruction is

    if (iniStationController) Ini_Dispose(iniStationController);

 

    // Create a new object 

    iniStationController = Ini_New( 0 );

    // Fill with content from file on disk

    Ini_ReadFromFile (iniStationController, directoryPathName);

//////// can you explain the fill with content with file on disk?

With ReadFromFile function the memory object is populated by the content read fromt the file. After this instruction you can query the elements read from disk with the appropriate Ini_Get functions

 

    // Update some field 

    Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
    Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
    // Write the updated content to disk

    Ini_WriteToFile(iniStationController, iniFilePathName);

    // Dispose the object after using it

    if (iniStationController) Ini_Dispose(iniStationController);

//I guess my problem is understanding the dispose function!!!

Like in any other case, you need to free the memory allocated by some particular object when you no longer need it: this is done by Ini_Dispose function which properly gets rid of all the memory allocated.

 

In case you want to study it, the inifile instrument is deployed at code level, that is you can find on your hard disk both the include and the source file of this instrument (they are located in <cvidir>\toolslib\toolbox folder), so you can look at it and understand how it's working



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?
Message 18 of 33
(1,847 Views)

Darnell:

 

Going back to your comment "for some reason the ini_new   erases all my sections and input only the section I requested":

I know Roberto already underlined what Ini_New() does, and it sounds like you got past that problem, but here's a more general suggestion.  If you don't understand the behavior of a CVI library function you're using in your program, study the help for that function.  CVI help is pretty good, but, just like with C code, you need to read it pretty carefully to understand it.

0 Kudos
Message 19 of 33
(1,825 Views)
Thanks al and roberto for your help. what is a good book for great error handling. Im just curious.
0 Kudos
Message 20 of 33
(1,819 Views)