我正在尝试开发一个模块来从我的应用程序发送短信。问题是当我向连接的手机发送 AT 命令时,我的应用程序停止响应。我使用的是诺基亚 6720C,并且我已经安装了 Pc Suite。它也出现在 Com Ports 中。
我的代码如下。我究竟做错了什么?
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