Creates a task for reading from other inputs and writing to other outputs at the same time.

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

Syntax

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

Parameters

samplesInBuffer
Type: System..::.Int32

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

inputChannels
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: .

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

An array containing the numbers of the other output channels to be written 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 and writing the samples for the task.

Remarks

The TaskCreateOtherReaderOtherWriter method creates a task for reading from the specified other input channels and writing to the specified other output channels at the same time. The task allows other operations to be performed while the other inputs are being read and the other outputs are being written "in the background". The data read from the other inputs is stored in an internal circular "task input buffer". The data written to the other outputs is read from an internal circular "task output buffer". The application may read the data from the task input buffer and write data to the task output buffer at any time using the ReadOtherWriteOther(Int32, array<Double>[]()[], array<Double>[]()[]) method. Data may also be read separately from the task input buffer using the ReadOther(Int32, array<Double>[]()[]) method, and data may also be written into the task output buffer using the WriteOther(Int32, array<Double>[]()[]) method. The size of this task buffer is determined by the samplesInBuffer parameter.

The WriteOther(Int32, array<Double>[]()[]) method is typically called prior to starting the task in order to put the initial samples in the the task output buffer. After the task is started, ReadOtherWriteOther(Int32, array<Double>[]()[], array<Double>[]()[]) is typically called to read the other input values from the task input buffer and to put more data into the task output buffer for the other outputs.

The task does not actually start reading from the other inputs and storing the data in the task input buffer or reading the data from the task output buffer and writing it to the other outputs until the Start(Hil..::.Clock, Double, Int32) method is called. In order for data to be available in the task buffer as soon as the task starts, store data in the buffer using WriteOther(Int32, array<Double>[]()[]) prior to starting the task.

Each sampling instant, the task first reads from the other input channels selected and stores the data in the task input buffer. Then, in the same sampling instant, the task extracts one sample from the task output buffer and writes to the selected other output channels. This synchronization of input and output is particularly useful for system identification because the time at which a sample is read and a sample is written is known, so no postprocessing is required to determine the response delay in the system been identified.

Since the task writes to the other outputs at the sampling rate specified when the task is started, it will be reading data from the task output buffer at that rate. Thus, ReadOtherWriteOther(Int32, array<Double>[]()[], array<Double>[]()[]) or WriteOther(Int32, array<Double>[]()[]) must be called to add more data to the task output buffer before all the data in the buffer is depleted. Otherwise the task will have no data to write to the other outputs and will return with an HilException exception the next time ReadOtherWriteOther(Int32, array<Double>[]()[], array<Double>[]()[]) or WriteOther(Int32, array<Double>[]()[]) is called. See Hil..::.Task for more information on tasks.

Examples

This example illustrates how to read other inputs and write other outputs at the same time using a task. The task reads other input channels 0-1 while writing to other output channels 2-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 [] inputChannels      = { 0, 1 };
int [] outputChannels     = { 2, 3 };
double frequency          = 1000;
int    samples            = 5000;
int    samplesInBuffer    = frequency;
int    samplesToReadWrite = 1;

double [] inputBuffer  = new double [samplesToReadWrite * inputChannels.length];
double [] outputBuffer = new double [samplesToReadWrite * outputChannels.length];
Hil.Task task;

/* ... fill output buffer with samplesToReadWrite samples to write ... */

task = card.TaskCreateOtherReaderOtherWriter(samplesInBuffer, inputChannels, outputChannels);

/* Preload task output buffer with first samplesToReadWrite samples prior to starting task */
task.WriteOther(samplesToReadWrite, outputBuffer);

/* Start task */
task.Start(Hil.Clock.Hardware0, frequency, samples);
for (int index = 0; index < samples; index += samplesToReadWrite) {
    /* ... fill output buffer with next samplesToReadWrite samples to write ... */

    /* 
        Block (if necessary) waiting to read next samplesToReadWrite samples from
        the hardware and for space in the task output buffer.
    */
    task.ReadOtherWriteOther(samplesToReadWrite, inputBuffer, outputBuffer);

    /* ... process samplesToReadWrite samples read ... */
}
task.Stop();
Visual Basic Copy Code
Dim inputChannels() As Integer = {0, 1}
Dim outputChannels() As Integer = {2, 3}
Dim frequency as Double = 1000
Dim samples As Integer = 5000
Dim samplesInBuffer As Integer = frequency
Dim samplesToReadWrite As Integer = 1

Dim inputBuffer(samplesToReadWrite * inputChannels.Length - 1) As Double
Dim outputBuffer(samplesToReadWrite * outputChannels.Length - 1) As Double
Dim task As Hil.Task
Dim index As Integer

' ... fill output buffer with samplesToReadWrite samples to write ...

' Create task
task = card.TaskCreateOtherReaderOtherWriter(samplesInBuffer, inputChannels, outputChannels)

' Preload task buffer with first samplesToReadWrite samples prior to starting task
task.WriteOther(samplesToWrite, outputBuffer)

' Start task
task.Start(Hil.Clock.Hardware0, frequency, samples)
For index = 0 To samples - 1 Step samplesToReadWrite
    ' ... fill buffer with next samplesToReadWrite samples to write ...

    ' Block (if necessary) waiting to read next samplesToReadWrite samples
    ' from the hardware and for space in the task output buffer.
    task.ReadOtherWriteOther(samplesToReadWrite, inputBuffer, outputBuffer)

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

array<double>^ inputBuffer  = gcnew array<double>(samplesToReadWrite * inputChannels->Length);
array<double>^ outputBuffer = gcnew array<double>(samplesToReadWrite * outputChannels->Length);
Hil::Task^ task;

/* ... fill output buffer with samplesToReadWrite samples to write ... */

/* Create task */
task = card->TaskCreateOtherReaderOtherWriter(samplesInBuffer, channels);

/* Preload task buffer with first samplesToWrite samples prior to starting task */
task->WriteOther(samplesToWrite, buffer);

/* Start task */
task->Start(Hil::Clock::Hardware0, frequency, samples);
for (int index = 0; index < samples; index += samplesToReadWrite) {
    /* ... fill output buffer with next samplesToReadWrite samples to write ... */

    /* 
        Block (if necessary) waiting to read next samplesToReadWrite samples from
        the hardware and for space in the task output buffer.
    */
    task->ReadOtherWriteOther(samplesToReadWrite, inputBuffer, outputBuffer);

    /* ... process samplesToReadWrite samples read ... */
}
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 I/O or tasks.

See Also