Problem with AT send with GSM modem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • UmDois
    New Member
    • Jan 2007
    • 2

    Problem with AT send with GSM modem

    I have a GSM modem, Wavecom.
    When I connect to it using HyperTerminal, i can send SMS with the standard AT comands, like this:

    AT+CMGS="+351nn nnnnnnn" <CR>
    > text to send in the message <Control-Z>

    and the SMS goes on.

    Note: <CR> means ENTER
    Note: <CR> is ASCII 13, and Control-Z is ASCII 26.

    When I use VisualBasic, the SAME AT sequence does not work.
    And I get an ERROR (twice).

    The manual says to do the following:

    MSComm.Output = "AT+CMGS=" & chr(34) & "+ "+351nnnnnn nnn" & chr(34) & chr(13)

    MsComm.Output = "text to send in the message" & chr(26).

    Note: chr(34) is the character for the commas(").

    What is wrong?

    Many thanks for any help.
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi. You could try this
    Code:
    Const quote As String = """"
    MsComm.Output = "AT+CMGS=" & quote & "+351nnnnnnnnn" & quote & vbCr

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by UmDois
      I have a GSM modem, Wavecom.
      When I connect to it using HyperTerminal, i can send SMS with the standard AT comands, like this:
      AT+CMGS="+351nn nnnnnnn" <CR>
      > text to send in the message <Control-Z>
      and the SMS goes on.
      When I use VisualBasic, the SAME AT sequence does not work.
      And I get an ERROR (twice).
      The manual says to do the following:
      MSComm.Output = "AT+CMGS=" & chr(34) & "+ "+351nnnnnn nnn" & chr(34) & chr(13)
      MsComm.Output = "text to send in the message" & chr(26).
      A couple of questions...
      • Are you certain that it's only a CR which is sent after the AT command?
      • What error are you getting?
      • What does the ">" represent on the second line? (I ask mainly because it is not present in the VB version.)
      • Are you sure you're in command mode? I seem to recall (from more than 10 years ago, I think) that you have to pause for at least a second, then send "+++" then another pause, to go into command mode. But this probably only applies if you are online at the time, right?
      • Is this code copied/pasted, or typed in here? Because
        MSComm.Output = "AT+CMGS=" & chr(34) & "+ "+351nnnnnn nnn" & chr(34) & chr(13)
        seems to have quotes in the wrong places. It probably should have been
        MSComm.Output = "AT+CMGS=" & chr(34) & "+351nnnnnn nnn" & chr(34) & chr(13)

      You can also make the code much more compact and readable by using CONST values as willakawill suggested. (Oops! Didn't realise you'd also fixed the mixed-up quotes, Will.)

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        Yeah. Get with it down there. You're supposed to be 13 hours ahead of me :)

        Comment

        • iburyak
          Recognized Expert Top Contributor
          • Nov 2006
          • 1016

          #5
          It looks like your error is here:


          [PHP]"+ "+351nnnnnn nnn" [/PHP]

          You have "+ twice.

          Comment

          • iburyak
            Recognized Expert Top Contributor
            • Nov 2006
            • 1016

            #6
            Try this:

            MSComm.Output = "AT+CMGS=""+351 nnnnnnnnn""" & chr(13)

            MsComm.Output = "text to send in the message" & chr(26).

            Comment

            • willakawill
              Top Contributor
              • Oct 2006
              • 1646

              #7
              Originally posted by iburyak
              Try this:

              MSComm.Output = "AT+CMGS=""+351 nnnnnnnnn""" & chr(13)

              MsComm.Output = "text to send in the message" & chr(26).
              You are posting the same answer that has already been posted by 2 others

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by willakawill
                Yeah. Get with it down there. You're supposed to be 13 hours ahead of me :)
                Yeah, well it's hard to forecast accurately what someone is going to say in 13 hours. ;)

                Comment

                • sirsnorklingtayo
                  New Member
                  • Jan 2007
                  • 26

                  #9
                  Originally posted by UmDois
                  I have a GSM modem, Wavecom.
                  When I connect to it using HyperTerminal, i can send SMS with the standard AT comands, like this:

                  AT+CMGS="+351nn nnnnnnn" <CR>
                  > text to send in the message <Control-Z>

                  and the SMS goes on.

                  Note: <CR> means ENTER
                  Note: <CR> is ASCII 13, and Control-Z is ASCII 26.

                  When I use VisualBasic, the SAME AT sequence does not work.
                  And I get an ERROR (twice).

                  The manual says to do the following:

                  MSComm.Output = "AT+CMGS=" & chr(34) & "+ "+351nnnnnn nnn" & chr(34) & chr(13)

                  MsComm.Output = "text to send in the message" & chr(26).

                  Note: chr(34) is the character for the commas(").

                  What is wrong?

                  Many thanks for any help.

                  Hi friend,

                  I've been in that kind of situation before and I used VB6 too, I developed a computer program that will keep all the SMS to my database and reply back with some information.

                  Ok here is the answer, before i tried that using chr(13) because this is the equivalent for the new line but unfortunately i dont know why this chr(13) is not working in MSCOM, but the only thing left is the constant value of VBCRLF you can use this as a substitute in chr(13)

                  Inshort

                  chr(13) = VBCRLF

                  and dont forget to send +++ it means that you will set the GSM in Command mode. Some1 already post this one, you better be careful in sending AT Command always keep in mind that before sending another batch of command you need to wait just for a second or 2, just use Sleep function in VB6.

                  Actually, after I solved that problem reagrading GSM and MSCOMM I realized that ANSI C is the much better language to use beacuse it is very easy to communicate with Devices like GSM. I am just telling you this because I experienced that before, but it will work fine in VB6 with MSCOMM


                  Norman

                  Comment

                  • sirsnorklingtayo
                    New Member
                    • Jan 2007
                    • 26

                    #10
                    Originally posted by sirsnorklingtay o
                    Hi friend,

                    I've been in that kind of situation before and I used VB6 too, I developed a computer program that will keep all the SMS to my database and reply back with some information.

                    Ok here is the answer, before i tried that using chr(13) because this is the equivalent for the new line but unfortunately i dont know why this chr(13) is not working in MSCOM, but the only thing left is the constant value of VBCRLF you can use this as a substitute in chr(13)

                    Inshort

                    chr(13) = VBCRLF

                    and dont forget to send +++ it means that you will set the GSM in Command mode. Some1 already post this one, you better be careful in sending AT Command always keep in mind that before sending another batch of command you need to wait just for a second or 2, just use Sleep function in VB6.

                    Actually, after I solved that problem reagrading GSM and MSCOMM I realized that ANSI C is the much better language to use beacuse it is very easy to communicate with Devices like GSM. I am just telling you this because I experienced that before, but it will work fine in VB6 with MSCOMM


                    Norman

                    EXAMPLE:

                    Code:
                    Option Explicit
                    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
                    
                    
                    Private Sub Command1_Click()
                    Dim strSMS As String
                    'set contact number
                    'buffer you message here
                    strSMS = "Hello World!"
                    'Before sending command
                    MSComm1.Output = "+++" & vbCrLf
                    'wait a second
                    Sleep 1
                    'send at commands
                    MSComm1.Output = "AT+CMGS=" & Chr(34) & "+351nnnnnnnnn" & Chr(34) & vbCrLf
                    
                    'There are some GSM modems that after sending "AT+CMGS"
                    'it will response before buffering the message
                    
                    'Ex.
                    ' step 1: MSComm1.Output = "AT+CMGS=" & Chr(34) & "+351nnnnnnnnn" & Chr(34) & vbCrLf
                    ' step 2: MSComm1.Input is equal to OK/ERROR
                    ' step 3: then > insert your message
                    
                    'In this case the GSM is allowing you to check first if the AT command is valid or not
                    'before buffering the message to GSM
                    
                    'I dont know if this is your case but you can check.
                    
                    While 1
                        'wait for 1 second or 2
                        
                        Sleep 1  'this is depend on how fast your GSM communicate with MSCOMM
                        
                        'Always wait this > sign to come out, because this the signal that the GSM is ready
                        'to get the Message
                        
                        'if MSComm1.Input = ">" send your Message to GSM
                        
                        'note: make it sure that no other chr(s) in MSComm1.Input except ">"
                        'The last thing to remember is do not ever try to use the DOEVENTS
                        
                        If StrComp(Left(MSComm1.Input, 1), ">", vbBinaryCompare) = 0 Then
                            MSComm1.Output = strSMS & Chr(26)
                            Sleep 2
                            'Before you do this pls remove the chr(26)
                            If StrComp(Replace(MSComm1.Input, Chr(26), ""), "OK", vbBinaryCompare) = 0 Then
                                'place your flag
                                GoTo ExitWhile
                            ElseIf StrComp(Replace(MSComm1.Input, Chr(26), ""), "ERROR", vbBinaryCompare) = 0 Then
                                'place your flag
                                GoTo ExitWhile
                            Else
                        End If
                    Wend
                    
                    ExitWhile:
                        'do your valdations here etc
                        'Check your falg here if error is true or false
                        Sleep 2
                        
                    
                    End Sub
                    Last edited by willakawill; Jan 31 '07, 12:06 PM. Reason: please use code tags when posting code

                    Comment

                    • sirsnorklingtayo
                      New Member
                      • Jan 2007
                      • 26

                      #11
                      Originally posted by sirsnorklingtay o
                      EXAMPLE:

                      Option Explicit
                      Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


                      Private Sub Command1_Click( )
                      Dim strSMS As String
                      'set contact number
                      'buffer you message here
                      strSMS = "Hello World!"
                      'Before sending command
                      MSComm1.Output = "+++" & vbCrLf
                      'wait a second
                      Sleep 1
                      'send at commands
                      MSComm1.Output = "AT+CMGS=" & Chr(34) & "+351nnnnnn nnn" & Chr(34) & vbCrLf

                      'There are some GSM modems that after sending "AT+CMGS"
                      'it will response before buffering the message

                      'Ex.
                      ' step 1: MSComm1.Output = "AT+CMGS=" & Chr(34) & "+351nnnnnn nnn" & Chr(34) & vbCrLf
                      ' step 2: MSComm1.Input is equal to OK/ERROR
                      ' step 3: then > insert your message

                      'In this case the GSM is allowing you to check first if the AT command is valid or not
                      'before buffering the message to GSM

                      'I dont know if this is your case but you can check.

                      While 1
                      'wait for 1 second or 2

                      Sleep 1 'this is depend on how fast your GSM communicate with MSCOMM

                      'Always wait this > sign to come out, because this the signal that the GSM is ready
                      'to get the Message

                      'if MSComm1.Input = ">" send your Message to GSM

                      'note: make it sure that no other chr(s) in MSComm1.Input except ">"
                      'The last thing to remember is do not ever try to use the DOEVENTS

                      If StrComp(Left(MS Comm1.Input, 1), ">", vbBinaryCompare ) = 0 Then
                      MSComm1.Output = strSMS & Chr(26)
                      Sleep 2
                      'Before you do this pls remove the chr(26)
                      If StrComp(Replace (MSComm1.Input, Chr(26), ""), "OK", vbBinaryCompare ) = 0 Then
                      'place your flag
                      GoTo ExitWhile
                      ElseIf StrComp(Replace (MSComm1.Input, Chr(26), ""), "ERROR", vbBinaryCompare ) = 0 Then
                      'place your flag
                      GoTo ExitWhile
                      Else
                      End If
                      Wend

                      ExitWhile:
                      'do your valdations here etc
                      'Check your falg here if error is true or false
                      Sleep 2


                      End Sub

                      In addition, please always use PDU mode in reading and sending TEXT SMS Messages.

                      MSComm1.Output = "AT+CMGS=0"

                      AT+CMGF: Message Format:
                      Command Possible response(s) +CMGF=[<mode>] +CMGF?+CMGF: <mode> +CMGF=?+CMGF: (list of supported <mode>s)
                      <mode>: 0: PDU mode;
                      <mode>: 1: TEXT mode;


                      check out about PDU encryption/Decryption methods

                      Comment

                      • Killer42
                        Recognized Expert Expert
                        • Oct 2006
                        • 8429

                        #12
                        [QUOTE=sirsnorkl ingtayo]
                        Code:
                        ...
                            'wait for 1 second or 2
                            [B]Sleep[/B] 1
                        ...
                        Is this a routine of your own? I don't think VB6 has a Sleep statement. Mine doesn't, anyway.

                        Comment

                        • sirsnorklingtayo
                          New Member
                          • Jan 2007
                          • 26

                          #13
                          [QUOTE=Killer42]
                          Originally posted by sirsnorklingtay o
                          Code:
                          ...
                              'wait for 1 second or 2
                              [B]Sleep[/B] 1
                          ...
                          Is this a routine of your own? I don't think VB6 has a Sleep statement. Mine doesn't, anyway.
                          Nop, SLEEP is an WIN32 API function it acts like a delay() function in ANSI C

                          Here is the declaration:
                          Code:
                          'You can place this in Form, Module Class etc but indicate the declration scope
                          'like Global,Public,Private
                          
                          Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
                          
                          'to use this
                          
                          Private Sub StopForAWhile(byval milliseconds as Integer)
                          
                            Sleep 1000 ' stop for 1 second
                          
                          end sub
                          and I admit that I made a mistake instead of Sleep 1 it should be Sleep 1000

                          Sleep 1 = 1/1000 second stop
                          Sleep 1000 = 1second stop


                          Sorry for my mistakes

                          hehehe

                          norman
                          Last edited by willakawill; Feb 1 '07, 10:36 PM. Reason: please use code tags

                          Comment

                          • Killer42
                            Recognized Expert Expert
                            • Oct 2006
                            • 8429

                            #14
                            Originally posted by sirsnorklingtay o
                            Nop, SLEEP is an WIN32 API function it acts like a delay() function in ANSI C
                            Ah! Thanks for the reminder. I think I used it, years ago.

                            Comment

                            • willakawill
                              Top Contributor
                              • Oct 2006
                              • 1646

                              #15
                              In the interests of clarity for those scouring these pages for tidbits, perhaps you mean:
                              Code:
                              Private Sub StopForAWhile(byval milliseconds as Integer)
                              
                              Sleep milliseconds ' stop for (milliseconds/1000) seconds
                              
                              end sub
                              This is also a useful way to call sleep:
                              Code:
                              Private Sub WaitSec(ByVal secs as Integer)
                              
                              Sleep secs * 1000 ' stop for secs seconds
                              
                              end sub

                              Comment

                              Working...