I’ve spent probably upwards of 10 hours or so searching online for a way to implement the Hardware watchdog using Visual Basic Code. I’ve found several references to how to do it in C#, but I just can’t find a reference to how to do it using visual basic code.
As soon as I try to include GHI.Premium.Hardware I receive this error on compile:
“An unhandled exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Hardware.dll”
Any assistance with this would be greatly appreciated.
Public Class Program
'Public COUNT As Int32
Dim intRecievedIndex As Int32 = 0
Dim bytRecievedData(16) As Byte
Dim bytrecieved(16) As Int32
Dim Out1 As GT.Interfaces.DigitalOutput
Dim Out2 As GT.Interfaces.DigitalOutput
Dim Cout() As GT.Interfaces.DigitalOutput = {Out1, Out2}
Dim RTUout() As Byte = {23, 24}
Public Sub ProgramStarted()
Cout(0) = breakout.SetupDigitalOutput(GT.Socket.Pin.Three, False)
Cout(1) = breakout.SetupDigitalOutput(GT.Socket.Pin.Four, False)
Here is some of where I was trying to set up the Watchdog with no luck, if I ignore the “Premium” version, (and take out the comments) this compiles, but never forces a reset
'Set up timer for Watchdog
'Dim spTimeout As TimeSpan = New TimeSpan(0, 0, 0, 0, 1) ' Set up the Timeout to be 15 minutes (or 1 ms for testing)
'Debug.Print(GHI.Premium.Hardware.LowLevel.Watchdog.LastResetCause.ToString())
'Watchdog.Timeout = spTimeout ' Apply the timeout period
'Watchdog.Behavior = WatchdogBehavior.HardReboot
'Watchdog.Enabled() = True
rs232.Initialize(baudRate:=9600)
Thread.Sleep(200) 'Needed to avoid glitches of not opening correctly
rs232.serialPort.Open()
Thread.Sleep(200)
AddHandler rs232.serialPort.DataReceived, AddressOf DataReceivedHandler
Debug.Print("232 open")
rs232.serialPort.DiscardInBuffer()
End Sub
Hi Mike,
Thanks for the assistance, and yes I had looked at that code, but every time I tried to run it, I would run into issues with it not liking the premium library. That said, your initial post about the OSHW libraries was extremely helpful, and now I have code that works as such below:
Load the correct HW library
Imports GHI.OSHW.Hardware
Initialization of the Registers. This is for the IWDG, there is another at 40002C00
Dim WDKR As GHI.OSHW.Hardware.LowLevel.Register = New GHI.OSHW.Hardware.LowLevel.Register(&H40003000) 'Correct Address of the IWDG timer for the Fez Cerberus
Dim WDPR As GHI.OSHW.Hardware.LowLevel.Register = New GHI.OSHW.Hardware.LowLevel.Register(&H40003004) 'Prescaler, bottom 3 bits.
Dim WDSR As GHI.OSHW.Hardware.LowLevel.Register = New GHI.OSHW.Hardware.LowLevel.Register(&H4000300C) ' // Not needed , gives status for being able to adjust the prescaler
Dim WDLR As GHI.OSHW.Hardware.LowLevel.Register = New GHI.OSHW.Hardware.LowLevel.Register(&H40003008) '' // Watchdog Count down value, default FFF
**The next section sets up the timeout, WDPR is the prescaler from with 1= /4 & 7=/256
**WDLR is the countdown amount from 1 to FFF
WDKR.Write(&H5555) 'Enable the changing of WDPR or WDLR
Thread.Sleep(1)
WDPR.Write(&H7) 'Change the prescaler to divide by 256, currently set for 30s
Thread.Sleep(1)
WDKR.Write(&HCCCC) ‘Start the Watchdog Timer
**Quick Subroutine to refresh the watchdog time.
Public Sub ResetCounter()
WDKR.Write(&HAAAA)
End Sub