title: Sending SMS via USB GSM Modem
body: <p>I am trying to develop a module to send SMS from my application. The problem is that when I send an AT Command to a connected cell phone, my app stops responding. I'm using a Nokia 6720C and I have installed Pc Suite. It also appears in the Com Ports.</p>
  
  <p>My code is below. What am I doing wrong?</p>
  
  <pre><code>Imports System
  Imports System.IO.Ports
  Imports System.Threading
  Imports System.ComponentModel
  
  Public Class Form1
  Delegate Sub SetTextCallback(ByVal [text] As String)
  Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
  
      With SerialPort1
          .PortName = "COM14"
          .DataBits = 8
          .Parity = IO.Ports.Parity.None
          .StopBits = StopBits.One
      End With
  
      SerialPort1.Open()
      SerialPort1.Write("AT" &amp; vbCr)
      SerialPort1.Close()
  End Sub
  
  Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
      ReceivedText(SerialPort1.ReadExisting())
  End Sub
  
  Private Sub ReceivedText(ByVal [text] As String)
      'compares the ID of the creating Thread to the ID of the calling Thread
      If Me.TxtResponse.InvokeRequired Then
          Dim x As New SetTextCallback(AddressOf ReceivedText)
          Me.Invoke(x, New Object() {(text)})
      Else
          Me.TxtResponse.Text &amp;= [text]
      End If
  End Sub
  </code></pre>