Read SW1 status and check serial for data at same time
#1
Posted 15 November 2011 - 10:14 PM
#2
Posted 15 November 2011 - 11:44 PM
- Arron Chapman likes this
#3
Posted 16 November 2011 - 07:26 AM
Hi Alberto,
Have you tried using the DataReceived event instead? That way you can grab data once it arrives, instead of just waiting for it?
You could also put some of your code on another thread, so it ran in parallel...
Chris
Hi Chris,
plase find the code underneath:
'Serial port declaration
Private WithEvents NDSerial As SerialPort
...
...
Sub Main()
..
NDSerial.Open()
'Wait for some event rises
Thread.Sleep(Timeout.Infinite)
..
End Sub
...
Private Sub SerialIn() Handles NDSerial.DataReceived
'HERE THE PROBLEM, I DON'T KNOW WHERE PLACE THE FOLLOWING CODE (OR SOMETHING SIMILAR) IN ORDER TO CHECK THE BUTTON STATUS OR BETTER, RISE AN EVENTS WHEN IT HAS BEEN PRESSED
While true
'Read ND+ button status
SW1_Button.Read()
loop
Thanx a lot for ur support!
Alberto
#4
Posted 16 November 2011 - 07:43 AM
#5
Posted 16 November 2011 - 08:19 AM
Hi Netduinerd,
You have to declare the switch as InterruptPort, so you will receive an event whenever it changes (as you receive interrupts with serial communication):
Private WithEvents SW1 As new InterruptPort(Pins.GPIO_PIN_6, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh)
Now it's clear.
Thanx a lot!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users