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.
- Gutworks likes this