I have a panel with a Graph on it. I launch this panel from my main application when the user selects a button. When this panel is open I sometimes have intermittent problems. It seems to effect the communication with a device I have connected to the USB. It does not happen often but seems to be related to when I change the size of the array I am sending to the graph. Specifically if I increase the size of the data sent to it, it has problems.
The array I send to this graph is dynamically allocated memory. After I send the data to the device I free the memory. Would this give the graph a problem? I figured after I populate the graph it must store this data in another memory location and does not need the original data array. Is this correct?
I am wondering if changing the size of the array being put on the graph might give it trouble. I don't think so because I have other graphs that I do the same thing to but they do not seem to have any trouble.
Here is where I launch the panel:
int CVICALLBACK DisplayMagnitudeGraph (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
if ((MagPanelHandle = LoadPanel (0, "mag_reader.uir", MAGNITUDE)) < 0)
return -1;
g_MagGraphActive = 1;
SetCtrlAttribute(panelHandle,PANEL_DISPLAY_MAGNITUDE,ATTR_DIMMED,1);
DisplayPanel (MagPanelHandle);
RunUserInterface ();
DiscardPanel (MagPanelHandle);
break;
case EVENT_RIGHT_CLICK:
break;
}
return 0;
}
Here is where I populate the graph:
/* update the Magnitude display */
if( 1 == g_MagGraphActive )
{
/* Set the x-axis of the magnitude plot to display correct time */
SetCtrlAttribute(MagPanelHandle,MAGNITUDE_MAG_GRAPH,ATTR_XAXIS_GAIN, 10000.0/g_iSampleRateFreq);
/* clear Magnitude graph */
DeleteGraphPlot(MagPanelHandle,MAGNITUDE_MAG_GRAPH, -1, VAL_DELAYED_DRAW);
plotHandle = PlotY (MagPanelHandle, MAGNITUDE_MAG_GRAPH, Magnitude_MagData, g_iDataLength, VAL_DOUBLE,
VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
strcpy( legendText, "Magnitude");
SetPlotAttribute(MagPanelHandle, MAGNITUDE_MAG_GRAPH, plotHandle,ATTR_PLOT_LG_TEXT, legendText);
for( i=0; i<g_iDataLength; i++)
{
Magnitude_MagData[i] = Average;
}
plotHandle = PlotY (MagPanelHandle, MAGNITUDE_MAG_GRAPH, Magnitude_MagData, g_iDataLength, VAL_DOUBLE,
VAL_FAT_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_GREEN);
strcpy( legendText, "Average");
SetPlotAttribute(MagPanelHandle, MAGNITUDE_MAG_GRAPH, plotHandle,ATTR_PLOT_LG_TEXT, legendText);
}
I am certain I am allocating enough memory for Magnitude_MagData so I figure the problem must be having the extra thread (MagPanelHandle) getting focus and not letting main application do its work. Any ideas or resources to look at to better understand what I am doing wrong. I am a novice LabWindows guy so I could be doing something that looks obviously wrong to a more experienced person.
thanks,
Don Pearce