Results 1 to 5 of 5

Thread: how to create a program that receives messages using at commands in vb 2010?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    7

    how to create a program that receives messages using at commands in vb 2010?

    hey guys i really need some help.

    i tried this codes below that i created but it cant receive messages. and if it can i like to read it directly in Richtextbox.

    here is the code:

    Public Sub receive()
    If srPort.IsOpen = True Then
    Try

    With srPort
    .WriteLine("AT")
    .WriteLine("AT+CMGF=1" & Chr(34) & vbCrLf)
    .WriteLine("AT+CSCS=""PCCP437""" & Chr(34) & vbCrLf)
    .WriteLine("AT+CPMS=""SM""" & Chr(34) & vbCrLf)
    .WriteLine("AT+CMGL=""REC UNREAD""" & receiveRT.Text & vbCrLf)


    End With
    Catch ex As Exception

    End Try

    End If
    End Sub

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: how to create a program that receives messages using at commands in vb 2010?

    You're trying to read yet....:-
    Code:
    .WriteLine("AT+CSCS=""PCCP437""" & Chr(34) & vbCrLf)
    You seriously don't expect a function named "WriteLine" to do any thing like reading, do you ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: how to create a program that receives messages using at commands in vb 2010?

    A couple of suggestions.

    1) Don't use WriteLine. Use Write. For example
    .WriteLine("AT+CMGF=1" & Chr(34) & vbCrLf)
    would be
    .Write("AT+CMGF=1" & Chr(34) & ControlChars.Cr)

    Note that the string is concatenated with CR because this is the default modem end-of-command character. Sending linefeeds is not required.

    2) After each write put a readline to read the results.

    I'd not use the With style. Try it like this

    Code:
            Dim s As String
            srPort.Write("AT" & ControlChars.Cr)
            s = srPort.ReadLine
            Debug.WriteLine(s)
    
            srPort.Write("AT+CMGF=1" & Chr(34) & ControlChars.Cr)
            s = srPort.ReadLine
            Debug.WriteLine(s)
    If the command returns more that one line you will need multiple readlines to get the results.

    Use code tags when you post code.
    Last edited by dbasnett; May 6th, 2013 at 08:03 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    7

    Re: how to create a program that receives messages using at commands in vb 2010?

    Quote Originally Posted by dbasnett View Post
    A couple of suggestions.

    1) Don't use WriteLine. Use Write. For example
    .WriteLine("AT+CMGF=1" & Chr(34) & vbCrLf)
    would be
    .Write("AT+CMGF=1" & Chr(34) & ControlChars.Cr)

    Note that the string is concatenated with CR because this is the default modem end-of-command character. Sending linefeeds is not required.

    2) After each write put a readline to read the results.

    I'd not use the With style. Try it like this

    Code:
            Dim s As String
            srPort.Write("AT" & ControlChars.Cr)
            s = srPort.ReadLine
            Debug.WriteLine(s)
    
            srPort.Write("AT+CMGF=1" & Chr(34) & ControlChars.Cr)
            s = srPort.ReadLine
            Debug.WriteLine(s)
    If the command returns more that one line you will need multiple readlines to get the results.

    Use code tags when you post code.
    sir will i be able to read my sms directly in textbox?

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: how to create a program that receives messages using at commands in vb 2010?

    Start with the code I posted. Do the debug statements show the output? If they do then 's' will contain the responses and since a TextBox.Text is a string you should be able to set the .Text with variable 's'. If you have multiple strings set the MultLine property of the textbox to true and use AppendText.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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