1
我想开发一个模块从我的应用程序发送短信。问题是,当我发送AT命令到连接的手机时,我的应用程序停止响应。我正在使用诺基亚6720C,并安装了Pc Suite。它也出现在COM端口中。通过USB GSM调制解调器发送短信
我的代码如下。我究竟做错了什么?
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
你在哪里定义'SerialPort1'? – Basic
我在我的窗体设计视图上使用SerialPort1 .. – Malik
谢谢。下一个问题,应用程序挂在哪一行?如果你在'SerialPort1.Open()'和“Step Over”每行代码上放置一个断点,你是否会到达'End Sub'?另外,你确定你有正确的COM端口吗? – Basic