LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with RegExpr_FindPatternInText()

Solved!
Go to solution

LabWindowsCVI does not compile the search function RegExpr_FindPatternInText()

It says 'Missing prototype'.

 

Q1. What include might I be missing? FindPattern() works fine.

 

I need to search a string for certain words and skip white spaces, CR's etc.

I want to search from the beginnng but I don't know what size the string will be.

 

Q2. Do I have to Get the string length prior to calling this function?

 

 

In this example I need to find out if a string contains the words 'serial', 'test', and 'passed'. The string can contain other characters and white spaces etc.

 

result = RegExpr_FindPatternInText ("fwmserial uetest owpassed * ",NOT_CASE_SENS, -1, "serial test passed",0, 1, RegExpr_MatchLargestNumChars,matched, matchPosition, matchLength);

 

I would like this test to pass.

Q3. Will this work or do I need some backslashes etc.? I can't try it until I can compile.

 

 

V8.5.1

WIN XP Pro

 

Thanks.

0 Kudos
Message 1 of 7
(4,503 Views)

Q1. FindPatter comes from the Formatting and I/O library, which is one of the standard libraries CVI uses; when you use some of the functions in these libraries the editor asks you to include the appropriate file and that's all. RegExpr_FindPatternInText comes from Regular Expression instrument, which need to be included in the project before you can use its functions; you can do this by loading it into the Instrument menu or adding it to the library menu (Library >> Customize and add the corresponding .fp file, next restart CVI). In any case you must #include "regexpr.h" into your code (the editor will do i for you once the instrument is included in the project).

 

Q2-Q3. If you want to search the text in the entire string and this one is nul-terminated, you can simply pass -1 in Text Lenght parameter. Nevertheless, you cannot perform a serch like the one you reported in a single pass, since the entire regular expression must be found in the string in the exact way it is passed to the function; moreover, you must pass the string to search in the first parameter of the function, and the text where to find theregular expression as Text to Search parameter. Finally, the last three parameters must be passed by reference. Your search can be performed this way:

 

    gMatchPosition = 0;
    z = RegExpr_FindPatternInText ("serial", 0, "fwmserial uetest owpassed * ", -1,
            RegExpr_SearchForwards, RegExpr_MatchLargestNumChars,
            &matched, &matchPosition, &matchLength);
    if (matched) gMatchPosition += matchPosition;
    z = RegExpr_FindPatternInText ("test", 0, "fwmserial uetest owpassed * " + gMatchPosition,
        strlen ("fwmserial uetest owpassed * ") + gMatchPosition,
            RegExpr_SearchForwards, RegExpr_MatchLargestNumChars,
            &matched, &matchPosition, &matchLength);
    if (matched) gMatchPosition += matchPosition;
    z = RegExpr_FindPatternInText ("fwmserial uetest owpassed * " + gMatchPosition,
        strlen ("fwmserial uetest owpassed * ") + gMatchPosition,
        "passed", -1, RegExpr_SearchForwards,
        RegExpr_MatchLargestNumChars, &matched, &matchPosition, &matchLength);



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 7
(4,492 Views)
Forgot to say that you can look at samples\toolbox\RegEx.prj example for a guide on using this instrument.


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 3 of 7
(4,489 Views)

Thanks for the help compiling RegExpr_!

 

/* these words appear in this order but there could be characters, spaces etc. between them */ 

const char FindSer[] = "{serial}|{passed}";

const char FindMem[] = "{memory}|{passed}";

const char FindPig[] = "{pig}|{passed}";

const char FindClk[] = "{clock}|{passed}";

const char FindFlt[] = "{floating}|{passed}";

const char FindCache[] = "{cache}|{passed}";

const char FindEeprom[] = "{eeprom}|{passed}";

const char FindFlsh[] = "{flash}|{passed}";

const char FindEth[] = "{ethernet}|{passed}";

const char FindScsi[] = "{scsi}|{passed}";

 

I was hoping I could use the Find*[] string that would check for all words in one RegExpr_FindPatternInText() call.

I could then find all with 10 calls embedded in a for loop if I put the Find strings in an array.

 

But it looks like it would take two calls the RegExpr_FindPatternInText() to determine if both words appear.

 

Here is one example of a text body that I am searching (this data is received from an RS-232 port and each line is put into a string buffer):

 

"Nitro Power Up Serial Test  PASSED"
"Nitro Power Up Memory Test  PASSED"
"Nitro Power Up PIG Counter/Timer Test   PASSED"
"Nitro Power Up Real Time Clock Test PASSED"
"Nitro Power Up Floating Point Test  PASSED"
"Nitro Power Up Cache Test   PASSED"
"Nitro Power Up EEPROM Test  PASSED"
"Nitro Power Up Flash Test   PASSED"
"Nitro Power Up Ethernet Test    PASSED"
"Nitro Power Up SCSI Test    PASSED"

0 Kudos
Message 4 of 7
(4,477 Views)

I can think of a couple of ways to manage your problem:

 

1. (the simplest and most rude) Perform you loop with two calls for each iterations

 

2. Preprocess each string putting all spaces away and then search for "SerialTestPASSED" and so on

 

3. (More efficient in my opinion) Search each string for "FAILED", "NOT PASSED" or whichever is the message received on a failed test: only in case it is found, search the string for the description of the failed test (a simple extraction from the 15th character up to matchPosition position in the previous search). In this case even a simpler FindPattern is enough



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 7
(4,458 Views)

Hi Roberto.

 

I had previouly thought about 3. but I am not 100% convinced yet. With the additional identifier I would have error information on which test Failed.

Although if a FAILED is detected, I could do another failed search to find the source.

 

Onother issue is that I do not have the source code of the legacy device under test so I do not know exactly what the data stream will contain on an error condition.

I will have the DUT running this week and I am not sure yet if I can force it to send any particular FAILED messages. It is a black box scenario.

For now I am going off a previousy written test document where all the testing is done manually with 3 different PC's each running hyperterminal type programs (pcplus) for testing.

LabWindows will eliminated all the manual comms testing and speed up completion.

 

Thanks for your valuable input.

 

PS. Too bad there wasn't an AND modifier like "{serial}&{passed}"

0 Kudos
Message 6 of 7
(4,452 Views)
Solution
Accepted by topic author NI Nubie

The '.' and '*' work with only one call to RegExpr_FindPatternInText().

If both are used together then any and all characters are ignored between the three token search words.

 

"Serial.*Test.*PASSED"

0 Kudos
Message 7 of 7
(4,418 Views)