成功发送短信后如何获得确认?

时间:2013-08-11 04:35:26

标签: vb.net sms

在我的VB.Net应用程序中,我使用调制解调器(加密狗)以及连接到它的手机进行短信发送。

我是用AT命令完成的。
我需要在发送短信后在屏幕上显示确认/响应 我该怎么做?

一些代码段:

If IsOpen = True Then
        SMSPort.Write("AT" & vbCr)
        SMSPort.Write("AT+CSCS=""GSM""" & vbCr)
        SMSPort.Write("AT+CMGF=1" & vbCr)
        SMSPort.Write("AT+CMGS=""+91" & CellNumber & """" & vbCr)
        _ContSMS = False
        SMSPort.WriteLine(MyMessage & vbCrLf & Chr(26))
        _Continue = False
        RaiseEvent Sending(False)
    End If

1 个答案:

答案 0 :(得分:0)

- 您需要制作接收数据事件;

Imports System
Imports System.IO.Ports

Class PortDataReceived
Public Shared Sub Main()
    Dim mySerialPort As New SerialPort("COM1")

    mySerialPort.BaudRate = 9600
    mySerialPort.Parity = Parity.None
    mySerialPort.StopBits = StopBits.One
    mySerialPort.DataBits = 8
    mySerialPort.Handshake = Handshake.None

    AddHandler mySerialPort.DataReceived, AddressOf DataReceivedHandler

    mySerialPort.Open()

    Console.WriteLine("Press any key to continue...")
    Console.WriteLine()
    Console.ReadKey()
    mySerialPort.Close()
End Sub 

Private Shared Sub DataReceivedHandler(
                    sender As Object,
                    e As SerialDataReceivedEventArgs)
    Dim sp As SerialPort = CType(sender, SerialPort)
    Dim indata As String = sp.ReadExisting()
    Console.WriteLine("Data Received:")
    Console.Write(indata)
End Sub 
End Class

然后您需要弄清楚如何与您的提供商和硬件进行确认。