LabWindows/CVI Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
Tholar

CVI IDE Enhancement - Custom addins/Programmatically control IDE

Status: New

I utilize arrays of function pointers (recipe in a state machine) in a couple of projects.  I have the same general definitions for each of the functions (return type, parameter, a few calls inside that are used in each function, commenting, etc...) inside the array.  I have written an application that can scan all of my header files in the project folder, create a list of unique functions, I can then drag functions into the array or type names for new functions.  Currently when I accept my input all I can really do is copy the new generated code to the clip board.

 

What I would like to do is:

1) have it insert any new function declarations into a specific header file (which may be open in the ide with pending changes that haven't been saved)

2) Insert the array of function pointers into the current cursor location inside the current source file in the ide

3) Insert any new function definitions in appropriate files.

 

In my current app I am afraid to open and change files, not know if there are any pending changes in CVI not saved yet.  Would hate to loose all that hard effort if I forget to press CTRL+S.

 

I think it would be wonder full if when typing a statement like "if " the ide would automagically replace it with "if () {} else {}" with the cursor inside the ()...if the else isn't populated it drops.  Same thing for a for loop.  This is only because I hate typing, but I hate using a mouse more, perhaps soon we can have "thought to code".  Also, you have to know that I am the type of person that if they need to a task a second time, a program is written. 

 

So, to ease my fears I would like to be able to run a tool that when it is ready to write to a file I can manipulate the code directly through a CVI api or something.  If this already exists please point me in the right direction.  I looked at the function panels, there is an insert button for those, but what I want is more complicated than a single function.

2 Comments
LuisG
NI Employee (retired)

Hi Tholar,

 

Although it wouldn't be as sophisticated as what you are suggesting, you could conceivably accomplish some of these tasks with keyboard macros. Have you tried that? Granted, you'd probably have to create different macros for different purposes, which would require you to have to remember multiple shortcut key combinations, but it might still be feasible.

 

Luis

Tholar
Member

Hello Luis,

 

Thank you for your suggestion, but I have found that macros don't cover my needs.  I am looking for something that is dynamically loading content from all of the header files within my project, provides a user interface for me to drag functions into my "array", allowing me to reorder them or create new function prototypes.  An example of the state machine style I am utilizing is below.  I am wanting to populate arrays like program_states using this tool, where functions like wait_for_enough might be in a header file/other source file.  Also if it didn't exist, create the prototypes as well as populate the array.

 

#include <stdio.h>
#include <conio.h>

int State=0;
int Choice=0;
double Coins=0.0;

typedef int (*int_f_pointer)(void);

int wait_for_enough(void);
int wait_for_decision(void);
int dispense_choice(void);
int return_excess(void);

int_f_pointer program_states[]=
{
wait_for_enough,
wait_for_decision,
dispense_choice,
return_excess
};

char *Prompts[]=
{
"Insert money",
"Please make a selection",
"Enjoy",
"Kaching...Kaching"
};

char *Selection[]=
{
"Refund",
"Pepsi",
"Coke",
"Diet Coke"
};

int main(int argn, char *argv[])
{
 int_f_pointer fpointer=program_states[State];
 printf("%08X\n",fpointer);
 system("CLS");
 while(fpointer())
 {
  fpointer=program_states[State];
 }
 return 0;
}

int wait_for_enough(void)
{
 char ch;
 printf("\rEnter Money (%2.2f) (N,D,Q,X): ",Coins);
 if(!feof(stdin))
 {
  ch=getch();
  if(ch=='N' || ch=='n')
  {
   Coins+=0.05;
  }
  if(ch=='D' || ch=='d')
  {
   Coins+=0.1;
  }
  if(ch=='Q' || ch=='q')
  {
   Coins+=0.25;
  }
  if(ch=='X' || ch=='x')
  {
   printf("\rKeeping Your Change");
   return 0;
  }
 }
 if(Coins>=1.35)
 {
  printf("\rEnough Money (%2.2f)               \n",Coins);
  State++;
 }
 return 1;
}

int wait_for_decision(void)
{
 char ch;
 printf("\rEnter Decision (P - Pepsi,C - Coke,D - Diet Coke,R - Coin Return):");
 if(!feof(stdin))
 {
  ch=getch();
  if(ch=='P' || ch=='p')
  {
   Choice=1;
   State++;
  }
  if(ch=='C' || ch=='c')
  {
   Choice=2;
   State++;
  }
  if(ch=='D' || ch=='d')
  {
   Choice=3;
   State++;
  }
  if(ch=='R' || ch=='r')
  {
   Choice=0;
   State+=2;
  }
  printf("\n");
 }
 return 1;
}

int dispense_choice(void)
{
 printf("Now dispensing %s\n",Selection[Choice]);
 Coins-=1.35;
 State++;
 return 1;
}

int return_excess(void)
{
 printf("Your Change is %.2f\n",Coins);
 Coins=0;
 State=0;
 return 1;
}