Assembly: Quanser.Hardware.Hil (in Quanser.Hardware.Hil.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Function TaskCreateWriter ( _ samplesInBuffer As Integer, _ analogChannels As Integer(), _ pwmChannels As Integer(), _ digitalChannels As Integer(), _ otherChannels As Integer() _ ) As Hil..::.Task |
C# |
---|
public Hil..::.Task TaskCreateWriter( int samplesInBuffer, int[] analogChannels, int[] pwmChannels, int[] digitalChannels, int[] otherChannels ) |
Visual C++ |
---|
public: Hil..::.Task^ TaskCreateWriter( int samplesInBuffer, array<int>^ analogChannels, array<int>^ pwmChannels, array<int>^ digitalChannels, array<int>^ otherChannels ) |
JavaScript |
---|
function taskCreateWriter(samplesInBuffer, analogChannels, pwmChannels, digitalChannels, otherChannels); |
Parameters
- samplesInBuffer
- Type: System..::.Int32
The number of samples in the task buffer. The Write(Int32, array<Double>[]()[], array<Double>[]()[], array<SByte>[]()[], array<Double>[]()[]) method cannot write more samples than this in a single call. If the task buffer underflows because Write(Int32, array<Double>[]()[], array<Double>[]()[], array<SByte>[]()[], array<Double>[]()[]) has not been called in time to add data to the task buffer then the next call to Write(Int32, array<Double>[]()[], array<Double>[]()[], array<SByte>[]()[], array<Double>[]()[]) will throw a HilException exception. See Hil..::.Task for more information on task buffers.
- analogChannels
- Type: array<
System..::.Int32
>[]()[]
An array containing the numbers of the analog 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. If no analog output channels are to be written then set this parameter to NoChannels or nullptr.
Select a board type to the list for board-specific details: .
- pwmChannels
- Type: array<
System..::.Int32
>[]()[]
An array containing the numbers of the PWM 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. If no PWM output channels are to be written then set this parameter to NoChannels or nullptr.
Select a board type to the list for board-specific details: .
- digitalChannels
- Type: array<
System..::.Int32
>[]()[]
An array containing the numbers of the digital 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. If no digital output channels are to be written then set this parameter to NoChannels or nullptr.
Select a board type to the list for board-specific details: .
- otherChannels
- 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. If no other output channels are to be written then set this parameter to NoChannels or nullptr.
Select a board type to 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 TaskCreateWriter method creates a task for writing to the specified output channels. The task allows other operations to be performed while the outputs are being written "in the background". The data written to the outputs is read from an internal circular "task buffer". This data may be written into the task buffer at any time using the Write(Int32, array<Double>[]()[], array<Double>[]()[], array<SByte>[]()[], array<Double>[]()[]) method. The size of this task buffer is determined by the samplesInBuffer parameter.
The task does not actually start writing to the outputs 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. In order for data to be available in the task buffer as soon as the task starts, also store data in the buffer using Write(Int32, array<Double>[]()[], array<Double>[]()[], array<SByte>[]()[], array<Double>[]()[]) prior to starting the task. Since the task writes to the outputs at the sampling rate specified when the task is started, it will be reading data from the task buffer at that rate. Thus, Write(Int32, array<Double>[]()[], array<Double>[]()[], array<SByte>[]()[], 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 outputs and will throw a HilException the next time Write(Int32, array<Double>[]()[], array<Double>[]()[], array<SByte>[]()[], array<Double>[]()[]) is called. See Hil..::.Task for more information on tasks.
The interpretation of the PWM samples to be written depends upon the PWM mode. Typically the data is interpreted as a duty cycle, in which a magnitude of 0.0 denotes a 0% duty cycle and magnitude of 1.0 indicates a 100% duty cycle. The sign determines the polarity of the output for those boards supporting bidirectional PWM outputs. However, other PWM modes are possible with some boards. Refer to the SetPwmMode(array<Int32>[]()[], array<Hil..::.PwmMode>[]()[]) method for details.
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 Write(Int32, array<Double>[]()[], array<Double>[]()[], array<SByte>[]()[], array<Double>[]()[]) method failing to write digital I/O as expected. |
Examples
C# | Copy Code |
---|---|
int [] analogChannels = { 0, 1, 2, 3 }; int [] pwmChannels = { 0, 1 }; double frequency = 1000; int samples = 5000; int samplesInBuffer = frequency; int samplesToWrite = 100; double [] analogBuffer = new double [samplesToWrite * analogChannels.Length]; double [] pwmBuffer = new double [samplesToWrite * pwmChannels.Length]; Hil.Task task; /* ... fill buffers with samplesToWrite samples ... */ /* Create task */ task = card.TaskCreateWriter(samplesInBuffer, analogChannels, pwmChannels, nullptr, nullptr); /* Preload task buffer with first samplesToWrite samples prior to starting task */ task.Write(samplesToWrite, analogBuffer, pwmBuffer, nullptr, nullptr); /* Start task */ task.Start(Hil.Clock.Hardware0, frequency, samples); for (int index = samples; index < samples; index += samples_to_write) { /* ... fill buffers 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.Write(samplesToWrite, analogBuffer, pwmBuffer, nullptr, nullptr); } /* Flush to make sure all data has been written to the hardware before stopping task */ task.Flush(); task.Stop(); |
Visual Basic | Copy Code |
---|---|
Dim analogChannels() As Integer = {0, 1, 2, 3} Dim pwmChannels() As Integer = {0, 1} Dim frequency as Double = 1000 Dim samples As Integer = 5000 Dim samplesInBuffer As Integer = frequency Dim samplesToWrite As Integer = 100 Dim analogBuffer(samplesToWrite * analogChannels.Length - 1) As Double Dim pwmBuffer(samplesToWrite * pwmChannels.Length - 1) As Double Dim task As Hil.Task Dim index As Integer ' ... fill buffers with samplesToWrite samples ... ' Create task task = card.TaskCreateWriter(samplesInBuffer, analogChannels, pwmChannels, Hil.NoChannels, Hil.NoChannels) ' Preload task buffer with first samplesToWrite samples prior to starting task task.Write(samplesToWrite, analogBuffer, pwmBuffer, Hil.NoBooleanBuffer, Hil.NoDoubleBuffer) ' Start task task.Start(Hil.Clock.Hardware0, frequency, samples) For index = 0 To samples - 1 Step samplesToWrite ' ... fill buffers 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.Write(samplesToWrite, analogBuffer, pwmBuffer, Hil.NoBooleanBuffer, Hil.NoDoubleBuffer) 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>^ analogChannels = { 0, 1, 2, 3 }; array<int>^ pwmChannels = { 0, 1 }; double frequency = 1000; int samples = 5000; int samplesInBuffer = frequency; int samplesToWrite = 100; array<double>^ analogBuffer = gcnew array<double>(samplesToWrite * analogChannels->Length); array<double>^ pwmBuffer = gcnew array<double>(samplesToWrite * pwmChannels->Length); Hil::Task^ task; /* ... fill buffers with samplesToWrite samples ... */ /* Create task */ task = card->TaskCreateWriter(samplesInBuffer, analogChannels, pwmChannels, nullptr, nullptr); /* Preload task buffer with first samplesToWrite samples prior to starting task */ task->Write(samplesToWrite, analogBuffer, pwmBuffer, nullptr, nullptr); /* Start task */ task->Start(Hil::Clock::Hardware0, frequency, samples); for (int index = 0; index < samples; index += samplesToWrite) { /* ... fill buffers 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->Write(samplesToWrite, analogBuffer, pwmBuffer, nullptr, nullptr); } /* Flush to make sure all data has been written to the hardware before stopping task */ task->Flush(); task->Stop(); |
Exceptions
Exception | Condition |
---|---|
Quanser.Hardware..::.HilException | If the task cannot be created then an exception is thrown. This situtation typically arises if the board does not support one of the outputs or tasks. |