Monday, May 4, 2009

Sending & Recieving SMS From VB.Net

For reading sms:

 Dim comSerial As New System.IO.Ports.SerialPort
        Dim atcCommand As String
        Dim sphnPhoneNo As String
        Dim cescQuote As Char
        Dim s As String


        With comSerial
            .PortName = "COM1"
            .BaudRate = "9600"
            .StopBits = IO.Ports.StopBits.One
            .DataBits = 8
            .Parity = IO.Ports.Parity.None
            .ReadBufferSize = 10000
            .ReadTimeout = 1000
            .WriteBufferSize = 10000
            .WriteTimeout = 10000
            .RtsEnable = True

            .Open()
            .DiscardOutBuffer()
            'for reading sms

            'atcCommand = "AT+CMGR=10"        'to read from inbox
            '.Write(atcCommand + vbCrLf)     'execute command on buffer
            'TextBox1.Text = .ReadExisting()



For sending sms:

 'for writing sms
            '.Write("AT+CMGF=1" + vbCrLf)

            
            cescQuote = Char.ConvertFromUtf32(34)
            sphnPhoneNo = "+914567352312"
            atcCommand = "AT+CMGS=" + cescQuote + sphnPhoneNo + cescQuote + vbCrLf + "WORLD" + Char.ConvertFromUtf32(26)
            '  .Write(atcCommand + vbCrLf)
            .WriteLine(atcCommand + vbCrLf)

            TextBox1.Text = .ReadExisting()
            .DiscardOutBuffer()
            .Close()

No comments:

Post a Comment