简体   繁体   English

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

[英]Sending SMS via USB GSM Modem

I am trying to develop a module to send SMS from my application. 我正在尝试开发一个模块来从我的应用程序发送SMS。 The problem is that when I send an AT Command to a connected cell phone, my app stops responding. 问题是,当我向连接的手机发送AT命令时,我的应用程序停止响应。 I'm using a Nokia 6720C and I have installed Pc Suite. 我正在使用诺基亚6720C,并且已经安装了PC套件。 It also appears in the Com Ports. 它也出现在通讯端口中。

My code is below. 我的代码如下。 What am I doing wrong? 我究竟做错了什么?

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

Well, at the end of the AT command you must add Chr(13) and Chr(10), you used Chr(13) only (which is "vbCr"), try replacing it with vbCrLf (Carriage-Return "Chr(13)" and Line Feed "Chr(10)"). 好吧,在AT命令的末尾,您必须添加Chr(13)和Chr(10),您仅使用了Chr(13)(即“ vbCr”),请尝试将其替换为vbCrLf(回车返回“ Chr(13) )”和换行符“ Chr(10)”)。 I think this is the problem (the command string is not complete). 我认为这是问题所在(命令字符串不完整)。

If the problem still resides, try the following to test your work: 如果问题仍然存在,请尝试以下方法测试您的工作:

  1. Try using your VB.NET code to communicate with a GSM modem (not your phone). 尝试使用您的VB.NET代码与GSM调制解调器(而非电话)进行通信。 If it works fine, then maybe the phone does not accept AT commands. 如果工作正常,则电话可能不接受AT命令。

  2. Try using a terminal program to send the AT command to the phone. 尝试使用终端程序将AT命令发送到电话。 The terminal program can be like "Hyper Terminal" or "Maestro Smart Terminal" (you can search for it on google). 终端程序可以像“超级终端”或“ Maestro智能终端”(可以在Google上搜索)。

I hope this was helpful, good luck. 我希望这会有所帮助,祝你好运。

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

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