LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Lab windows UI for frequency response

How do i create an UI for the below code

 

 

#include <visa.h>
#include <ansi_c.h>
#include <cvirte.h>
#include <userint.h>
#include "stepresponse.h"
#include "toolbox.h"

static int panelHandle = 0;

#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
#define _CRT_SECURE_NO_DEPRECATE
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "visa.h"
#include "utility.h"

static ViSession defaultRM;
static ViSession instr;
static ViSession instr2;
static ViStatus status;
static ViUInt32 retCount;
static ViUInt32 writeCount;
static unsigned char buffer[100];
static unsigned char buffer2[100];
static char stringinput[512];
static double knobval[512];
static char komand[512];
static double Save[1001];

// Global variables
int f;
double x;
int i;
double j;
int k=0;
double n;
double stepval;
double pointval;
double pval;
double sval;
double g;
double slideval;
int radioButtonVal;

int main (int argc, char *argv[])
{
status = viOpenDefaultRM(&defaultRM);
status = viOpen (defaultRM, "device address", VI_NULL, VI_NULL, &instr);
status = viOpen (defaultRM, "address", VI_NULL, VI_NULL, &instr2);

status = viSetAttribute (instr, VI_ATTR_TMO_VALUE, 5000);
status = viSetAttribute (instr2, VI_ATTR_TMO_VALUE, 5000);

if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "stepresponse.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);


return 0;
}

// UI callback function prototypes

/// HIFN Exit when the user dismisses the panel.
int CVICALLBACK panelCB (int panel, int event, void *callbackData,
int eventData1, int eventData2)
{
if (event == EVENT_CLOSE)
QuitUserInterface (0);
return 0;
}

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

// comand for gr initialisation
strcpy(stringinput,"*IDN?");
status = viWrite (instr, stringinput, strlen(stringinput), &writeCount);

// read data from gr 'instr' to variable 'buffer'
status = viRead (instr, buffer, 100, &retCount);
printf("Data read: %s\n",buffer);

// comand for mulmr initialisation
strcpy(stringinput,"*IDN?");
status = viWrite (instr2, stringinput, strlen(stringinput), &writeCount);

// read data from mulmr 'instr2' to variable 'buffer2'
status = viRead (instr2, buffer2, 100, &retCount);
printf("Data read: %s\n",buffer2);

//SET MULTIMETER
strcpy(stringinput, "CONF:VOLTage:AC");
status = viWrite (instr2, stringinput, strlen(stringinput), &writeCount);


// set channel 1 of GENERATOR to function sin
strcpy(stringinput,"SOUR1:FUNC SIN");
status = viWrite (instr, stringinput, strlen(stringinput), &writeCount);


//use knob to set amplitude from GENERATOR
GetCtrlVal(panel,PANEL_NUMERICKNOB,knobval);
sprintf(komand,"SOUR1:VOLT %f",*knobval);
strcpy(stringinput,komand);
status = viWrite (instr, stringinput, strlen(stringinput), &writeCount);

//use knob to set MIN frequency from GENERATOR
GetCtrlVal(panel,PANEL_NUMERICKNOBFREQ,knobval);
sprintf(komand,"SOUR1:FREQ %f",*knobval);
strcpy(stringinput,komand);
status = viWrite (instr, stringinput, strlen(stringinput), &writeCount);

//set MAX value
GetCtrlVal(panel,PANEL_NUMERIC_3,&slideval);
g=slideval;

GetCtrlVal (panelHandle, PANEL_RADIOBUTTON, &radioButtonVal);
if (radioButtonVal == 1) {

//Input step value
GetCtrlVal(panel,PANEL_NUMERIC, &stepval);
sval=stepval;
n=sval;}

else
{
//Input point number
GetCtrlVal(panel,PANEL_NUMERIC_2, &pointval);
GetCtrlVal(panel,PANEL_NUMERICKNOBFREQ,knobval);
pval=((g - *knobval)/pointval);
n=pval;

}


j = *knobval;
for (f=j,k=0; f<=g; f+=n,k++)
{
sprintf(komand,"SOUR1:FREQ %f",(double)f);
strcpy(stringinput,komand);
status = viWrite (instr, stringinput, strlen(stringinput), &writeCount);

//DELAY!!!
Delay (0.1);

//READ FROM MULTIMETER
strcpy(stringinput, "MEASure:VOLTage:AC?");
status = viWrite (instr2, stringinput, strlen(stringinput), &writeCount);

status = viRead (instr2, buffer2, 100, &retCount);
printf("Amplitude read: %s", buffer2);

//save to array
x = atof(buffer2);

Save[k] = x;


}


//Display Output
printf("Result:\n");

putchar('\n');
for (i=0; i<k; printf("%3.1lf ",Save[i++]));
putchar('\n');

//sinepattern (100. Save[k], 180.0, 2.0, sine);
PlotY (panelHandle, PANEL_Output, Save, k, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, VAL_DASH, VAL_RED);

//printf("Closing Sessions\nHit enter to continue.");

// session closing
//fflush(stdin);
//getchar();
//status = viClose(instr);
//status = viClose(instr2);
//status = viClose(defaultRM);


break;
case EVENT_RIGHT_CLICK:

break;
}
return 0;
}

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

// session closing
fflush(stdin);
getchar();
status = viClose(instr);
status = viClose(instr2);
status = viClose(defaultRM);

QuitUserInterface(0);

break;
case EVENT_RIGHT_CLICK:

break;
}
return 0;
}

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

break;
case EVENT_RIGHT_CLICK:

break;
}
return 0;
}

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

break;
case EVENT_RIGHT_CLICK:

break;
}
return 0;
}


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

break;
case EVENT_RIGHT_CLICK:

break;
}
return 0;
}

int CVICALLBACK StepToggleCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
SetCtrlVal (panelHandle, PANEL_RADIOBUTTON_2, 0);
SetInputMode (panelHandle, PANEL_NUMERIC, 1);
SetInputMode(panel, PANEL_NUMERIC_2, 0);

break;
case EVENT_RIGHT_CLICK:

break;
}
return 0;
}

int CVICALLBACK PointToggleCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
SetCtrlVal (panelHandle, PANEL_RADIOBUTTON, 0);
SetInputMode(panel, PANEL_NUMERIC, 0);
SetInputMode (panelHandle, PANEL_NUMERIC_2, 1);

break;
case EVENT_RIGHT_CLICK:

break;
}
return 0;
}

0 Kudos
Message 1 of 4
(3,049 Views)

Where does the code come from? It already has instructions for driving controls on a panel, so I suppose the .UIR file should be included in the packet the code comes from.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 4
(3,007 Views)

Respected Sir,

   The task for me is to construct the UI for this code. As I don't know the basics of this lab window I m writing in this forum

0 Kudos
Message 3 of 4
(3,002 Views)

Who passed you the code? Is it a school / training task?

The best solution I can give you is to go through the getting started manual and learn CVI basics so that you understand how panels / controls are treated by the IDE and next go through your code and build the appropriate set of controls in your UI.

An alternative is to attend some CVI course either on line or in class.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(2,998 Views)