05-26-2017 02:14 PM
Hi all,
I hope this is the correct place to post this question.
I'm having something strange happen. I'm using VB.NET 2010 and Measurement Studio 2010 to acquire, display and (optionally) log data to a file. I'm starting off simple: a function generator sending a signal into my DAQ on a single channel. The program reads the signal, displays it in a WaveformGraph and logs the data into a TDMS file. It works great. Here's the interface (below).
But I'm getting some strange behavior. [NOTE: It does not seem to matter if I am logging data to a file or not.] I can start the process and after some time stop it. Then start it a second time. When I click the stop button the second time, the process will stop, but after several seconds have gone by. If I start the process a third time, and click the stop button, the program will not respond at all. The data continues to be updated in the graph and will not stop. The UI is unresponsive. This happens whether it is run from the IDE or the compiled EXE.
Using the TASK manager to monitor resource use I have noticed that during the data acquisition process, the resource use is almost zero. When I stop the process (click the STOP button), "devenv.exe" and "DAQ_Test_1.vshost.exe" (the program) use a good bit of resources. When I restart the program the 2nd and 3rd time the CPU usage goes back down to basically zero.
Here is my code (variables are declared elsewhere):
----------------------------------------------------------------------------------------------------------------
btnStart_Click:
'Create a new analog input task for reading sensor data
aiTask = New Task
'Create new analog input channels for the task
aiTask.AIChannels.CreateVoltageChannel("/Dev1/ai0", "", AITerminalConfiguration.Differential, -10.0, 10.0, AIVoltageUnits.Volts)
'Configure the timing to use the hardware/internal clock
aiTask.Timing.ConfigureSampleClock("", CDbl(txtScanRate.Text), SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, CDbl(txtScanRate.Text))
'Create a channel reader object
aiSingleChannelReader = New AnalogSingleChannelReader(aiTask.Stream)
'If logging data to a file
If Switch_LogData.Value = True Then
aiTask.ConfigureLogging(SaveFilePath, TdmsLoggingOperation.OpenOrCreate, LoggingMode.LogAndRead, "Group Name")
End If
'Start acquiring the waveform data
aiSingleChannelReader.BeginReadWaveform(CInt(txtNumberOfPoints.Text), New AsyncCallback(AddressOf TestCallBack), Nothing)
'enable/disable the start/stop buttons
btnStart.enabled = false
btnStop.enabled = true
----------------------------------------------------------------------------------------------------------------
TestCallBack sub
'Get the data and put it into the variable
data = aiSingleChannelReader.ReadWaveform(CInt(txtNumberOfPoints.Text))
'Plot the data in the WaveformGraph
WaveformGraph1.PlotWaveform(data)
WaveformGraph1.Refresh()
'Set the callback to perform another read
aiSingleChannelReader.BeginReadWaveform(CInt(txtNumberOfPoints.Text), New AsyncCallback(AddressOf TestCallBack), aiTask)
----------------------------------------------------------------------------------------------------------------
btnStop_Click
'Stop the running task
aiTask.Stop()
'Cleanup
aiTask.Dispose()
'enable/disable the start/stop buttons
btnStart.enabled = true
btnStop.enabled = false
---------------------------------------------------------------------------------------------------------------
Start the 1st time & stop: it works great.
Start the 2nd time & stop: wait several seconds, then stop.
Start 3rd time: starts, but will not stop. The UI is unresponsive.
I've tried moving my start and stop button enable/disable to other parts of the subroutine (perhaps this has something to do with it?), but that makes no difference.
This is being done on a desktop running Windows XP SP3. I have also tried the code on a laptop running Windows 7 Professional. It makes no difference.
Does anyone have any ideas what might be causing this?
I can provide my whole program if someone thinks they might want to see it.
Thanks.
Solved! Go to Solution.
05-31-2017 11:23 AM
Hi crumpms,
Are you seeing any memory spikes as well when you are starting and stopping multiple times? How quickly are you starting and stopping each acquisition? Please try to run one of the VB examples located in <Public\Documents\National Instruments\NI-DAQ\Examples> in Measurement Studio to see if you also see the CPU spike/UI unresponsiveness with other examples.
Josh
Applications Engineer
National Instruments
06-12-2017 09:23 AM
Hi Josh,
thanks for the response. Sorry for the very long delay, I've been out of town for the last 2 weeks on a family medical issue.
Let me look into the issues you raise and I'll try to get an answer for you today.
Thanks for the suggestions,
Mike
06-13-2017 11:44 AM
Hi Josh,
I solved the problem. In my callback procedure I had a flag in a "if/then" statement. If flag=true then plot the data, log to file, etc.. Setting up the callback to perform another read operation was outside the if/then statement. Regardless if the flag was true or false, the callback to acquire more data was performed, even after I had stopped and disposed of the task elsewhere. I guess this was causing conflicts in the code that would allow starting/stopping only twice, and starting only a third time.
Thanks for looking at this and offering suggestions. It seems to be performing nicely now. I guess you need to occasionally step away from the code for a while and clear your head.
Thanks again,
Mike
06-13-2017 02:28 PM
Mike,
I'm glad to hear you found the issue! Easy problems always seem obvious after you find/fix them..
Best,
Josh
Applications Engineer
National Instruments
06-13-2017 02:42 PM
Very true. Now for the follow-on problem: replacing all my hair I pulled out during this. 🙂