LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

integrating C++ codes in Labwindows

Hello

 

I am quite new to Labwindows. I have a C++ windows console program that generates a Square wave signal and saves the data file as ".sig". When the program is run, the user enters the period and amplitude.

I need to integrate the same program in Labwindows. The GUI in Labwindows shoud look like this. See attachment.I have already created the user controls in gui, but i dont know how to integrate the C++ code ( like connecting the inpout in C++ program here in CVI gui input control.

 

any ideas?

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 1 of 26
(4,499 Views)

Hi,

 

for integration of the GUI with your source code it might be helpful to look at the many samples provided with CVI. You can use the example finder and search for UI. You might want to start with the project simple.cws

 

Concerning your C++ code, you will need to manually change it to C code because CVI does not support C++.

0 Kudos
Message 2 of 26
(4,493 Views)

Could you please give a small example for it? I mean .. i have gone through the examples available in CVi, but could not understand a thing,

Could you please give a short example project for this:

 

Adding two numbers. Here the user enters the two numbers in Visual C++ application. How can one select these inputs as control in a CVI GUI.

 

#include <iostream>
using  namespace std;
int main()
{
int number1,number2,answer;
cout << "number1? ";
cin >> number1;
cout << "number2? ";
cin >> number2;
answer = number1 + number2;
cout << "Answer is " << answer;
}

 

----------------------

 

Number 1 & number 2 are two controls on User interface GUI in CVI. I am using a 2009 CVI version.

 

Thanks

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 3 of 26
(4,471 Views)

OK,

 

here is a simple example.

 

 

0 Kudos
Message 4 of 26
(4,466 Views)

Hi Nghtcrwlr,

 

Have you succeeded with your efforts?

0 Kudos
Message 5 of 26
(4,397 Views)

Hi Wolfgang

 

Thnx for the example. I was trying to understand your example and to implement a similar one by myself. It was succuessful. Now am trying to find a solution for my question using this one.

Once something happens i will ask your help again.

 

Thankyou very much!!

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 6 of 26
(4,394 Views)

Hey Wolfgang

 

Now i am trying soemthing else. Thought of doing the work step by step. I need to get display of an image based on the type of ring selected.

Here is the full code attached. when i select squarewave i need its image to be displayed. Is there something worng with my code??????

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 26
(4,381 Views)

Hi,

 

it appears that your question is almost the same as the one posted here ? Duplicated posts will not speed up answers. Most contributors here are volunteers and may be busy...  

0 Kudos
Message 8 of 26
(4,376 Views)

Sorry Wolfgang. After posting it here only i recoginzed that it is better to post it as a seperate question . thats why i posted in in another thread. and  unfortunately I forgot to delete it from here.

 

 

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 9 of 26
(4,342 Views)

I have a generate button in tzhe front panel. When i click the generate button, i shoukd perform the following C++ code. COuld you please check whether this is correct. I have manually changed it to C code.  But it is not working .

 

-.------------------------------------------------------------------------------------------------------

 

int CVICALLBACK GenerateCallback (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
 {
  case EVENT_COMMIT:
   
   

double p ,a;

double square(const double x)

{
 // Period and amplitude.
 static const double period = (p/2);
 static const double amplitude = a;

 // Force positive argument.
 const int neg = x < 0.0;
 const double xx = neg ? -x : x;

 // Scale the argument and compute the return value.
 const double x_scaled = xx - floor(xx / period) * period;
 const double ret_val = x_scaled < period / 2.0 ? amplitude : -amplitude;

 // Antisymmetric square wave.
 return !neg ? ret_val : -ret_val;
}

struct POINT
{
 double x;
 double y;
};

int main(int argc, char* argv[]) //; <= no semicolon here
 {
 unsigned int n;

 //cout << "Maximum number of Samples = " <<  endl;

 int no_of_points = 130944; // default value

 //cin >> no_of_points;

 //if(argc > 1)

  //std::istringstream(argv[1]) >> no_of_points;

  POINT* points = new POINT[no_of_points];

  cout << "Enter the Period :\n";

  cin >> p;

  cout << "Enter the Amplitude:\n";
  cin >> a;

  int w ;

  double g= 512;

  //Create a file to write to
  FILE *OutFile = fopen("Extern_stimulussignal.sig","w");

  for(w=0;w<10;w++)
   {
    const double increment = 1.0;
    points[0].x = 0;
    points[0].y = square(points[0].x);

    for(n = 1; n <= (128*g)/pow((double)2, w); n++)
     {
      points[n].x = points[n-1].x+ increment;
      points[n].y = square(points[n].x);
     
      printf("%12.7f\t%12.7f\n", points[n].x, points[n].y);
      
      //Send data to file
      fprintf(OutFile,"%12.7f\n", points[n].y) ;
         
      //("%12.7f\t%12.7f\n", points[n].x, points[n].y);
     }
   }

 //Close the file
 fclose(OutFile);

 cout << endl;

 cin.get();

return 0;
}

 

   
   break;
 }
 return 0;
}
-----------------------------------------------------------------------------------------------------------------------

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 10 of 26
(4,310 Views)