LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ini_SetSectionFilter

Solved!
Go to solution

Hi,

I want to know how to use the ini_SetSectionFilter funtions.

 

when read the help file: Ini_SetSectionFilter

int Ini_SetSectionFilter (IniText handle, Ini_SectionFilterFunc sectionFilterFunction, void *callbackData);

a new function needed to be defined

 

int CVICALLBACK FilterFunction(IniText theIniText, void *callbackData, char *sectionName);

 

anyway, how to define this  FilterFunction function? is there any sample codes? and, where I can get the iniText's members defines?

 

I'm try to save some testing data into files using the iniText functions because of the data is readable and searchable. but when data grows, I need  to read a subset of the saved data without the overhead of reading the entire file into memory.


Thanks a lot  in advance.

 

 

0 Kudos
Message 1 of 6
(3,535 Views)

Hi allen,

 

First of all, I do not believe ini files are a good way of storing test data.

They are mainly for storing and accessing later global settings of a test program, like GPIB addresses of the instruments and sometimes the test pass/fail limits.

The TDM Streaming Library can be a better solution for you.

I've never used it and you may need DIAdem to get the full power from it but at least it is designed for storing and reading back large amount of test data.

 

To answer your question, the filter function is like a callback. It is called automatically (if programmed) by the Ini_ReadFromFile function for every section name read from the file.

This filter function that you will write will get this section name automatically in its sectionName parameter and you can parse it to decide whether it is a section that you want to get data from.

 

You decide to skip the section name if your filter function returns 0 (zero). If you want to read the contents of the section you return 1.

That's it.

 

You've asked how to define the function. I do not know if there is a sample app for this in the CVI installation.

But, actually the code line you copied from the function help is a definition of the function.

 

Just paste it to your code among the other prototypes and write some code to implement it.

You should pass the name of your filter function ( given in the help text as "FilterFunction" ) as the second parameter to Ini_SetSectionFilter.

 

You can put a breakpoint in the implementation and see what you have in the parameters when it is called. 

Hope this helps. 

Message Edited by ebalci on 11-14-2008 11:37 AM
S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 6
(3,528 Views)

Thank you, ebalci,

 

my applications is for a sensor networks. say, we have 50pcs sensors, for about half an hour, we get the sensors readings and store it.

as the data is updated not so frequently,  also as no experience in using the TDM, we now use the iniText functions. as the stored file can be opened by any text editors, and at the same time is searchable in CVI via ini functions.

 

in your message: 

".....

the filter function is like a callback. It is called automatically (if programmed) by the Ini_ReadFromFile function for every section name read from the file.

This filter function that you will write will get this section name automatically in its sectionName parameter and you can parse it to decide whether it is a section that you want to get data from.

.....

"

 

you mentioned it can get its sectionName parameter. but the  sectionName parameter passed to whom? where i can read it? 

and, where i can find the member defines for the ini structure?

 

best regards,

 

 

0 Kudos
Message 3 of 6
(3,524 Views)
Solution
Accepted by topic author LV_allen

Hi again,

 

I may sound like I'm repeating myself, but it is because there is only one way of explaining this.

The sectionName parameter is passed to your callback as an input.

It is filled by Ini_ReadFromFile depending on the current section name it is reading.

 

So, first you need to declare and implement a function like this: int CVICALLBACK MyFilterFunction(IniText theIniText, void *callbackData, char *sectionName);

 

Second, you have to type this name (FilterFunction) as the second parameter in Ini_SetSectionFilter(...)

So your code will look like:  Ini_SetSectionFilter(iniHandle, MyFilterFunction, NULL);

Even at this stage your code will compile but you have to fill the MyFilterFunction soit operates as desired.

 

So, when you are implementing the MyFilterFunction, you will write something like this:

 

int CVICALLBACK MyFilterFunction(IniText iniHandle, void *callbackData, char sectionName[100])
{
if (sectionName[0] == 'A') return 1;
else return 0;
}

 

The example function I gave above will filter out (skip) all section names not starting with 'A'.

 

Hope this helps,

S. Eren BALCI
IMESTEK
Message 4 of 6
(3,517 Views)

Thanks, ebalci,

 

thanks for your help. 

 

 when I 1st view the function int CVICALLBACK MyFilterFunction(IniText theIniText, void *callbackData, char *sectionName);  i thought the parameter - char *sectionName , is a input  , but after reading your instruction, it's a output . then it's clear. thank you very much for the kindly help.

 

Best regards,

 

0 Kudos
Message 5 of 6
(3,503 Views)

Some more information:

 

You can turn off the filter by calling the function like this: Ini_SetSectionFilter(iniHandle, 0, NULL);

So you can give the user of the program to turn on/off filtering.

 

Using the ini file for such a purpose might be OK. I just wanted to point that if your data gets too big, the process may get slower.

That's why I suggested the TDM option as it is claimed to be a fast way of doing it.

 

Have a nice day! 

S. Eren BALCI
IMESTEK
0 Kudos
Message 6 of 6
(3,500 Views)