⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testatsms.vb

📁 通过串口发送短信的模块,采用vb.net编写
💻 VB
📖 第 1 页 / 共 2 页
字号:
    End Sub

    Private Sub btnATDiagnostics_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnATDiagnostics.Click
        Try
            MsgBox("AT command file should be c:\temp\AT.txt, output file is c:\temp\ATout.txt", MsgBoxStyle.Information)
            If oPhone.Diagnose("c:\temp\at.txt", "c:\temp\atout.txt") Then
                MsgBox("Diagnostics done")
            End If
        Catch ex As System.Exception
            MsgBox(ex.Message, MsgBoxStyle.Information)
        End Try
    End Sub

    Private Sub oPhone_NewIncomingCall(ByVal e As ATSMS.NewIncomingCallEventArgs) Handles _
                oPhone.NewIncomingCall
        txtMsg.Text = txtMsg.Text & "Incoming call from " & e.CallerID & ControlChars.CrLf
    End Sub


    Private Sub btnClass2SMS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClass2SMS.Click
        If Len(txtMSISDN.Text) = 0 Then
            MsgBox("Please enter a phone number", MsgBoxStyle.Information)
            Exit Sub
        End If
        oPhone.Encoding = EnumEncoding.Class2_7_Bit
        Dim msgId As String = oPhone.SendSMS(txtMSISDN.Text, txtMsg.Text)
        MsgBox("Message sent. Message id is " + msgId)
    End Sub

    Private Sub oPhone_NewMessageReceived(ByVal e As ATSMS.NewMessageReceivedEventArgs) Handles oPhone.NewMessageReceived
        txtMsg.Text = "Received msg from " & e.MSISDN & ControlChars.CrLf & e.TextMessage & ControlChars.CrLf
    End Sub

    Private Sub btnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbout.Click
        MsgBox(oPhone.About)
    End Sub


    Private Sub btnSMS8Bit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSMS8Bit.Click
        If Len(txtMSISDN.Text) = 0 Then
            MsgBox("Please enter a phone number", MsgBoxStyle.Information)
            Exit Sub
        End If
        oPhone.Encoding = EnumEncoding.Class2_8_Bit
        Dim msgId As String = oPhone.SendSMS(txtMSISDN.Text, txtMsg.Text)
        MsgBox("Message sent. Message id is " + msgId)
    End Sub

    Private Sub btnOutbox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOutbox.Click
        If Len(txtMSISDN.Text) = 0 Then
            MsgBox("Please enter a phone number", MsgBoxStyle.Information)
            Exit Sub
        End If
        oPhone.Encoding = EnumEncoding.GSM_Default_7Bit
        Dim i As Integer
        For i = 1 To 3
            Dim msgId As String = oPhone.SendSMSToOutbox(txtMSISDN.Text, txtMsg.Text)
            MsgBox("Message sent to Outbox . Queue message id is " + msgId)
        Next
    End Sub

    Private Sub oPhone_OutboxSMSSent(ByVal e As ATSMS.OutboxSMSSentEventArgs) Handles oPhone.OutboxSMSSent
        MsgBox("Queue msg no " + e.QueueMessageKey + " Msg Ref No: " + e.MessageReference)
    End Sub

    Private Sub btnAnalyzePhone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnalyzePhone.Click
        If oPhone.IsConnected Then
            oPhone.CheckATCommands()
        End If
    End Sub

    Private Sub btnInbox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMsgStore.Click
        If oPhone.IsConnected Then
            Dim msgStore As MessageStore = oPhone.MessageStore
            oPhone.MessageMemory = EnumMessageMemory.PHONE
            msgStore.Refresh()
            Dim i As Integer
            For i = 0 To msgStore.Count - 1
                Dim sms As SMSMessage = msgStore.Message(i)
                MsgBox(sms.Text)
                sms.Delete()
            Next
        End If
    End Sub

    Private Sub btnManualConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnManualConnect.Click
        Dim strComPort As String = InputBox("Enter COM Port", "COM Port Setting")
        Try
            If oPhone.IsConnected Then oPhone.Disconnect()
            oPhone.Port = strComPort
            oPhone.BaudRate = 9600
            oPhone.DataBits = 8
            oPhone.Parity = EnumParity.None
            oPhone.StopBits = EnumStopBits.One
            oPhone.FlowControl = EnumFlowControl.RTS_CTS
            oPhone.Connect()
            MsgBox("Connected to " + oPhone.Port, MsgBoxStyle.Information)
            oPhone.Echo = False
            EnableButtons()
        Catch ex As GeneralException
            DisableButtons()
            MsgBox("Error connecting: " + ex.Message)
        End Try
    End Sub

    Private Sub EnableButtons()
        btnAutoDetect.Enabled = False
        btnManualConnect.Enabled = False
        btnDisconnect.Enabled = True
        btnIMSI.Enabled = True
        btnIMEI.Enabled = True
        btnPhoneModel.Enabled = True
        btnDial.Enabled = True
        btnAnswer.Enabled = True
        btnHangup.Enabled = True
        btnDtmfDigits.Enabled = True
        btnSendDtmf.Enabled = True
        btnSendTextSms.Enabled = True
        btnSendHexSms.Enabled = True
        btnSendUnicodeSms.Enabled = True
        btnSMSC.Enabled = True
        btnEnableCLIP.Enabled = True
        btnDisableCLIP.Enabled = True
        btnMSISDN.Enabled = True
        btnManufacturer.Enabled = True
        btnRevision.Enabled = True
        btnInitMsgIndication.Enabled = True
        btnQueryMsgIndication.Enabled = True
        btnQueryStorageSupported.Enabled = True
        btnQueryStorageSettings.Enabled = True
        btnEnableCLIR.Enabled = True
        btnDisableCLIR.Enabled = True
        btnQueryLocation.Enabled = True
        btnQueryBatteryLevel.Enabled = True
        btnQueryRSSI.Enabled = True
        btnATDiagnostics.Enabled = True
        btnClass2SMS.Enabled = True
        btnSMS8Bit.Enabled = True
        btnOutbox.Enabled = True
        btnAnalyzePhone.Enabled = True
        btnMsgStore.Enabled = True
        btnVCard.Enabled = True
        btnVCalendar.Enabled = True
        btnWapPush.Enabled = True
        btnDeleteMsg.Enabled = True

        oPhone.NewMessageIndication = True
        oPhone.IncomingCallIndication = True
        oPhone.AutoDeleteSentMessage = True
        oPhone.AutoDeleteReadMessage = False

    End Sub

    Private Sub DisableButtons()
        btnDisconnect.Enabled = False
        btnIMSI.Enabled = False
        btnIMEI.Enabled = False
        btnPhoneModel.Enabled = False
        btnDial.Enabled = False
        btnAnswer.Enabled = False
        btnHangup.Enabled = False
        btnDtmfDigits.Enabled = False
        btnSendDtmf.Enabled = False
        btnSendTextSms.Enabled = False
        btnSendHexSms.Enabled = False
        btnSendUnicodeSms.Enabled = False
        btnSMSC.Enabled = False
        btnEnableCLIP.Enabled = False
        btnDisableCLIP.Enabled = False
        btnMSISDN.Enabled = False
        btnManufacturer.Enabled = False
        btnRevision.Enabled = False
        btnInitMsgIndication.Enabled = False
        btnQueryMsgIndication.Enabled = False
        btnQueryStorageSupported.Enabled = False
        btnQueryStorageSettings.Enabled = False
        btnEnableCLIR.Enabled = False
        btnDisableCLIR.Enabled = False
        btnQueryLocation.Enabled = False
        btnQueryBatteryLevel.Enabled = False
        btnQueryRSSI.Enabled = False
        btnATDiagnostics.Enabled = False
        btnClass2SMS.Enabled = False
        btnSMS8Bit.Enabled = False
        btnOutbox.Enabled = False
        btnAnalyzePhone.Enabled = False
        btnMsgStore.Enabled = False
        btnVCard.Enabled = False
        btnVCalendar.Enabled = False
        btnWapPush.Enabled = False
        btnDeleteMsg.Enabled = False
    End Sub

    Private Sub btnVCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVCard.Click
        Dim v As New vCard
        v.LastName = "Meng Wang"
        'v.Emails = New vCard.vEmails()
        'v.Emails.Add(New vCard.vEmail("mengwangk@gmail.com"))
        v.Telephones = New vCard.vTelephones
        v.Telephones.Add(New vCard.vTelephone("0192292309", vCard.vLocations.CELL, vCard.vPhoneTypes.VOICE, True))
        If Len(txtMSISDN.Text) = 0 Then
            MsgBox("Please enter a phone number", MsgBoxStyle.Information)
            Exit Sub
        End If
        Dim msgId As String = oPhone.SendSMS(txtMSISDN.Text, v.ToString)
        MsgBox("Message sent. Message id is " + msgId)
    End Sub

    Private Sub btnVCalendar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVCalendar.Click
        Dim v As New vCalendar
        Dim vE As New vCalendar.vEvent
        vE.DTStart = New Date
        vE.DTEnd = New Date
        vE.Organizer = "Test Org"
        vE.Summary = "Test Summary"
        v.Events.Add(vE)
        If Len(txtMSISDN.Text) = 0 Then
            MsgBox("Please enter a phone number", MsgBoxStyle.Information)
            Exit Sub
        End If
        Dim msgId As String = oPhone.SendSMS(txtMSISDN.Text, v.ToString)
        MsgBox("Message sent. Message id is " + msgId)
    End Sub

    Private Sub btnWapPush_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWapPush.Click

        Dim href As String = "http://www.sharemymobile.com"
        Dim text As String = "Share your mobile today"
        Dim body As String = New WapPushMessage(href, text).ToString
        MsgBox(body)
        If Len(txtMSISDN.Text) = 0 Then
            MsgBox("Please enter a phone number", MsgBoxStyle.Information)
            Exit Sub
        End If
        oPhone.Encoding = EnumEncoding.Hex_Message
        Dim msgId As String = oPhone.SendSMS(txtMSISDN.Text, body)
        MsgBox("Message sent. Message id is " + msgId)
    End Sub

    Private Sub btnDeleteMsg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteMsg.Click
        If oPhone.IsConnected Then
            Dim msgStore As MessageStore = oPhone.MessageStore
            oPhone.MessageMemory = EnumMessageMemory.PHONE
            msgStore.Refresh()
            Dim i As Integer
            For i = 0 To msgStore.Count - 1
                Dim sms As SMSMessage = msgStore.Message(i)
                sms.Delete()
            Next
        End If
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -