Creates a task for writing to other outputs.

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

Syntax

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

Parameters

samplesInBuffer
Type: System..::.Int32

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

channels
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 writing the samples output by the task "in the background".

Remarks

The TaskCreateOtherWriter method creates a task for writing to the specified other output channels. The task allows other operations to be performed while the other outputs are being written "in the background". The data written to the other outputs is read from an internal circular "task buffer". This data may be written into the task buffer at any time using the WriteOther(Int32, array<Double>[]()[]) method. The size of this task buffer is determined by the samplesInBuffer parameter.

The task does not actually start writing 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. 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 buffer at that rate. Thus, WriteOther(Int32, array<Double>[]()[]) must be called to add more data to the task 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 throw a HilException the next time WriteOther(Int32, array<Double>[]()[]) is called. See Hil..::.Task for more information on tasks.

Examples

This example illustrates how to write other outputs using a task. The task writes other channels 0-3 every millisecond using a hardware clock. The data to write is computed every 0.1 seconds, with 100 samples being computed at a time. The task 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    samplesToWrite  = 100;

double [] buffer = new double [samplesToWrite * channels.Length];
Hil.Task task;

/* ... fill buffer with samplesToWrite samples ... */

/* Create task */
task = Hil.TaskCreateOtherWriter(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 = samples; index < samples; index += samples_to_write) {
    /* ... fill buffer with next samplesToWrite samples ... */

    /*
        Block (if necessary) waiting to write next samplesToWrite samples.
        However, it only waits for space in the task buffer (which can contain
        samplesInBuffer samples), not for the data to actually be written to
        the hardware. Hence, it will not block until the task buffer is full
        (a little over one second in this example since samplesInBuffer is 1000).
    */
    task.WriteOther(samplesToWrite, buffer);
}

/* Flush to make sure all data has been written to the hardware before stopping task */
task.Flush();
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 samplesToWrite As Integer = 100

Dim buffer(samplesToWrite * channels.Length - 1) As Double
Dim task As Hil.Task
Dim index As Integer

' ... fill buffer with samplesToWrite samples ...

' Create task
task = card.TaskCreateOtherWriter(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 index = 0 To samples - 1 Step samplesToWrite
    ' ... fill buffer with next samplesToWrite sample ...

    ' Block (if necessary) waiting to write next samplesToWrite samples.
    ' However, it only waits for space in the task buffer (which can contain
    ' samplesInBuffer samples), not for the data to actually be written to
    ' the hardware. Hence, it will not block until the task buffer is full
    ' (a little over one second in this example since samplesInBuffer is 1000).
    task.WriteOther(samplesToWrite, buffer)
Next

' Flush to make sure all data has been written to the hardware before stopping task
task.Flush()
task.Stop()
Visual C++ Copy Code
array<int>^ channels        = { 0, 1, 2, 3 };
double      frequency       = 1000;
int         samples         = 5000;
int         samplesInBuffer = frequency;
int         samplesToWrite  = 100;

array<double>^ buffer = gcnew array<double>(samplesToWrite * channels->Length);
Hil::Task^ task;

/* ... fill buffer with samplesToWrite samples ... */

/* Create task */
task = card->TaskCreateOtherWriter(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 += samplesToWrite) {
    /* ... fill buffer with next samplesToWrite samples ... */

    /*
        Block (if necessary) waiting to write next samplesToWrite samples.
        However, it only waits for space in the task buffer (which can contain
        samplesInBuffer samples), not for the data to actually be written to
        the hardware. Hence, it will not block until the task buffer is full
        (a little over one second in this example since samplesInBuffer is 1000).
    */
    task->WriteOther(samplesToWrite, buffer);
}

/* Flush to make sure all data has been written to the hardware before stopping task */
task->Flush();
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 outputs or tasks.

See Also