Some people ask me to have any soft start guide using microframework serial port. Well, as you know in desktop apps is the typical “Hello World”, the translation into serial port apps are “Echo for response”.
This code shows how to open the serial port to read incoming bytes and resend it as an echo. Is the first brick to check that the UART is all right! After this lab, you are ready to build your own DCE/DTE protocol and play serial commands between both sides.
Imports System.IO.Ports Imports System.Text Imports Microsoft.SPOT Imports Microsoft.SPOT.Hardware Module EchoResponse Private WithEvents SerialComm As SerialPort = New SerialPort("COM1", 9600, Parity.None, 8, StopBits.One) Private DataReceived As String = "" Private PortActivity As New OutputPort(CType(55, Cpu.Pin), False) Sub Main() SerialComm.Open() ' include your functions here Thread.Sleep(Timeout.Infinite) End Sub Private Sub SerialIn() Handles SerialComm.DataReceived PortActivity.Write(True) Dim Length As Integer = SerialComm.BytesToRead Dim Frame(Length) As Byte SerialComm.Read(Frame, 0, Length) SerialComm.Write(Frame, 0, Length) DataReceived = "" PortActivity.Write(False) End Sub End Module