如何使用AT命令删除所有消息

时间:2018-01-11 13:47:50

标签: vb.net at-command

我有一个华为调制解调器连接到我的VB.net项目 所有AT命令都起作用,例如CONNECTREADSEND 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"总是

您认为我的代码有什么问题?除此之外,所有其他命令都有效。

2 个答案:

答案 0 :(得分:0)

我明白了,我只需要在每个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

答案 1 :(得分:0)

希望这会有所帮助。

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