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

Serialport.read


  • Please log in to reply
26 replies to this topic

#21 JeroenG

JeroenG

    Member

  • Members
  • PipPip
  • 13 posts

Posted 26 November 2012 - 07:09 PM

Which error? On what line? :)


The error says: no conectie with netduino plus
The program is not loading, flashing of the netduino also not help.
I think that the problem is with the code: thred.sleep(infinite).
If i load a other program then is there no connection error.

And what are the voltage levels of te netduino UART i use a max 232.

Thanks a lot

#22 caEstrada

caEstrada

    Advanced Member

  • Members
  • PipPipPip
  • 84 posts

Posted 03 December 2012 - 02:24 AM

MAX232 should work with Netduino. However, do you have the diagram are you using with Max232 and its connections to Netduino? Any sample of your software code?

#23 caEstrada

caEstrada

    Advanced Member

  • Members
  • PipPipPip
  • 84 posts

Posted 03 December 2012 - 02:26 AM

In your code, execute a loop to read char by char waiting on the serial port. I have a problem reading complete lines and it was solved reading char by char...

#24 caEstrada

caEstrada

    Advanced Member

  • Members
  • PipPipPip
  • 84 posts

Posted 03 December 2012 - 02:33 AM

You download your program using USB. Netduino provides communications and debugging via USB with VisualStudio. So, you write your software and donwload it using USB. The UART (pin0, pin1) are used when you want to communicate with other equipments of your own, hyperterminal or other sensors. In simple words, use USB strictly to download and debug.

#25 JeroenG

JeroenG

    Member

  • Members
  • PipPip
  • 13 posts

Posted 04 December 2012 - 07:53 AM

I use this code but the code does not load in the netduino. If the program is loading in the netduino then says visual basic connection error with usb. If i loading an other program in the netduino example the led blink program then is there no connection error with usb.

Here's a program that will accept a string from the serial port and turn the LED on or off

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports System.IO.Ports
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.Netduino
Imports System.Text
Imports Microsoft.VisualBasic.Constants

Module Module1

  Private WithEvents UART As SerialPort
  Private DataFromPC As String = ""
  Private LED As New OutputPort(Pins.ONBOARD_LED, False)

  Sub Main()
    UART = New SerialPort("COM1", 19200, Parity.Even, 8, StopBits.One)
    UART.Open()
    Thread.Sleep(Timeout.Infinite)
  End Sub

  Private Sub SerialIn() Handles UART.DataReceived
    Dim Length As Integer = UART.BytesToRead
    Dim Datax(Length) As Byte

    UART.Read(Datax, 0, Length)
    DataFromPC &= New String(Encoding.UTF8.GetChars(Datax))

    If DataFromPC.IndexOf(vbLf) >= 0 Then
      DataFromPC = DataFromPC.Trim.ToUpper
      If DataFromPC = "ON" Then
        LED.Write(True)
      ElseIf DataFromPC = "OFF" Then
        LED.Write(False)
      Else
      End If
      DataFromPC = ""

    End If

  End Sub

End Module



#26 Selti

Selti

    New Member

  • Members
  • Pip
  • 5 posts

Posted 13 December 2012 - 04:14 PM

Hello, I am trying to test the above Code. The following wiring is based on: PC with USB to Serial (http://www.ftdichip....232R_CABLES.pdf) TTL 232R / pin 1 (black) GND --- Netduino GND          / Pin 4(orange) TXD --- Netduino pin 0 (RX)          / Pin 5 (Yellow) RXD --- Netduiono pin 1 (TX) But without success. Also the exchange of pin 0/1 was unsuccessful. Is the wiring wrong? Thanks'

#27 JeroenG

JeroenG

    Member

  • Members
  • PipPip
  • 13 posts

Posted 14 January 2013 - 09:53 AM

Imports Microsoft.SPOT

Imports Microsoft.SPOT.Hardware

Imports SecretLabs.NETMF.Hardware

Imports SecretLabs.NETMF.Hardware.NetduinoPlus

Imports System.IO.Ports

Imports Microsoft.VisualBasic.Constants

Imports System.Text

 

Module Module1

 

 

Private WithEvents rs232 As SerialPort

Dim led As New OutputPort(Pins.ONBOARD_LED, False)

Private sData As String = " "

 

Sub Main()

 

rs232 =New SerialPort("COM1", 9600, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One)

rs232.Open()

 

Do

 

Loop

 

End Sub

 

Private Sub SerialIn(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles rs232.DataReceived

 

 

Dim Length As Integer = rs232.BytesToRead

 

 

Dim Datax(Length) As Byte

 

rs232.Read(Datax, 0, Length)

 

sData &= System.Text.Encoding.UTF8.GetChars(Datax)

 

If sData = "OFF" Then

led.Write(False)

 

ElseIf sData = "ON" Then

led.Write(True)

 

End If

 

sData = " "

 

End Sub






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.