Enaud
Posts: 2
Joined: Tue Feb 05, 2019 3:58 am

How to shutdown Pi from Visual Basic 2017 Code

Tue Feb 05, 2019 4:03 am

Hi, I've been searching for how to shutdown my Pi from Visual Basic 2017 code without success.
I have an app I have developed that will run when the Pi boots up and when a specific GPIO pin detects a switch closure I want to shut down the Pi.
I'm reading/writing GPIO pins just fine from VB. My issue is the coding to invoke shutdown.
Does anyone have any experience getting the Pi to shutdown/reboot from a Visual Basic app?

Cheers.

scotty101
Posts: 3402
Joined: Fri Jun 08, 2012 6:03 pm

Re: How to shutdown Pi from Visual Basic 2017 Code

Tue Feb 05, 2019 1:44 pm

Does this help you?
https://marcominerva.wordpress.com/2016 ... a-uwp-app/

There should be a VB equivalent.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Enaud
Posts: 2
Joined: Tue Feb 05, 2019 3:58 am

Re: How to shutdown Pi from Visual Basic 2017 Code - Solved

Thu Feb 07, 2019 6:36 am

Hi Scotty,
Thanks for the link. I had a little trouble navigating through the Visual Studio 2017 environment. (Haven't been doing VB since version 2008, so I had a bit of a learning curve to tackle.)
Anyway, I got it working!
Here's what I had to do:

Add reference:
Windows IoT Extensions for the UWP


At top of MainPage.xaml.vb:
Imports Windows.System


In my btnShutDown_Click event
ShutdownManager.BeginShutdown(ShutdownKind.Shutdown, TimeSpan.FromSeconds(0))


In my timer event
If activeShutDownpinIn.Read = GpioPinValue.Low Then
'ShutDown the device.
ShutdownManager.BeginShutdown(ShutdownKind.Shutdown, TimeSpan.FromSeconds(0))
End If


In Package.manifest
xmlns:iot="http://schemas.microsoft.com/appx/manif ... /windows10" (This is in the Package section.)
<iot:Capability Name="systemManagement" /> (This is in the Capabilities section.)


The environment complained about invalid child object but I saw another post that said to ignore it. I did and it worked.!

Thanks for the link! Cheers

Return to “Windows 10 for IoT”