LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Control memory usage of Graph object

basic background:
LabWindows 7.0
Graph object
Data Mode: (Retain, Discard)
Application executes "PlotLine()" function in a timed loop to update the Graph with real-time data.

When I set Data Mode to "Retain", the object will consume additional memory forever, ultimately crippling the PC
When I set Data Mode to "Discard", I only get the last element plotted.

Is there any way to get this control to retain the bitmap image of the data plotted over extended period of time, while restricting its memory usage?

thanks
Keith
0 Kudos
Message 1 of 5
(3,605 Views)
No!

What I would suggest to reslove the problem is to change your approach. Log the data to a file and display some of it, the last 15 minutes or so on a stripchart and the display all of it in a graph once the logging is completed. Stripcharts keeps the graphics but discards the data, so memory is not consumed and you canb predetermine the number of point you want to show.
Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd
0 Kudos
Message 2 of 5
(3,597 Views)
Keith,

The only way you can have multiple plots visible at the same time while only maintaining the last plot in memory is if you do the following:

1. Set the Data Mode to Discard
2. Make sure Smooth Update is enabled
3. fix the range of both axes at a particular max-min interval.

You're probably missing the last condition, and that is why you are only seeing the last plot.

Every time one of the axis changes its range, the graph needs to remap and replot all of its plots. But if you are using Discard mode, all those plots are no longer available, so they simply disappear. If you are using autoscaling, each time you add a new plot there's a very good chance that the range of one or both axes will change, so you run into this problem. The only way to fix is it for you to decide ahead of time what the range should be, and then turn off auto-scaling.

Finally, you should also consider Jattie's suggestion, which is probably a better solution for your type of application. I don't know if all the lines you are plotting connect to each other to form one or more traces, but if they do, it really does seem that a strip chart would be a better control for displaying them.

Luis
NI
0 Kudos
Message 3 of 5
(3,588 Views)
Luis & Jattie,

Thanks for the feedback. I agree the stripchart is a better solution - in fact, we're rewriting most of the application. But in the short term I have this existing app. In most cases, logistics force the operator to move away from this graph screen - thus avoiding the issue (the control seems to reuse previously allocated memory). I have one test stand that the operator doesn't need to do that - so occasionally the machine sits uselessly on this graph screen for many hours.

I have thought of trying to automatically detect that there hasn't been any activity and move away from it - too complicated (for a dead-end application) and uncertain, to realistically achieve. Telling the operators to exit this panel does work most of the time.

Luis' comments seemed hopeful - I identified a couple of default "Auto" settings (on unused scales), turned them off, but didn't seem to have desired result. These included auto-scale, auto-divisions, and auto-precision: are there more I'm not seeing or are only available programmatically? I have reviewed all 4 axis, even though I'm only using 2.

I do occasionally adjust the axis scales programmatically to fixed values, but only under specific conditions - so it's not occuring on a regular basis forcing the redraw.

I also had some selection logic which programmatically selected Left/Right Y-Axis as the active axis which I temporarily turned off.

So I now have a system that, once setup, is only accessing the control with a periodic PlotLine() call. (Confirmed with Breakpoints) There are other "active" controls on the PANEL, but not overlapping in any way.

All things considered, do I have any hope of a short term solution...
0 Kudos
Message 4 of 5
(3,577 Views)
Keith,

Try running the following code, and tell me what you see. When I run it, I can see all the lines in the graph at the same time. Do you only see the last line?

#include
#include
#include
#include

int main (int argc, char *argv[])
{
int i, panel, graph;

panel = NewPanel (0, "", 100, 100, 500, 500);
graph = NewCtrl (panel, CTRL_GRAPH_LS, "", 100, 100);
SetCtrlAttribute (panel, graph, ATTR_DATA_MODE, VAL_DISCARD);
SetAxisScalingMode (panel, graph, VAL_BOTTOM_XAXIS, VAL_MANUAL, 0.0, 100.0);
SetAxisScalingMode (panel, graph, VAL_LEFT_YAXIS, VAL_MANUAL, 0.0, 100.0);

DisplayPanel (panel);
for (i = 0; i < 10; i++)
{
PlotLine (panel, graph, 100.0 * rand() / RAND_MAX, 100.0 * rand() / RAND_MAX,
100.0 * rand() / RAND_MAX, 100.0 * rand() / RAND_MAX, VAL_WHITE);
Delay (0.5);
}

return 0;
}

Assuming that this example works for you, there must be some other factor specific to your project that I'm not thinking of right now. It could be the way that your graph is configured that is causing it somehow. Are you creating your graph programmatically, or loading it from a .UIR? If you are loading it from a .UIR, try replacing the NewPanel/NewCtrl calls in this example with a LoadPanel from your .UIR and see if it makes a difference. If it does, would you mind attaching the .UIR here, so that I can see if I can figure it out?

Thanks,
Luis
0 Kudos
Message 5 of 5
(3,562 Views)