如何使用 AT 命令删除所有消息
How to delete all messages using AT commands
我有一个华为调制解调器连接到我的 VB.net 项目
所有 AT 命令都有效,例如 CONNECT
、READ
和 SEND SMS
我唯一无法使用的是 DELETE SMS
我有这个代码:
With SerialPort1
.Write("AT")
Threading.Thread.Sleep(1000)
.Write("AT+CMGF=1")
Threading.Thread.Sleep(1000)
.Write("AT+CPMS=""SM""" & vbCrLf)
Threading.Thread.Sleep(1000)
.Write("AT+CMGD=1,4")
Threading.Thread.Sleep(1000)
MsgBox(at_status.ToString)
End With
但是at_status
总是让我"ERROR"。
AT+CMGD=1,4
因为我在文档中读到的是正确的命令,但它总是给我一个 "ERROR"。
您认为我的代码有什么问题?所有其他命令都有效,除了这个。
我想出来了,我只需要在每个 AT 指令后放一些换行符& vbCrLf
。
With SerialPort1
.Write("AT" & vbCrLf)
Threading.Thread.Sleep(1000)
.Write("AT+CMGF=1" & vbCrLf)
Threading.Thread.Sleep(1000)
.Write(TextBox3.Text & vbCrLf)
Threading.Thread.Sleep(1000)
.Write("AT+CMGD=1,4" & vbCrLf)
Threading.Thread.Sleep(1000)
MsgBox(at_status.ToString)
End With
希望对您有所帮助。
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Try
With SerialPort1
.Write("AT" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CMGF=1" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CPMS=""SM""" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CMGD=" & Label9.Text & "" & vbCrLf)
Threading.Thread.Sleep(100)
'MsgBox(ReceivedData.ToString
If ReceivedData.ToString.Contains("ERROR") Then
MsgBox("Got some error", MsgBoxStyle.Critical, "Error")
Else
MsgBox("Message Deleted", MsgBoxStyle.Information, "Deleted")
ListView1.Items.Clear()
ReceivedData = ""
Try
With SerialPort1
.Write("AT" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CMGF=1" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CPMS=""SM""" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CMGL=""ALL""" & vbCrLf)
Threading.Thread.Sleep(100)
ReadMesssage()
End With
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Label11.Text = ListView1.Items.Count
Label9.Text = ""
End If
End With
Catch ex As Exception
End Try
End Sub
我有一个华为调制解调器连接到我的 VB.net 项目
所有 AT 命令都有效,例如 CONNECT
、READ
和 SEND SMS
我唯一无法使用的是 DELETE SMS
我有这个代码:
With SerialPort1
.Write("AT")
Threading.Thread.Sleep(1000)
.Write("AT+CMGF=1")
Threading.Thread.Sleep(1000)
.Write("AT+CPMS=""SM""" & vbCrLf)
Threading.Thread.Sleep(1000)
.Write("AT+CMGD=1,4")
Threading.Thread.Sleep(1000)
MsgBox(at_status.ToString)
End With
但是at_status
总是让我"ERROR"。
AT+CMGD=1,4
因为我在文档中读到的是正确的命令,但它总是给我一个 "ERROR"。
您认为我的代码有什么问题?所有其他命令都有效,除了这个。
我想出来了,我只需要在每个 AT 指令后放一些换行符& vbCrLf
。
With SerialPort1
.Write("AT" & vbCrLf)
Threading.Thread.Sleep(1000)
.Write("AT+CMGF=1" & vbCrLf)
Threading.Thread.Sleep(1000)
.Write(TextBox3.Text & vbCrLf)
Threading.Thread.Sleep(1000)
.Write("AT+CMGD=1,4" & vbCrLf)
Threading.Thread.Sleep(1000)
MsgBox(at_status.ToString)
End With
希望对您有所帮助。
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Try
With SerialPort1
.Write("AT" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CMGF=1" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CPMS=""SM""" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CMGD=" & Label9.Text & "" & vbCrLf)
Threading.Thread.Sleep(100)
'MsgBox(ReceivedData.ToString
If ReceivedData.ToString.Contains("ERROR") Then
MsgBox("Got some error", MsgBoxStyle.Critical, "Error")
Else
MsgBox("Message Deleted", MsgBoxStyle.Information, "Deleted")
ListView1.Items.Clear()
ReceivedData = ""
Try
With SerialPort1
.Write("AT" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CMGF=1" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CPMS=""SM""" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CMGL=""ALL""" & vbCrLf)
Threading.Thread.Sleep(100)
ReadMesssage()
End With
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Label11.Text = ListView1.Items.Count
Label9.Text = ""
End If
End With
Catch ex As Exception
End Try
End Sub