繁体   English   中英

通过USB GSM调制解调器发送短信

[英]Sending SMS via USB GSM Modem

我正在尝试开发一个模块来从我的应用程序发送SMS。 问题是,当我向连接的手机发送AT命令时,我的应用程序停止响应。 我正在使用诺基亚6720C,并且已经安装了PC套件。 它也出现在通讯端口中。

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

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

好吧,在AT命令的末尾,您必须添加Chr(13)和Chr(10),您仅使用了Chr(13)(即“ vbCr”),请尝试将其替换为vbCrLf(回车返回“ Chr(13) )”和换行符“ Chr(10)”)。 我认为这是问题所在(命令字符串不完整)。

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

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

  2. 尝试使用终端程序将AT命令发送到电话。 终端程序可以像“超级终端”或“ Maestro智能终端”(可以在Google上搜索)。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM