【发布时间】:2015-05-07 23:59:02
【问题描述】:
我正在尝试使用 vb.net 2008 开发一个应用程序,以便从我的电脑向电话号码发送短信。我已经使用 USB 电缆(与 COM3 端口连接)将诺基亚手机连接到我的电脑。鉴于我编写的波纹管代码应该可以工作,但没有发送消息,并且我的应用程序处于死锁状态:
Imports System
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim ports As String() = SerialPort.GetPortNames
Dim port As String
For Each port In ports
ComboBox1.Items.Add(port)
Next port
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConnect.Click
Try
With SerialPort1
.PortName = ComboBox1.Text
.BaudRate = 9600
.Parity = Parity.None
.StopBits = StopBits.One
.DataBits = 8
.Handshake = Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
.Open()
MsgBox("Connected !", MsgBoxStyle.Information)
End With
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
Try
If SerialPort1.IsOpen Then
With SerialPort1
.Write("AT" & vbCrLf)
.Write("AT+CMGF=1" & vbCrLf)
.Write("AT+CMGS=" & Chr(34) & TextBox1.Text & Chr(34) & vbCrLf)
.Write(RichTextBox1.Text & Chr(26))
.Close()
MsgBox("Message Sent!", MsgBoxStyle.Information)
End With
Else
MsgBox("Error on port")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
【问题讨论】:
-
您能否阐明您遇到的确切问题以及它在代码中出现的位置,以便其他用户能够更好地帮助您?
-
尝试连接 com3 端口时,一切正常。但是当我点击发送按钮时,没有发送消息。我也遇到了僵局。