LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

search and replace string in a CVI file

Hello anyone with CVI experience,

I am new to CVI and only have limited experience writing PERL in Linux.  I am hoping to gain some information on how to write a CVI script that will search a particular CVI script and replace a function with another string/blockofcode so I can use it for a particular function.

Any advise would be greatly appreciated, for I am lost and have a deadline approaching at school.  I have spent much time on google and I am getting burnt out looking for a solutions.

Kind regards
0 Kudos
Message 1 of 6
(5,024 Views)

First of all, you must consider that CVI is not a scripting language, it's always a compiled one. That is, you cannot change source code on the fly neither in the compiled executable nor when running in debugging mode.

What you can do is to design your software so that its behaviour changes depending on some particular conditions (choice messages to the operator, content of some files, signals received from tcp/ip or from some acquisition device,,,) , but you must know the possible situations in advance and write code before running the application.

One of the possible option is to drive CVI via activeX so that you can create, compile and execute a different program from your application. A little example of these activities can be found in <cvidir>\samples\activex\cvi directory but it's not an easy way to walk bay especially if you are new to CVI. Moreover, it requires full installation of CVI on the target machine for all this to run.

Given this, if you can give us some more detail on your needs we can try to help you in more detail.

Message Edited by Roberto Bozzolo on 04-13-2007 08:47 AM



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 6
(5,016 Views)
Like Roberto said, it's not really clear what you want to achieve.
If you want to change functions during execution, you can use function
pointers.
If you want self-modifying code: forget it.
If you want to batch-change some code in the source files, you can always
install cygwin which will give you a perl in windows.
--
Guillaume Dargaud
http://www.gdargaud.net/
"1. Sort of
2. Sort of
3. Yes
4. Nope
5. Nope
6. Sorry, no
7. Not sure
8. No
9. Not sure
10. Technically yes." - Answers to the question: "Do the US
constitution amendments still matter ?"


0 Kudos
Message 3 of 6
(5,008 Views)
> If you want to batch-change some code in the source files, you can always
> install cygwin which will give you a perl in windows.

good advice, Guillaume Smiley Happy
although perl is also available standalone, you also get bash with cygwin, which is much more powerful than lame cmd.exe.
see the following perl script rxr.pl as example:

#!/usr/bin/perl

$searchfor = $ARGV[0];
$replacewith = $ARGV[1];
$error=0;
if ($searchfor eq "") {
    print "Regular Expression and String Replacement\nWritten by Ulli Meybohm, www.meybohm.de\n";
    print "Usage   :  rxr.pl from [to]\n\n";
    print "Program reads filelist from stdin and replaces every\n";
    print "\"from\"-String to \"to\"-string in these files.\n";
    print "If \"to\" is empty, every \"from\" string will be deleted.\n";
    print "Check the sourcecode, \"man perl\" and \"man perlre\" for more information.\n\n";
    print "Example 1: rxr \"umeybohm\@aol.com\" \"ulli\@meybohm.de\" < homepagefiles.lst\n";
    print "             This example replaces the old mail-address with my new one\n";
    print "             in every file listed in homepagefiles.lst.\n";
    print "Example 2: find * | grep \".html\" | rxr \"meybohm\@gmx.de\" \"ulli\@meybohm.de\"\n";
    print "             Does the same as E1, but replaces in every \".html\"-file\n";
    print "             recursively from the current working directory.\n";
    exit 1;
}

@files=<stdin>;
foreach $file (@files) {
    print "Processing ";
    print $file;
    chop $file;
    if (-e $file) {
        open(INPUT, "<$file");
        @text=<INPUT>;
        close (INPUT);
        foreach $row (@text) {
            $row=~s/$searchfor/$replacewith/ixg;
        }
        open(OUTPUT, ">$file");
        print OUTPUT @text;
                close(OUTPUT);
    } else {
        print "File does not exist! Skipping...\n";
        $error++;
    }
}
if ($error > 0) {
    print "Finished with ";
    print $error;
    print " errors!\n";
}
--
Once the game is over, the king and the pawn go back into the same box.
0 Kudos
Message 4 of 6
(4,992 Views)
Hello All,

I now see that I was very unclear on my objectives.  Hence, I will try to clear this up.

I am currently automating some CNC machines with Motion Assistant in a lab.  Motion Assistant is basically being used to generate CVI code for x particular moves.  Also, the lab has some in-house code in CVI that tells a VNA to take measurements and download data.  It does a little more than this, but the rest is irrelevant for this story.

Hence, after generating the CVI with Motion Assistant (MA), I need to use this code to move our CNC motors to a location.  Then, the in-house CVI code tells the VNA to measure x specific parameters.

So, this is what I need.  I need the MA CVI code to wait for the VNA CVI code to tell it to go ahead and execute (move), then when done with the move I need the VNA code to measure and then tell the MA CVI code to move, then measure, move, measure, move and so forth.

The problem that I am having is that the Motion Assitant setup only allows a pause in the motion with a keystroke or time (ms) before excuting the next move.  Since I need automation I am hoping to generate the code with Motion Assistant, "run a search and replace script" so that the MA CVI code now waits for a flag in the VNA CVI code to tell it to move.

We also plan on hard coding the VNA CVI code with a motion option that will have the flags for MA and so forth.

Hence, the key is that I need to develope a search and replace script, almost like regular expressions for a function called MotionErrChk(Measurement()); and replace the 'Measurement()' with either a Wait for measurement to be done block of code, or the similar Wait code from the VNA CVI program. 

Also, I did not write the VNA CVI program so I am working with another graduate student to learn it today.

Since I only know PERL I did consider using the cygwin but then decided against it, because I might not be working in the lab after this semester and someone will have to maintain it and no one knowsPERL.


Finally, I am not looking to change the code on the fly, but rather after it has been generated.  Then the two programs can be ran simultaneously after the script from MA has been re-created/massaged.

Thanks for your help, I really appreciate it.  Please me know if I made more sense this time.

Cheers,
em_student
0 Kudos
Message 5 of 6
(4,978 Views)
All,

I also forgot to change my thought process that CVI is not a scripting language.  Sorry Roberto for my inconsistancies.

Cheers,
em_student
0 Kudos
Message 6 of 6
(4,977 Views)