Here is my code....
Dim awatingResponseString As String = ""
Dim awaitingResponse As Boolean = False
Dim sp As SerialPort
Public Sub Main() Dim sp As New SerialPort(SerialPorts.COM1, 19200, Parity.Odd, 8, StopBits.One) SendSMS("18005551212", "test") End Sub
Public Sub PrintLine(ByVal line As String, Optional ByVal awaitResponse As Boolean = False, Optional ByVal awaitResponseString As String = "") If Not awaitResponseString.Equals("") Then awatingResponseString = awaitResponseString While Not awatingResponseString.Equals("") Thread.Sleep(1000) End While End If Print(line) If awaitResponse Then awaitingResponse = True While awaitingResponse Thread.Sleep(100) End While End If End Sub Private Sub Print(ByVal line As String) Dim encoder As New System.Text.UTF8Encoding() Dim bytesToSend As Byte() = encoder.GetBytes(line) sp.Write(bytesToSend, 0, bytesToSend.Length) End Sub Public Sub SendSMS(ByVal msisdn As String, ByVal message As String) 'PrintLine(""); PrintLine("AT+CMGF=1", True) PrintLine("AT+CMGS=""" & msisdn & """", False) PrintLine(message) Thread.Sleep(100) PrintEnd() Thread.Sleep(500) 'Debug.Print("SMS Sent!"); End Sub Private Sub PrintEnd() Dim bytesToSend As Byte() = New Byte(0) {} bytesToSend(0) = 26 sp.Write(bytesToSend, 0, 1) Thread.Sleep(200) End Sub
In the Print() function I get this error:
An unhandled exception of type 'System.NullReferenceException' occurred in Netduino Power Control.exe
And I get this error when I issue the sp.write.
I am trying understand how to test and debug with serial port but keep bumping my head here.
Can anyone offer help?
Thanks