Flushes the task buffer.

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

Syntax

Visual Basic (Declaration)
Sub Flush
C#
void Flush()
Visual C++
void Flush()
JavaScript
function flush();

Remarks

The Flush()()() method flushes the task buffer for a writer or read-writer task. This function has no effect on reader tasks. Flushing the task buffer ensures that all the data written to the task buffer has been transferred to the actual hardware. This method does not return until all the data in the task buffer has been flushed to the hardware or the task is stopped.

Examples

This sample demonstrates the use of the Flush()()() method. It writes 5000 samples at 1 kHz to the first four analog output channels using Hardware0. 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 ... */
task = Hil.TaskCreateAnalogWriter(samplesInBuffer, channels); /* create task */
task.WriteAnalog(samplesToWrite, buffer); /* pre-fill the task buffer prior to starting the task */
task.Start(Hil.Clock.Hardware0, frequency, samples);
for (int index = samples; index < samples; index += samples_to_write) {
    /* ... fill buffer with next samplesToWrite samples ... */
    task.WriteAnalog(samplesToWrite, buffer); /* does not wait for data to be written to the hardware, */
                                              /* only waits for space in the task buffer */
}
task.Flush(); /* make sure all data has been written to the hardware prior to stopping task */
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 ...
task = card.TaskCreateAnalogWriter(samplesInBuffer, channels)
task.WriteAnalog(samplesToWrite, buffer) ' pre-fill the task buffer prior to starting the task
task.Start(Hil.Clock.Hardware0, frequency, samples)
For index = 0 To samples - 1 Step samplesToWrite
    ' ... fill buffer with next samplesToWrite samples ...

    ' Does not wait for data to be written to the hardware, only for space in the task buffer
    task.WriteAnalog(samplesToWrite, buffer)
Next
task.Flush() ' make sure all data has been written to the hardware prior to stopping task
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 ... */
task = card->TaskCreateAnalogWriter(samplesInBuffer, channels);
task->WriteAnalog(samplesToWrite, buffer) /* pre-fill the task buffer prior to starting the task */
task->Start(Hil::Clock::Hardware0, frequency, samples);
for (int index = 0; index < samples; index += samplesToWrite) {
    /* ... fill buffer with next samplesToWrite samples ... */
    task->WriteAnalog(samplesToWrite, buffer); /* does not wait for data to be written to the hardware, */
                                               /* only waits for space in the task buffer */
}
task->Flush(); /* make sure all data has been written to the hardware prior to stopping task */
task->Stop();

Exceptions

ExceptionCondition
Quanser.Hardware..::.HilException If the task buffer cannot be flushed then an exception is thrown. This situtation typically arises if the task buffer underflowed (ran out of data) after the last call to a Write or ReadWrite method.

See Also