Stops a running task.

Namespace:  Quanser.Hardware
Assembly:  Quanser.Hardware.Hil (in Quanser.Hardware.Hil.dll)

Syntax

Visual Basic (Declaration)
Sub Stop
C#
void Stop()
Visual C++
void Stop()
JavaScript
function stop();

Remarks

The Stop()()() method stops a task that is running. A task may be stopped before it has processed all of its samples. Tasks may also be restarted using the Start(Hil..::.Clock, Double, Int32) method.

Examples

This example illustrates how to stop a task. The task reads analog channels 0-3 every millisecond using a hardware clock. The data may be processed each sampling instant. It runs for 5 seconds before stopping. Exceptions are ignored for simplicity.
C# Copy Code
int [] channels        = { 0, 1, 2, 3 };
double frequency       = 1000;
int    samples         = 5000;
int    samplesInBuffer = frequency;
int    samplesToRead   = 1;

double [] buffer = new double [samplesToRead * channels.Length];
Hil.Task task;

task = card.TaskCreateAnalogReader(samplesInBuffer, channels);
task.Start(Hil.Clock.Hardware0, frequency, samples);
for (int index = 0; index < samples; index += samplesToRead) {
    /* Block (if necessary) waiting for next samplesToRead samples */
    task.ReadAnalog(samplesToRead, buffer);

    /* ... process sample ... */
}
task.Stop();
Visual Basic Copy Code
Dim channels() As Integer = {0, 1, 2, 3}
Dim frequency as Double = 1000
Dim samples As Integer = 5000
Dim samplesInBuffer As Integer = frequency
Dim samplesToRead As Integer = 1

Dim buffer(samplesToRead * channels.Length - 1) As Double
Dim task As Hil.Task
Dim index As Integer

task = card.TaskCreateAnalogReader(samplesInBuffer, channels)
task.Start(Hil.Clock.Hardware0, frequency, samples)
For index = 0 To samples - 1 Step samplesToRead
    ' Block (if necessary) waiting for next samplesToRead samples
    task.ReadAnalog(samplesToRead, buffer)

    ' ... process sample ...
Next
task.Stop()
Visual C++ Copy Code
array<int>^ channels        = { 0, 1, 2, 3 };
double      frequency       = 1000;
int         samples         = 5000;
int         samplesInBuffer = frequency;
int         samplesToRead   = 1;

array<double>^ buffer = gcnew array<double>(samplesToRead * channels->Length);
Hil::Task^ task;

task = card->TaskCreateAnalogReader(samplesInBuffer, channels);
task->Start(Hil::Clock::Hardware0, frequency, samples);
for (int index = 0; index < samples; index += samplesToRead) {
    /* Block (if necessary) waiting for next samplesToRead samples */
    task->ReadAnalog(samplesToRead, buffer);

    /* ... process sample ... */
}
task->Stop();

Exceptions

ExceptionCondition
Quanser.Hardware..::.HilException If an error occurs attempting to stop the task then an exception is thrown. This situtation is unlikely to occur if the task was successfully started.

See Also