27 jan 2010

Sending SMS with GSM modem


i lost the link to the original webpage where i found this.
but it works ....

i used an HUAWEI E160E modem


Imports System.IO.Ports


Public Class SMSSender



Dim WithEvents serialport As New IO.Ports.SerialPort
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub New()

End Sub

Public Sub SendMessage(ByVal SerialPortName As String, ByVal PhoneNumber As String, ByVal TextMessage As String)
If SerialPort.IsOpen Then
SerialPort.Close()
End If

Try
SerialPort.PortName = SerialPortName
SerialPort.BaudRate = 192000
SerialPort.Parity = Parity.None
SerialPort.DataBits = 8
SerialPort.StopBits = StopBits.One
SerialPort.Handshake = Handshake.RequestToSend
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf
SerialPort.Open()

SerialPort.WriteLine("AT+CMGF=1" & vbCr)
System.Threading.Thread.Sleep(200)
SerialPort.WriteLine("AT+CMGS=" & Chr(34) & PhoneNumber & Chr(34) & vbCr)
System.Threading.Thread.Sleep(200)
SerialPort.WriteLine(TextMessage & vbCrLf & Chr(26))
System.Threading.Thread.Sleep(200)
Catch ex As Exception

Finally

SerialPort.Close()
End Try

End Sub

Public Sub GetModes(ByVal SerialPortName As String)
If SerialPort.IsOpen Then
SerialPort.Close()
End If
Dim myline As Object
Try
SerialPort.PortName = SerialPortName
SerialPort.BaudRate = 96000
SerialPort.Parity = Parity.None
SerialPort.DataBits = 8
SerialPort.StopBits = StopBits.One
SerialPort.Handshake = Handshake.RequestToSend
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf
SerialPort.Open()

SerialPort.WriteLine("AT+CMGF=1" & vbCr)
System.Threading.Thread.Sleep(200)
serialport.WriteLine("AT+CMGL=" + Chr(34) + "ALL" + Chr(34) & vbCr)
serialport.WriteLine("AT+CMGL=" + Chr(34) + "REC UNREAD" + Chr(34) & vbCr)
myline = SerialPort.ReadExisting()

Catch ex As Exception

Finally

serialport.Close()
serialport.Dispose()
End Try

End Sub

End Class


If you want to deploy sms for all your users use an smtp2sms gateway
there are plenty on the internet

i did a setup with
Network SMS Gateway and took about 5 minutes

enjoy

Geen opmerkingen:

Een reactie posten