Vb.net 通过USB GSM调制解调器发送短信
我正在尝试开发一个模块,从我的应用程序发送短信。问题是,当我向连接的手机发送AT命令时,我的应用程序停止响应。我使用的是诺基亚6720C,我已经安装了Pc套件。它也出现在Com端口中 我的代码如下。我做错了什么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
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)”。我认为这就是问题所在(命令字符串不完整) 如果问题仍然存在,请尝试以下方法来测试您的工作:
我希望这会有帮助,祝你好运。你在哪里定义了
SerialPort1
?我在表单设计视图中使用了SerialPort1。谢谢。下一个问题,应用程序挂在哪一行?如果在SerialPort1.Open()
上放置一个断点并“跳过”每一行代码,您是否到达结束子节点
?另外,您确定有正确的COM端口吗?我将断点放在SerialPort1.open()上。。。它卡在了第二行,我正在给Port写信。。。它无法结束Sub…是的,我100%确定我使用的是正确的COM端口。。