使用VB.NET我需要使用GSM调制解调器向手机发送短信。
目前我有以下代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If serialport.IsOpen Then
serialport.Close()
End If
Try
With serialport
.PortName = ComboBox1.Text
.BaudRate = 96000
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Handshake = Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
End With
serialport.Open()
Catch ex As Exception
End Try
serialport.WriteLine("AT+CMGF=1" & vbCr)
System.Threading.Thread.Sleep(200)
serialport.WriteLine("AT+CMGS=" & Chr(34) & "destination" & Chr(34) & vbCr)
System.Threading.Thread.Sleep(200)
serialport.WriteLine("test message" & vbCrLf & Chr(26))
System.Threading.Thread.Sleep(200)
End Sub
问题是,似乎这段代码无效。
你能检查一下这是否正确。或者只是给我一些可以帮助我的线程。
答案 0 :(得分:0)
此代码适用于我,可以向您的手机发送消息:
{
SerialPort1.WriteLine("AT")
System.Threading.Thread.Sleep(300)
SerialPort1.WriteLine("AT+CMGF=1" & vbCrLf)
System.Threading.Thread.Sleep(300)
SerialPort1.WriteLine("AT+CSCA=" & Chr(34) & MessageCenter & Chr(34) & vbCrLf)
System.Threading.Thread.Sleep(300)
SerialPort1.WriteLine("AT+CMGS=" & Chr(34) & PhoneNumber & Chr(34) & vbCrLf)
System.Threading.Thread.Sleep(300)
SerialPort1.WriteLine(Message & Chr(26))
MsgBox("Send")
}
请注意;这个代码我尝试并从我的手机收到这样的消息; “?????#$ ??#????”。