Hi,
I Have an IoT project running in VB.net. The program is running on a RaspBerry Pi 3 on Windows IoT Core. I use a FezHat to get temperature and lightlevel values. I initialize the FezHat with the Hat = Await FEZHAT.CreateAsync() command. I run into problems when I switch to another program (panel) in the same app. When I later return to the main program in which the FezHat is used, it is not possible to init the FezHat again, The CreateAsync cannot be used again. The led on the FezHat is still on, to the connection between the Pi and the FezHat is still active. When I dispose the Hat when I switch to another panel, the Led goes of (hurray) and on return, the CreateAsync can be used again. But then, when I try to read the temperature I get a message the the FezHat is disposed and the operations are not allowed.
Is it possible to restart the FezHat after a panel switch or to get rid of the Disposed status?
Thanks in advance,
Adrian Hondema,
The Netherlands
@ a.a.hondema@ home.nl - Can you post a small but complete example that shows the issue you’re having?
During the initialization of the program the Hat is initiated:
' FEZHAT
Public Hat As FEZHAT
Protected Async Sub InitFezHat()
Try
If Hat Is Nothing Then
Hat = Await FEZHAT.CreateAsync()
End If
Catch ex As Exception
txt_status.Text = "No FezHat detected..."
End Try
End Sub
With the use of a timer, the temperature and lightlevel are read every 5 minutes:
Protected Sub GetTemperatureFEZHAT()
Try
Temperature.Waarde = Hat.GetTemperature()
Catch ex As Exception
End Try
End Sub
Using a side-menu I can switch to another frame within the same application by clicking a button. The FezHat is disposed.
Private Sub Menu_NodeList_Click(sender As Object, e As RoutedEventArgs) Handles Menu_NodeList.Click
FezHatDispose()
Frame.Navigate(GetType(NodeList), AppSettings)
End Sub
Private Sub FezHatDispose()
Try
If Not Hat Is Nothing Then
Hat.Dispose()
End If
Catch ex As Exception
System.Diagnostics.Debug.WriteLine("FezHatDispose exception: " + ex.Message.ToString)
End Try
End Sub
When I switch back to the initial frame the Fezhat is initiated again but the Dispose status is kept. When I try to read the temperature, I get a message that the Hat is disposed. I Cannot find a command to set the Disposed status back to ‘False’. I also tried to delete the Hat ( Hat = nothing) before initiating the Hat again. but that did not work either.
I also tried to switch to another frame without disposing the Hat, but then the CreateAsync fails and the message “No FezHat detected” is shown.
As long as I don’t switch to another program, the FezHat works as it should.
Regards,
Adrian
@ a.a.hondema@ home.nl - Can you try the below code:
Public Hat As FEZHAT
Protected Async Sub InitFezHat()
If Hat Is Nothing Then
Hat = Await FEZHAT.CreateAsync()
End If
End Sub
Protected Sub GetTemperatureFEZHAT()
Try
Temperature.Waarde = Hat.GetTemperature()
Catch ex As Exception
End Try
End Sub
Private Sub Menu_NodeList_Click(sender As Object, e As RoutedEventArgs) Handles Menu_NodeList.Click
FezHatDispose()
Frame.Navigate(GetType(NodeList), AppSettings)
End Sub
Private Sub FezHatDispose()
If Not Hat Is Nothing Then
Hat.Dispose()
Hat = Nothing
End If
End Sub
Hi John,
Yes, that does the trick! Thank you very much.
Adrian
@ a.a.hondema@ home.nl - Happy to help