LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing scripts in CVI

AL S, im stuck on this one. can you give me an example on my project just one line, im a visual person. its not working for me
0 Kudos
Message 11 of 27
(2,734 Views)

hi AL for some reason after i inserted this he giving me alot of errors affecting one of my call backs.

can you assist me. I went off the example that you gave. and also put in some test conditions

 

 

 

       if (strlen(VARIABLE_HOLDER))
          {
    
              if ( !strstr(VARIABLE_HOLDER,"//"))
              {
                    if (strstr(VARIABLE_HOLDER,"MMW_CHASSIS_SW1" ))
                        
                    {
                            strtok(VARIABLE_HOLDER," ");
    
                            strcpy(BINARY_TO_OUTPUT,(strtok(NULL," ")));
        
                            CHANGE_CHAR_TO_INTERGER=atoi(BINARY_TO_OUTPUT);

                        //    SetCtrlVal(panelHandle, PANEL_NUMERIC_1,CHANGE_CHAR_TO_INTERGER);
    
                    }
               
                 else     if (strstr(VARIABLE_HOLDER,"MMW_CHASSIS_SW2" ))

                   {         strtok(VARIABLE_HOLDER," ");
    
                            strcpy(BINARY_TO_OUTPUT,(strtok(NULL," ")));
        
                            CHANGE_CHAR_TO_INTERGER=atoi(BINARY_TO_OUTPUT);

                        //    SetCtrlVal(panelHandle, PANEL_NUMERIC_1,CHANGE_CHAR_TO_INTERGER);
                   }
    

                

                              else     if (strstr(VARIABLE_HOLDER,"MMW_CHASSIS_SW2" ))

                   {         strtok(VARIABLE_HOLDER," ");
    
                            strcpy(BINARY_TO_OUTPUT,(strtok(NULL," ")));
        
                            CHANGE_CHAR_TO_INTERGER=atoi(BINARY_TO_OUTPUT);

                            //SetCtrlVal(panelHandle, PANEL_NUMERIC_1,CHANGE_CHAR_TO_INTERGER);
                   }
                            
                                  else     if (strstr(VARIABLE_HOLDER,"MMW_CHASSIS_SW3" ))

                   {         strtok(VARIABLE_HOLDER," ");
    
                            strcpy(BINARY_TO_OUTPUT,(strtok(NULL," ")));
        
                            CHANGE_CHAR_TO_INTERGER=atoi(BINARY_TO_OUTPUT);

                        //    SetCtrlVal(panelHandle, PANEL_NUMERIC_1,CHANGE_CHAR_TO_INTERGER);
                   }
    
                                      else     if (strstr(VARIABLE_HOLDER,"MMW_CHASSIS_SW4" ))

                   {         strtok(VARIABLE_HOLDER," ");
    
                            strcpy(BINARY_TO_OUTPUT,(strtok(NULL," ")));
        
                            CHANGE_CHAR_TO_INTERGER=atoi(BINARY_TO_OUTPUT);

                        //    SetCtrlVal(panelHandle, PANEL_NUMERIC_1,CHANGE_CHAR_TO_INTERGER);
                   }
                                    
                                      else     if (strstr(VARIABLE_HOLDER,"MMW_CHASSIS_SW5" ))

                   {         strtok(VARIABLE_HOLDER," ");
    
                            strcpy(BINARY_TO_OUTPUT,(strtok(NULL," ")));
        
                            CHANGE_CHAR_TO_INTERGER=atoi(BINARY_TO_OUTPUT);

                        //    SetCtrlVal(panelHandle, PANEL_NUMERIC_1,CHANGE_CHAR_TO_INTERGER);
                   }
    
                                           else     if (strstr(VARIABLE_HOLDER,"MMW_CHASSIS_ATTN" ))

                   {         strtok(VARIABLE_HOLDER," ");
    
                            strcpy(BINARY_TO_OUTPUT,(strtok(NULL," ")));
        
                            CHANGE_CHAR_TO_INTERGER=atoi(BINARY_TO_OUTPUT);

                        //    SetCtrlVal(panelHandle, PANEL_NUMERIC_1,CHANGE_CHAR_TO_INTERGER);
                   }
    
             }


}   

fclose(f1);
//GetKey();
return 0;
}

 

 

0 Kudos
Message 12 of 27
(2,723 Views)

Never AL S i fix it, the thing that happen was I had included a Defines.h  in my code. ANd in the HEADER FILE WAS COMMAND CALL RESET, which was one of my

 

CALL BACKS COMMANDS. thats funny. it took me a hour to figure that out. thats why i couldnt get my code to work. but im able to read each line of the text file.

 

thanks for advice.

0 Kudos
Message 13 of 27
(2,720 Views)

Darnell:

 

I have a question on what you want your project to do.  Do you still want to accept interactive input from each numeric control on your UIR or do you just want to accept data from the script file?  If you want to do both, think about leaving your Update button accepting input from the numeric controls, and add a Run Script button to read the data from the script file instead.  Your may also want to allow the user to select the script file as in ChillerParser.zip example I posted here.

 

To read from a script file, you don't want to read the file for each numeric control, you want to read the file once and update any numeric control as commanded by the script file.

 

As I suggested earlier, don't read the file one character at a time using getc(), read it one line at a time using gets().

 

It looks like you're making things more complicated using strtok(), strcpy(), and atoi().  Why not use sscanf() as I did in the example I posted?  You can read your switch value directly to an integer.

 

Good idea testing for comments ("//").

 

With the format of your MMW chassis commands, parsing is even easier.  Try someting like this.

 

   fpScript = fopen (scriptName, "r");
   if (fpScript == NULL)
   {
    sprintf(statusMsg, "Error opening file %s", scriptName);
    MessagePopup ("File Open Error", statusMsg);
   }
   else
   {
    while (fgets (scriptLine, 256, fpScript) != NULL)
    {
     if (strstr (scriptLine, "MMW_CHASSIS") != NULL)
     {
      // found MMW Chassis command
      // expect a command string and a switch value
      items = sscanf(scriptLine, "%s%d",cmdString, &switchValue);
      if (items == 2)
      {
       if (strcmp(cmdString,"MMW_CHASSIS_SW1") == 0)
       {
        panelHandleSetCtrlVal (panelHandle, PANEL_NUMERIC_1, switchValue);
        BIT_CONVERSION(PANEL_NUMERIC_1, BINARY_READ_1);
       }
       else if (strcmp(cmdString,"MMW_CHASSIS_SW2") == 0)
       {
        panelHandleSetCtrlVal (panelHandle, PANEL_NUMERIC_2, switchValue);
        BIT_CONVERSION(PANEL_NUMERIC_2, BINARY_READ_2);
       }
       // add else if blocks for other controls
       // ...
       else
       {
        sprintf(statusMsg, "Unknown command at line %d:\n%s",
         lineNumber, scriptLine);
        MessagePopup ("Script Error", statusMsg);
       }
      }
      else
      {
       sprintf(statusMsg, "Error in script file line %d\n%s",
         lineNumber, scriptLine);
       MessagePopup ("Script Format Error", statusMsg);
      }
     }
     
     lineNumber++;
    }
    fclose(fpScript);
   }

0 Kudos
Message 14 of 27
(2,707 Views)

IS there a sample program of talking to a device card? and also bitWise OR program that i can take a look at.

 

im trying to refresh my memory on OR iing bits.

 

 

0 Kudos
Message 15 of 27
(2,704 Views)

Question 1: I'm not clear on what you mean by talking to a device card.  There are several examples on communication.  Which version of CVI are you using?

In CVI 6, from the project window go to Help >> Contents,  click on the Index tab and enter Example, then click on I/O Interfaces.

In CVI 9.01, go to Help >> Find Examples, go to the Browse tab, Browse according to: Task, and click on Hardware Input and Output.

 

Question 2:

In C, bit-wise OR-ing is done with the | operator (shift-backslash on the keyboard).  Logical OR-ing (True or False) is done with ||.

 

Bit-wise OR-ing is done to set an individual bit in a binary value.  Bit-wise OR-ing can only change a 0 to a 1; it cannot change a 1 to a 0.  (Bit-wise AND'ing using the & operator can change a 1 to a 0).  If the bit being OR'ed is already 1, the value is unchanged.

 

1 | 0 = 1

1 | 1 = 1

1 | 2 = 3

0x55 | 0xAA = 0xFF

 

Here's some code that marches through some bit patterns.

#include <utility.h>
#include <ansi_c.h>
main()
{
 unsigned int a, b, i;
 
 
 a = 0;
 
 for (i=0; i<8; i++)
 {
  b = 1<<i;
  
  printf("%0x bit-wise OR'ed with %0x = ", a, b);
  a = a | b;
  printf("%0x\n", a);
 }
 
 a = 0x55;
 b=0xAA;
 
 printf("\n%0x bit-wise OR'ed with %0x = ", a, b);
 a = a | b;
 printf("%0x\n", a);
 
 a = 3;
 b=1;
 
 printf("\n%0x bit-wise OR'ed with %0x = ", a, b);
 a = a | b;
 printf("%0x\n", a);

 printf("\npress any key to continue...");
 GetKey ();
 
 
}

0 Kudos
Message 16 of 27
(2,700 Views)

So basically its the same logic over and over. you write some thing and then you read.

 

cool.

 

 

can you explain 0x8000. or maybe 0x0,or  0x804000?

 

just want to get the understanding of  these type of address.

 

 

 if (ibsta & 0x8000) can you explain this line of what its doing. I understand what any particular if statement does. I want a brief defnition of just 0x8000

0 Kudos
Message 17 of 27
(2,696 Views)

0x8000 is just a number in hex.  0x is the prefix to indicate hexadecimal representation to a C compiler.

 

0x8000 is a 16 bit number, with bit 15 (starting at bit 0) set to 1, and all other bits are set to 0.

 

0x8000 = 1000 0000 0000 0000 in binary (each hex character represents 4 binary bits)

0x8000 = 32768 decimal

 

0x804000 is a 24 bit number, with bits 23 and 14 set to 1, and all other bits set to 0.

0x804000 = 1000 0000 0100 0000 0000 0000

 

Many drivers and functions use bit-encoded values.  Each bit can mean one thing if it's set and another if it's cleared.  With having the value bit-encoded, you can create a combination of options using just one number.

 

if (ibsta & 0x8000) is testing if bit 15 is set to 1 in the value ibsta.  In this case, you are doing a bit-wise AND.  (ibsta & 0x8000) will only be TRUE is bit 15 in ibsta is 1.

For example

given ibsta = 0x123

(ibsta & 0x8000) is FALSE.  Bit 15 is 0, not 1, in the value 0x123.

given ibsta = 0xFFFF

(ibsta & 0x8000) is TRUE. Bit 15 is 1 in the value 0xFFFF.

Message Edited by Al S on 08-31-2009 04:37 PM
0 Kudos
Message 18 of 27
(2,695 Views)

1000 0000 0000 0000   , i know this is  a 16 bit. but0x8000

 

does the 1 respresent 8 0r something.

 

 

what does 0x3000?      in binary

0x2000? in binary

 

 

trying to catch the pattern

0 Kudos
Message 19 of 27
(2,691 Views)

ibsta is the global status variable for GPIB operations.  Bit 15 in ibsta is the error flag.  If bit 15 is set, an error occurred on the last GPIB operation.

 

Look at the GPIB sample project that ships with CVI and at the CVI help on GPIB functions.

0 Kudos
Message 20 of 27
(2,691 Views)