locked
AT Commands' Trouble - GSM Modem 900A RRS feed

  • Question

  • Hi!

    A simple test application with a single button on a form, code as follows, does not work. Working perfectly in Putty. Any reason/solution?

    Imports System
    Imports System.Threading
    Imports System.ComponentModel
    Imports System.IO.Ports
    Public Class Form1
        Dim SMSEngine As New SMSCOMMS("COM5")
        Dim i As Integer
        Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles Button1.Click
            SMSEngine.Open()
            SMSEngine.SendSMS()
        End Sub
    End Class
    Public Class SMSCOMMS
        Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
        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)
            SMSPort = New SerialPort
            With SMSPort
                .PortName = COMMPORT
                .BaudRate = 9600
                .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
                SMSPort.Write("AT" & vbCrLf)
                Sleep(1000)
                SMSPort.Write("AT+CMGF=1" & vbCrLf)
                Sleep(1000)
                SMSPort.Write("AT+CSCA=""+923330005150"",145" & vbCrLf)
                Sleep(1000)
                SMSPort.Write("AT+CMGS=""+923019270563"",145" & vbCrLf)
                Sleep(1000)
                _ContSMS = False
                SMSPort.Write("Hey!!! Got My Msg Correct???" & vbCrLf & Chr(26))
                Sleep(1000)
                MessageBox.Show("dONE")
                SMSPort.Close()
            End If
        End Function
     
        Public Sub Open()
            If Not (SMSPort.IsOpen = TrueThen
                SMSPort.Open()
            End If
        End Sub
     
        Public Sub Close()
            If SMSPort.IsOpen = True Then
                SMSPort.Close()
            End If
        End Sub
    End Class
    



    Saturday, June 25, 2016 9:21 AM