Reads from inputs and writes to outputs immediately.

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

Syntax

Visual Basic (Declaration)
Public Sub ReadWrite ( _
	analogInputChannels As Integer(), _
	encoderInputChannels As Integer(), _
	digitalInputChannels As Integer(), _
	otherInputChannels As Integer(), _
	analogOutputChannels As Integer(), _
	pwmOutputChannels As Integer(), _
	digitalOutputChannels As Integer(), _
	otherOutputChannels As Integer(), _
	analogInputVoltages As Double(), _
	encoderInputCounts As Integer(), _
	digitalInputBits As SByte(), _
	otherInputValues As Double(), _
	analogOutputVoltages As Double(), _
	pwmOutputDutyCycles As Double(), _
	digitalOutputBits As SByte(), _
	otherOutputValues As Double() _
)
C#
public void ReadWrite(
	int[] analogInputChannels,
	int[] encoderInputChannels,
	int[] digitalInputChannels,
	int[] otherInputChannels,
	int[] analogOutputChannels,
	int[] pwmOutputChannels,
	int[] digitalOutputChannels,
	int[] otherOutputChannels,
	double[] analogInputVoltages,
	int[] encoderInputCounts,
	sbyte[] digitalInputBits,
	double[] otherInputValues,
	double[] analogOutputVoltages,
	double[] pwmOutputDutyCycles,
	sbyte[] digitalOutputBits,
	double[] otherOutputValues
)
Visual C++
public:
void ReadWrite(
	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>^ analogInputVoltages, 
	array<int>^ encoderInputCounts, 
	array<signed char>^ digitalInputBits, 
	array<double>^ otherInputValues, 
	array<double>^ analogOutputVoltages, 
	array<double>^ pwmOutputDutyCycles, 
	array<signed char>^ digitalOutputBits, 
	array<double>^ otherOutputValues
)
JavaScript
function readWrite(analogInputChannels, encoderInputChannels, digitalInputChannels, otherInputChannels, analogOutputChannels, pwmOutputChannels, digitalOutputChannels, otherOutputChannels, analogInputVoltages, encoderInputCounts, digitalInputBits, otherInputValues, analogOutputVoltages, pwmOutputDutyCycles, digitalOutputBits, otherOutputValues);

Parameters

analogInputChannels
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 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 be written. 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: .

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

An array for receiving the voltage values read from the analog inputs. Each element in the analogInputVoltages array corresponds to the same element in the analogInputChannels array. Hence, there must be as many elements in the analogInputVoltages array as there are channels.

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

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

An array for receiving the count values read from the encoder inputs. Each element in the encoderInputCounts array corresponds to the same element in the encoderInputChannels array. Hence, there must be as many elements in the encoderInputCounts array as there are channels.

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

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

An array for receiving the binary values read from the digital inputs. Each element in the digitalInputBits array corresponds to the same element in the digitalInputChannels array. Hence, there must be as many elements in the digitalInputBits array as there are channels.

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

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

An array for receiving the values read from the other inputs. Each element in the otherInputValues array corresponds to the same element in the otherInputChannels array. Hence, there must be as many elements in the otherInputValues array as there are channels.

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

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

An array containing the voltage values to write to the analog outputs. Each element in the analogOutputVoltages array corresponds to the same element in the analogOutputChannels array. Hence, there must be as many elements in the analogOutputVoltages array as there are channels.

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

pwmOutputDutyCycles
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. Each element in the pwmOutputDutyCycles array corresponds to the same element in the pwmOutputChannels array. Hence, there must be as many elements in the pwmOutputDutyCycles array as there are channels.

If no PWM output channels are being written then this parameter may be set to NoDoubleBuffer or nullptr.

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

An array containing the binary values to write to the digital outputs. Each element in the digitalOutputBits array corresponds to the same element in the digitalOutputChannels array. Hence, there must be as many elements in the digitalOutputBits array as there are channels.

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

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

An array containing the values to write to the other outputs. Each element in the otherOutputValues array corresponds to the same element in the otherOutputChannels array. Hence, there must be as many elements in the otherOutputValues array as there are channels.

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

Remarks

The ReadWrite method reads from the specified analog, encoder, digital and/or other input channels and writes to the specified analog, PWM, digital and/or other output channels immediately, in a single method call. 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 the data has been read and written.

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

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.

Examples

This example illustrates how to read inputs and write outputs immediately, in a single operation. It reads analog input channels 0-1, encoder input channels 3-4 and digital input channels 1-2 and writes 0.5V and 1.5V to analog output channels 0 and 3 respectively, and the values 1, 0 and 1 to digital output channels 5-7 respectively. Exceptions are ignored for simplicity.
C# Copy Code
int []    analogInputChannels   = { 0, 1 };
int []    encoderInputChannels  = { 3, 4 };
int []    digitalInputChannels  = { 1, 2 };
int []    analogOutputChannels  = { 0, 3 };
int []    digitalOutputChannels = { 5, 6, 7 };

double [] analogInputBuffer    = new double [analogInputChannels.Length];
int []    encoderInputBuffer   = new int    [encoderInputChannels.Length];
sbyte []  digitalInputBuffer   = new sbyte  [digitalInputChannels.Length];
double [] analogOutputBuffer   = { 0.5, 1.5 };
sbyte []  digitalOutputBuffer  = { 1, 0, 1 };

card.ReadWrite(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 = {3, 4}
Dim digitalInputChannels() As Integer = {1, 2}
Dim analogOutputChannels() As Integer = {0, 3}
Dim digitalOutputChannels() As Integer = {5, 6, 7}

Dim analogInputBuffer(analogInputChannels.Length - 1) As Double
Dim encoderInputBuffer(encoderInputChannels.Length - 1) As Integer
Dim digitalInputBuffer(digitalInputChannels.Length - 1) As SByte
Dim analogOutputBuffer() As Double = {0.5, 1.5}
Dim digitalOutputBuffer() As SByte = {1, 0, 1}

card.ReadWrite(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  = { 3, 4 };
array<int>^    digitalInputChannels  = { 1, 2 };
array<int>^    analogOutputChannels  = { 0, 3 };
array<int>^    digitalOutputChannels = { 5, 6, 7 };

array<double>^ analogInputBuffer     = gcnew array<double>(analogInputChannels->Length);
array<int>^    encoderInputBuffer    = gcnew array<int>(encoderInputChannels->Length);
array<char>^   digitalInputBuffer    = gcnew array<char>(digitalInputChannels->Length);
array<double>^ analogOutputBuffer    = { 0.5, 1.5 };
array<char>^   digitalOutputBuffer   = { 1, 0, 1 };

card->ReadWrite(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 this method.

See Also