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.

PhillipMorris

Member Since 08 May 2012
Offline Last Active Apr 09 2013 04:52 AM
-----

#29436 NetduinoGo - PC Serial Communication

Posted by PhillipMorris on 20 May 2012 - 05:45 PM

I would like to share my experience so far.
I used this board : FOCA Board v2.1

Connections
NetduinoGo gobus (Socket#1) pin 4 (Rx) to FOCA Board Tx
NetduinoGo gobus (Socket#1) pin 5 (Tx) to FOCA Board Rx
NetduinoGo gobus (Socket#1) pin 10 (Grd) to FOCA Board Grd

Here is the code :
Imports System.IO.Ports
Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoGo
Imports System.Text
Imports Microsoft.VisualBasic.Constants

Module Module1
    Dim IncomingText As String = ""

    Dim reading As Boolean = False
    Dim count As Integer
    Dim readLength As Integer
    Dim InTray As Byte()
    Public WithEvents SerialPort As New SerialPort("COM1", 9600, Parity.None, 8, StopBits.One)


    Sub Main()

        SerialPort.Open()
        AddHandler SerialPort.DataReceived, New SerialDataReceivedEventHandler(AddressOf serialPort_Datareceived)
        AddHandler SerialPort.ErrorReceived, New SerialErrorReceivedEventHandler(AddressOf serialPort_ErrorReceived)
        Thread.Sleep(Timeout.Infinite)

    End Sub

    Sub serialPort_ErrorReceived(ByVal sender As Object, ByVal e As SerialErrorReceivedEventArgs)
        Debug.Print(e.ToString)
    End Sub

    Sub serialPort_Datareceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
        'Debug.Print("Data Received")

        'Incoming Bytes
        Dim IncomingBytes As Integer = SerialPort.BytesToRead
        ' Create a new temporary store
        Dim DataStore(IncomingBytes) As Byte
        'Read in the bytes
        SerialPort.Read(DataStore, 0, IncomingBytes)
        'Convert Bytes to String
        IncomingText = System.Text.Encoding.UTF8.GetChars(DataStore)
        'Check for CarrageReturn and trim
        If IncomingText.IndexOf(vbCrLf) > 0 Then
            IncomingText = IncomingText.Trim
            Debug.Print(IncomingText & "  Len: " & IncomingText.Length)
            IncomingText = ""
        Else
            Debug.Print(IncomingText & "  Len: " & IncomingText.Length)
        End If

        'Send Data back
        'SerialPort.Write(Encoding.UTF8.GetBytes(strDataStore), 0, strDataStore.Length)

        'Do something with the data
        CheckRecievedData(IncomingText)
    End Sub

    'Do something with the data
    Sub CheckRecievedData(ByVal strData As String)
        Select Case strData
            Case ""

            Case "ON"

            Case "OFF"

        End Select
    End Sub

End Module

I will post the code of the Windows Application which accepts and send data from/to NetduinoGo probably tomorrow.
I hope that somebody will find it usefull.


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.