vb.net 通过GSM调制解调器向手机发送短信
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15048609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending SMS through GSM modem to mobile phone
提问by MakAdin
Using VB.NET I need to send a SMS using GSM modem to a mobile phone.
使用 VB.NET 我需要使用 GSM 调制解调器向手机发送 SMS。
Currently I have the following code:
目前我有以下代码:
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
The thing is, it seems that this code is not working.
问题是,这段代码似乎不起作用。
Can you check if this is correct or not. Or just give me some threads which can help me with this.
你能检查一下这是否正确。或者只是给我一些可以帮助我解决这个问题的线程。
回答by Herdyawan Jaya
This code works for me and can send a message to your phone:
此代码适用于我,可以向您的手机发送消息:
{
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")
}
Note; this code I tried and received message from my phone like this; "?????#$??#????".
笔记; 这段代码我尝试过并从我的手机收到这样的消息;“?????#$??#????”。

