Creates a task for reading from digital inputs.
Namespace:
Quanser.Hardware
Assembly:
Quanser.Hardware.Hil (in Quanser.Hardware.Hil.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Function TaskCreateDigitalReader ( _
samplesInBuffer As Integer, _
channels As Integer() _
) As Hil..::.Task |
C# |
---|
public Hil..::.Task TaskCreateDigitalReader(
int samplesInBuffer,
int[] channels
) |
Visual C++ |
---|
public:
Hil..::.Task^ TaskCreateDigitalReader(
int samplesInBuffer,
array<int>^ channels
) |
JavaScript |
---|
function taskCreateDigitalReader(samplesInBuffer, channels); |
Parameters
- samplesInBuffer
- Type: System..::.Int32
The number of samples in the task buffer. The ReadDigital(Int32, array<SByte>[]()[])
method cannot read more samples than this in a single call. If the task
buffer overflows because ReadDigital(Int32, array<SByte>[]()[])
has not been called in time to remove the data from the task buffer then the
next call to ReadDigital(Int32, array<SByte>[]()[]) will throw an HilException exception.
See Hil..::.Task for more information on task buffers.
- channels
- Type: array<
System..::.Int32
>[]()[]
An array containing the numbers of the digital input channels to be read by the task.
Channel numbers are zero-based. Thus, channel 0 is the first channel, channel 1 the second channel, etc.
Select a board type from 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 reading the samples collected by the task "in the background".
Remarks
Examples
This example illustrates how to read digital inputs using a task. The task reads digital channels 0-3
every millisecond using a hardware clock. The data may be processed each sampling instant.
It runs for 5 seconds before stopping.
Exceptions are ignored for simplicity.
C# | Copy Code |
---|
int [] channels = { 0, 1, 2, 3 };
double frequency = 1000;
int samples = 5000;
int samplesInBuffer = frequency;
int samplesToRead = 1;
sbyte [] buffer = new sbyte [samplesToRead * channels.Length];
Hil.Task task;
task = card.TaskCreateDigitalReader(samplesInBuffer, channels);
task.Start(Hil.Clock.Hardware0, frequency, samples);
for (int index = 0; index < samples; index += samplesToRead) {
/* Block (if necessary) waiting for next samplesToRead samples */
task.ReadDigital(samplesToRead, buffer);
/* ... process sample ... */
}
task.Stop();
|
Visual Basic | Copy Code |
---|
Dim channels() As Integer = {0, 1, 2, 3}
Dim frequency as Double = 1000
Dim samples As Integer = 5000
Dim samplesInBuffer As Integer = frequency
Dim samplesToRead As Integer = 1
Dim buffer(samplesToRead * channels.Length - 1) As SByte
Dim task As Hil.Task
Dim index As Integer
task = card.TaskCreateDigitalReader(samplesInBuffer, channels)
task.Start(Hil.Clock.Hardware0, frequency, samples)
For index = 0 To samples - 1 Step samplesToRead
' Block (if necessary) waiting for next samplesToRead samples
task.ReadDigital(samplesToRead, buffer)
' ... process sample ...
Next
task.Stop()
|
Visual C++ | Copy Code |
---|
array<int>^ channels = { 0, 1, 2, 3 };
double frequency = 1000;
int samples = 5000;
int samplesInBuffer = frequency;
int samplesToRead = 1;
array<char>^ buffer = gcnew array<char>(samplesToRead * channels->Length);
Hil::Task^ task;
task = card->TaskCreateDigitalReader(samplesInBuffer, channels);
task->Start(Hil::Clock::Hardware0, frequency, samples);
for (int index = 0; index < samples; index += samplesToRead) {
/* Block (if necessary) waiting for next samplesToRead samples */
task->ReadDigital(samplesToRead, buffer);
/* ... process sample ... */
}
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 digital inputs or tasks.
|
See Also