functions of sending sms

LiL_Is

Member
Joined
Jul 16, 2009
Messages
11
Programming Experience
Beginner
how to write codes on sending sms?

Hi all,

I am new to visual basic and currently doing my major project on sending sms using visual studio 2005. I want to create it in window application. I have search the net but I could not understand it. Can anyone help me????

I have download some of the project that the net has found for me but when i test it the receiver did not received any message but the application have come out the popped out box saying "message send". Is there any method to solve the problem.

Thanks

Regard
LiL_Is
 
read the data from the serial port

Hi all,

I have this code for sending sms but the problem is that the message that has been sent out is not the full message. Here is the code that i am using:

VB.NET:
Public Class Form1
    Private WithEvents serialPort As New IO.Ports.SerialPort

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '---display all the serial port names on the local computer---
        For i As Integer = 0 To _
        My.Computer.Ports.SerialPortNames.Count - 1
            cbbCOMPorts.Items.Add( _
            My.Computer.Ports.SerialPortNames(i))
        Next
        btnDisconnect.Enabled = False
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        serialPort.Write("AT+CMGS=" & TextBox2.Text & vbCrLf & TextBox1.Text & Chr(26)) 'set command message format to text mode(1)
        MsgBox("sent")

    End Sub

    Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
        '---close the serial port if it is open---
        If serialPort.IsOpen Then
            serialPort.Close()
        End If
        Try
            '---configure the various parameters of the serial port---
            With serialPort
                .PortName = cbbCOMPorts.Text
                .BaudRate = 115200
                .Parity = IO.Ports.Parity.None
                .DataBits = 8
                .StopBits = IO.Ports.StopBits.One
            End With
            '---open the serial port---
            serialPort.Open()
            '---update the status of the serial port and
            ' enable/disable the buttons---
            lblMessage.Text = cbbCOMPorts.Text & " connected."
            btnConnect.Enabled = False
            btnDisconnect.Enabled = True
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
        Try
            '---close the serial port---
            serialPort.Close()
            '---update the status of the serial port and
            ' enable/disable the buttons---
            lblMessage.Text = serialPort.PortName & " disconnected."
            btnConnect.Enabled = True
            btnDisconnect.Enabled = False
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        serialPort.Write("AT" & vbCrLf) 'set command message format to text mode(1)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        serialPort.Write("AT+cmgf=1" & vbCrLf) 'set command message format to text mode(1)
    End Sub
End Class
 
Last edited by a moderator:
Hi all,

I have this code of sending sms but the difference is that i did not make a serial port as one class. I just make combine all as one. but with this code i can but the problem is that the sending is slow. I did not know how to implement it. As i asked the professional, they said that i have to include some thread class. Can anyone help me??? I have seen the other code for sending sms but the problem is the receiver did not received. Hope that anyone can help me..
Thanks
Here is the code that I am using:

Imports System.IO.Ports
Imports System.Threading
Imports System.Text.Encoding

Public Class Form1

Private WithEvents serialPort As New IO.Ports.SerialPort
Dim receivedData As String
Private ReadThread As Thread


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'---------------Display all the ports name which available-----------'
For i As Integer = 0 To _
My.Computer.Ports.SerialPortNames.Count - 1
cbbCOMPorts.Items.Add( _
My.Computer.Ports.SerialPortNames(i))
Next
btnDisconnect.Enabled = False
End Sub

Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
'---close the serial port if it is open---
If serialPort.IsOpen Then
serialPort.Close()
End If
Try
'---configure the various parameters of the serial port---
With serialPort
.PortName = cbbCOMPorts.Text
.BaudRate = 115200
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
'-----set the encoding to Unicode-----
.Encoding = System.Text.Encoding.Unicode

End With
'---open the serial port---
serialPort.Open()
'---update the status of the serial port and
' enable/disable the buttons---
lblShow.Text = cbbCOMPorts.Text & " connected."
btnConnect.Enabled = False
btnDisconnect.Enabled = True
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub

Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
Try
'---close the serial port---
serialPort.Close()
'---update the status of the serial port and
' enable/disable the buttons---
lblShow.Text = serialPort.PortName & " disconnected."
btnConnect.Enabled = True
btnDisconnect.Enabled = False
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click

serialPort.Write("AT+CMGS=" & RichTextBox1.Text & vbCrLf & TextBox1.Text & Chr(26)) 'set command message format to text mode(1)
MsgBox("Message has been sent")
End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
serialPort.Write("AT" & vbCrLf) 'set command message format to text mode(1)

End Sub

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
serialPort.Write("AT+CMGF=1" & vbCrLf) 'set command message format to text mode(1)

End Sub

Private Sub btnTo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTo.Click
Me.Hide()
Form2.Show()
End Sub

End Class
 
what is the error of this code?

Hi all,

I have this code of sending sms but the difference is that i did not make a serial port as one class. I just make combine all as one. but with this code i can but the problem is that the sending is slow. I did not know how to implement it. As i asked the professional, they said that i have to include some thread class. Can anyone help me??? I have seen the other code for sending sms but the problem is the receiver did not received. Hope that anyone can help me..
Thanks
Here is the code that I am using:

Imports System.IO.Ports
Imports System.Threading
Imports System.Text.Encoding

Public Class Form1

Private WithEvents serialPort As New IO.Ports.SerialPort
Dim receivedData As String
Private ReadThread As Thread


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'---------------Display all the ports name which available-----------'
For i As Integer = 0 To _
My.Computer.Ports.SerialPortNames.Count - 1
cbbCOMPorts.Items.Add( _
My.Computer.Ports.SerialPortNames(i))
Next
btnDisconnect.Enabled = False
End Sub

Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
'---close the serial port if it is open---
If serialPort.IsOpen Then
serialPort.Close()
End If
Try
'---configure the various parameters of the serial port---
With serialPort
.PortName = cbbCOMPorts.Text
.BaudRate = 115200
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
'-----set the encoding to Unicode-----
.Encoding = System.Text.Encoding.Unicode

End With
'---open the serial port---
serialPort.Open()
'---update the status of the serial port and
' enable/disable the buttons---
lblShow.Text = cbbCOMPorts.Text & " connected."
btnConnect.Enabled = False
btnDisconnect.Enabled = True
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub

Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
Try
'---close the serial port---
serialPort.Close()
'---update the status of the serial port and
' enable/disable the buttons---
lblShow.Text = serialPort.PortName & " disconnected."
btnConnect.Enabled = True
btnDisconnect.Enabled = False
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click

serialPort.Write("AT+CMGS=" & RichTextBox1.Text & vbCrLf & TextBox1.Text & Chr(26)) 'set command message format to text mode(1)
MsgBox("Message has been sent")
End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
serialPort.Write("AT" & vbCrLf) 'set command message format to text mode(1)

End Sub

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
serialPort.Write("AT+CMGF=1" & vbCrLf) 'set command message format to text mode(1)

End Sub

Private Sub btnTo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTo.Click
Me.Hide()
Form2.Show()
End Sub

End Class
 
not sending the whole message that is sent

Hi all,

I have this code of sending sms. I am sending the message using a serial port. The problem is that when i am sending the sms, it did not abstract the whole message that i type in the textbox. Does it got to do with the serial port?? Besides that, the receiver receives the message a bit late. Do I have to put a timeout for the serial port?? Hope that anyone can help.

Thanks
 
How to create a thread

Hi all,

I am having problems with my codes and i don't quite understand how to create thread. In this case why i use thread is because the sms that i am sending is only half of the sms that the receiver receives. Therefore, i am sending sms using the serialport. If can, hope to get help on creating the thread. Here is the code that i am implying.

Thanks.

Public Class Form1

Private WithEvents serialPort As New IO.Ports.SerialPort
Dim receivedData As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'---------------Display all the ports name which available-----------'
For i As Integer = 0 To _
My.Computer.Ports.SerialPortNames.Count - 1
cbbCOMPorts.Items.Add( _
My.Computer.Ports.SerialPortNames(i))
Next
btnDisconnect.Enabled = False
End Sub

Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
'---close the serial port if it is open---
If serialPort.IsOpen Then
serialPort.Close()
End If
Try
'---configure the various parameters of the serial port---
With serialPort
.PortName = cbbCOMPorts.Text
.BaudRate = 115200
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
'-----set the encoding to Unicode-----
.Encoding = System.Text.Encoding.Unicode

End With
'---open the serial port---
serialPort.Open()
'---update the status of the serial port and
' enable/disable the buttons---
lblShow.Text = cbbCOMPorts.Text & " connected."
btnConnect.Enabled = False
btnDisconnect.Enabled = True
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub

Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
Try
'---close the serial port---
serialPort.Close()
'---update the status of the serial port and
' enable/disable the buttons---
lblShow.Text = serialPort.PortName & " disconnected."
btnConnect.Enabled = True
btnDisconnect.Enabled = False
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click

serialPort.Write("AT+CMGS=" & RichTextBox1.Text & vbCrLf & TextBox1.Text & Chr(26)) 'set command message format to text mode(1)
MsgBox("Message has been sent")
End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
serialPort.Write("AT" & vbCrLf) 'set command message format to text mode(1)

End Sub

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
serialPort.Write("AT+CMGF=1" & vbCrLf) 'set command message format to text mode(1)

End Sub
End Class
 
Okay buddy, I'll tell you something...as far as I feel it you're close to the edge of spamming, and I wouldn't wonder if a mod kicks in if you don't stop that.

You sure haven't read the rules of the board (or any other community), or otherwise you'd know that you should not post a question more than once, cross-post or any other kind of spam the board.

As far as I see it there are two possibilities why nobody answers your call, first, nobody knows the answer, second, nobody understands your question. To make this even worse the code you're using isn't your own (I think I read that in a another post of you, if it is your own, sorry) and you might not even have clue of what's going on in or what the code even should do.

But to your question, it sounds more like you're violating the AT-Commands or SMS standards. Have a look at Wikipedia for explanation of the AT-Commands and also of the SMS standard.
VB.NET:
serialPort.Write("AT+CMGS=" & RichTextBox1.Text & vbCrLf & TextBox1.Text & Chr(26))
If you would have read through this stuff, you'd immediately recognize that that line is absolute crap. As far as I see it, the call shoudl be more like this:
VB.NET:
serialPort.Write("AT+CMGS=" & RichTextBox1.Text.Length.ToString() & vbCrLf & "PDU-encoded message goes here" & Chr(26))

Bobby
 
why did the sms that I send is only the first letter that the receiver receive?

Hi all,

I encounter some problem. The problem is that when I send the sms to the receiver but the receiver receives only the first letter of the sms. Eg:When I send the word:"helloo", the receiver receives only the letter "h". Is there any method to solve the problem that I encounter? Hope that anyone could help me.

Thanks
Here is the code that I am using:
Imports System.Windows.Forms.Form
Imports System.Text.Encoding
Imports System.Threading
Imports System.IO.Ports


Public Class Form1

Private WithEvents serialPort As New SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'---------------Display all the ports name which available-----------'
For i As Integer = 0 To _
My.Computer.Ports.SerialPortNames.Count - 1
cbbCOMPorts.Items.Add( _
My.Computer.Ports.SerialPortNames(i))
Next
End Sub

Private Sub Connect()
If cbbCOMPorts.SelectedIndex <> -1 Then
MessageBox.Show(cbbCOMPorts.Text)

End If

Try
'---configure the various parameters of the serial port---
With serialPort
.PortName = cbbCOMPorts.Text
.BaudRate = 115200
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
'-----set the encoding to Unicode-----
.Encoding = System.Text.Encoding.Unicode

End With


'---open the serial port---
serialPort.Open()
'---update the status of the serial port and
' enable/disable the buttons---
lblShow.Text = serialPort.PortName & " connected."

Catch ex As Exception
MessageBox.Show("you must select an item")
MsgBox(ex.ToString)

End Try

End Sub

Private Sub Disconnect()
Try
'---close the serial port---
serialPort.Close()
'---update the status of the serial port and
' enable/disable the buttons---
lblShow.Text = cbbCOMPorts.Text & " disconnected."
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Connect()
Try
Dim atcCommand As String
atcCommand = "AT+CMGS=" + RichTextBox1.Text
atcCommand = atcCommand & vbCrLf
serialPort.Write(atcCommand) 'enter the mobile number whom you want to send the SMS

serialPort.Write(textBox1.Text & vbCrLf & Chr(26))

While serialPort.BytesToWrite > 0
System.Threading.Thread.Sleep(100)
End While

MsgBox("Message sent")
Catch ex As Exception
MessageBox.Show("There was an error while sending")
'MessageBox.Show(ex.ToString) 'if you have erors
Finally
Disconnect()
End Try

End Sub
End Class
 
Back
Top