Hi all,
I know a little bit of thread but the problem is that I did not know how to implement it to my code. I have this code that send sms but when the sms is send, it sent successfully but the message that is sent is only half the message that i have type. I am using serial port to send sms. Hope that anyone can help.
Thanks.Here is the code that i am using:
Public Class Form1Private WithEvents serialPort As New IO.Ports.SerialPort
Dim receivedData As String
Private ReadThread As ThreadPrivate 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 SubPrivate 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.UnicodeEnd 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 TryEnd 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 SubPrivate 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