08-25-2009 08:08 AM
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?
08-25-2009 09:05 AM
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?
08-25-2009 01:05 PM
08-25-2009 01:06 PM
Hi AL s I just posted a simple so i know where to start from.
check the attachment below
08-26-2009 01:04 PM
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
08-26-2009 01:41 PM - edited 08-26-2009 01:43 PM
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.
08-26-2009 01:51 PM
thanks i will brb. going to lunch lolololol
08-27-2009 11:47 AM
08-31-2009 08:08 AM
question do i have to use the if statements to get to the line.
or could i just go
strstr etc.......
08-31-2009 08:14 AM - edited 08-31-2009 08:15 AM
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