1

我正在尝试开发一个模块来从我的应用程序发送短信。问题是当我向连接的手机发送 AT 命令时,我的应用程序停止响应。我使用的是诺基亚 6720C,并且我已经安装了 Pc Suite。它也出现在 Com Ports 中。

我的代码如下。我究竟做错了什么?

Imports System
Imports System.IO.Ports
Imports System.Threading
Imports System.ComponentModel

Public Class Form1
Delegate Sub SetTextCallback(ByVal [text] As String)
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click

    With SerialPort1
        .PortName = "COM14"
        .DataBits = 8
        .Parity = IO.Ports.Parity.None
        .StopBits = StopBits.One
    End With

    SerialPort1.Open()
    SerialPort1.Write("AT" & vbCr)
    SerialPort1.Close()
End Sub

Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
    ReceivedText(SerialPort1.ReadExisting())
End Sub

Private Sub ReceivedText(ByVal [text] As String)
    'compares the ID of the creating Thread to the ID of the calling Thread
    If Me.TxtResponse.InvokeRequired Then
        Dim x As New SetTextCallback(AddressOf ReceivedText)
        Me.Invoke(x, New Object() {(text)})
    Else
        Me.TxtResponse.Text &= [text]
    End If
End Sub
4

1 回答 1

0

好吧,在 AT 命令的末尾你必须添加 Chr(13) 和 Chr(10),你只使用了 Chr(13)(即 "vbCr"),尝试用 vbCrLf 替换它(Carriage-Return "Chr(13) )" 和换行符 "Chr(10)")。我认为这是问题所在(命令字符串不完整)。

如果问题仍然存在,请尝试以下方法来测试您的工作:

  1. 尝试使用您的 VB.NET 代码与 GSM 调制解调器(而不是您的手机)进行通信。如果它工作正常,那么可能手机不接受 AT 命令。

  2. 尝试使用终端程序向手机发送 AT 命令。终端程序可以是“超级终端”或“大师智能终端”(你可以在谷歌上搜索)。

我希望这有帮助,祝你好运。

于 2013-01-03T17:55:33.670 回答