用vb和modem 3g发送sms消息

时间:2018-02-03 06:10:43

标签: vb.net

大家好,我创建了一个Windows窗体,它具有使用我的3g调制解调器向手机发送短信息的基本功能。我的调制解调器3g有负载用于发短信。我检查了我的设备管理器,我看到我的调制解调器3g已经连接但不幸的是,它没有向我的手机号码发送短信。到目前为止这是我的代码。顺便说一下,我的设备端口名是com4

Imports System.IO.Ports
Imports System.Threading
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As 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
            ComboBox1.SelectedIndex = 0
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.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()
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.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))
                    MsgBox("Succesfully Send!")
                End With
            Else
                MsgBox("Port not open!")
            End If
        Catch ex As Exception

        End Try
    End Sub
End Class

0 个答案:

没有答案