Creates a task for reading from other inputs.

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

Syntax

Visual Basic (Declaration)
Public Function TaskCreateOtherReader ( _
	samplesInBuffer As Integer, _
	channels As Integer() _
) As Hil..::.Task
C#
public Hil..::.Task TaskCreateOtherReader(
	int samplesInBuffer,
	int[] channels
)
Visual C++
public:
Hil..::.Task^ TaskCreateOtherReader(
	int samplesInBuffer, 
	array<int>^ channels
)
JavaScript
function taskCreateOtherReader(samplesInBuffer, channels);

Parameters

samplesInBuffer
Type: System..::.Int32

The number of samples in the task buffer. The ReadOther(Int32, array<Double>[]()[]) method cannot read more samples than this in a single call. If the task buffer overflows because ReadOther(Int32, array<Double>[]()[]) has not been called in time to remove the data from the task buffer then the next call to ReadOther(Int32, array<Double>[]()[]) will throw an HilException exception. See Hil..::.Task for more information on task buffers.

channels
Type: array< System..::.Int32 >[]()[]

An array containing the numbers of the other input channels to be read by the task. Channel numbers are zero-based. Thus, channel 0 is the first channel, channel 1 the second channel, etc.

Select a board type from the list for board-specific details: .

Return Value

Returns a Hil..::.Task interface for manipulating the task, including starting and stopping the task, and for reading the samples collected by the task "in the background".

Remarks

The TaskCreateOtherReader method creates a task for reading from the specified other input channels. The task allows other operations to be performed while the other inputs are being read "in the background". The data is read into an internal circular "task buffer" from which it can be read at any time using the ReadOther(Int32, array<Double>[]()[]) method. The size of this task buffer is determined by the samplesInBuffer parameter.

The task does not actually start reading from the other inputs until the Start(Hil..::.Clock, Double, Int32) method is called. See Hil..::.Task for more information on tasks.

Examples

This example illustrates how to read other inputs using a task. The task reads other 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.TaskCreateOtherReader(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.ReadOther(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.TaskCreateOtherReader(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.ReadOther(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->TaskCreateOtherReader(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->ReadOther(samplesToRead, buffer);

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

Exceptions

ExceptionCondition
Quanser.Hardware..::.HilException If the task cannot be created then an exception is thrown. This situtation typically arises if the board does not support other inputs or tasks.

See Also