LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing scripts in CVI

HI.   Are there any tutorials on how to generate a write a script. I have not generate a script before. So im trying to see where to start from. I want to know things like, do i have to include then in my workspace in order to use the commands i create in the script file. So where do i start?

 

 im going to provide example of how my script file needs to look like. My question what do i need to do call those commands thats in that script file.

 

in my labwindow c code. because what i want to do is to use those commands in a test executive . basically i wrote a code already talking to a device which is a RS33 chiller through RS 232 interface cable. now im trying to write a script file with  commands so that a non software person edit at anytime and use. 

 

 

where do i start from?

 

                   

0 Kudos
Message 1 of 27
(6,016 Views)

First you need to define your command list and format.  Your program will need to know each command and what parameters are involved.

 

As far as your CVI project is concerned, a script file is just a data file that your program will read.  You do not include script files in you project.

 

If you want a non-programmer to be able to write a script file, the file will be a text file (regardless of what extension you choose to use).  Note that if you want your script extension to be .SCR, by default Windows associates .SCR files with screen saver files.  If you double-click on an SCR file, Windows will try to run it as a screen saver.  You can change the default action for .SCR files to be associated with Notepad instead to make editing the scritps easier.

 

Your program will need to allow the user to select which script to run.  You can use FileSelectPopup() for this.

You then need to open the file and read it line by line, parsing each line to identify the commands and parameters.

You can go fully ANSI C using fopen() and fgets() or fscanf().

Or you can use the CVI file functions OpenFile() and ReadFile() or ReadLine().

For parsing each line, you can use strstr() in a multiple if ...  else if... structure to find the command within the list you have.

 

Our firewall doesn't allow us to download .SCR files.  Could you post an example script as a .txt file?

Message 2 of 27
(6,002 Views)
Hi AL s I just posted a simple so i know where to start from.
0 Kudos
Message 3 of 27
(5,981 Views)

Hi AL s I just posted a simple so i know where to start from.

 

 

check the attachment below

0 Kudos
Message 4 of 27
(5,980 Views)

HI AL i sent another tex file that yu requested. is there any suggestion on parsing the script file are thereany examples in labwindows with parsing

 

 

im just trying to parse

 

 

just CHILLER 22

 

 

 

0 Kudos
Message 5 of 27
(5,941 Views)

Here is a simple example program that lets you select a script file, opens it, does some simple parsing with rudimentary error checking, and puts up some dialog boxes to let you know what it's doing.  (It doesn't really do anything).  It includes a copy of your script file, plus another copy with an intentional syntax error to show some error handling.

 

There are a lot more sophisticated parsing tools (like the regular expression tools that menchar and Roberto referred you to here: http://forums.ni.com/ni/board/message?board.id=180&thread.id=42653) but it looks like your needs are pretty simple and kind of a brute force method will work as well.

Message Edited by Al S on 08-26-2009 01:43 PM
0 Kudos
Message 6 of 27
(5,934 Views)

thanks i will brb. going to lunch lolololol

 

0 Kudos
Message 7 of 27
(5,930 Views)
I just noticed that in ChillerScript.c, I put the comments "add chiller command here" in the wrong place. I had them there before I added the error checking for the correct number of parameters. You should add the chiller commands in the if(items == 3) block directly above where the comments are now.
0 Kudos
Message 8 of 27
(5,896 Views)

question do i have to use the if statements to get to the line.

 

 or could i just go

strstr etc.......

0 Kudos
Message 9 of 27
(5,848 Views)

Darnell:

 

Which if statements are you asking about?  I added a few in-line comments to the if statements in the following chunk of code from the RunCallback function in ChillerScript.c.  All of the if statements are important.

 

 

      if (strstr (scriptLine, "SET_TEMP") != NULL)  // check if command is SET_TEMP
      {
       items = sscanf(scriptLine, "%s%s%d",
         tmpString, tmpString2, &temperature);
       if (items == 3)  // check if command line had the 3 expected parameters
       {
        sprintf(statusMsg, "Setting temperature to %d",
          temperature);
        MessagePopup ("Temperature Set", statusMsg);
       // add chiller command here to set the temperature
       }
       else
       {
        sprintf(statusMsg, "Error parsing temperature from line %d\n%s",
          lineNumber, scriptLine);
        MessagePopup ("Script Format Error", statusMsg);
        
       }
       
      }
      else if (strstr (scriptLine, "READ_TEMP") != NULL)  // check for next command type

Message Edited by Al S on 08-31-2009 08:15 AM
0 Kudos
Message 10 of 27
(5,845 Views)