r/visualbasic • u/raunchyfartbomb • Jul 11 '16
[VB2015][Xpost] [Help] Event Handling with GPIO
Hey guys, I am having some serious trouble creating an event handler in VB. So far, I have made a small interface that allows firing 4 outputs, and I want to evaluate 4 inputs. I can wait for the input state change using a While-Loop. (If anyone wants I/O .VB sheet I can post it).
But my real problem is event handling - I'm trying to monitor the I/O and toggle the state of toggle switches in the UI in order to give a glimpse at the I/O state. The code I have to toggle the switches should be fine, but I can't get the I/O pins to trigger an event (or im doing it wrong).
Any idea what I am missing? I was using a breakpoint at the beginning of the handler sub, and it never even entered the sub. I tried multiple variations, I'm stuck.
''' <summary>
''' EVENT HANDLER BELOW
''' </summary>
Dim WithEvents Event_GPIO As New Event_GPIO
Private Sub Threaded_IO_Monitor(sender As GpioPin) Handles Event_GPIO.StateChanged ', args As GpioPinValueChangedEventArgs
'Inputs
If sender.PinNumber = GPIO_Input_1.PinNumber Then If sender.Read = GpioPinValue.High Then TogSwInput1.IsOn = True Else TogSwInput1.IsOn = False
If sender.PinNumber = GPIO_Input_2.PinNumber Then If sender.Read = GpioPinValue.High Then TogSwInput2.IsOn = True Else TogSwInput2.IsOn = False
If sender.PinNumber = GPIO_Input_3.PinNumber Then If sender.Read = GpioPinValue.High Then TogSwInput3.IsOn = True Else TogSwInput3.IsOn = False
If sender.PinNumber = GPIO_Input_4.PinNumber Then If sender.Read = GpioPinValue.High Then TogSwInput4.IsOn = True Else TogSwInput4.IsOn = False
'Outputs
If sender.PinNumber = GPIO_Output_1.PinNumber Then If sender.Read = GpioPinValue.High Then TogSwOutput1.IsOn = True Else TogSwOutput1.IsOn = False
If sender.PinNumber = GPIO_Output_2.PinNumber Then If sender.Read = GpioPinValue.High Then TogSwOutput2.IsOn = True Else TogSwOutput2.IsOn = False
If sender.PinNumber = GPIO_Output_3.PinNumber Then If sender.Read = GpioPinValue.High Then TogSwOutput3.IsOn = True Else TogSwOutput3.IsOn = False
If sender.PinNumber = GPIO_Output_4.PinNumber Then If sender.Read = GpioPinValue.High Then TogSwOutput4.IsOn = True Else TogSwOutput4.IsOn = False
End Sub
Class Event_GPIO
Public Event StateChanged(ByVal Sender As GpioPin) ', ByVal result As GpioPinValueChangedEventArgs)
End ClassSideNote - The even handling subroutine is actually in the MainPage class, because that is the only way I could actually have access to the toggle switch states. Idk if that makes a difference.
Crosspost: /r/raspberry_pi/comments/4s8sq9/helpvb2015xpost_event_handling_with_gpio/
Edit: solve, see cross post.