Creates a task for reading from encoder inputs.

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

Syntax

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

Parameters

samplesInBuffer
Type: System..::.Int32

The number of samples in the task buffer. The ReadEncoder(Int32, array<Int32>[]()[]) method cannot read more samples than this in a single call. If the task buffer overflows because ReadEncoder(Int32, array<Int32>[]()[]) has not been called in time to remove the data from the task buffer then the next call to ReadEncoder(Int32, array<Int32>[]()[]) 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 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.

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

The task does not actually start reading from the encoder 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 encoder inputs using a task. The task reads encoder 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;

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

task = card.TaskCreateEncoderReader(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.ReadEncoder(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 Integer
Dim task As Hil.Task
Dim index As Integer

task = card.TaskCreateEncoderReader(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.ReadEncoder(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<int>^ buffer = gcnew array<int>(samplesToRead * channels->Length);
Hil::Task^ task;

task = card->TaskCreateEncoderReader(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->ReadEncoder(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 encoder inputs or tasks.

See Also