Starts the watchdog timer with the given timeout interval.
Namespace:
Quanser.HardwareAssembly: Quanser.Hardware.Hil (in Quanser.Hardware.Hil.dll)
Syntax
| Visual Basic (Declaration) |
|---|
Public Sub WatchdogStart ( _ timeout As Double _ ) |
| C# |
|---|
public void WatchdogStart( double timeout ) |
| Visual C++ |
|---|
public: void WatchdogStart( double timeout ) |
| JavaScript |
|---|
function watchdogStart(timeout); |
Parameters
- timeout
- Type: System..::.Double
The expiration timeout interval in seconds.
Select a board type to the list for board-specific details: .
Remarks
The WatchdogStart method starts the watchdog timer with the given timeout interval. It should only be called after the expiration states have been configured using the WatchdogSetXxxxExpirationState methods. Once the watchdog timer has been started, it must be reloaded each time before it expires using the WatchdogReload()()() method.
Examples
This example configures a watchdog timer that will expire every 0.1 seconds and reset the
analog outputs to 0V and the digital outputs to tristate upon expiration.
Also create a task for performing real-time control that reads
four encoder channels every millisecond. The watchdog is reloaded every sampling
instant.
Exceptions are ignored for simplicity.
| C# | |
|---|---|
int [] encoderChannels = { 0, 1, 2, 3 };
double frequency = 1000;
int samples = 5000;
int samplesInBuffer = frequency;
int samplesToRead = 1;
double timeout = 0.1;
int index;
int [] counts = new int [samplesToRead * encoderChannels.Length];
int [] digitalChannels = new int [16];
Hil.DigitalState [] digitalStates = new Hil.DigitalState [digitalChannels.Length];
int [] analogChannels = new int [4];
double [] analogStates = new double [analogChannels.Length];
Hil.Task task;
for (index = 0; index < analogChannels.Length; index++) {
analogChannels[index] = index;
analogStates[index] = 0;
}
for (index = 0; index < digitalChannels.Length; index++) {
digitalChannels[index] = index;
digitalStates[index] = Hil.DigitalState.Tristate;
}
card.WatchdogSetAnalogExpirationState(analogChannels, analogStates);
card.WatchdogSetDigitalExpirationState(digitalChannels, digitalStates);
task = card.TaskCreateEncoderReader(samplesInBuffer, channels);
card.WatchdogStart(timeout);
task.Start(Hil.Clock.Hardware0, frequency, samples);
for (int index = 0; index < samples; index += samplesToRead) {
/*
Block (if necessary) waiting for next samplesToRead samples.
Returns every millisecond (since samplesToRead is 1 and frequency is 1000)
with the next sample.
*/
task.ReadEncoder(samplesToRead, buffer);
/* Reload watchdog before using counts for control */
card.WatchdogReload();
/* ... do control calculations and output motor torques using WriteAnalog(array<Int32>[]()[], array<Double>[]()[]) ... */
}
task.Stop();
card.WatchdogStop();
| |
| Visual Basic | |
|---|---|
Dim encoderChannels() 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 timeout As Double = 0.1
Dim index As Integer
Dim counts(samplesToRead * encoderChannels.Length - 1) As Integer
Dim digitalChannels(15) As Integer
Dim digitalStates(digitalChannels.Length - 1) As Hil.DigitalState
Dim analogChannels(4) As Integer
Dim analogStates(analogChannels.Length - 1) As Double
Hil.Task task
For index = 0 To analogChannels.Length
analogChannels(index) = index
analogStates(index) = 0
Next
For index = 0 To digitalChannels.Length
digitalChannels(index) = index
digitalStates(index) = Hil.DigitalState.Tristate
Next
card.WatchdogSetAnalogExpirationState(analogChannels, analogStates)
card.WatchdogSetDigitalExpirationState(digitalChannels, digitalStates)
task = card.TaskCreateEncoderReader(samplesInBuffer, channels)
card.WatchdogStart(timeout)
task.Start(Hil.Clock.Hardware0, frequency, samples)
For index = 0 To samples Step samplesToRead
' Block (if necessary) waiting for next samplesToRead samples.
' Returns every millisecond (since samplesToRead is 1 and frequency is 1000)
' with the next sample.
task.ReadEncoder(samplesToRead, buffer)
' Reload watchdog before using counts for control
card.WatchdogReload()
' ... do control calculations and output motor torques using WriteAnalog(array<Int32>[]()[], array<Double>[]()[]) ...
Next
task.Stop()
card.WatchdogStop()
| |
| Visual C++ | |
|---|---|
array<int>^ encoderChannels = { 0, 1, 2, 3 };
double frequency = 1000;
int samples = 5000;
int samplesInBuffer = frequency;
int samplesToRead = 1;
double timeout = 0.1;
int index;
array<int>^ counts = gcnew array<int>(samplesToRead * encoderChannels->Length);
array<int>^ digitalChannels = gcnew array<int>(16);
array<Hil::DigitalState>^ digitalStates = gcnew array<Hil::DigitalState>(digitalChannels->Length);
array<int>^ analogChannels = gcnew array<int>(4);
array<double>^ analogStates = gcnew array<double>(analogChannels->Length);
Hil::Task^ task;
for (index = 0; index < analogChannels->Length; index++) {
analogChannels[index] = index;
analogStates[index] = 0;
}
for (index = 0; index < digitalChannels->Length; index++) {
digitalChannels[index] = index;
digitalStates[index] = Hil::DigitalState::Tristate;
}
card->WatchdogSetAnalogExpirationState(analogChannels, analogStates);
card->WatchdogSetDigitalExpirationState(digitalChannels, digitalStates);
task = card->TaskCreateEncoderReader(samplesInBuffer, channels);
card->WatchdogStart(timeout);
task->Start(Hil::Clock::Hardware0, frequency, samples);
for (int index = 0; index < samples; index += samplesToRead) {
/*
Block (if necessary) waiting for next samplesToRead samples.
Returns every millisecond (since samplesToRead is 1 and frequency is 1000)
with the next sample.
*/
task->ReadEncoder(samplesToRead, buffer);
/* Reload watchdog before using counts for control */
card->WatchdogReload();
/* ... do control calculations and output motor torques using WriteAnalog(array<Int32>[]()[], array<Double>[]()[]) ... */
}
task->Stop();
card->WatchdogStop();
| |
Exceptions
| Exception | Condition |
|---|---|
| Quanser.Hardware..::.HilException | If the watchdog cannot be started then an exception is thrown. This situtation typically arises if the board does not support a watchdog timer, or the hardware resources required are in use by a task. |