Starts the task.

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

Syntax

Visual Basic (Declaration)
Sub Start ( _
	clock As Hil..::.Clock, _
	frequency As Double, _
	numSamples As Integer _
)
C#
void Start(
	Hil..::.Clock clock,
	double frequency,
	int numSamples
)
Visual C++
void Start(
	Hil..::.Clock clock, 
	double frequency, 
	int numSamples
)
JavaScript
function start(clock, frequency, numSamples);

Parameters

clock
Type: Quanser.Hardware..::.Hil..::.Clock
The clock used to time the operation. Note that some clocks allow faster sampling rates than others. Some data acquisition cards support system timers as well as hardware timebases, such as the Quanser Q8-series of cards, but many do not. System timers may generally be used in a variety of contexts at the same time, but hardware timers are a limited resource that can not typically be shared.
frequency
Type: System..::.Double
The frequency in Hertz at which to process samples. For example, if the frequency is set to 1000, then the Start(Hil..::.Clock, Double, Int32) method causes the task to process one sample every millisecond.
numSamples
Type: System..::.Int32

The total number of samples to process. Each "sample" consists of all the channels specified when the task was created. For example, if the frequency is set to 1000 and the number of samples is set to 5000, then the task will run for 5 seconds, processing 5000 samples.

If the number of samples is set to -1 then the task will run until Stop()()() is called. The number of samples to process is viewed as infinite in this case.

Remarks

Tasks do not process any data until they are started. Tasks may be started using a hardware timebase or a system timer. Not all data acquisition cards support the use of a system timer for tasks. For the Quanser Q8-series of cards, the system timer corresponds to a kernel-level system timer with one millisecond resolution.

The task runs at the sampling frequency specified and processes the total number of samples specified. The task will stop itself after the given number of samples has been processed, but the Stop()()() method must still be called. If the number of samples is set to -1 then the task will continue to process samples until the Stop()()() method is called.

Stop the task using the Stop()()() method. Tasks should always be stopped when no longer in use in order to free up any resources required by the running task.

Examples

This example illustrates how to start 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 the task cannot be started then an exception is thrown. This situtation typically arises if the required hardware resources are unavailable. The resources may be in use by another task or may not be supported by the card. Alternatively, the frequency may be outside the range supported by the card.

See Also