Assembly: Quanser.Hardware.Hil (in Quanser.Hardware.Hil.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Sub WriteBuffer ( _ clock As Hil..::.Clock, _ frequency As Double, _ numSamples As Integer, _ analogChannels As Integer(), _ pwmChannels As Integer(), _ digitalChannels As Integer(), _ otherChannels As Integer(), _ analogBuffer As Double(), _ pwmBuffer As Double(), _ digitalBuffer As SByte(), _ otherBuffer As Double() _ ) |
C# |
---|
public void WriteBuffer( Hil..::.Clock clock, double frequency, int numSamples, int[] analogChannels, int[] pwmChannels, int[] digitalChannels, int[] otherChannels, double[] analogBuffer, double[] pwmBuffer, sbyte[] digitalBuffer, double[] otherBuffer ) |
Visual C++ |
---|
public: void WriteBuffer( Hil..::.Clock clock, double frequency, int numSamples, array<int>^ analogChannels, array<int>^ pwmChannels, array<int>^ digitalChannels, array<int>^ otherChannels, array<double>^ analogBuffer, array<double>^ pwmBuffer, array<signed char>^ digitalBuffer, array<double>^ otherBuffer ) |
JavaScript |
---|
function writeBuffer(clock, frequency, numSamples, analogChannels, pwmChannels, digitalChannels, otherChannels, analogBuffer, pwmBuffer, digitalBuffer, otherBuffer); |
Parameters
- clock
- Type: Quanser.Hardware..::.Hil..::.Clock
The clock used to time the operation. Note that some clocks allow faster sampling rates than others. See the Hil..::.Clock enumeration for more information on clocks.
Select a board type to the list for board-specific details: .
- frequency
- Type: System..::.Double
The frequency in Hertz at which to write to the output channels. For example, if frequency is set to 1000, then the WriteBuffer method will write all the selected channels every millisecond.
- numSamples
- Type: System..::.Int32
The number of samples to generate. Each "sample" consists of all the output channels specified. For example, if frequency is set to 1000 and numSamples is set to 5000, then the WriteBuffer method will return after 5 seconds, having written 5000 samples. If 3 channels of a particular type have been selected, then the corresponding buffer parameter must therefore contain 15,000 elements.
- analogChannels
- Type: array<
System..::.Int32
>[]()[]
An array containing the numbers of the analog output channels to which to write. 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 which to write. 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 which to write. 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 which to write. 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: .
- analogBuffer
- Type: array<
System..::.Double
>[]()[]
An array containing the voltage values to write to the analog outputs. The array must contain analogChannels.Length * numSamples elements. The array must be organized as a linear array of samples, with each sample consisting of a group of channels. For example, if analog output channels 0, 1 and 3 are being written, than the data must appear in the array as follows, where the numbers correspond to channel numbers:
0 1 3 0 1 3 ... If no analog output channels are being written then this parameter may be set to NoDoubleBuffer or nullptr.
- pwmBuffer
- Type: array<
System..::.Double
>[]()[]
An array containing the values to write to the PWM outputs. How these values are interpreted depends on the PWM mode. The PWM mode is configured using the SetPwmMode(array<Int32>[]()[], array<Hil..::.PwmMode>[]()[]) method. The array must contain pwmChannels.Length * numSamples elements. The array must be organized as a linear array of samples, with each sample consisting of a group of channels. For example, if PWM output channels 0, 1 and 3 are being written, than the data must appear in the array as follows, where the numbers correspond to channel numbers:
0 1 3 0 1 3 ... If no PWM output channels are being written then this parameter may be set to NoDoubleBuffer or nullptr.
- digitalBuffer
- Type: array<
System..::.SByte
>[]()[]
An array containing the binary values to write to the digital outputs. The array must contain channels.Length * numSamples elements. The array must be organized as a linear array of samples, with each sample consisting of a group of channels. For example, if digital output channels 0, 1 and 3 are being written, than the data must appear in the array as follows, where the numbers correspond to channel numbers:
0 1 3 0 1 3 ... If no digital output channels are being written then this parameter may be set to NoBooleanBuffer or nullptr.
- otherBuffer
- Type: array<
System..::.Double
>[]()[]
An array containing the values to write to the other outputs. The array must contain otherChannels.Length * numSamples elements. The array must be organized as a linear array of samples, with each sample consisting of a group of channels. For example, if other output channels 0, 1 and 3 are being written, than the data must appear in the array as follows, where the numbers correspond to channel numbers:
0 1 3 0 1 3 ... If no other output channels are being written then this parameter may be set to NoDoubleBuffer or nullptr.
Remarks
The WriteBuffer method writes the specified number of samples to the output channels at the given sampling frequency. This method does not return until all the data has been written.
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 WriteBuffer(Hil..::.Clock, Double, Int32, array<Int32>[]()[], array<Int32>[]()[], array<Int32>[]()[], array<Int32>[]()[], array<Double>[]()[], array<Double>[]()[], array<SByte>[]()[], array<Double>[]()[]) method failing to write the digital I/O as expected. |
Examples
C# | Copy Code |
---|---|
int [] analogChannels = { 0, 1 }; int [] pwmChannels = { 0, 1 }; int [] digitalChannels = { 4, 5, 6, 7 }; double frequency = 1000; int samples = 5000; double [] analogBuffer = new double [samples * analogChannels.Length]; double [] pwmBuffer = new double [samples * pwmChannels.Length]; sbyte [] digitalBuffer = new double [samples * digitalChannels.Length]; double time; int s, c; for (s = 0; s < samples; s++) { time = s / frequency; for (c = 0; c < analogChannels.Length; c++) { analogBuffer[s * analogChannels.Length + c] = (c + 7.0) * Math.sin(2 * Math.PI * time); } for (c = 0; c < pwmChannels.Length; c++) { pwmBuffer[s * pwmChannels.Length + c] = 0.5 + 0.5 * Math.sin(2 * Math.PI * time); } for (c = 0; c < digitalChannels.Length; c++) { digitalBuffer[s * digitalChannels.Length + c] = (s % (c + 2)) >= (c + 2)/2; } } card.WriteBuffer(Hil.Clock.Hardware0, frequency, samples, analogChannels, pwmChannels, digitalChannels, nullptr, analogBuffer, pwmBuffer, digitalBuffer, nullptr); |
Visual Basic | Copy Code |
---|---|
Dim analogChannels() As Integer = {0, 1} Dim pwmChannels() As Integer = {0, 1} Dim digitalChannels() As Integer = {4, 5, 6, 7} Dim frequency As Double = 1000 Dim samples As Integer = 5000 Dim analogBuffer(samples * analogChannels.Length - 1) As Double Dim pwmBuffer(samples * pwmChannels.Length - 1) As Double Dim digitalBuffer(samples * digitalChannels.Length - 1) As SByte Dim time As Double Dim s As Integer Dim c As Integer For s = 0 To samples time = s / frequency For c = 0 To analogChannels.Length analogBuffer(s * analogChannels.Length + c) = (c + 7.0) * Math.sin(2 * Math.PI * time) Next For c = 0 To pwmChannels.Length pwmBuffer(s * pwmChannels.Length + c) = 0.5 + 0.5 * Math.sin(2 * Math.PI * time) Next For c = 0 To digitalChannels.Length digitalBuffer(s * digitalChannels.Length + c) = (s Mod (c + 2)) >= (c + 2)/2 Next Next card.WriteBuffer(Hil.Clock.Hardware0, frequency, samples, _ analogChannels, pwmChannels, digitalChannels, Hil.NoChannels, _ analogBuffer, pwmBuffer, digitalBuffer, Hil.NoDoubleBuffer) |
Visual C++ | Copy Code |
---|---|
array<int>^ analogChannels = { 0, 1 }; array<int>^ pwmChannels = { 0, 1 }; array<int>^ digitalChannels = { 4, 5, 6, 7 }; double frequency = 1000; int samples = 5000; array<double>^ analogBuffer = gcnew array<double>(samples * analogChannels->Length); array<double>^ pwmBuffer = gcnew array<double>(samples * pwmChannels->Length); array<char>^ digitalBuffer = gcnew array<char>(samples * digitalChannels->Length); double time; int s, c; for (s = 0; s < samples; s++) { time = s / frequency; for (c = 0; c < analogChannels->Length; c++) { analogBuffer[s * analogChannels->Length + c] = (c + 7.0) * Math::sin(2 * Math::PI * time); } for (c = 0; c < pwmChannels->Length; c++) { pwmBuffer[s * pwmChannels->Length + c] = 0.5 + 0.5 * Math::sin(2 * Math::PI * time); } for (c = 0; c < digitalChannels->Length; c++) { digitalBuffer[s * digitalChannels->Length + c] = (s % (c + 2)) >= (c + 2)/2; } } card->WriteBuffer(Hil::Clock::Hardware0, frequency, samples, analogChannels, pwmChannels, digitalChannels, nullptr, analogBuffer, pwmBuffer, digitalBuffer, nullptr); |
Exceptions
Exception | Condition |
---|---|
Quanser.Hardware..::.HilException | If the write cannot be performed then an exception is thrown. This situtation typically arises if the board does not support one of the outputs or the hardware resources required are in use by a task. |