Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to cleanly stop an active pulse width measuring task before it has triggered in VB.NET

Hello

 

I am using an USB-6218 with measurement studio 8.5 in a Visual Studio VB.Net application. The .NET samples provide an example for what I want to do in C\...\National Instruments\NI-DAQ\Examples\DotNET2.0\Counter\Measure Period or Pulse Width\MeasPulseWidth\vb.

Further, I added a stop button to this example that was intended to end the task. This was implemented via the standard 'myTask.Dispose()' within the stop button click event.

 

With the unit waiting to be triggered, but NOT YET TRIGGERED due to a non existant input signal, you CANNOT then shut down or stop the task. The application freezes for an indeterminate time. I have changed the task timout property to -1 to remove the timout error altogether, but have as yet not been able to terminate the task nicely and cleanly in this state under any circumstances.

 

My application calls for such a measurment as part of a much more complex environment where a task may be waiting for an unknown length of time, but also can be aborted at any time without having such an effect. Help in resolving this strange issue would be very much appreciated. Thankyou.

 

Engineer Pete

Message Edited by Engineer Pete on 11-25-2008 04:46 AM
0 Kudos
Message 1 of 2
(3,619 Views)

Hi Pete,

 

One way we can do this is to build a parallel loop in code with a 100ms delay that polls the value of your boolean stop control.  We can use a case structure to call the DAQmx Control Task and then abort the DAQmx task.  This immediately puts the task in an unstable state; restarting the task down the line will restore the task to a stable state.  

 

For information on the correct code to use in your program, open the NI-DAQmx C Reference Help file located at  Start>Program>National Instruments>NI-DAQ>NI-DAQmx C Reference Help.  Once the help opens, click on the Search tab and search for "DAQmxTaskControl."  There should be one search result that describes, among other things, the DAQmx_Val_Task_Abort command.

 

For your reference, I have included LabVIEW code that aborts as you describe.  Post up if you have any trouble implementing this in VB.

 

 

Message Edited by Knights Who Say NI on 11-26-2008 10:19 AM
-John Sullivan
Problem Solver
0 Kudos
Message 2 of 2
(3,598 Views)