Results 1 to 9 of 9

Thread: [RESOLVED] SMS sending only working in Debug mode

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    162

    Resolved [RESOLVED] SMS sending only working in Debug mode

    hello. i have a small application that is meant to send out smses using AT commands in Vb .net.
    the code seems to be working fine when i am debugging but when i run the normal way no sms is send. the following is my code, please help me see where i am going wrong.

    dim smsPort As New SerialPort

    smsPort.PortName = "COM18"
    smsPort.BaudRate = "921600"
    smsPort.Parity = Parity.None
    smsPort.DataBits = 8
    smsPort.StopBits = StopBits.One
    smsPort.Handshake = Handshake.RequestToSend
    smsPort.DtrEnable = True
    smsPort.RtsEnable = True
    smsPort.NewLine = vbCrLf

    If Not (smsPort.IsOpen = True) Then
    smsPort.Open()
    End If

    smsPort.WriteLine("AT" & vbCrLf)
    smsPort.WriteLine("AT+CMGF=1" & vbCrLf)
    smsPort.WriteLine("AT+CMGS=" + Chr(34) + Trim(TextBoxMobileNumber.Text) + Chr(34) + vbCrLf)
    smsPort.WriteLine(Trim(TextBoxMessage.Text) + vbCrLf + Chr(26))


    If smsPort.IsOpen = True Then
    smsPort.Close()
    End If

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: SMS sending only working in Debug mode

    If you are doing this on the same machine, likely you are opending the port but not always closing it.
    You need to add some error trapping to tell you what the problem is. We don't have your modem or your settings to test it . Have you tried running it as a .exe after a reboot (ie BEFORE running it in debug).

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    162

    Re: SMS sending only working in Debug mode

    the problem is its not giving any error at all.

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: SMS sending only working in Debug mode

    Show the whole method and how you call it, not just the part in question.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    162

    Re: SMS sending only working in Debug mode

    thats pretty much everything..of course with beginning and end of sub for the button click event.if i step through in code an sms is send but if i run without debug nothing is send. i will give the code again anyway as follows,

    Public smsPort As New SerialPort
    Private Sub ButtonSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSend.Click
    smsPort.PortName = "COM18"
    smsPort.BaudRate = "921600"
    smsPort.Parity = Parity.None
    smsPort.DataBits = 8
    smsPort.StopBits = StopBits.One
    smsPort.Handshake = Handshake.RequestToSend
    smsPort.DtrEnable = True
    smsPort.RtsEnable = True
    smsPort.NewLine = vbCrLf

    If Not (smsPort.IsOpen = True) Then
    smsPort.Open()
    End If

    smsPort.WriteLine("AT" & vbCrLf)
    smsPort.WriteLine("AT+CMGF=1" & vbCrLf)
    smsPort.WriteLine("AT+CMGS=" + Chr(34) + Trim(TextBoxMobileNumber.Text) + Chr(34) + vbCrLf)
    smsPort.WriteLine(Trim(TextBoxMessage.Text) + vbCrLf + Chr(26))

    If smsPort.IsOpen = True Then
    smsPort.Close()
    End If


    MsgBox("message sending complete")
    End Sub

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: SMS sending only working in Debug mode

    There is nothing in your code that makes any difference in run mode. How do you run it "the normal way"? Are you using any breakpoints which might be slowing down the execution?
    Last edited by Grimfort; May 27th, 2011 at 05:18 PM.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    162

    Re: SMS sending only working in Debug mode

    finally i stumbled on a solution to my problem. i have added a "sleeper" code before and after writing the message as follows,

    smsPort.WriteLine("AT" & vbCrLf)
    smsPort.WriteLine("AT+CMGF=1" & vbCrLf)
    smsPort.WriteLine("AT+CMGS=" + Chr(34) + Trim(txtRecipient.Text) + Chr(34) + vbCrLf)

    System.Threading.Thread.Sleep(200)
    smsPort.WriteLine(Trim(txtMessage.Text) + vbCrLf + Chr(26))
    System.Threading.Thread.Sleep(200)

    someone else used this code and it works for me though i dont quite understand it. i was thinking more along the lines of a refresh but looks like this sleeper code did it.

  8. #8
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: SMS sending only working in Debug mode

    Well was on the right track, if you were stepping through the code in debug, it would slow down the code. Sending the data through to fast to the modem would make it believe it is all one command.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Posts
    162

    Re: [RESOLVED] SMS sending only working in Debug mode

    i see..it makes sense...perhaps you can help me solve my next question. i have posted it as another thread. now i am trying to loop through a list of numbers sending smses and it only sends to the first one. the loop is working fine but the other numbers are not receiving anything.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width