Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Read SW1 status and check serial for data at same time


  • Please log in to reply
4 replies to this topic

#1 Netduinerd

Netduinerd

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationVenice, Italy

Posted 15 November 2011 - 10:14 PM

Hi all, I'm trying to read the SW1 button status while my ND+ is waiting for data on the serial port without success. I did it separately, but I can't do it at the same time. Some suggestion? Thanx in advance. Alberto

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 15 November 2011 - 11:44 PM

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

#3 Netduinerd

Netduinerd

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationVenice, Italy

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 Dixon

Dixon

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 16 November 2011 - 07:43 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)

#5 Netduinerd

Netduinerd

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationVenice, Italy

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

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.