From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

measurement studio graph crashes

We have developed a windows form based application using measurement studio 2013 std edition and visual studio 2012 on a Win 7 laptop. The DAQ card we are using is the USB 6009, which we have used successfully for many years with LabView.

 

In our current application, we are using the ScatterGraph component of mstudio for reading the analog input from the DAQ. Sampling rate is 10Hz. However, every now and then, the graph crashes soon after starting the acquisition, usually within a few seconds of starting. The plot area shows a white box with a red cross mark. 

 

Any idea why this could be happening and how to resolve this problem?

 

To clarify, I have attached screenshots of the graph below, when working and when not working [grouped together]!

 

Thank you very much for your help.

0 Kudos
Message 1 of 6
(5,525 Views)

Hi,

 

There is probably something wrong with yout plot data. You might have a null or empty value in your data.

Check for something like that.

 

Curt

0 Kudos
Message 2 of 6
(5,507 Views)

Curt...Thanks a lot for that quick response. 

But I am taking an average of the 10 data points/second to plot. Can that still be causing a problem of null value? 

As I said, the problem usually happens only during the first few seconds of the start and if it doesn't crash then, it works fine! 

Any other possibilities? 

Do you think the problem should have anything to do with the history capacity of the plot? Or the CPU availability? 

Thanks again. 

 

0 Kudos
Message 3 of 6
(5,496 Views)

Are you using any threads?  I seem to recall that happening to me once.  You can only update the chart from the GUI thread.

Message 4 of 6
(5,480 Views)

Hey justwakingup! Thanks! Yes, we are using threads. Good catch on that. What you say seems to make sense. Can you possibly share sample code on how to update the chart data using a GUI thread? That will help us a lot. Thanks again. 

0 Kudos
Message 5 of 6
(5,474 Views)

It depends on which version of .NET you are using.  If you are using .NET 2.0 you could take a look at this info on InvokeRequired http://stackoverflow.com/questions/2367718/automating-the-invokerequired-code-pattern .  InvokeRequired is basically a check to see which thread is trying to update the form control.  If I'm not mistaken each control created knows the thread it was created from...........  The example provided on stackoverflow is an extension method that looks like this....

 

public static class ObjExtensions
{
  public static void InvokeIfRequired(this Control control, MethodInvoker action)
  {
   if (control.InvokeRequired)
   {
     control.Invoke(action);
   }
   else
   {
     action();
   }
 }
}

 

You then create a method something like this (activeLogList in this case is a listbox you would use the graph plot method)

 

void AddActiveLog(string log)
{
   activeLogList.InvokeIfRequired(() =>
   {
     activeLogList.Items.Add(log);
   });

}

 

Finally call that method from the thread like this

 

AddActiveLog(log);

 

If you are using .NET 4.0 or higher you can use the Task Parallel Library (TPL) to simplify things.  There is a nice article here http://www.codeproject.com/Articles/152765/Task-Parallel-Library-of-n

 

I'm not sure how fast you are updating data but if the rate is relatively slow you could add a timer to the form and use a Lock to protect the data.

 

Hope that helps out.  

 

Cheers,

Tony

0 Kudos
Message 6 of 6
(5,469 Views)