Reads the specified number of samples from the analog, encoder, digital and/or other input channels and writes the specified number of samples to the analog, PWM, digital and/or other output output channels at the indicated sampling rate.

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

Syntax

Visual Basic (Declaration)
Public Sub ReadWriteBuffer ( _
	clock As Hil..::.Clock, _
	frequency As Double, _
	numSamples As Integer, _
	analogInputChannels As Integer(), _
	encoderInputChannels As Integer(), _
	digitalInputChannels As Integer(), _
	otherInputChannels As Integer(), _
	analogOutputChannels As Integer(), _
	pwmOutputChannels As Integer(), _
	digitalOutputChannels As Integer(), _
	otherOutputChannels As Integer(), _
	analogInputBuffer As Double(), _
	encoderInputBuffer As Integer(), _
	digitalInputBuffer As SByte(), _
	otherInputBuffer As Double(), _
	analogOutputBuffer As Double(), _
	pwmOutputBuffer As Double(), _
	digitalOutputBuffer As SByte(), _
	otherOutputBuffer As Double() _
)
C#
public void ReadWriteBuffer(
	Hil..::.Clock clock,
	double frequency,
	int numSamples,
	int[] analogInputChannels,
	int[] encoderInputChannels,
	int[] digitalInputChannels,
	int[] otherInputChannels,
	int[] analogOutputChannels,
	int[] pwmOutputChannels,
	int[] digitalOutputChannels,
	int[] otherOutputChannels,
	double[] analogInputBuffer,
	int[] encoderInputBuffer,
	sbyte[] digitalInputBuffer,
	double[] otherInputBuffer,
	double[] analogOutputBuffer,
	double[] pwmOutputBuffer,
	sbyte[] digitalOutputBuffer,
	double[] otherOutputBuffer
)
Visual C++
public:
void ReadWriteBuffer(
	Hil..::.Clock clock, 
	double frequency, 
	int numSamples, 
	array<int>^ analogInputChannels, 
	array<int>^ encoderInputChannels, 
	array<int>^ digitalInputChannels, 
	array<int>^ otherInputChannels, 
	array<int>^ analogOutputChannels, 
	array<int>^ pwmOutputChannels, 
	array<int>^ digitalOutputChannels, 
	array<int>^ otherOutputChannels, 
	array<double>^ analogInputBuffer, 
	array<int>^ encoderInputBuffer, 
	array<signed char>^ digitalInputBuffer, 
	array<double>^ otherInputBuffer, 
	array<double>^ analogOutputBuffer, 
	array<double>^ pwmOutputBuffer, 
	array<signed char>^ digitalOutputBuffer, 
	array<double>^ otherOutputBuffer
)
JavaScript
function readWriteBuffer(clock, frequency, numSamples, analogInputChannels, encoderInputChannels, digitalInputChannels, otherInputChannels, analogOutputChannels, pwmOutputChannels, digitalOutputChannels, otherOutputChannels, analogInputBuffer, encoderInputBuffer, digitalInputBuffer, otherInputBuffer, analogOutputBuffer, pwmOutputBuffer, digitalOutputBuffer, otherOutputBuffer);

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 read from the input channels and write to the output channels. For example, if frequency is set to 1000, then the ReadWriteBuffer method will read all the input channels and write all the output channels every millisecond.

numSamples
Type: System..::.Int32

The number of samples to generate. Each "sample" consists of all the input channels and all the output channels specified. For example, if frequency is set to 1000 and numSamples is set to 5000, then the ReadWriteBuffer method will return after 5 seconds, having read 5000 samples and written 5000 samples. If three input channels of a particular type have been selected, then the input buffer for that channel type will contain 15,000 elements. If two output channels for a specific channel type have been selected, then the corresponding output buffer must contain 10,000 elements.

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

An array containing the numbers of the analog input channels from which to read. Channel numbers are zero-based. Thus, channel 0 is the first channel, channel 1 the second channel, etc. If no analog input channels are to be read then set this parameter to NoChannels or nullptr.

Select a board type to the list for board-specific details: .

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

An array containing the numbers of the encoder input channels to be read. Channel numbers are zero-based. Thus, channel 0 is the first channel, channel 1 the second channel, etc. If no encoder input channels are to be read then set this parameter to NoChannels or nullptr.

Select a board type to the list for board-specific details: .

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

An array containing the numbers of the digital input channels to be read. Channel numbers are zero-based. Thus, channel 0 is the first channel, channel 1 the second channel, etc. If no digital input channels are to be read then set this parameter to NoChannels or nullptr.

Select a board type to the list for board-specific details: .

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

An array containing the numbers of the other input channels to be read. Channel numbers are zero-based. Thus, channel 0 is the first channel, channel 1 the second channel, etc. If no other input channels are to be read then set this parameter to NoChannels or nullptr.

Select a board type to the list for board-specific details: .

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

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

An array containing the numbers of the PWM output channels to be written. 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: .

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

An array containing the numbers of the digital output channels to be written. 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: .

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

An array containing the numbers of the other output channels to be written. 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: .

analogInputBuffer
Type: array< System..::.Double >[]()[]

An array for receiving the voltage values read from the analog inputs. The array must contain analogInputChannels.Length * numSamples elements. The array is organized as a linear array of samples, with each sample consisting of a group of channels. For example, if analog input channels 0, 1 and 3 are being read, than the data appears in the array as follows, where the numbers correspond to channel numbers:

0 1 3 0 1 3 ...

If no analog input channels are being read then this parameter may be set to NoDoubleBuffer or nullptr.

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

An array for receiving the count values read from the encoder inputs. The array must contain encoderInputChannels.Length * numSamples elements. The array is organized as a linear array of samples, with each sample consisting of a group of channels. For example, if encoder input channels 0, 1 and 3 are being read, than the data appears in the array as follows, where the numbers correspond to channel numbers:

0 1 3 0 1 3 ...

If no encoder input channels are being read then this parameter may be set to NoIntegerBuffer or nullptr.

digitalInputBuffer
Type: array< System..::.SByte >[]()[]

An array for receiving the binary values read from the digital inputs. The array must contain digitalInputChannels.Length * numSamples elements. The array is organized as a linear array of samples, with each sample consisting of a group of channels. For example, if digital input channels 0, 1 and 3 are being read, than the data appears in the array as follows, where the numbers correspond to channel numbers:

0 1 3 0 1 3 ...

If no digital input channels are being read then this parameter may be set to NoBooleanBuffer or nullptr.

otherInputBuffer
Type: array< System..::.Double >[]()[]

An array for receiving the values read from the other inputs. The array must contain otherInputChannels.Length * numSamples elements. The array is organized as a linear array of samples, with each sample consisting of a group of channels. For example, if other input channels 0, 1 and 3 are being read, than the data appears in the array as follows, where the numbers correspond to channel numbers:

0 1 3 0 1 3 ...

If no other input channels are being read then this parameter may be set to NoDoubleBuffer or nullptr.

analogOutputBuffer
Type: array< System..::.Double >[]()[]

An array containing the voltage values to write to the analog outputs. The array must contain analogOutputChannels.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.

pwmOutputBuffer
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 pwmOutputChannels.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.

digitalOutputBuffer
Type: array< System..::.SByte >[]()[]

An array containing the binary values to write to the digital outputs. The array must contain digitalOutputChannels.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.

otherOutputBuffer
Type: array< System..::.Double >[]()[]

An array containing the values to write to the other outputs. The array must contain otherOutputChannels.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 ReadWriteBuffer method reads the specified number of samples from the input channels and writes to the specified output channels at the given sampling rate in a single method call. Each sampling instant, the write operation occurs immediately following the read operation. Since the read-write operation occurs at the lowest level the read and write occur virtually concurrently. The method does not return until all the data has been read and written. This method is particularly useful for system identification since the read and write operations are synchronized. In particular, the value read in one sampling instant is the result of the write operation in the previous sampling instant.

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.

Warning

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 ReadDigitalWriteDigitalBuffer(Hil..::.Clock, Double, Int32, array<Int32>[]()[], array<Int32>[]()[], array<SByte>[]()[], array<SByte>[]()[]) method failing to read or write the digital I/O as expected.

Examples

This example illustrates how to read inputs and write outputs at a specified rate, in one operation. It reads 5000 samples from analog input channels 0-1, encoder input channels 0-1 and digital input channels 6-7 and writes at the same time to analog output channels 0-1 and digital output channels 0-2 at 1 kHz. The call to ReadWriteBuffer does not return until all the samples have been read and written, 5 seconds later. One Hertz sine waves are written to the outputs, with amplitudes of 7V, 8V, 9V and 10V respectively and square waves of differing frequencies are written to the digital outputs. Exceptions are ignored for simplicity.
C# Copy Code
int []    analogInputChannels   = { 0, 1 };
int []    encoderInputChannels  = { 0, 1 };
int []    digitalInputChannels  = { 6, 7 };
int []    analogOutputChannels  = { 0, 1 };
int []    digitalOutputChannels = { 0, 1, 2 };
double    frequency             = 1000;
int       samples               = 5000;
double [] analogInputBuffer     = new double [samples * analogInputChannels.Length];
int []    encoderInputBuffer    = new int    [samples * encoderInputChannels.Length];
sbyte []  digitalInputBuffer    = new sbyte  [samples * digitalInputChannels.Length];
double [] analogOutputBuffer    = new double [samples * analogOutputChannels.Length];
sbyte []  digitalOutputBuffer   = new sbyte  [samples * digitalOutputChannels.Length];
double    time;
int       s, c;

for (s = 0; s < samples; s++) {
   time = s / frequency;
   for (c = 0; c < analogOutputChannels.Length; c++) {
       analogOutputBuffer[s * analogOutputChannels.Length + c] = (c + 7.0) * Math.sin(2 * Math.PI * time);
   }
   for (c = 0; c < digitalOutputChannels.Length; c++) {
       digitalOutputBuffer[s * digitalOutputChannels.Length + c] = (s % (c + 2)) >= (c + 2)/2;
   }
}
   
card.ReadWriteBuffer(Hil.Clock.Hardware0, frequency, samples,
    analogInputChannels, encoderInputChannels, digitalInputChannels, nullptr,
    analogOutputChannels, nullptr, digitalOutputChannels, nullptr,
    analogInputBuffer, encoderInputBuffer, digitalInputBuffer, nullptr,
    analogOutputBuffer, nullptr, digitalOutputBuffer, nullptr);
Visual Basic Copy Code
Dim analogInputChannels() As Integer = {0, 1}
Dim encoderInputChannels() As Integer = {0, 1}
Dim digitalInputChannels() As Integer = {6, 7}
Dim analogOutputChannels() As Integer = {0, 1}
Dim digitalOutputChannels() As Integer = {0, 1, 2}
Dim frequency As Double = 1000
Dim samples As Integer = 5000
Dim analogInputBuffer(samples * analogInputChannels.Length - 1) As Double
Dim encoderInputBuffer(samples * encoderInputChannels.Length - 1) As Integer
Dim digitalInputBuffer(samples * digitalInputChannels.Length - 1) As SByte
Dim analogOutputBuffer(samples * analogOutputChannels.Length - 1) As Double
Dim digitalOutputBuffer(samples * digitalOutputChannels.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 analogOutputChannels.Length
       analogOutputBuffer(s * analogOutputChannels.Length + c) = (c + 7.0) * Math.sin(2 * Math.PI * time)
   Next
   For c = 0 To digitalOutputChannels.Length
       digitalOutputBuffer(s * digitalOutputChannels.Length + c) = (s Mod (c + 2)) >= (c + 2)/2
   Next
Next

card.ReadWriteBuffer(Hil.Clock.Hardware0, frequency, samples, _
    analogInputChannels, encoderInputChannels, digitalInputChannels, Hil.NoChannels, _
    analogOutputChannels, Hil.NoChannels, digitalOutputChannels, Hil.NoChannels, _
    analogInputBuffer, encoderInputBuffer, digitalInputBuffer, Hil.NoDoubleBuffer, _
    analogOutputBuffer, Hil.NoDoubleBuffer, digitalOutputBuffer, Hil.NoDoubleBuffer)
Visual C++ Copy Code
array<int>^    analogInputChannels   = { 0, 1 };
array<int>^    encoderInputChannels  = { 0, 1 };
array<int>^    digitalInputChannels  = { 6, 7 };
array<int>^    analogOutputChannels  = { 0, 1 };
array<int>^    digitalOutputChannels = { 0, 1, 2 };
double         frequency             = 1000;
int            samples               = 5000;
array<double>^ analogInputBuffer     = gcnew array<double>(samples * analogInputChannels->Length);
array<int>^    encoderInputBuffer    = gcnew array<int>(samples * encoderInputChannels->Length);
array<char>^   digitalInputBuffer    = gcnew array<char>(samples * digitalInputChannels->Length);
array<double>^ analogOutputBuffer    = gcnew array<double>(samples * analogOutputChannels->Length);
array<char>^   digitalOutputBuffer   = gcnew array<char>(samples * digitalOutputChannels->Length);
double         time;
int            s, c;

for (s = 0; s < samples; s++) {
   time = s / frequency;
   for (c = 0; c < analogOutputChannels->Length; c++) {
       analogOutputBuffer[s * analogOutputChannels->Length + c] = (c + 7.0) * Math::sin(2 * Math::PI * time);
   }
   for (c = 0; c < digitalOutputChannels->Length; c++) {
       digitalOutputBuffer[s * digitalOutputChannels->Length + c] = (s % (c + 2)) >= (c + 2)/2;
   }
}
   
card->ReadWriteBuffer(Hil::Clock::Hardware0, frequency, samples,
    analogInputChannels, encoderInputChannels, digitalInputChannels, nullptr,
    analogOutputChannels, nullptr, digitalOutputChannels, nullptr,
    analogInputBuffer, encoderInputBuffer, digitalInputBuffer, nullptr,
    analogOutputBuffer, nullptr, digitalOutputBuffer, nullptr);

Exceptions

ExceptionCondition
Quanser.Hardware..::.HilException If the read or write cannot be performed then an exception is thrown. This situtation typically arises if the board does not support one of the inputs or outputs or the hardware resources required are in use by a task.

See Also