The font used in the demo is bold 14-point NIDialog. To customize the font, click
. Move the text message control to the top left corner of the decoration control.
The font used in the demo is bold 14 point NIDialog. To customize the font, click
. Move the text message control to the top left corner of the decoration control.
The font used in the demo is bold 14 point NIDialog. To customize the font, click
. Move the text message control to the top left corner of the decoration control.
- Select File»Save As and save the UI as CVIDemo.uir. When you save this file, LabWindows/CVI automatically creates a header file (.h), which is the link between the .uir file and the .c file.
- Select File»Add File to Project.
- Return to the Project window and select Edit»Add Files to Project»Include (*.h).
- Select CVIDemo.h and click Add.
- Click OK.
Generating the Source Code
Complete the following steps to generate the source code:
- Return to the User Interface Editor and select Code»Generate»All Code. This command opens the Generate All Code dialog box.
- In the Generate All Code dialog box, select the Add to Current Project option in the Target Files section.
- Select MAINPANEL as the panel to load and display at startup. Then, enter panelHandle in Panel Variable Name.
- Select Quit and OK as the Select QuitUserInterface Callbacks.
- Click OK. LabWindows/CVI generates skeleton code, names the file CVIDemo.c, and adds the .c file to your project. You are now ready to modify the source code.
Modifying the Source Code
Complete the following steps to modify the source code required for the demo:
- Add the following code to the top of the file (under the include files already listed):
#include <analysis.h>
#include <ansi_c.h>
#include <cviauto.h>
#include "dataskt.h"
/************************************************************************
The following constants have been defined for use throughout the program.
MAX_POINTS represents the maximum number of points the user can acquire.
************************************************************************/
#define TRUE 1
#define FALSE 0
#define MAX_POINTS 2048
- Replace the existing panelHandle declaration with the following code.
/************************************************************************
numpoints holds the number of points the user requests. array stores
either the acquired data or the analyzed data. oldarray stores the
originally acquired data.
************************************************************************/
static int panelHandle, handle, numpoints=16;
static double array[MAX_POINTS], oldarray[MAX_POINTS];
static DSHandle dsData;
- In the main function, add the following bold code. This code opens a session to DataSocket and discards the session after use.
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "CVIDemo.uir", MAINPANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
// Open connection to DataSocket site.
DS_Open ("dstp://weather.ni.com/msdemo", DSConst_Read, dsDataCallback, NULL, &dsData);
RunUserInterface ();
DS_DiscardObjHandle (dsData);
DiscardPanel (panelHandle);
return 0;
}
- Insert the following code after the DataSocket handle declaration:
/****************************************************************************
This is the callback function for the DataSocket handle. For more information
on callback functions and DataSocket, refer to the DS_Open function panel help.
******************************************************************************/
void dsDataCallback (DSHandle dsHandle, int event, void *callbackData)
{
if (event == DS_EVENT_STATUSUPDATED)
{
HRESULT hr = NOERROR;
char message[1000];
hr = DS_GetLastMessage (dsHandle, message, 1000);
if (SUCCEEDED(hr))
ResetTextBox (panelHandle, MAINPANEL_STATUS, message);
}
}
This code is the DataSocket handle callback. For more information, refer to the DS_Open function panel help by right-clicking the DS_Open function and selecting
Recall Function Panel.
- Replace the existing AcquireData callback function with the following code:
/*****************************************************************
This callback is called when an event occurs onthe Acquire button.
If the button is clicked, the following happens:
1. Check to see how many points the user wants to acquire.
2. Acquire the specified number of points.
3. Output the resulting graph on the Original Data graph.
*****************************************************************/
int CVICALLBACK AcquireData (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
int size;
double *value;
switch (event)
{
case EVENT_COMMIT:
//Delete old graphs from the Original Graph display.
DeleteGraphPlot (panelHandle, MAINPANEL_ORIGINALGRAPH, -1, VAL_IMMEDIATE_DRAW);
//Get the number of points the user has requested.
GetCtrlVal (panelHandle, MAINPANEL_NUMBERPOINTS, &numpoints);
//Copy the data into oldarray[] as a backup.
DS_Update (dsData);
DS_GetDataType (dsData, NULL, &size, NULL);
value = malloc (size* (sizeof(double)));
DS_GetDataValue (dsData, CAVT_DOUBLE | CAVT_ARRAY, value, size*sizeof(double), 0, 0);
Copy1D (value, numpoints, array);
Copy1D (array, numpoints, oldarray);
//Plot the data onto the Original Graph.
PlotY (panelHandle, MAINPANEL_ORIGINALGRAPH, array, numpoints, VAL_DOUBLE, VAL_THIN_LINE, VAL_SOLID_SQUARE, VAL_SOLID, 1, VAL_GREEN);
free (value);
break;
}
return 0;
}
- To determine which analysis function the user wants to perform, replace the existing AnalyzeData callback function with the following. This code determines which analysis function the user wants to perform.
int CVICALLBACK AnalyzeData (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
int boolean, function, PointsToPlot=numpoints;
double *tempArray, df, *staticArray, dt=1/2048;
switch (event)
{
case EVENT_COMMIT:
/************************************************************************
The Copy1D function restores array with the original data acquired. This
functionality is important because every time you perform an analysis on
array, its original values are overwritten. If a user calls the Analysis
function multiple times without re-acquiring data, the program analyzes
existing data.
************************************************************************/
Copy1D (oldarray, numpoints, array);
tempArray = malloc (numpoints*sizeof(double));
staticArray = malloc (numpoints*sizeof(double));
staticArray = tempArray = array;
GetCtrlAttribute (panelHandle, MAINPANEL_ANALYSIS, ATTR_CTRL_VAL, &function);
/**********************************************************************
The switch statement determines which function to perform. The program
performs the appropriate analysis function and then plots the analyzed
data on the Analyzed Data graph.
**********************************************************************/
switch (function)
{
case 0:
// Power Spectrum
AutoPowerSpectrum (staticArray, numpoints, dt, tempArray, &df);
PointsToPlot=numpoints/2;
break;
case 1:
// Filter
Bw_LPF (staticArray, numpoints, 2048, 25, 5, tempArray);
break;
case 2:
// Power Spectrum with Filter
Bw_LPF (tempArray, numpoints, 2048, 25, 5, staticArray);
AutoPowerSpectrum (staticArray, numpoints, dt, tempArray, &df);
PointsToPlot=100;
break;
}
DeleteGraphPlot (panelHandle, MAINPANEL_ANALYZEDGRAPH, -1, VAL_IMMEDIATE_DRAW);
PlotY (panelHandle, MAINPANEL_ANALYZEDGRAPH, tempArray, PointsToPlot, VAL_DOUBLE, VAL_THIN_LINE, VAL_SOLID_SQUARE, VAL_SOLID, 1, VAL_WHITE);
break;
}
return 0;
}
- Add the following code to the Help callback below the case EVENT_COMMIT: statement:
/*This code displays the Help panel.*/
int CVICALLBACK Help (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
if ((handle = LoadPanel (0, "CVIDemo.uir", HELP)) < 0)
return -1;
DisplayPanel (handle);
RunUserInterface ();
DiscardPanel (handle);
- Save CVIDemo.c.
- Save the project.
- Select Build»Create Debuggable Executable to compile the project.
- Select Run»Debug CVIDemo_dbg.exe to run the application.