Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 通过USB GSM调制解调器发送短信_Vb.net_Serial Port - Fatal编程技术网

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

Vb.net 通过USB GSM调制解调器发送短信,vb.net,serial-port,Vb.net,Serial Port,我正在尝试开发一个模块,从我的应用程序发送短信。问题是,当我向连接的手机发送AT命令时,我的应用程序停止响应。我使用的是诺基亚6720C,我已经安装了Pc套件。它也出现在Com端口中 我的代码如下。我做错了什么 Imports System Imports System.IO.Ports Imports System.Threading Imports System.ComponentModel Public Class Form1 Delegate Sub SetTextCallback(B

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

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

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)”。我认为这就是问题所在(命令字符串不完整)

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

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

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


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

    你在哪里定义了
    SerialPort1
    ?我在表单设计视图中使用了SerialPort1。谢谢。下一个问题,应用程序挂在哪一行?如果在
    SerialPort1.Open()
    上放置一个断点并“跳过”每一行代码,您是否到达
    结束子节点
    ?另外,您确定有正确的COM端口吗?我将断点放在SerialPort1.open()上。。。它卡在了第二行,我正在给Port写信。。。它无法结束Sub…是的,我100%确定我使用的是正确的COM端口。。