通过vb.net应用发送短信 [英] Sending SMS through vb.net aaplication

查看:73
本文介绍了通过vb.net应用发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用以下代码从vb.net aaplication发送短信.

这里的代码:

Hi,

I am using the following code to send sms from vb.net aaplication.

Here the code:

Dim SMSEngine As New SMSCOMMS("COM1")
   Dim i As Integer

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SMSEngine.Open() 'open the port
        SMSEngine.SendSMS() 'send the SMS
    End Sub

Public Class SMSCOMMS
    Private WithEvents SMSPort As SerialPort
    Private SMSThread As Thread
    Private ReadThread As Thread
    Shared _Continue As Boolean = False
    Shared _ContSMS As Boolean = False
    Private _Wait As Boolean = False
    Shared _ReadPort As Boolean = False
    Public Event Sending(ByVal Done As Boolean)
    Public Event DataReceived(ByVal Message As String)
    

    Public Sub New(ByRef COMMPORT As String)
        'initialize all values
        SMSPort = New SerialPort
        With SMSPort
            .PortName = COMMPORT
            .BaudRate = 19200
            .Parity = Parity.None
            .DataBits = 8
            .StopBits = StopBits.One
            .Handshake = Handshake.RequestToSend
            .DtrEnable = True
            .RtsEnable = True
            .NewLine = vbCrLf
        End With
    End Sub

    Public Function SendSMS() As Boolean
        If SMSPort.IsOpen = True Then
            'sending AT commands
            SMSPort.WriteLine("AT")
            SMSPort.WriteLine("AT+CMGF=1" & vbCrLf) 'set command message format to text mode(1)
            SMSPort.WriteLine("AT+CSCA=""+919869099994""" & vbCrLf) 'set service center address (which varies for service providers (idea, airtel))
            SMSPort.WriteLine("AT+CMGS=  + TextBox1.text + " & vbCrLf) ' enter the mobile number whom you want to send the SMS
            _ContSMS = False
            SMSPort.WriteLine("+ TextBox1.text +" & vbCrLf & Chr(26)) 'SMS sending
            MessageBox.Show(":send")
            SMSPort.Close()
        End If
    End Function

    Public Sub Open()
        If Not (SMSPort.IsOpen = True) Then
            SMSPort.Open()
        End If
    End Sub

    Public Sub Close()
        If SMSPort.IsOpen = True Then
            SMSPort.Close()
        End If
    End Sub


请帮帮我,我在SMSPort.WriteLine("AT")
遇到错误
预先感谢,
parshu


Please help me out, I am getting error at SMSPort.WriteLine("AT")

Thanks in advance,
parshu

推荐答案

这里有几点要提.首先,您正在使用图书馆,因此您想与图书馆作者交谈.他们知道如何使用他们的图书馆.其次,就像有人说的那样,我出错了"是没有用的.什么错误?你读过它吗 ?您对此做了什么?
There''s a few points to raise here. First of all, you''re using a library, so you want to talk to the library authors. They know how to use their library. Second, as someone said, ''I am getting an error'' is useless. What error ? Did you read it ? What did you do about it ?


这篇关于通过vb.net应用发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆