Creates a task for reading from analog, encoder, digital and/or other inputs.

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

Syntax

Visual Basic (Declaration)
Public Function TaskCreateReader ( _
	samplesInBuffer As Integer, _
	analogChannels As Integer(), _
	encoderChannels As Integer(), _
	digitalChannels As Integer(), _
	otherChannels As Integer() _
) As Hil..::.Task
C#
public Hil..::.Task TaskCreateReader(
	int samplesInBuffer,
	int[] analogChannels,
	int[] encoderChannels,
	int[] digitalChannels,
	int[] otherChannels
)
Visual C++
public:
Hil..::.Task^ TaskCreateReader(
	int samplesInBuffer, 
	array<int>^ analogChannels, 
	array<int>^ encoderChannels, 
	array<int>^ digitalChannels, 
	array<int>^ otherChannels
)
JavaScript
function taskCreateReader(samplesInBuffer, analogChannels, encoderChannels, digitalChannels, otherChannels);

Parameters

samplesInBuffer
Type: System..::.Int32

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

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

An array containing the numbers of the analog 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. If no analog input channels are to be read then set this parameter to NoChannels or nullptr.

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

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

An array containing the numbers of the encoder 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. If no encoder input channels are to be read then set this parameter to NoChannels or nullptr.

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

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

An array containing the numbers of the digital 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. If no digital input channels are to be read then set this parameter to NoChannels or nullptr.

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

otherChannels
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. If no other input channels are to be read then set this parameter to NoChannels or nullptr.

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 TaskCreateReader method creates a task for reading from the specified input channels. The task allows other operations to be performed while the 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 Read(Int32, array<Double>[]()[], array<Int32>[]()[], array<SByte>[]()[], array<Double>[]()[]) method. The size of this task buffer is determined by the samplesInBuffer parameter.

The task does not actually start reading from the inputs until the Start(Hil..::.Clock, Double, Int32) method is called. Before starting the task, the directions of the digital I/O lines should be set using the SetDigitalDirections(array<Int32>[]()[], array<Int32>[]()[]) method. See Hil..::.Task for more information on tasks.

Warning

Many cards allow the digital I/O lines to be programmed as inputs or outputs. The digital I/O lines are configured as inputs or outputs using the SetDigitalDirections(array<Int32>[]()[], array<Int32>[]()[]) method. All the channels which will be used as digital inputs or outputs must be configured accordingly using this function. Failure to configure the digital I/O may result in the Read(Int32, array<Double>[]()[], array<Int32>[]()[], array<SByte>[]()[], array<Double>[]()[]) method failing to read digital I/O as expected.

Examples

This example illustrates how to read analog and encoder inputs using a task. The task reads from the first four analog input channels, and first two encoder input channels 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 [] analogChannels  = { 0, 1, 2, 3 };
int [] encoderChannels = { 0, 1 };
double frequency       = 1000;
int    samples         = 5000;
int    samplesInBuffer = frequency;
int    samplesToRead   = 1;

double [] analogBuffer  = new double [samplesToRead * analogChannels.length];
int []    encoderBuffer = new int    [samplesToRead * encoderChannels.length];

Hil.Task task;

task = card.TaskCreateReader(samplesInBuffer, analogChannels, encoderChannels, nullptr, nullptr);
task.Start(Hil.Clock.Hardware0, frequency, samples);
for (int index = 0; index < samples; index += samplesToRead) {
    /* Block (if necessary) waiting for next samplesToRead samples */
    task.Read(samplesToRead, analogBuffer, encoderBuffer, nullptr, nullptr);

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

Dim analogBuffer(samplesToRead * analogChannels.Length - 1) As Double
Dim encoderBuffer(samplesToRead * encoderChannels.Length - 1) As Integer
Dim task As Hil.Task
Dim index As Integer

task = card.TaskCreateReader(samplesInBuffer, analogChannels, encoderChannels, Hil.NoChannels, Hil.NoChannels)
task.Start(Hil.Clock.Hardware0, frequency, samples)
For index = 0 To samples - 1 Step samplesToRead
    ' Block (if necessary) waiting for next samplesToRead samples
    task.Read(samplesToRead, analogBuffer, encoderBuffer, Hil.NoBooleanBuffer, Hil.NoDoubleBuffer)

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

array<double>^ analogBuffer = gcnew array<double>(samplesToRead * analogChannels->Length);
array<int>^ encoderBuffer = gcnew array<int>(samplesToRead * encoderChannels->Length);
Hil::Task^ task;

task = card->TaskCreateReader(samplesInBuffer, analogChannels, encoderChannels, nullptr, nullptr);
task->Start(Hil::Clock::Hardware0, frequency, samples);
for (int index = 0; index < samples; index += samplesToRead) {
    /* Block (if necessary) waiting for next samplesToRead samples */
    task->Read(samplesToRead, analogBuffer, encoderBuffer, nullptr, nullptr);

    /* ... 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 analog inputs or tasks.

See Also