Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Code VB 2010 - Send SMS via AT command

Code VB 2010 - Send SMS via AT command

Scheduled Pinned Locked Moved Windows Forms
graphics
2 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    caopv
    wrote on last edited by
    #1

    Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Text Imports System.IO.Ports Imports System.Threading Imports System.Text.RegularExpressions Public Class clsSMS #Region "Open and Close Ports" 'Open Port Public Function OpenPort(p_strPortName As String, p_uBaudRate As Integer, p_uDataBits As Integer, p_uReadTimeout As Integer, p_uWriteTimeout As Integer) As SerialPort receiveNow = New AutoResetEvent(False) Dim port As New SerialPort() Try port.PortName = p_strPortName 'COM1 port.BaudRate = p_uBaudRate '9600 port.DataBits = p_uDataBits '8 port.StopBits = StopBits.One '1 port.Parity = Parity.None 'None port.ReadTimeout = p_uReadTimeout '300 port.WriteTimeout = p_uWriteTimeout '300 port.Encoding = Encoding.GetEncoding("iso-8859-1") AddHandler port.DataReceived, New SerialDataReceivedEventHandler(AddressOf port_DataReceived) port.Open() port.DtrEnable = True port.RtsEnable = True Catch ex As Exception Throw ex End Try Return port End Function 'Close Port Public Sub ClosePort(port As SerialPort) Try port.Close() RemoveHandler port.DataReceived, New SerialDataReceivedEventHandler(AddressOf port_DataReceived) port = Nothing Catch ex As Exception Throw ex End Try End Sub #End Region 'Execute AT Command Public Function ExecCommand(port As SerialPort, command As String, responseTimeout As Integer, errorMessage As String) As String Try port.DiscardOutBuffer() port.DiscardInBuffer() receiveNow.Reset() port.Write(command & vbCr) Dim input As String = ReadResponse(port, responseTimeout) If (input.Length = 0) OrElse ((Not input.EndsWith(vbCr & vbLf & "> ")) AndAlso (Not input.EndsWith(vbCr & vbLf & "OK" & vbCr & vbLf))) Then Throw New ApplicationException("No success message was received.") End If Return input Catch ex As Exception Throw ex End Try End Function 'Receive data from port Public Sub port_DataReceived(sender As Object, e A

    B 1 Reply Last reply
    0
    • C caopv

      Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Text Imports System.IO.Ports Imports System.Threading Imports System.Text.RegularExpressions Public Class clsSMS #Region "Open and Close Ports" 'Open Port Public Function OpenPort(p_strPortName As String, p_uBaudRate As Integer, p_uDataBits As Integer, p_uReadTimeout As Integer, p_uWriteTimeout As Integer) As SerialPort receiveNow = New AutoResetEvent(False) Dim port As New SerialPort() Try port.PortName = p_strPortName 'COM1 port.BaudRate = p_uBaudRate '9600 port.DataBits = p_uDataBits '8 port.StopBits = StopBits.One '1 port.Parity = Parity.None 'None port.ReadTimeout = p_uReadTimeout '300 port.WriteTimeout = p_uWriteTimeout '300 port.Encoding = Encoding.GetEncoding("iso-8859-1") AddHandler port.DataReceived, New SerialDataReceivedEventHandler(AddressOf port_DataReceived) port.Open() port.DtrEnable = True port.RtsEnable = True Catch ex As Exception Throw ex End Try Return port End Function 'Close Port Public Sub ClosePort(port As SerialPort) Try port.Close() RemoveHandler port.DataReceived, New SerialDataReceivedEventHandler(AddressOf port_DataReceived) port = Nothing Catch ex As Exception Throw ex End Try End Sub #End Region 'Execute AT Command Public Function ExecCommand(port As SerialPort, command As String, responseTimeout As Integer, errorMessage As String) As String Try port.DiscardOutBuffer() port.DiscardInBuffer() receiveNow.Reset() port.Write(command & vbCr) Dim input As String = ReadResponse(port, responseTimeout) If (input.Length = 0) OrElse ((Not input.EndsWith(vbCr & vbLf & "> ")) AndAlso (Not input.EndsWith(vbCr & vbLf & "OK" & vbCr & vbLf))) Then Throw New ApplicationException("No success message was received.") End If Return input Catch ex As Exception Throw ex End Try End Function 'Receive data from port Public Sub port_DataReceived(sender As Object, e A

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      ? A big code dump. So what? What's the problem?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups