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

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

Syntax

Visual Basic (Declaration)
Public Sub ReadBuffer ( _
	clock As Hil..::.Clock, _
	frequency As Double, _
	numSamples As Integer, _
	analogChannels As Integer(), _
	encoderChannels As Integer(), _
	digitalChannels As Integer(), _
	otherChannels As Integer(), _
	analogBuffer As Double(), _
	encoderBuffer As Integer(), _
	digitalBuffer As SByte(), _
	otherBuffer As Double() _
)
C#
public void ReadBuffer(
	Hil..::.Clock clock,
	double frequency,
	int numSamples,
	int[] analogChannels,
	int[] encoderChannels,
	int[] digitalChannels,
	int[] otherChannels,
	double[] analogBuffer,
	int[] encoderBuffer,
	sbyte[] digitalBuffer,
	double[] otherBuffer
)
Visual C++
public:
void ReadBuffer(
	Hil..::.Clock clock, 
	double frequency, 
	int numSamples, 
	array<int>^ analogChannels, 
	array<int>^ encoderChannels, 
	array<int>^ digitalChannels, 
	array<int>^ otherChannels, 
	array<double>^ analogBuffer, 
	array<int>^ encoderBuffer, 
	array<signed char>^ digitalBuffer, 
	array<double>^ otherBuffer
)
JavaScript
function readBuffer(clock, frequency, numSamples, analogChannels, encoderChannels, digitalChannels, otherChannels, analogBuffer, encoderBuffer, 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 from the list for board-specific details: .

frequency
Type: System..::.Double

The frequency in Hertz at which to sample the input channels. For example, if frequency is set to 1000, then the ReadBuffer method will read all the selected channels every millisecond.

numSamples
Type: System..::.Int32

The number of samples to collect. Each "sample" consists of all the input channels specified. For example, if frequency is set to 1000 and numSamples is set to 5000, then the ReadBuffer method will return after 5 seconds with 5000 samples. If 3 channels in total have been selected, then the output buffer will contain 15,000 elements.

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

An array containing the numbers of the analog 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 analog input channels are to be read then set this parameter to NoChannels or nullptr.

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

encoderChannels
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 from the list for board-specific details: .

digitalChannels
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 from the list for board-specific details: .

otherChannels
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 from the list for board-specific details: .

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

An array for receiving the voltage values read from the analog inputs. The array must contain analogChannels.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.

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

An array for receiving the count values read from the encoder inputs. The array must contain encoderChannels.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.

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

An array for receiving the binary values read from the digital inputs. The array must contain digitalChannels.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.

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

An array for receiving the values read from the other inputs. The array must contain otherChannels.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.

Remarks

The ReadBuffer method reads the specified number of samples from the input channels at the given sampling frequency. This method does not return until all the data has been read.

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

Examples

This example illustrates how to read inputs at a specified rate. It reads 5000 samples of analog channels 0-1, encoder channels 0-1 and digital channels 0-3 at 1 kHz. The call to ReadBuffer does not return until all the samples have been read, 5 seconds later. Exceptions are ignored for simplicity.
C# Copy Code
int []    analogChannels  = { 0, 1 };
int []    encoderChannels = { 0, 1 };
int []    digitalChannels = { 0, 1, 2, 3 };
double    frequency       = 1000;
int       samples         = 5000;
double [] analogBuffer    = new double [samples * analogChannels.Length];
int []    encoderBuffer   = new int    [samples * encoderChannels.Length];
sbyte []  digitalBuffer   = new sbyte  [samples * digitalChannels.Length];

card.ReadBuffer(Hil.Clock.Hardware0, frequency, samples,
                analogChannels, encoderChannels, digitalChannels, nullptr,
                analogBuffer, encoderBuffer, digitalBuffer, nullptr);
Visual Basic Copy Code
Dim analogChannels() As Integer = {0, 1}
Dim encoderChannels() As Integer = {0, 1}
Dim digitalChannels() As Integer = {0, 1, 2, 3}
Dim frequency As Double = 1000
Dim samples As Integer = 5000
Dim analogBuffer(samples * analogChannels.Length - 1) As Double
Dim encoderbuffer(samples * encoderChannels.Length - 1) As Integer
Dim digitalBuffer(samples * digitalChannels.Length - 1) As SByte

card.ReadBuffer(Hil.Clock.Hardware0, frequency, samples, _
                analogChannels, encoderChannels, digitalChannels, Hil.NoChannels, _
                analogBuffer, encoderBuffer, digitalBuffer, Hil.NoDoubleBuffer);
Visual C++ Copy Code
array<int>^    analogChannels  = { 0, 1 };
array<int>^    encoderChannels = { 0, 1 };
array<int>^    digitalChannels = { 0, 1, 2, 3 };
double         frequency       = 1000;
int            samples         = 5000;
array<double>^ analogBuffer    = gcnew array<double>(samples * analogChannels->Length);
array<int>^    encoderBuffer   = gcnew array<int>(samples * encoderChannels->Length);
array<char>^   digitalBuffer   = gcnew array<char>(samples * digitalChannels->Length);

card->ReadBuffer(Hil::Clock::Hardware0, frequency, samples,
                analogChannels, encoderChannels, digitalChannels, nullptr,
                analogBuffer, encoderBuffer, digitalBuffer, nullptr);

Exceptions

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

See Also