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
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
Exception | Condition |
---|
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